Fix MouseFocus Sensor objects for dynamic cameras. (Bug 1165)
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Mon, 26 Apr 2004 07:19:18 +0000 (07:19 +0000)
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Mon, 26 Apr 2004 07:19:18 +0000 (07:19 +0000)
source/gameengine/Ketsji/KX_Camera.cpp
source/gameengine/Ketsji/KX_Camera.h
source/gameengine/Ketsji/KX_MouseFocusSensor.cpp

index c99e4824851d316e35e27e9825a6713a2ced092b..cc970d90339def93da95aeb9b5611a87d6470476 100644 (file)
@@ -46,6 +46,8 @@ KX_Camera::KX_Camera(void* sgReplicationInfo,
 {
        // setting a name would be nice...
        m_name = "cam";
+       m_projection_matrix.setIdentity();
+       m_modelview_matrix.setIdentity();
        SetProperty("camera",new CIntValue(1));
 }
 
@@ -138,9 +140,9 @@ void KX_Camera::SetModelviewMatrix(const MT_Matrix4x4 & mat)
 /**
 * Gets the projection matrix that is used by the rasterizer.
 */
-void KX_Camera::GetProjectionMatrix(MT_Matrix4x4 & mat)
+const MT_Matrix4x4& KX_Camera::GetProjectionMatrix()
 {
-       mat = m_projection_matrix;
+       return m_projection_matrix;
 }
 
 
@@ -148,9 +150,9 @@ void KX_Camera::GetProjectionMatrix(MT_Matrix4x4 & mat)
 /**
 * Gets the modelview matrix that is used by the rasterizer.
 */
-void KX_Camera::GetModelviewMatrix(MT_Matrix4x4 & mat)
+const MT_Matrix4x4& KX_Camera::GetModelviewMatrix()
 {
-       mat = m_modelview_matrix;
+       return m_modelview_matrix;
 }
 
 
index 25a3b891e01ca01043ffdbf4724eea93208c9b0f..0185a0ba9d5ec6d1ef876f4d8ba02d4219e03b5e 100644 (file)
@@ -96,10 +96,12 @@ public:
        void                            SetModelviewMatrix(const MT_Matrix4x4 & mat);
                
        /** Gets the projection matrix that is used by the rasterizer. */
-       void                            GetProjectionMatrix(MT_Matrix4x4 & mat);
+       const MT_Matrix4x4&             GetProjectionMatrix();
        
-       /** Gets the modelview matrix that is used by the rasterizer. */
-       void                            GetModelviewMatrix(MT_Matrix4x4 & mat);
+       /** Gets the modelview matrix that is used by the rasterizer. 
+        *  @warning If the Camera is a dynamic object then this method may return garbage.  Use GetCameraToWorld() instead.
+        */
+       const MT_Matrix4x4&             GetModelviewMatrix();
 
        /** Gets the focal lenght. */
        float                           GetLens();
index 6f6f86bd7820d47ac3ad0da58fcdc633abb2e1d9..3d6264674bc330520f6bba4955372c483dbd69e2 100644 (file)
@@ -208,14 +208,11 @@ bool KX_MouseFocusSensor::ParentObjectHasFocus(void)
        );
 
        /* camera to world  */
-       MT_Matrix4x4 camcs_wcs_matrix;
-       cam->GetModelviewMatrix(camcs_wcs_matrix);
-       camcs_wcs_matrix.invert();
+       MT_Matrix4x4 camcs_wcs_matrix = MT_Matrix4x4(cam->GetCameraToWorld());
 
-       MT_Matrix4x4 clip_camcs_matrix;
        /* badly defined, the first time round.... I wonder why... I might
         * want to guard against floating point errors here.*/
-       cam->GetProjectionMatrix(clip_camcs_matrix);
+       MT_Matrix4x4 clip_camcs_matrix = MT_Matrix4x4(cam->GetProjectionMatrix());
        clip_camcs_matrix.invert();
 
        /* shoot-points: clip to cam to wcs . win to clip was already done.*/
@@ -223,7 +220,7 @@ bool KX_MouseFocusSensor::ParentObjectHasFocus(void)
        topoint   = clip_camcs_matrix * topoint;
        frompoint = camcs_wcs_matrix * frompoint;
        topoint   = camcs_wcs_matrix * topoint;
-
+       
        /* from hom wcs to 3d wcs: */
        MT_Point3 frompoint3 = MT_Point3(frompoint[0]/frompoint[3], 
                                                                         frompoint[1]/frompoint[3],