From 3257be1f76540055c033026fc32abd1dd5ae6003 Mon Sep 17 00:00:00 2001 From: tristan Date: Thu, 14 Jun 2018 23:59:00 +0200 Subject: [PATCH] UPBGE: Move camera zoom setting in BL_Converter and RAS_CameraData. The camera zoom setting was previously only stored into the ketsji engine, to avoid storing a setting only for override camera, this zoom is stored in RAS_CameraData. Then the override camera zoom is initialized easily from LA_BlenderPlayer and for other camera, the zoom is copied from BL_Converter global zoom variable (m_camZoom) initialized at the converter construction from the launcher. --- .../Converter/BL_BlenderDataConversion.cpp | 13 ++++++----- .../Converter/BL_BlenderDataConversion.h | 2 +- source/gameengine/Converter/BL_Converter.cpp | 11 ++++----- source/gameengine/Converter/BL_Converter.h | 5 ++-- source/gameengine/Ketsji/KX_Camera.cpp | 5 +++- source/gameengine/Ketsji/KX_Camera.h | 3 ++- source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 23 +------------------ source/gameengine/Ketsji/KX_KetsjiEngine.h | 11 --------- source/gameengine/Ketsji/KX_PlanarMap.cpp | 5 +--- .../Launcher/LA_BlenderLauncher.cpp | 18 +++------------ .../gameengine/Launcher/LA_BlenderLauncher.h | 1 - source/gameengine/Launcher/LA_Launcher.cpp | 8 +++---- source/gameengine/Launcher/LA_Launcher.h | 6 +++-- .../gameengine/Launcher/LA_PlayerLauncher.cpp | 7 +----- .../gameengine/Launcher/LA_PlayerLauncher.h | 1 - source/gameengine/Rasterizer/RAS_CameraData.h | 6 +++-- 16 files changed, 38 insertions(+), 87 deletions(-) diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 1ba0daf51bdd..2e823643d562 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -793,10 +793,10 @@ static KX_LightObject *BL_GameLightFromBlenderLamp(Lamp *la, unsigned int layerf return gamelight; } -static KX_Camera *BL_GameCameraFromBlenderCamera(Object *ob, KX_Scene *kxscene, RAS_ICanvas *canvas) +static KX_Camera *BL_GameCameraFromBlenderCamera(Object *ob, KX_Scene *kxscene, RAS_ICanvas *canvas, float camZoom) { Camera *ca = static_cast(ob->data); - RAS_CameraData camdata(ca->lens, ca->ortho_scale, ca->sensor_x, ca->sensor_y, ca->sensor_fit, ca->shiftx, ca->shifty, ca->clipsta, ca->clipend, ca->type == CAM_PERSP, ca->YF_dofdist); + RAS_CameraData camdata(ca->lens, ca->ortho_scale, ca->sensor_x, ca->sensor_y, ca->sensor_fit, ca->shiftx, ca->shifty, ca->clipsta, ca->clipend, ca->type == CAM_PERSP, ca->YF_dofdist, camZoom); KX_Camera *gamecamera; gamecamera = new KX_Camera(kxscene, KX_Scene::m_callbacks, camdata); @@ -835,7 +835,7 @@ static KX_Camera *BL_GameCameraFromBlenderCamera(Object *ob, KX_Scene *kxscene, } static KX_GameObject *BL_GameObjectFromBlenderObject(Object *ob, KX_Scene *kxscene, RAS_Rasterizer *rendertools, - RAS_ICanvas *canvas, BL_SceneConverter &converter) + RAS_ICanvas *canvas, BL_SceneConverter &converter, float camZoom) { KX_GameObject *gameobj = nullptr; Scene *blenderscene = kxscene->GetBlenderScene(); @@ -853,7 +853,7 @@ static KX_GameObject *BL_GameObjectFromBlenderObject(Object *ob, KX_Scene *kxsce case OB_CAMERA: { - KX_Camera *gamecamera = BL_GameCameraFromBlenderCamera(ob, kxscene, canvas); + KX_Camera *gamecamera = BL_GameCameraFromBlenderCamera(ob, kxscene, canvas, camZoom); gameobj = gamecamera; kxscene->GetCameraList()->Add(CM_AddRef(gamecamera)); @@ -1185,6 +1185,7 @@ void BL_ConvertBlenderObjects(struct Main *maggie, RAS_ICanvas *canvas, BL_SceneConverter& converter, bool alwaysUseExpandFraming, + float camZoom, bool libloading) { @@ -1323,7 +1324,7 @@ void BL_ConvertBlenderObjects(struct Main *maggie, Object *blenderobject = base->object; allblobj.insert(blenderobject); - KX_GameObject *gameobj = BL_GameObjectFromBlenderObject(base->object, kxscene, rendertools, canvas, converter); + KX_GameObject *gameobj = BL_GameObjectFromBlenderObject(base->object, kxscene, rendertools, canvas, converter, camZoom); bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) != 0; if (gameobj) { @@ -1360,7 +1361,7 @@ void BL_ConvertBlenderObjects(struct Main *maggie, if (!converter.FindGameObject(blenderobject)) { allblobj.insert(blenderobject); groupobj.insert(blenderobject); - KX_GameObject *gameobj = BL_GameObjectFromBlenderObject(blenderobject, kxscene, rendertools, canvas, converter); + KX_GameObject *gameobj = BL_GameObjectFromBlenderObject(blenderobject, kxscene, rendertools, canvas, converter, camZoom); bool isInActiveLayer = false; if (gameobj) { diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.h b/source/gameengine/Converter/BL_BlenderDataConversion.h index 19c4da571e5e..8532b44c5c9b 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.h +++ b/source/gameengine/Converter/BL_BlenderDataConversion.h @@ -61,7 +61,7 @@ void BL_ConvertDerivedMeshToArray(DerivedMesh *dm, Mesh *me, const std::vectorGetTaskScheduler(), nullptr); @@ -231,6 +232,7 @@ void BL_Converter::ConvertScene(BL_SceneConverter& converter, bool libloading) m_ketsjiEngine->GetCanvas(), converter, m_alwaysUseExpandFraming, + m_camZoom, libloading); m_sceneSlots.emplace(scene, converter); @@ -272,11 +274,6 @@ void BL_Converter::RemoveScene(KX_Scene *scene) m_sceneSlots.erase(scene); } -void BL_Converter::SetAlwaysUseExpandFraming(bool to_what) -{ - m_alwaysUseExpandFraming = to_what; -} - void BL_Converter::RegisterInterpolatorList(KX_Scene *scene, BL_InterpolatorList *interpolator, bAction *for_act) { SceneSlot& sceneSlot = m_sceneSlots[scene]; diff --git a/source/gameengine/Converter/BL_Converter.h b/source/gameengine/Converter/BL_Converter.h index ad09fb3ecc95..f229ae485ead 100644 --- a/source/gameengine/Converter/BL_Converter.h +++ b/source/gameengine/Converter/BL_Converter.h @@ -104,9 +104,10 @@ class BL_Converter KX_KetsjiEngine *m_ketsjiEngine; bool m_alwaysUseExpandFraming; + float m_camZoom; public: - BL_Converter(Main *maggie, KX_KetsjiEngine *engine); + BL_Converter(Main *maggie, KX_KetsjiEngine *engine, bool alwaysUseExpandFraming, float camZoom); virtual ~BL_Converter(); void ConvertScene(BL_SceneConverter& converter, bool libloading); @@ -129,8 +130,6 @@ class BL_Converter */ void RemoveScene(KX_Scene *scene); - void SetAlwaysUseExpandFraming(bool to_what); - void RegisterInterpolatorList(KX_Scene *scene, BL_InterpolatorList *interpolator, bAction *for_act); BL_InterpolatorList *FindInterpolatorList(KX_Scene *scene, bAction *for_act); /// Register a mesh object copy. diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index f54e8c74caff..ef326368273e 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -216,7 +216,10 @@ float KX_Camera::GetFocalLength() const return m_camdata.m_focallength; } - +float KX_Camera::GetZoom() const +{ + return m_camdata.m_zoom; +} RAS_CameraData *KX_Camera::GetCameraData() { diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h index 8e77583cdd3d..e59312612b19 100644 --- a/source/gameengine/Ketsji/KX_Camera.h +++ b/source/gameengine/Ketsji/KX_Camera.h @@ -114,7 +114,7 @@ class KX_Camera : public KX_GameObject KX_Camera(void* sgReplicationInfo,SG_Callbacks callbacks,const RAS_CameraData& camdata, bool frustum_culling = true); virtual ~KX_Camera(); - + /** * Inherited from EXP_Value -- return a new copy of this * instance allocated on the heap. Ownership of the new @@ -171,6 +171,7 @@ class KX_Camera : public KX_GameObject float GetCameraFar() const; /** Gets the focal length (only used for stereo rendering) */ float GetFocalLength() const; + float GetZoom() const; /** Gets all camera data. */ RAS_CameraData* GetCameraData(); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index f1c40448800d..15be35d3a372 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -170,8 +170,6 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem *system) m_exitkey(130), m_exitcode(KX_ExitRequest::NO_REQUEST), m_exitstring(""), - m_cameraZoom(1.0f), - m_overrideCamZoom(1.0f), m_logger(KX_TimeCategoryLogger(25)), m_average_framerate(0.0), m_showBoundingBox(KX_DebugOption::DISABLE), @@ -757,25 +755,6 @@ const std::string& KX_KetsjiEngine::GetExitString() return m_exitstring; } -void KX_KetsjiEngine::SetCameraZoom(float camzoom) -{ - m_cameraZoom = camzoom; -} - -void KX_KetsjiEngine::SetCameraOverrideZoom(float camzoom) -{ - m_overrideCamZoom = camzoom; -} - -float KX_KetsjiEngine::GetCameraZoom(KX_Camera *camera) const -{ - KX_Scene *scene = camera->GetScene(); - const bool overrideCamera = ((m_flags & CAMERA_OVERRIDE) != 0) && (scene->GetName() == m_overrideSceneName) && - (camera->GetName() == "__default__cam__"); - - return overrideCamera ? m_overrideCamZoom : m_cameraZoom; -} - void KX_KetsjiEngine::EnableCameraOverride(const std::string& forscene, const mt::mat4& projmat, const mt::mat4& viewmat, const RAS_CameraData& camdata) { @@ -910,7 +889,7 @@ mt::mat4 KX_KetsjiEngine::GetCameraProjectionMatrix(KX_Scene *scene, KX_Camera * const float farfrust = cam->GetCameraFar(); const float focallength = cam->GetFocalLength(); - const float camzoom = override_camera ? m_overrideCamZoom : m_cameraZoom; + const float camzoom = cam->GetZoom(); if (orthographic) { RAS_FramingManager::ComputeOrtho( diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index ef7933edca6f..24165bd59e59 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -202,14 +202,10 @@ class KX_KetsjiEngine : public mt::SimdClassAllocator KX_ExitRequest m_exitcode; std::string m_exitstring; - float m_cameraZoom; - std::string m_overrideSceneName; RAS_CameraData m_overrideCamData; mt::mat4 m_overrideCamProjMat; mt::mat4 m_overrideCamViewMat; - /// Default camera zoom. - float m_overrideCamZoom; /// Categories for profiling display. typedef enum { @@ -373,13 +369,6 @@ class KX_KetsjiEngine : public mt::SimdClassAllocator void GetSceneViewport(KX_Scene *scene, KX_Camera *cam, const RAS_Rect& displayArea, RAS_Rect& area, RAS_Rect& viewport); - /// Sets zoom for camera objects, useful only with extend and scale framing mode. - void SetCameraZoom(float camzoom); - /// Sets zoom for default camera, = 2 in embedded mode. - void SetCameraOverrideZoom(float camzoom); - /// Get the camera zoom for the passed camera. - float GetCameraZoom(KX_Camera *camera) const; - void EnableCameraOverride(const std::string& forscene, const mt::mat4& projmat, const mt::mat4& viewmat, const RAS_CameraData& camdata); // Update animations for object in this scene diff --git a/source/gameengine/Ketsji/KX_PlanarMap.cpp b/source/gameengine/Ketsji/KX_PlanarMap.cpp index 10184e077029..623111191d4d 100644 --- a/source/gameengine/Ketsji/KX_PlanarMap.cpp +++ b/source/gameengine/Ketsji/KX_PlanarMap.cpp @@ -27,7 +27,6 @@ #include "KX_PlanarMap.h" #include "KX_Camera.h" #include "KX_PyMath.h" -#include "KX_Globals.h" #include "RAS_Rasterizer.h" #include "RAS_Texture.h" @@ -121,9 +120,7 @@ const mt::mat4& KX_PlanarMap::GetProjectionMatrix(RAS_Rasterizer *rasty, KX_Scen } if (!sceneCamera->GetViewport()) { - KX_KetsjiEngine *engine = KX_GetActiveEngine(); - const float camzoom = engine->GetCameraZoom(sceneCamera); - + const float camzoom = sceneCamera->GetZoom(); frustum.x1 *= camzoom; frustum.x2 *= camzoom; frustum.y1 *= camzoom; diff --git a/source/gameengine/Launcher/LA_BlenderLauncher.cpp b/source/gameengine/Launcher/LA_BlenderLauncher.cpp index 5edd2f66a311..e1126f672db0 100644 --- a/source/gameengine/Launcher/LA_BlenderLauncher.cpp +++ b/source/gameengine/Launcher/LA_BlenderLauncher.cpp @@ -53,11 +53,10 @@ extern "C" { LA_BlenderLauncher::LA_BlenderLauncher(GHOST_ISystem *system, Main *maggie, Scene *scene, GlobalSettings *gs, RAS_Rasterizer::StereoMode stereoMode, int argc, char **argv, bContext *context, rcti *camframe, ARegion *ar, int alwaysUseExpandFraming) - :LA_Launcher(system, maggie, scene, gs, stereoMode, scene->gm.aasamples, argc, argv), + :LA_Launcher(system, maggie, scene, gs, stereoMode, scene->gm.aasamples, alwaysUseExpandFraming, argc, argv), m_context(context), m_ar(ar), m_camFrame(camframe), - m_alwaysUseExpandFraming(alwaysUseExpandFraming), m_drawLetterBox(false) { m_windowManager = CTX_wm_manager(m_context); @@ -100,36 +99,25 @@ RAS_Rasterizer::DrawType LA_BlenderLauncher::GetRasterizerDrawMode() return drawmode; } -bool LA_BlenderLauncher::GetUseAlwaysExpandFraming() -{ - return m_alwaysUseExpandFraming; -} - void LA_BlenderLauncher::InitCamera() { RegionView3D *rv3d = CTX_wm_region_view3d(m_context); - - // Some blender stuff. - float camzoom = 1.0f; - if (rv3d->persp == RV3D_CAMOB) { if (m_startScene->gm.framing.type == SCE_GAMEFRAMING_BARS) { /* Letterbox */ m_drawLetterBox = true; } else { - camzoom = 1.0f / BKE_screen_view3d_zoom_to_fac(rv3d->camzoom); + m_camZoom = 1.0f / BKE_screen_view3d_zoom_to_fac(rv3d->camzoom); } } - m_ketsjiEngine->SetCameraZoom(camzoom); - m_ketsjiEngine->SetCameraOverrideZoom(2.0f); - if (rv3d->persp != RV3D_CAMOB) { 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); + camdata.m_zoom = 2.0f; m_ketsjiEngine->EnableCameraOverride(m_startSceneName, mt::mat4(rv3d->winmat), mt::mat4(rv3d->viewmat), camdata); } diff --git a/source/gameengine/Launcher/LA_BlenderLauncher.h b/source/gameengine/Launcher/LA_BlenderLauncher.h index 42a5aa2343a7..22c509172604 100644 --- a/source/gameengine/Launcher/LA_BlenderLauncher.h +++ b/source/gameengine/Launcher/LA_BlenderLauncher.h @@ -59,7 +59,6 @@ class LA_BlenderLauncher : public LA_Launcher virtual RAS_ICanvas *CreateCanvas(RAS_Rasterizer *rasty); virtual RAS_Rasterizer::DrawType GetRasterizerDrawMode(); - virtual bool GetUseAlwaysExpandFraming(); virtual void InitCamera(); virtual void SetWindowOrder(short order); diff --git a/source/gameengine/Launcher/LA_Launcher.cpp b/source/gameengine/Launcher/LA_Launcher.cpp index 120a968b347b..1c2b8ded5621 100644 --- a/source/gameengine/Launcher/LA_Launcher.cpp +++ b/source/gameengine/Launcher/LA_Launcher.cpp @@ -80,7 +80,7 @@ extern "C" { #endif LA_Launcher::LA_Launcher(GHOST_ISystem *system, Main *maggie, Scene *scene, GlobalSettings *gs, - RAS_Rasterizer::StereoMode stereoMode, int samples, int argc, char **argv) + RAS_Rasterizer::StereoMode stereoMode, int samples, bool alwaysUseExpandFraming, int argc, char **argv) :m_startSceneName(scene->id.name + 2), m_startScene(scene), m_maggie(maggie), @@ -98,6 +98,8 @@ LA_Launcher::LA_Launcher(GHOST_ISystem *system, Main *maggie, Scene *scene, Glob #ifdef WITH_PYTHON m_globalDict(nullptr), #endif // WITH_PYTHON + m_alwaysUseExpandFraming(alwaysUseExpandFraming), + m_camZoom(1.0f), m_samples(samples), m_stereoMode(stereoMode), m_argc(argc), @@ -280,7 +282,7 @@ void LA_Launcher::InitEngine() #endif // WITH_PYTHON // Create a scene converter, create and convert the stratingscene. - m_converter = new BL_Converter(m_maggie, m_ketsjiEngine); + m_converter = new BL_Converter(m_maggie, m_ketsjiEngine, m_alwaysUseExpandFraming, m_camZoom); m_ketsjiEngine->SetConverter(m_converter); m_kxStartScene = m_ketsjiEngine->CreateScene(m_startScene); @@ -296,8 +298,6 @@ void LA_Launcher::InitEngine() AUD_Device_setDistanceModel(device, AUD_DistanceModel(m_startScene->audio.distance_model)); #endif // WITH_AUDASPACE - m_converter->SetAlwaysUseExpandFraming(GetUseAlwaysExpandFraming()); - // Convert scene data. m_ketsjiEngine->ConvertScene(m_kxStartScene); diff --git a/source/gameengine/Launcher/LA_Launcher.h b/source/gameengine/Launcher/LA_Launcher.h index 31930867acea..d768f68e5006 100644 --- a/source/gameengine/Launcher/LA_Launcher.h +++ b/source/gameengine/Launcher/LA_Launcher.h @@ -84,6 +84,9 @@ class LA_Launcher PyObject *m_globalDict; #endif // WITH_PYTHON + bool m_alwaysUseExpandFraming; + float m_camZoom; + /// The number of render samples. int m_samples; @@ -125,14 +128,13 @@ class LA_Launcher virtual RAS_ICanvas *CreateCanvas(RAS_Rasterizer *rasty) = 0; virtual RAS_Rasterizer::DrawType GetRasterizerDrawMode() = 0; - virtual bool GetUseAlwaysExpandFraming() = 0; virtual void InitCamera() = 0; virtual void SetWindowOrder(short order) = 0; public: LA_Launcher(GHOST_ISystem *system, Main *maggie, Scene *scene, GlobalSettings *gs, - RAS_Rasterizer::StereoMode stereoMode, int samples, int argc, char **argv); + RAS_Rasterizer::StereoMode stereoMode, int samples, bool alwaysUseExpandFraming, int argc, char **argv); virtual ~LA_Launcher(); #ifdef WITH_PYTHON diff --git a/source/gameengine/Launcher/LA_PlayerLauncher.cpp b/source/gameengine/Launcher/LA_PlayerLauncher.cpp index b1b3fc75abad..9e370d03a9a5 100644 --- a/source/gameengine/Launcher/LA_PlayerLauncher.cpp +++ b/source/gameengine/Launcher/LA_PlayerLauncher.cpp @@ -58,7 +58,7 @@ extern "C" { LA_PlayerLauncher::LA_PlayerLauncher(GHOST_ISystem *system, GHOST_IWindow *window, Main *maggie, Scene *scene, GlobalSettings *gs, RAS_Rasterizer::StereoMode stereoMode, int samples, int argc, char **argv, const std::string& pythonMainLoop) - :LA_Launcher(system, maggie, scene, gs, stereoMode, samples, argc, argv), + :LA_Launcher(system, maggie, scene, gs, stereoMode, samples, false, argc, argv), m_mainWindow(window), m_pythonMainLoop(pythonMainLoop) { @@ -115,11 +115,6 @@ RAS_Rasterizer::DrawType LA_PlayerLauncher::GetRasterizerDrawMode() return RAS_Rasterizer::RAS_TEXTURED; } -bool LA_PlayerLauncher::GetUseAlwaysExpandFraming() -{ - return false; -} - void LA_PlayerLauncher::InitCamera() { } diff --git a/source/gameengine/Launcher/LA_PlayerLauncher.h b/source/gameengine/Launcher/LA_PlayerLauncher.h index ce8365fd79da..fc4a60c0343d 100644 --- a/source/gameengine/Launcher/LA_PlayerLauncher.h +++ b/source/gameengine/Launcher/LA_PlayerLauncher.h @@ -55,7 +55,6 @@ class LA_PlayerLauncher : public LA_Launcher virtual RAS_ICanvas *CreateCanvas(RAS_Rasterizer *rasty); virtual RAS_Rasterizer::DrawType GetRasterizerDrawMode(); - virtual bool GetUseAlwaysExpandFraming(); virtual void InitCamera(); virtual void SetWindowOrder(short order); diff --git a/source/gameengine/Rasterizer/RAS_CameraData.h b/source/gameengine/Rasterizer/RAS_CameraData.h index bc8433afd055..b5e938ed7ea8 100644 --- a/source/gameengine/Rasterizer/RAS_CameraData.h +++ b/source/gameengine/Rasterizer/RAS_CameraData.h @@ -50,11 +50,12 @@ struct RAS_CameraData int m_viewportright; int m_viewporttop; float m_focallength; + float m_zoom; RAS_CameraData(float lens = 35.0f, float scale = 6.0f, float sensor_x = 32.0f, float sensor_y = 18.0f, short sensor_fit = 0, float shift_x = 0.0f, float shift_y = 0.0f, float clipstart = 0.1f, float clipend = 5000.0f, bool perspective = true, - float focallength = 3.0f, bool viewport = false, int viewportleft = 0, int viewportbottom = 0, + float focallength = 3.0f, float zoom = 1.0f, bool viewport = false, int viewportleft = 0, int viewportbottom = 0, int viewportright = 0, int viewporttop = 0) : m_lens(lens), m_scale(scale), @@ -71,7 +72,8 @@ struct RAS_CameraData m_viewportbottom(viewportbottom), m_viewportright(viewportright), m_viewporttop(viewporttop), - m_focallength(focallength) + m_focallength(focallength), + m_zoom(zoom) { } };