]> git.tdb.fi Git - libs/gl.git/blobdiff - source/camera.cpp
Refresh lighting and culling uniforms if the camera changes in pop_state
[libs/gl.git] / source / camera.cpp
index d119e1eff1b67245b9fca74c4058b5d5077af8e3..ae35f632438df2d9a7a8a416f838deabde6b8320 100644 (file)
@@ -56,6 +56,12 @@ void Camera::set_frustum_axis(float x, float y)
        update_projection_matrix();
 }
 
+void Camera::set_frustum_rotation(const Geometry::Angle<float> &r)
+{
+       rotate = r;
+       update_projection_matrix();
+}
+
 void Camera::set_position(const Vector3 &p)
 {
        position = p;
@@ -93,10 +99,15 @@ Vector3 Camera::project(const Vector3 &p) const
 Vector4 Camera::unproject(const Vector4 &p) const
 {
        Vector4 r = invert(proj_matrix)*Vector4(p.x, p.y, p.z, 1.0f);
-       r = object_matrix*Vector4(r.x, r.y, r.z, p.w);
+       r = object_matrix*Vector4(r.x/r.w, r.y/r.w, r.z/r.w, p.w);
        return r;
 }
 
+Vector3 Camera::unproject(const Vector3 &p) const
+{
+       return unproject(Vector4(p.x, p.y, p.z, 1.0f)).slice<3>(0);
+}
+
 void Camera::apply() const
 {
        MatrixStack::projection() = proj_matrix;
@@ -115,6 +126,7 @@ void Camera::update_projection_matrix()
                proj_matrix = Matrix::frustum(left, right, bottom, top, clip_near, clip_far);
        else
                proj_matrix = Matrix::ortho(left, right, bottom, top, clip_near, clip_far);
+       proj_matrix = Matrix::rotation(rotate, Vector3(0, 0, 1))*proj_matrix;
 }
 
 void Camera::update_object_matrix()