Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>2004-07-20 16:07:06 +0400
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>2004-07-20 16:07:06 +0400
commitb6e0899607aa1b55da590bfb233e7c186a0bc6c3 (patch)
tree9d91b5a9126ffa2a0b4b7aa4a82d296241f3fe74 /source/gameengine
parent7b3b3ae432f692ed32f57aa70bdab5b89a05be21 (diff)
Added support for cameras in Blender's Ortho mode.
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/Ketsji/KX_Camera.cpp31
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.cpp32
-rw-r--r--source/gameengine/PyDoc/KX_Camera.py9
3 files changed, 42 insertions, 30 deletions
diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp
index d32ea269d3a..0b12ddfe0d1 100644
--- a/source/gameengine/Ketsji/KX_Camera.cpp
+++ b/source/gameengine/Ketsji/KX_Camera.cpp
@@ -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))
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
index 91e81f77904..73a826c3d0d 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
@@ -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);
}
diff --git a/source/gameengine/PyDoc/KX_Camera.py b/source/gameengine/PyDoc/KX_Camera.py
index 939da3da591..4cadf1c0ed0 100644
--- a/source/gameengine/PyDoc/KX_Camera.py
+++ b/source/gameengine/PyDoc/KX_Camera.py
@@ -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.