From 0d585cac23773f5fe6d3476de8d9a256fae4608f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Mon, 11 Jan 2016 09:11:18 -0500 Subject: [PATCH] lib/gamnit: intro `EulerCamera::look_at` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/gamnit/cameras.nit | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/gamnit/cameras.nit b/lib/gamnit/cameras.nit index 2dfc706..df29341 100644 --- a/lib/gamnit/cameras.nit +++ b/lib/gamnit/cameras.nit @@ -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 -- 1.7.9.5