]> git.localhorst.tv Git - blank.git/blobdiff - src/app.cpp
basic aiming
[blank.git] / src / app.cpp
index 8c957a78a815f348fb423f86c8840e6c35deea7f..70c45d478c7284ffdf42866ed6900049c082771d 100644 (file)
@@ -1,5 +1,7 @@
 #include "app.hpp"
 
+#include "geometry.hpp"
+
 #include <iostream>
 #include <stdexcept>
 
@@ -17,12 +19,12 @@ Application::Application()
 , move_velocity(0.003f)
 , pitch_sensitivity(-0.0025f)
 , yaw_sensitivity(-0.001f)
-, testBlockType(true)
+, blockType()
 , cam()
 , chunk()
 , light_position(17.0f, 17.0f, 17.0f)
 , light_color(1.0f, 1.0f, 1.0f)
-, light_power(100.0f)
+, light_power(250.0f)
 , m_handle(0)
 , v_handle(0)
 , mv_handle(0)
@@ -107,12 +109,27 @@ Application::Application()
 
        cam.Position(glm::vec3(0, 4, 4));
 
-       chunk.BlockAt(glm::vec3(0, 0, 0)) = Block(&testBlockType);
-       chunk.BlockAt(glm::vec3(1, 0, 0)) = Block(&testBlockType);
-       chunk.BlockAt(glm::vec3(1, 1, 0)) = Block(&testBlockType);
-       chunk.BlockAt(glm::vec3(1, 1, 1)) = Block(&testBlockType);
-       chunk.BlockAt(glm::vec3(2, 1, 1)) = Block(&testBlockType);
-       chunk.BlockAt(glm::vec3(2, 2, 1)) = Block(&testBlockType);
+       blockType.Add(BlockType(true, glm::vec3(1, 1, 1)));
+       blockType.Add(BlockType(true, glm::vec3(1, 0, 0)));
+       blockType.Add(BlockType(true, glm::vec3(0, 1, 0)));
+       blockType.Add(BlockType(true, glm::vec3(0, 0, 1)));
+
+       chunk.BlockAt(glm::vec3(0, 0, 0)) = Block(blockType[4]);
+       chunk.BlockAt(glm::vec3(0, 0, 1)) = Block(blockType[1]);
+       chunk.BlockAt(glm::vec3(1, 0, 0)) = Block(blockType[2]);
+       chunk.BlockAt(glm::vec3(1, 0, 1)) = Block(blockType[3]);
+       chunk.BlockAt(glm::vec3(2, 0, 0)) = Block(blockType[4]);
+       chunk.BlockAt(glm::vec3(2, 0, 1)) = Block(blockType[1]);
+       chunk.BlockAt(glm::vec3(3, 0, 0)) = Block(blockType[2]);
+       chunk.BlockAt(glm::vec3(3, 0, 1)) = Block(blockType[3]);
+       chunk.BlockAt(glm::vec3(2, 0, 2)) = Block(blockType[4]);
+       chunk.BlockAt(glm::vec3(2, 0, 3)) = Block(blockType[1]);
+       chunk.BlockAt(glm::vec3(3, 0, 2)) = Block(blockType[2]);
+       chunk.BlockAt(glm::vec3(3, 0, 3)) = Block(blockType[3]);
+       chunk.BlockAt(glm::vec3(1, 1, 0)) = Block(blockType[1]);
+       chunk.BlockAt(glm::vec3(1, 1, 1)) = Block(blockType[4]);
+       chunk.BlockAt(glm::vec3(2, 1, 1)) = Block(blockType[3]);
+       chunk.BlockAt(glm::vec3(2, 2, 1)) = Block(blockType[2]);
        chunk.Invalidate();
 
        m_handle = program.UniformLocation("M");
@@ -219,6 +236,17 @@ void Application::Update(int dt) {
        cam.OrientationVelocity(vel);
 
        cam.Update(dt);
+
+       Ray aim = cam.Aim();
+       int blkid;
+       float dist;
+       if (chunk.Intersection(aim, glm::mat4(1.0f), &blkid, &dist)) {
+               glm::vec3 pos = Chunk::ToCoords(blkid);
+               std::cout << "pointing at: <" << pos.x << ", " << pos.y << ", " << pos.z << ">, "
+                       "distance: " << dist << std::endl;
+       } else {
+               std::cout << "pointing at: nothing" << std::endl;
+       }
 }
 
 void Application::Render() {