lib/gamnit: intro `EulerCamera::look_at`
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 11 Jan 2016 14:11:18 +0000 (09:11 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Sun, 17 Jan 2016 22:50:28 +0000 (17:50 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/gamnit/cameras.nit

index 2dfc706..df29341 100644 (file)
@@ -98,6 +98,17 @@ class EulerCamera
                position.y += dy
        end
 
+       # Aim the camera at `x, y, z`
+       fun look_at(x, y, z: Float)
+       do
+               var dx = position.x
+               var dy = position.y
+               var dz = position.z
+
+               yaw = atan2(dx, dz)
+               pitch = atan2(-dy, dz)
+       end
+
        # Rotation matrix produced by the current rotation of the camera
        protected fun rotation_matrix: Matrix
        do