Added support for cameras in Blender's Ortho mode.
This commit is contained in:
@@ -49,7 +49,7 @@ KX_Camera::KX_Camera(void* sgReplicationInfo,
|
||||
m_camdata(camdata),
|
||||
m_dirty(true),
|
||||
m_normalised(false),
|
||||
m_frustum_culling(frustum_culling),
|
||||
m_frustum_culling(frustum_culling && camdata.m_perspective),
|
||||
m_set_projection_matrix(false),
|
||||
m_set_frustum_centre(false)
|
||||
{
|
||||
@@ -70,12 +70,7 @@ KX_Camera::~KX_Camera()
|
||||
MT_Transform KX_Camera::GetWorldToCamera() const
|
||||
{
|
||||
MT_Transform camtrans;
|
||||
MT_Transform trans;
|
||||
|
||||
trans.setBasis(NodeGetWorldOrientation());
|
||||
trans.setOrigin(NodeGetWorldPosition());
|
||||
|
||||
camtrans.invert(trans);
|
||||
camtrans.invert(MT_Transform(NodeGetWorldPosition(), NodeGetWorldOrientation()));
|
||||
|
||||
return camtrans;
|
||||
}
|
||||
@@ -84,11 +79,7 @@ MT_Transform KX_Camera::GetWorldToCamera() const
|
||||
|
||||
MT_Transform KX_Camera::GetCameraToWorld() const
|
||||
{
|
||||
MT_Transform trans;
|
||||
trans.setBasis(NodeGetWorldOrientation());
|
||||
trans.setOrigin(NodeGetWorldPosition());
|
||||
|
||||
return trans;
|
||||
return MT_Transform(NodeGetWorldPosition(), NodeGetWorldOrientation());
|
||||
}
|
||||
|
||||
|
||||
@@ -116,11 +107,7 @@ const MT_Point3 KX_Camera::GetCameraLocation() const
|
||||
/* I want the camera orientation as well. */
|
||||
const MT_Quaternion KX_Camera::GetCameraOrientation() const
|
||||
{
|
||||
MT_Transform trans;
|
||||
trans.setBasis(NodeGetWorldOrientation());
|
||||
trans.setOrigin(NodeGetWorldPosition());
|
||||
|
||||
return trans.getRotation();
|
||||
return NodeGetWorldOrientation().getRotation();
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +195,7 @@ void KX_Camera::ExtractClipPlanes()
|
||||
if (!m_dirty)
|
||||
return;
|
||||
|
||||
MT_Matrix4x4 m = m_projection_matrix * GetWorldToCamera();
|
||||
MT_Matrix4x4 m = m_projection_matrix * m_modelview_matrix;
|
||||
// Left clip plane
|
||||
m_planes[0] = m[3] + m[0];
|
||||
// Right clip plane
|
||||
@@ -434,6 +421,8 @@ PyObject* KX_Camera::_getattr(const STR_String& attr)
|
||||
return PyFloat_FromDouble(GetCameraFar()); /* new ref */
|
||||
if (attr == "frustum_culling")
|
||||
return PyInt_FromLong(m_frustum_culling); /* new ref */
|
||||
if (attr == "perspective")
|
||||
return PyInt_FromLong(m_camdata.m_perspective); /* new ref */
|
||||
if (attr == "projection_matrix")
|
||||
return PyObjectFrom(GetProjectionMatrix()); /* new ref */
|
||||
if (attr == "modelview_matrix")
|
||||
@@ -455,6 +444,12 @@ int KX_Camera::_setattr(const STR_String &attr, PyObject *pyvalue)
|
||||
m_frustum_culling = PyInt_AsLong(pyvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (attr == "perspective")
|
||||
{
|
||||
m_camdata.m_perspective = PyInt_AsLong(pyvalue);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (PyFloat_Check(pyvalue))
|
||||
|
||||
@@ -736,6 +736,7 @@ void KX_KetsjiEngine::SetupRenderFrame(KX_Scene *scene)
|
||||
void KX_KetsjiEngine::RenderFrame(KX_Scene* scene)
|
||||
{
|
||||
float left, right, bottom, top, nearfrust, farfrust;
|
||||
const float ortho = 100.0;
|
||||
KX_Camera* cam = scene->GetActiveCamera();
|
||||
|
||||
if (!cam)
|
||||
@@ -752,14 +753,24 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene)
|
||||
} else
|
||||
{
|
||||
RAS_FrameFrustum frustum;
|
||||
float lens = cam->GetLens();
|
||||
nearfrust = cam->GetCameraNear();
|
||||
farfrust = cam->GetCameraFar();
|
||||
|
||||
if (!cam->GetCameraData()->m_perspective)
|
||||
{
|
||||
lens *= ortho;
|
||||
nearfrust = (nearfrust + 1.0)*ortho;
|
||||
farfrust *= ortho;
|
||||
}
|
||||
|
||||
RAS_FramingManager::ComputeFrustum(
|
||||
scene->GetFramingType(),
|
||||
m_canvas->GetDisplayArea(),
|
||||
scene->GetSceneViewport(),
|
||||
cam->GetLens(),
|
||||
cam->GetCameraNear(),
|
||||
cam->GetCameraFar(),
|
||||
lens,
|
||||
nearfrust,
|
||||
farfrust,
|
||||
frustum
|
||||
);
|
||||
|
||||
@@ -773,17 +784,14 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene)
|
||||
MT_Matrix4x4 projmat = m_rasterizer->GetFrustumMatrix(
|
||||
left, right, bottom, top, nearfrust, farfrust);
|
||||
|
||||
m_rasterizer->SetProjectionMatrix(projmat);
|
||||
cam->SetProjectionMatrix(projmat);
|
||||
}
|
||||
|
||||
MT_Scalar cammat[16];
|
||||
cam->GetWorldToCamera().getValue(cammat);
|
||||
MT_Matrix4x4 viewmat;
|
||||
viewmat.setValue(cammat); // this _should transpose ...
|
||||
// if finally transposed take care of correct usage
|
||||
// in RAS_OpenGLRasterizer ! (row major vs column major)
|
||||
|
||||
MT_Transform camtrans(cam->GetWorldToCamera());
|
||||
if (!cam->GetCameraData()->m_perspective)
|
||||
camtrans.getOrigin()[2] *= ortho;
|
||||
MT_Matrix4x4 viewmat(camtrans);
|
||||
|
||||
m_rasterizer->SetViewMatrix(viewmat, cam->NodeGetWorldPosition(),
|
||||
cam->GetCameraLocation(), cam->GetCameraOrientation());
|
||||
cam->SetModelviewMatrix(viewmat);
|
||||
@@ -796,7 +804,7 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene)
|
||||
// runs through the individual objects.
|
||||
scene->CalculateVisibleMeshes(m_rasterizer);
|
||||
|
||||
scene->RenderBuckets(cam->GetWorldToCamera(), m_rasterizer, m_rendertools);
|
||||
scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,15 @@ class KX_Camera(KX_GameObject):
|
||||
@type near: float
|
||||
@ivar far: The camera's far clip distance.
|
||||
@type far: float
|
||||
@ivar perspective: True if this camera has a perspective transform.
|
||||
|
||||
If perspective is False, this camera has an orthographic transform.
|
||||
|
||||
Note that the orthographic transform is faked by multiplying the lens attribute
|
||||
by 100.0 and translating the camera 100.0 along the z axis.
|
||||
|
||||
This is the same as Blender. If you want a true orthographic transform, see L{setProjectionMatrix}.
|
||||
@type perspective: boolean
|
||||
@ivar frustum_culling: True if this camera is frustum culling.
|
||||
@type frustum_culling: boolean
|
||||
@ivar projection_matrix: This camera's 4x4 projection matrix.
|
||||
|
||||
Reference in New Issue
Block a user