Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #include "guiCameraView.h"
- #include "console/consoleTypes.h"
- #include "T3D/gameBase/gameBase.h"
- #include "T3D/gameBase/gameConnection.h"
- #include "T3D/shapeBase.h"
- #include "T3D/gameFunctions.h"
- #include "console/engineAPI.h"
- #include "T3D/camera.h"
- //----------------------------------------------------------------------------
- // Class: GuiCameraView
- //----------------------------------------------------------------------------
- IMPLEMENT_CONOBJECT(GuiCameraView);
- ConsoleDocClass( GuiCameraView,
- "@brief A custom 3D viewport from a selected camera.\n\n"
- "@ingroup Gui3D\n");
- GuiCameraView::GuiCameraView()
- {
- mCameraName = StringTable->insert("");
- mOrthoMode = false;
- mCam_nearPlane = 0;
- mCam_farPlane = 0;
- mPostFX = false;
- }
- //---------------------------------------------------------------------------
- F32 GuiCameraView::getFOVdata()
- {
- if(mForceFOV != 0)
- return mForceFOV;
- else
- {
- SimObject *obj = Sim::findObject(mCameraName);
- if (!obj)
- return Con::getFloatVariable("$cameraFov",45.0f);
- bool is_camera=false;
- AbstractClassRep* pRep = obj->getClassRep();
- while(pRep)
- {
- if( !dStricmp(pRep->getClassName(), "Camera" ) )
- {
- //matches
- is_camera = true;
- }
- pRep = pRep->getParentClass();
- }
- if (!is_camera)
- return Con::getFloatVariable("$cameraFov",45.0f);
- ShapeBase *camobj = dynamic_cast<ShapeBase*>(obj);
- F32 FOVdata=camobj->getCameraFov();
- return (FOVdata!=0)? FOVdata : Con::getFloatVariable("$cameraFov",45.0f);
- }
- }
- bool GuiCameraView::processCameraQuery(CameraQuery *camq)
- {
- //mCameraName can be also a number id in a string as findObject auto-detects that
- SimObject *obj = Sim::findObject(mCameraName);
- if (!obj)
- return false;
- bool is_camera=false;
- AbstractClassRep* pRep = obj->getClassRep();
- while(pRep)
- {
- if( !dStricmp(pRep->getClassName(), "Camera" ) )
- {
- //matches
- is_camera = true;
- }
- pRep = pRep->getParentClass();
- }
- if (!is_camera)
- return false;
- Camera *camobj = dynamic_cast<Camera*>(obj);
- camq->object = obj;
- if (mCam_nearPlane !=0)
- {
- camq->nearPlane = mCam_nearPlane;
- }
- else
- {
- camq->nearPlane = gClientSceneGraph->getNearClip();
- }
- camq->cameraMatrix = camobj->getTransform();
- if (mCam_farPlane !=0)
- {
- camq->farPlane = mCam_farPlane;
- }
- else
- {
- // Scale the normal visible distance by the performance
- // tuning scale which we never let over 1.
- F32 visible_distance_scale = Con::getFloatVariable("$pref::Camera::distanceScale",1.0f);
- visible_distance_scale = mClampF( visible_distance_scale, 0.01f, 1.0f );
- camq->farPlane = gClientSceneGraph->getVisibleDistance() * visible_distance_scale;
- }
- camq->eyeTransforms[0] = camq->cameraMatrix;
- camq->eyeTransforms[1] = camq->cameraMatrix;
- camq->ortho = mOrthoMode;
- if(mForceFOV != 0)
- camq->fov = mDegToRad(mForceFOV);
- else
- {
- ShapeBase *camobjshapebase = dynamic_cast<ShapeBase*>(obj);
- F32 FOVdata=camobjshapebase->getCameraFov();
- if (FOVdata!=0)
- camq->fov = mDegToRad(FOVdata);
- else
- camq->fov = mDegToRad(Con::getFloatVariable("$cameraFov",45.0f));
- }
- return true;
- }
- void GuiCameraView::renderWorld(const RectI &updateRect)
- {
- //Parent::renderWorld(updateRect);
- //return;
- PROFILE_START(GuiCamViewRenderWorld);
- SceneRenderState state
- (
- gClientSceneGraph,
- SPT_Diffuse,
- SceneCameraState::fromGFX(),
- gClientSceneGraph->getDefaultRenderPass(),
- mPostFX//false
- );
- gClientSceneGraph->renderScene( &state );
- GFX->updateStates();
- PROFILE_END();
- }
- //---------------------------------------------------------------------------
- void GuiCameraView::initPersistFields()
- {
- addGroup( "SelectedCamera" );
- addField("camera", TypeString, Offset( mCameraName, GuiCameraView ),
- "Global name or id of the camera object for this view." );
- addField( "orthoMode", TypeBool, Offset( mOrthoMode, GuiCameraView ),
- "Enables orthographic projection." );
- addField( "nearClip", TypeF32, Offset( mCam_nearPlane, GuiCameraView ),
- "Closest distance from the camera's position to render the world. "
- "Use 0 for LevelInfo default." );
- addField( "visibleDistance", TypeF32, Offset( mCam_farPlane, GuiCameraView ),
- "Furthest distance from the camera's position to render the world. "
- "Use 0 for LevelInfo default." );
- addField( "enablePostFX", TypeBool, Offset( mPostFX, GuiCameraView ),
- "Enables PostFX." );
- endGroup( "SelectedCamera" );
- Parent::initPersistFields();
- removeField( "cameraZRot" );
- removeField( "renderStyle" );
- }
- //-----------------------------------------------------------------------------
- DefineEngineMethod( GuiCameraView, getFOV, F32, (),,
- "@brief Gets the FOV used in this view.\n")
- {
- return object->getFOVdata();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement