- View(bool fill = false) :
- m_modelview(g_matrix4_identity),
- m_projection(g_matrix4_identity),
- m_scissor(g_matrix4_identity),
- m_fill(fill)
- {
- }
- void Construct(const Matrix4& projection, const Matrix4& modelview, std::size_t width, std::size_t height)
- {
- // modelview
- m_modelview = modelview;
-
- // projection
- m_projection = projection;
-
- // viewport
- m_viewport = g_matrix4_identity;
- m_viewport[0] = float(width/2);
- m_viewport[5] = float(height/2);
- if(fabs(m_projection[11]) > 0.0000001)
- m_viewport[10] = m_projection[0] * m_viewport[0];
- else
- m_viewport[10] = 1 / m_projection[10];
-
- construct();
- }
- void EnableScissor(float min_x, float max_x, float min_y, float max_y)
- {
- m_scissor = g_matrix4_identity;
- m_scissor[0] = static_cast<float>((max_x - min_x) * 0.5);
- m_scissor[5] = static_cast<float>((max_y - min_y) * 0.5);
- m_scissor[12] = static_cast<float>((min_x + max_x) * 0.5);
- m_scissor[13] = static_cast<float>((min_y + max_y) * 0.5);
- matrix4_full_invert(m_scissor);
-
- construct();
- }
- void DisableScissor()
- {
- m_scissor = g_matrix4_identity;
-
- construct();
- }
-
- bool TestPoint(const Vector3& point) const
- {
- return viewproj_test_point(m_viewproj, point);
- }
- bool TestLine(const Segment& segment) const
- {
- return frustum_test_line(m_frustum, segment);
- }
- bool TestPlane(const Plane3& plane) const
- {
- debug_count_plane();
- return viewer_test_plane(m_viewer, plane);
- }
- bool TestPlane(const Plane3& plane, const Matrix4& localToWorld) const
- {
- debug_count_oriented_plane();
- return viewer_test_transformed_plane(m_viewer, plane, localToWorld);
- }
- VolumeIntersectionValue TestAABB(const AABB& aabb) const
- {
- debug_count_bbox();
- return frustum_test_aabb(m_frustum, aabb);
- }
- VolumeIntersectionValue TestAABB(const AABB& aabb, const Matrix4& localToWorld) const
- {
- debug_count_oriented_bbox();
- return frustum_intersects_transformed_aabb(m_frustum, aabb, localToWorld);
- }
-
- const Matrix4& GetViewMatrix() const
- {
- return m_viewproj;
- }
- const Matrix4& GetViewport() const
- {
- return m_viewport;
- };
- const Matrix4& GetModelview() const
- {
- return m_modelview;
- }
- const Matrix4& GetProjection() const
- {
- return m_projection;
- }
-
- bool fill() const
- {
- return m_fill;
- }
- const Vector3& getViewer() const
- {
- return vector4_to_vector3(m_viewer);
- }
+ View(bool fill = false) :
+ m_modelview(g_matrix4_identity),
+ m_projection(g_matrix4_identity),
+ m_scissor(g_matrix4_identity),
+ m_fill(fill)
+ {
+ }
+
+ void Construct(const Matrix4 &projection, const Matrix4 &modelview, std::size_t width, std::size_t height)
+ {
+ // modelview
+ m_modelview = modelview;
+
+ // projection
+ m_projection = projection;
+
+ // viewport
+ m_viewport = g_matrix4_identity;
+ m_viewport[0] = float(width / 2);
+ m_viewport[5] = float(height / 2);
+ if (fabs(m_projection[11]) > 0.0000001) {
+ m_viewport[10] = m_projection[0] * m_viewport[0];
+ } else {
+ m_viewport[10] = 1 / m_projection[10];
+ }
+
+ construct();
+ }
+
+ void EnableScissor(float min_x, float max_x, float min_y, float max_y)
+ {
+ m_scissor = g_matrix4_identity;
+ m_scissor[0] = static_cast<float>((max_x - min_x) * 0.5 );
+ m_scissor[5] = static_cast<float>((max_y - min_y) * 0.5 );
+ m_scissor[12] = static_cast<float>((min_x + max_x) * 0.5 );
+ m_scissor[13] = static_cast<float>((min_y + max_y) * 0.5 );
+ matrix4_full_invert(m_scissor);
+
+ construct();
+ }
+
+ void DisableScissor()
+ {
+ m_scissor = g_matrix4_identity;
+
+ construct();
+ }
+
+ bool TestPoint(const Vector3 &point) const
+ {
+ return viewproj_test_point(m_viewproj, point);
+ }
+
+ bool TestLine(const Segment &segment) const
+ {
+ return frustum_test_line(m_frustum, segment);
+ }
+
+ bool TestPlane(const Plane3 &plane) const
+ {
+ debug_count_plane();
+ return viewer_test_plane(m_viewer, plane);
+ }
+
+ bool TestPlane(const Plane3 &plane, const Matrix4 &localToWorld) const
+ {
+ debug_count_oriented_plane();
+ return viewer_test_transformed_plane(m_viewer, plane, localToWorld);
+ }
+
+ VolumeIntersectionValue TestAABB(const AABB &aabb) const
+ {
+ debug_count_bbox();
+ return frustum_test_aabb(m_frustum, aabb);
+ }
+
+ VolumeIntersectionValue TestAABB(const AABB &aabb, const Matrix4 &localToWorld) const
+ {
+ debug_count_oriented_bbox();
+ return frustum_intersects_transformed_aabb(m_frustum, aabb, localToWorld);
+ }
+
+ const Matrix4 &GetViewMatrix() const
+ {
+ return m_viewproj;
+ }
+
+ const Matrix4 &GetViewport() const
+ {
+ return m_viewport;
+ };
+
+ const Matrix4 &GetModelview() const
+ {
+ return m_modelview;
+ }
+
+ const Matrix4 &GetProjection() const
+ {
+ return m_projection;
+ }
+
+ bool fill() const
+ {
+ return m_fill;
+ }
+
+ const Vector3 &getViewer() const
+ {
+ return vector4_to_vector3(m_viewer);
+ }