diff options
author | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-05-30 15:04:26 +0400 |
---|---|---|
committer | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-05-30 15:04:26 +0400 |
commit | b97c77df2bafd7add01ea9dc8bfcad1e82714559 (patch) | |
tree | db7ba1f4290677e22effe5511ecaa3185cc68ab9 /source/gameengine/Ketsji/KX_Camera.cpp | |
parent | 62c333a5629bc5e264fd2740b032cc6ac28311dc (diff) |
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.
Diffstat (limited to 'source/gameengine/Ketsji/KX_Camera.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_Camera.cpp | 11 |
1 files 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; } |