app.nit: add default behavior to `TextAsset::load` for unit tests
[nit.git] / lib / gamnit / cameras.nit
index 245d071..401e1ce 100644 (file)
@@ -133,7 +133,7 @@ class EulerCamera
                view = view * rotation_matrix
 
                # Use a projection matrix with a depth
-               var projection = new Matrix.perspective(pi*field_of_view_y/2.0,
+               var projection = new Matrix.perspective(field_of_view_y,
                        display.aspect_ratio, near, far)
 
                return view * projection
@@ -185,7 +185,7 @@ class EulerCamera
                var near_height = (field_of_view_y/2.0).tan * near
                var cross_screen_to_near = near_height / (display.height.to_f/2.0)
                var cross_near_to_target = (position.z - target_z) / near
-               var mod = cross_screen_to_near * cross_near_to_target * 1.72 # FIXME drop the magic number
+               var mod = cross_screen_to_near * cross_near_to_target
 
                var wx = position.x + (x.to_f-display.width.to_f/2.0) * mod
                var wy = position.y - (y.to_f-display.height.to_f/2.0) * mod
@@ -234,22 +234,34 @@ class UICamera
 
                var wx = x.to_f * width / display.width.to_f - position.x
                var wy = y.to_f * height / display.height.to_f - position.y
-               return new Point[Float](wx, wy)
+               return new Point[Float](wx, -wy)
        end
 
        # Center of the screen, from the point of view of the camera, at z = 0
        fun center: Point3d[Float] do return new Point3d[Float](position.x + width / 2.0, position.y - height / 2.0, 0.0)
 
-       # Anchor in the top left corner of the screen, at z = 0
+       # Center of the top of the screen, at z = 0
+       fun top: Point3d[Float] do return new Point3d[Float](position.x + width / 2.0, position.y, 0.0)
+
+       # Center of the bottom of the screen, at z = 0
+       fun bottom: Point3d[Float] do return new Point3d[Float](position.x + width / 2.0, position.y - height, 0.0)
+
+       # Center of the left border of the screen, at z = 0
+       fun left: Point3d[Float] do return new Point3d[Float](position.x, position.y - height / 2.0, 0.0)
+
+       # Center of the right border of the screen, at z = 0
+       fun right: Point3d[Float] do return new Point3d[Float](position.x + width, position.y - height / 2.0, 0.0)
+
+       # Top left corner of the screen, at z = 0
        fun top_left: Point3d[Float] do return new Point3d[Float](position.x, position.y, 0.0)
 
-       # Anchor in the top right corner of the screen, at z = 0
+       # Top right corner of the screen, at z = 0
        fun top_right: Point3d[Float] do return new Point3d[Float](position.x + width, position.y, 0.0)
 
-       # Anchor in the bottom left corner of the screen, at z = 0
+       # Bottom left corner of the screen, at z = 0
        fun bottom_left: Point3d[Float] do return new Point3d[Float](position.x, position.y - height, 0.0)
 
-       # Anchor in the bottom right corner of the screen, at z = 0
+       # Bottom right corner of the screen, at z = 0
        fun bottom_right: Point3d[Float] do return new Point3d[Float](position.x + width, position.y - height, 0.0)
 
        # TODO cache the anchors and the matrix