]> git.localhorst.tv Git - tacos.git/blobdiff - src/tacos.cpp
ray/floor intersection experiments
[tacos.git] / src / tacos.cpp
index e477ab4a97e00a17da46bcbd151cea7eb0608480..fe1c7aa68c73bc1b5b5f3d39e39677c93b59d537 100644 (file)
@@ -218,7 +218,7 @@ int main(int argc, char *argv[]) {
                VP = viewport.Perspective() * V;
                { // mouse
                        inverse_VP = glm::inverse(VP);
-                       glm::vec2 clip_mouse((screen_mouse / glm::vec2(viewport.Width(), viewport.Height()) - 0.5f) * 2.0f);
+                       glm::vec2 clip_mouse((screen_mouse * viewport.InverseSize() - 0.5f) * 2.0f);
                        // viewport space has origin in lower left, but sdl gives coordinates with orgin in upper left,
                        // so Y is inverted here (since it maps from -1 to 1 simply by negating)
                        glm::vec4 ray_begin(inverse_VP * glm::vec4(clip_mouse.x, -clip_mouse.y, -1.0f, 1.0f));
@@ -227,10 +227,13 @@ int main(int argc, char *argv[]) {
                        world_mouse.direction = glm::normalize((glm::vec3(ray_end) / ray_end.w) - world_mouse.origin);
                }
 
+               //std::cout << "ray " << world_mouse.origin << ", " << world_mouse.direction << std::endl;
                if (floor.Intersection(world_mouse, pointer)) {
                        cursor.FloorTile(floor, int(pointer.x), int(pointer.z));
+                       //std::cout << "        +++ intersecting at " << pointer << std::endl;
                } else {
                        cursor.Hide();
+                       //std::cout << "        --- not intersecting" << std::endl;
                }
 
                // render