{
// setting a name would be nice...
m_name = "cam";
+ m_projection_matrix.setIdentity();
+ m_modelview_matrix.setIdentity();
SetProperty("camera",new CIntValue(1));
}
/**
* 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;
}
/**
* 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;
}
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();
);
/* 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.*/
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],