From 21a20b29bb772fe65ea860ef26a544e9a6c5f15d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 13 Dec 2015 12:25:00 -0500 Subject: [PATCH] lib/gamnit: intro `EulerCamera::reset_to_fit` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/gamnit/cameras.nit | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/gamnit/cameras.nit b/lib/gamnit/cameras.nit index 43aae77..2dfc706 100644 --- a/lib/gamnit/cameras.nit +++ b/lib/gamnit/cameras.nit @@ -38,7 +38,7 @@ abstract class Camera fun mvp_matrix: Matrix is abstract end -# Simple camera with perspective oriented with Euler angles (`pitch`, `yaw`, `roll`) +# Simple camera with perspective oriented with Euler angles (`pitch, yaw, roll`) class EulerCamera super Camera @@ -63,8 +63,8 @@ class EulerCamera # Clipping wall the farthest of the camera, in world dimensions # - # Default at `100.0` but this one should be adapted to each context. - var far = 100.0 is writable + # Default at `10000.0` but this one should be adapted to each context. + var far = 10000.0 is writable # Look around sensitivity, used by `turn` var sensitivity = 0.005 is writable @@ -127,6 +127,30 @@ class EulerCamera return view * projection end + + # Reset the camera position so that `height` world units are visible on the y axis at z=0 + # + # By default, `height` is set to `display.height`. + # + # After the reset, the camera sits on the Z axis and rotation values are reset to 0. + # The X axis is horizontal on the screen and the Y axis is vertical. + # Higher values on the Z axis are closer to the camera. + fun reset_height(height: nullable Float) + do + if height == null then height = display.height.to_f + + var opp = height / 2.0 + var angle = field_of_view_y / 2.0 + var adj = opp / angle.tan + + position.x = 0.0 + position.y = 0.0 + position.z = adj + + pitch = 0.0 + yaw = 0.0 + roll = 0.0 + end end # Orthogonal camera to draw UI objects with services to work with screens of different sizes -- 1.7.9.5