From b97c77df2bafd7add01ea9dc8bfcad1e82714559 Mon Sep 17 00:00:00 2001 From: Kester Maddock Date: Sun, 30 May 2004 11:04:26 +0000 Subject: Check for zero normal vectors in the clip planes (if eg Python has set a strange projection matrix) Fix the transformation of the frustum bound sphere to world coordinates. --- source/gameengine/Ketsji/KX_Camera.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index ffab2c946a9..4ed7b1e62d0 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -232,7 +232,11 @@ void KX_Camera::NormaliseClipPlanes() return; for (unsigned int p = 0; p < 6; p++) - m_planes[p] /= sqrt(m_planes[p][0]*m_planes[p][0] + m_planes[p][1]*m_planes[p][1] + m_planes[p][2]*m_planes[p][2]); + { + MT_Scalar factor = sqrt(m_planes[p][0]*m_planes[p][0] + m_planes[p][1]*m_planes[p][1] + m_planes[p][2]*m_planes[p][2]); + if (!MT_fuzzyZero(factor)) + m_planes[p] /= factor; + } m_normalised = true; } @@ -257,11 +261,12 @@ void KX_Camera::ExtractFrustumSphere() // Compute centre m_frustum_centre = MT_Point3(0., 0., - -(nearpoint.dot(nearpoint) - farpoint.dot(farpoint))/(2.0*(m_camdata.m_clipend - m_camdata.m_clipstart))); + (nearpoint.dot(nearpoint) - farpoint.dot(farpoint))/(2.0*(m_camdata.m_clipend - m_camdata.m_clipstart))); m_frustum_radius = m_frustum_centre.distance(farpoint); // Transform to world space. - m_frustum_centre = GetWorldToCamera()(m_frustum_centre); + m_frustum_centre = GetCameraToWorld()(m_frustum_centre); + m_frustum_radius /= fabs(NodeGetWorldScaling()[NodeGetWorldScaling().closestAxis()]); m_set_frustum_centre = true; } -- cgit v1.2.3