Skip to content

Commit

Permalink
UPBGE: Send RAS_CameraData for override camera settings in KX_KetsjiE…
Browse files Browse the repository at this point in the history
…ngine.

Previously all the settins were set by different setters and after packed to a
RAS_CameraData. This behaviour is simplified by packing the datas in the
RAS_CameraData before send it to the ketsji engine. The engine store it under
m_overrideCamData.
  • Loading branch information
panzergame committed Jan 18, 2017
1 parent 09f88ce commit 783d801
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 68 deletions.
61 changes: 12 additions & 49 deletions source/gameengine/Ketsji/KX_KetsjiEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem *system)
m_exitstring(""),
m_cameraZoom(1.0f),
m_overrideCam(false),
m_overrideCamUseOrtho(false),
m_overrideCamNear(0.0f),
m_overrideCamFar(0.0f),
m_overrideCamZoom(1.0f),
m_stereo(false),
m_curreye(0),
Expand Down Expand Up @@ -727,47 +724,26 @@ const std::string& KX_KetsjiEngine::GetExitString()
return m_exitstring;
}

void KX_KetsjiEngine::EnableCameraOverride(const std::string& forscene)
{
m_overrideCam = true;
m_overrideSceneName = forscene;
}

void KX_KetsjiEngine::SetCameraZoom(float camzoom)
{
m_cameraZoom = camzoom;
}

void KX_KetsjiEngine::SetCameraOverrideUseOrtho(bool useOrtho)
{
m_overrideCamUseOrtho = useOrtho;
}

void KX_KetsjiEngine::SetCameraOverrideProjectionMatrix(const MT_CmMatrix4x4& mat)
{
m_overrideCamProjMat = mat;
}

void KX_KetsjiEngine::SetCameraOverrideViewMatrix(const MT_CmMatrix4x4& mat)
{
m_overrideCamViewMat = mat;
}

void KX_KetsjiEngine::SetCameraOverrideClipping(float nearfrust, float farfrust)
void KX_KetsjiEngine::SetCameraOverrideZoom(float camzoom)
{
m_overrideCamNear = nearfrust;
m_overrideCamFar = farfrust;
m_overrideCamZoom = camzoom;
}

void KX_KetsjiEngine::SetCameraOverrideLens(float lens)
void KX_KetsjiEngine::EnableCameraOverride(const std::string& forscene, const MT_CmMatrix4x4& projmat,
const MT_CmMatrix4x4& viewmat, const RAS_CameraData& camdata)
{
m_overrideCamLens = lens;
m_overrideCam = true;
m_overrideSceneName = forscene;
m_overrideCamProjMat = projmat;
m_overrideCamViewMat = viewmat;
m_overrideCamData = camdata;
}

void KX_KetsjiEngine::SetCameraOverrideZoom(float camzoom)
{
m_overrideCamZoom = camzoom;
}

