daily pastebin goal
11%
SHARE
TWEET

guiCameraView.cpp

a guest Nov 19th, 2016 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22.  
  23. #include "guiCameraView.h"
  24. #include "console/consoleTypes.h"
  25. #include "T3D/gameBase/gameBase.h"
  26. #include "T3D/gameBase/gameConnection.h"
  27. #include "T3D/shapeBase.h"
  28. #include "T3D/gameFunctions.h"
  29. #include "console/engineAPI.h"
  30.  
  31. #include "T3D/camera.h"
  32.  
  33. //----------------------------------------------------------------------------
  34. // Class: GuiCameraView
  35. //----------------------------------------------------------------------------
  36.  
  37. IMPLEMENT_CONOBJECT(GuiCameraView);
  38.  
  39. ConsoleDocClass( GuiCameraView,
  40.     "@brief A custom 3D viewport from a selected camera.\n\n"
  41.     "@ingroup Gui3D\n");
  42.  
  43. GuiCameraView::GuiCameraView()
  44. {
  45.    mCameraName = StringTable->insert("");
  46.    mOrthoMode = false;
  47.    mCam_nearPlane = 0;
  48.    mCam_farPlane = 0;
  49.    mPostFX = false;
  50. }
  51. //---------------------------------------------------------------------------
  52. F32 GuiCameraView::getFOVdata()
  53. {
  54.    if(mForceFOV != 0)
  55.       return mForceFOV;
  56.    else
  57.    {
  58.       SimObject *obj = Sim::findObject(mCameraName);
  59.       if (!obj)
  60.          return Con::getFloatVariable("$cameraFov",45.0f);
  61.       bool is_camera=false;
  62.       AbstractClassRep* pRep = obj->getClassRep();
  63.       while(pRep)
  64.       {
  65.           if( !dStricmp(pRep->getClassName(), "Camera" ) )
  66.           {
  67.               //matches
  68.               is_camera = true;
  69.           }
  70.           pRep  =   pRep->getParentClass();
  71.       }
  72.       if (!is_camera)
  73.          return Con::getFloatVariable("$cameraFov",45.0f);
  74.       ShapeBase *camobj = dynamic_cast<ShapeBase*>(obj);
  75.       F32 FOVdata=camobj->getCameraFov();
  76.       return (FOVdata!=0)? FOVdata : Con::getFloatVariable("$cameraFov",45.0f);
  77.    }
  78. }
  79.  
  80. bool GuiCameraView::processCameraQuery(CameraQuery *camq)
  81. {
  82.    //mCameraName can be also a number id in a string as findObject auto-detects that
  83.    SimObject *obj = Sim::findObject(mCameraName);
  84.    if (!obj)
  85.        return false;
  86.    
  87.    bool is_camera=false;
  88.    AbstractClassRep* pRep = obj->getClassRep();
  89.    while(pRep)
  90.    {
  91.       if( !dStricmp(pRep->getClassName(), "Camera" ) )
  92.       {
  93.          //matches
  94.          is_camera = true;
  95.       }
  96.  
  97.       pRep  =   pRep->getParentClass();
  98.    }
  99.    
  100.    if (!is_camera)
  101.        return false;
  102.    
  103.    Camera *camobj = dynamic_cast<Camera*>(obj);
  104.    
  105.    camq->object = obj;
  106.    
  107.    if (mCam_nearPlane !=0)
  108.    {
  109.        camq->nearPlane = mCam_nearPlane;
  110.    }
  111.    else
  112.    {
  113.        camq->nearPlane = gClientSceneGraph->getNearClip();
  114.    }
  115.    
  116.    camq->cameraMatrix = camobj->getTransform();
  117.    
  118.    if (mCam_farPlane !=0)
  119.    {
  120.        camq->farPlane = mCam_farPlane;
  121.    }
  122.    else
  123.    {
  124.        // Scale the normal visible distance by the performance
  125.        // tuning scale which we never let over 1.
  126.        F32 visible_distance_scale = Con::getFloatVariable("$pref::Camera::distanceScale",1.0f);
  127.        visible_distance_scale = mClampF( visible_distance_scale, 0.01f, 1.0f );
  128.        camq->farPlane = gClientSceneGraph->getVisibleDistance() * visible_distance_scale;
  129.    }
  130.  
  131.    camq->eyeTransforms[0] = camq->cameraMatrix;
  132.    camq->eyeTransforms[1] = camq->cameraMatrix;
  133.    camq->ortho = mOrthoMode;
  134.  
  135.    if(mForceFOV != 0)
  136.       camq->fov = mDegToRad(mForceFOV);
  137.    else
  138.    {
  139.       ShapeBase *camobjshapebase = dynamic_cast<ShapeBase*>(obj);
  140.       F32 FOVdata=camobjshapebase->getCameraFov();
  141.       if (FOVdata!=0)
  142.          camq->fov = mDegToRad(FOVdata);
  143.       else
  144.          camq->fov = mDegToRad(Con::getFloatVariable("$cameraFov",45.0f));
  145.    }      
  146.    return true;
  147. }
  148.  
  149. void GuiCameraView::renderWorld(const RectI &updateRect)
  150. {
  151.    //Parent::renderWorld(updateRect);
  152.    //return;
  153.    
  154.    PROFILE_START(GuiCamViewRenderWorld);
  155.  
  156.    SceneRenderState state
  157.    (
  158.       gClientSceneGraph,
  159.       SPT_Diffuse,
  160.       SceneCameraState::fromGFX(),
  161.       gClientSceneGraph->getDefaultRenderPass(),
  162.       mPostFX//false
  163.    );
  164.  
  165.    gClientSceneGraph->renderScene( &state );
  166.    GFX->updateStates();
  167.    PROFILE_END();
  168. }
  169.  
  170. //---------------------------------------------------------------------------
  171.  
  172. void GuiCameraView::initPersistFields()
  173. {
  174.    addGroup( "SelectedCamera" );
  175.    
  176.       addField("camera", TypeString, Offset( mCameraName, GuiCameraView ),
  177.          "Global name or id of the camera object for this view." );
  178.       addField( "orthoMode", TypeBool, Offset( mOrthoMode, GuiCameraView ),
  179.          "Enables orthographic projection." );
  180.       addField( "nearClip", TypeF32, Offset( mCam_nearPlane, GuiCameraView ),
  181.          "Closest distance from the camera's position to render the world. "
  182.          "Use 0 for LevelInfo default." );
  183.       addField( "visibleDistance", TypeF32, Offset( mCam_farPlane, GuiCameraView ),
  184.          "Furthest distance from the camera's position to render the world. "
  185.          "Use 0 for LevelInfo default." );
  186.       addField( "enablePostFX", TypeBool, Offset( mPostFX, GuiCameraView ),
  187.          "Enables PostFX." );
  188.          
  189.    endGroup( "SelectedCamera" );
  190.      
  191.    Parent::initPersistFields();
  192.    
  193.    removeField( "cameraZRot" );
  194.    removeField( "renderStyle" );
  195. }
  196.  
  197. //-----------------------------------------------------------------------------
  198.  
  199. DefineEngineMethod( GuiCameraView, getFOV, F32, (),,
  200.    "@brief Gets the FOV used in this view.\n")
  201. {
  202.     return object->getFOVdata();
  203. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top