summaryrefslogtreecommitdiff
path: root/src/world.cpp
diff options
context:
space:
mode:
authortylermurphy534 <tylermurphy534@gmail.com>2022-10-03 06:50:49 -0400
committertylermurphy534 <tylermurphy534@gmail.com>2022-10-03 06:50:49 -0400
commit1701aa5a616f3de55b0a426f8d9e679f2c98a0c6 (patch)
tree87a6c13fb8b7884046f9fdf8c0b7dcaaf6952f28 /src/world.cpp
parentmove chunk loading into world class (diff)
downloadminecraftvulkan-1701aa5a616f3de55b0a426f8d9e679f2c98a0c6.tar.gz
minecraftvulkan-1701aa5a616f3de55b0a426f8d9e679f2c98a0c6.tar.bz2
minecraftvulkan-1701aa5a616f3de55b0a426f8d9e679f2c98a0c6.zip
mouse pickingHEADmain
Diffstat (limited to 'src/world.cpp')
-rw-r--r--src/world.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/world.cpp b/src/world.cpp
index 485615d..d11e4bc 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -6,7 +6,7 @@ World::World(xe::GameObject& viewer, int renderDistance, int worldSeed)
: viewer{viewer},
renderDistance{renderDistance},
worldSeed{worldSeed},
- chunkRenderer{Chunk::getTextures()} {
+ skinnedRenderer{Chunk::getTextures()} {
reloadChunks(renderDistance);
}
@@ -92,7 +92,26 @@ void World::updateChunkMeshs() {
void World::render(xe::Camera& camera) {
camera.setViewYXZ(viewer.transform.translation, viewer.transform.rotation);
- chunkRenderer.render(loadedChunks, camera);
+ // World::Ray ray = raycast(7, 100);
+ skinnedRenderer.render(loadedChunks, camera);
+}
+
+World::Ray World::raycast(float distance, int steps) {
+
+ glm::vec3 position = glm::vec3(viewer.transform.translation);
+
+ float pitch = viewer.transform.rotation.x;
+ float yaw = viewer.transform.rotation.y;
+ float clamp = 1-fabs(sin(-pitch));
+ const glm::vec3 step = glm::normalize(glm::vec3(sin(yaw)*clamp, sin(-pitch), cos(yaw)*clamp)) * (distance/steps);
+
+ for(int i = 0; i < steps; i++) {
+ position += step;
+ int hit = Chunk::getGlobalBlock(position.x, position.y, position.z);
+ if(hit == AIR) continue;
+ return World::Ray{position, hit};
+ }
+ return World::Ray{position, INVALID};
}
} \ No newline at end of file