void KX_KetsjiEngine::GetSceneViewport(KX_Scene *scene, KX_Camera *cam, RAS_Rect& area, RAS_Rect& viewport)
{
Expand Down Expand Up @@ -797,7 +773,7 @@ void KX_KetsjiEngine::GetSceneViewport(KX_Scene *scene, KX_Camera *cam, RAS_Rect

area = userviewport;
}
else if (!m_overrideCam || (scene->GetName() != m_overrideSceneName) || m_overrideCamUseOrtho) {
else if (!m_overrideCam || (scene->GetName() != m_overrideSceneName) || !m_overrideCamData.m_perspective) {
RAS_FramingManager::ComputeViewport(
scene->GetFramingType(),
m_canvas->GetDisplayArea(),
Expand Down Expand Up @@ -929,7 +905,7 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene *scene, KX_Camera *cam, unsigned shor
override_camera = m_overrideCam && (scene->GetName() == m_overrideSceneName) &&
(cam->GetName() == "__default__cam__");

if (override_camera && m_overrideCamUseOrtho) {
if (override_camera && !m_overrideCamData.m_perspective) {
m_rasterizer->SetProjectionMatrix(m_overrideCamProjMat);
if (!cam->hasValidProjectionMatrix()) {
// needed to get frustum planes for culling
Expand All @@ -949,11 +925,6 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene *scene, KX_Camera *cam, unsigned shor
focallength = cam->GetFocalLength();
MT_Matrix4x4 projmat;

if (override_camera) {
nearfrust = m_overrideCamNear;
farfrust = m_overrideCamFar;
}

float camzoom = override_camera ? m_overrideCamZoom : m_cameraZoom;
if (orthographic) {

Expand Down Expand Up @@ -1123,15 +1094,7 @@ void KX_KetsjiEngine::PostProcessScene(KX_Scene *scene)
if (!scene->GetActiveCamera() || override_camera) {
KX_Camera *activecam = NULL;

RAS_CameraData camdata = RAS_CameraData();
if (override_camera) {
camdata.m_lens = m_overrideCamLens;
camdata.m_clipstart = m_overrideCamNear;
camdata.m_clipend = m_overrideCamFar;

camdata.m_perspective = !m_overrideCamUseOrtho;
}
activecam = new KX_Camera(scene, KX_Scene::m_callbacks, camdata);
activecam = new KX_Camera(scene, KX_Scene::m_callbacks, override_camera ? m_overrideCamData : RAS_CameraData());
activecam->SetName("__default__cam__");

// set transformation
Expand Down
17 changes: 4 additions & 13 deletions source/gameengine/Ketsji/KX_KetsjiEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "KX_Scene.h"
#include "EXP_Python.h"
#include "KX_WorldInfo.h"
#include "RAS_CameraData.h"
#include <vector>

struct TaskScheduler;
Expand Down Expand Up @@ -152,13 +153,9 @@ class KX_KetsjiEngine

bool m_overrideCam;
std::string m_overrideSceneName;

bool m_overrideCamUseOrtho;
RAS_CameraData m_overrideCamData;
MT_CmMatrix4x4 m_overrideCamProjMat;
MT_CmMatrix4x4 m_overrideCamViewMat;
float m_overrideCamNear;
float m_overrideCamFar;
float m_overrideCamLens;
/// Default camera zoom.
float m_overrideCamZoom;

Expand Down Expand Up @@ -315,17 +312,11 @@ class KX_KetsjiEngine

/// Sets zoom for camera objects, useful only with extend and scale framing mode.
void SetCameraZoom(float camzoom);

void EnableCameraOverride(const std::string& forscene);

void SetCameraOverrideUseOrtho(bool useOrtho);
void SetCameraOverrideProjectionMatrix(const MT_CmMatrix4x4& mat);
void SetCameraOverrideViewMatrix(const MT_CmMatrix4x4& mat);
void SetCameraOverrideClipping(float near, float far);
void SetCameraOverrideLens(float lens);
/// Sets zoom for default camera, = 2 in embedded mode.
void SetCameraOverrideZoom(float camzoom);

void EnableCameraOverride(const std::string& forscene, const MT_CmMatrix4x4& projmat, const MT_CmMatrix4x4& viewmat, const RAS_CameraData& camdata);

// Update animations for object in this scene
void UpdateAnimations(KX_Scene *scene);

Expand Down
13 changes: 7 additions & 6 deletions source/gameengine/Launcher/LA_BlenderLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ void LA_BlenderLauncher::InitCamera()
m_ketsjiEngine->SetCameraOverrideZoom(2.0f);

if (rv3d->persp != RV3D_CAMOB) {
m_ketsjiEngine->EnableCameraOverride(m_startSceneName);
m_ketsjiEngine->SetCameraOverrideUseOrtho((rv3d->persp == RV3D_ORTHO));
m_ketsjiEngine->SetCameraOverrideProjectionMatrix(MT_CmMatrix4x4(rv3d->winmat));
m_ketsjiEngine->SetCameraOverrideViewMatrix(MT_CmMatrix4x4(rv3d->viewmat));
m_ketsjiEngine->SetCameraOverrideClipping(m_view3d->near, m_view3d->far);
m_ketsjiEngine->SetCameraOverrideLens(m_view3d->lens);
RAS_CameraData camdata = RAS_CameraData();
camdata.m_lens = m_view3d->lens;
camdata.m_clipstart = m_view3d->near;
camdata.m_clipend = m_view3d->far;
camdata.m_perspective = (rv3d->persp != RV3D_ORTHO);

m_ketsjiEngine->EnableCameraOverride(m_startSceneName, MT_CmMatrix4x4(rv3d->winmat), MT_CmMatrix4x4(rv3d->viewmat), camdata);
}
}

Expand Down

0 comments on commit 783d801

Please sign in to comment.