Revision: 2470
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2470&view=rev
Author:   rorthomas
Date:     2012-03-16 06:46:40 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
improved camera system

Modified Paths:
--------------
    trunk/source/main/gfx/camera/CameraBehavior.h
    trunk/source/main/gfx/camera/CameraBehaviorFree.cpp
    trunk/source/main/gfx/camera/CameraBehaviorFree.h
    trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp
    trunk/source/main/gfx/camera/CameraBehaviorOrbit.h
    trunk/source/main/gfx/camera/CameraBehaviorWheelChase.cpp
    trunk/source/main/gfx/camera/CameraBehaviorWheelChase.h
    trunk/source/main/gfx/camera/CameraManager.cpp
    trunk/source/main/gfx/camera/CameraManager.h

Modified: trunk/source/main/gfx/camera/CameraBehavior.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehavior.h       2012-03-15 22:03:08 UTC 
(rev 2469)
+++ trunk/source/main/gfx/camera/CameraBehavior.h       2012-03-16 06:46:40 UTC 
(rev 2470)
@@ -44,8 +44,8 @@
        virtual bool mousePressed(const OIS::MouseEvent& _arg, 
OIS::MouseButtonID _id) = 0;
        virtual bool mouseReleased(const OIS::MouseEvent& _arg, 
OIS::MouseButtonID _id) = 0;
 
-       virtual void activate() = 0;
-       virtual void deactivate() = 0;
+       virtual void activate(cameraContext_t &ctx) = 0;
+       virtual void deactivate(cameraContext_t &ctx) = 0;
 
        virtual bool allowInteraction() = 0;
 };

Modified: trunk/source/main/gfx/camera/CameraBehaviorFree.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorFree.cpp 2012-03-15 22:03:08 UTC 
(rev 2469)
+++ trunk/source/main/gfx/camera/CameraBehaviorFree.cpp 2012-03-16 06:46:40 UTC 
(rev 2470)
@@ -28,7 +28,7 @@
 using namespace Ogre;
 
 
-void CameraBehaviorFree::activate()
+void CameraBehaviorFree::activate(cameraContext_t &ctx)
 {
        // enter free camera mode
        DOFManager *dof = CameraManager::getSingleton().getDOFManager();
@@ -43,7 +43,7 @@
 #endif // USE_MYGUI
 }
 
-void CameraBehaviorFree::deactivate()
+void CameraBehaviorFree::deactivate(cameraContext_t &ctx)
 {
        // change back to normal camera
        DOFManager *dof = CameraManager::getSingleton().getDOFManager();

Modified: trunk/source/main/gfx/camera/CameraBehaviorFree.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorFree.h   2012-03-15 22:03:08 UTC 
(rev 2469)
+++ trunk/source/main/gfx/camera/CameraBehaviorFree.h   2012-03-16 06:46:40 UTC 
(rev 2470)
@@ -26,8 +26,8 @@
 class CameraBehaviorFree : public CameraBehavior
 {
 public:
-       void activate();
-       void deactivate();
+       void activate(cameraContext_t &ctx);
+       void deactivate(cameraContext_t &ctx);
 
        void update(cameraContext_t &ctx);
 

Modified: trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp        2012-03-15 
22:03:08 UTC (rev 2469)
+++ trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp        2012-03-16 
06:46:40 UTC (rev 2470)
@@ -44,7 +44,7 @@
 
 }
 
-void CameraBehaviorOrbit::activate()
+void CameraBehaviorOrbit::activate(cameraContext_t &ctx)
 {
        float fov = FSETTING("FOV External", 60);
 
@@ -61,7 +61,7 @@
        cam->setFOVy(Degree(fov));
 }
 
-void CameraBehaviorOrbit::deactivate()
+void CameraBehaviorOrbit::deactivate(cameraContext_t &ctx)
 {
 }
 

Modified: trunk/source/main/gfx/camera/CameraBehaviorOrbit.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorOrbit.h  2012-03-15 22:03:08 UTC 
(rev 2469)
+++ trunk/source/main/gfx/camera/CameraBehaviorOrbit.h  2012-03-16 06:46:40 UTC 
(rev 2470)
@@ -35,8 +35,8 @@
 
        CameraBehaviorOrbit();
 
-       void activate();
-       void deactivate();
+       void activate(cameraContext_t &ctx);
+       void deactivate(cameraContext_t &ctx);
 
        void update(cameraContext_t &ctx);
 

Modified: trunk/source/main/gfx/camera/CameraBehaviorWheelChase.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorWheelChase.cpp   2012-03-15 
22:03:08 UTC (rev 2469)
+++ trunk/source/main/gfx/camera/CameraBehaviorWheelChase.cpp   2012-03-16 
06:46:40 UTC (rev 2470)
@@ -29,11 +29,11 @@
 
 using namespace Ogre;
 
-void CameraBehaviorWheelChase::activate()
+void CameraBehaviorWheelChase::activate(cameraContext_t &ctx)
 {
 }
 
-void CameraBehaviorWheelChase::deactivate()
+void CameraBehaviorWheelChase::deactivate(cameraContext_t &ctx)
 {
 }
 

Modified: trunk/source/main/gfx/camera/CameraBehaviorWheelChase.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorWheelChase.h     2012-03-15 
22:03:08 UTC (rev 2469)
+++ trunk/source/main/gfx/camera/CameraBehaviorWheelChase.h     2012-03-16 
06:46:40 UTC (rev 2470)
@@ -26,8 +26,8 @@
 class CameraBehaviorWheelChase : public CameraBehavior
 {
 public:
-       void activate();
-       void deactivate();
+       void activate(cameraContext_t &ctx);
+       void deactivate(cameraContext_t &ctx);
 
        void update(cameraContext_t &ctx);
 

Modified: trunk/source/main/gfx/camera/CameraManager.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraManager.cpp      2012-03-15 22:03:08 UTC 
(rev 2469)
+++ trunk/source/main/gfx/camera/CameraManager.cpp      2012-03-16 06:46:40 UTC 
(rev 2470)
@@ -51,11 +51,7 @@
        cameramode=CAMERA_EXT;
        mMoveScale = 0.0f;
        mRotScale = 0.0f;
-       //camIdealPosition = Vector3::ZERO;
        lastPosition = Vector3::ZERO;
-       //camRotX=0;
-       //camRotY=Degree(12);
-       //camDist=20;
        camCollided=false;
        camPosColl=Vector3::ZERO;
        mSceneDetailIndex = 0;
@@ -72,10 +68,11 @@
                mDOF->setEnabled(true);
        }
 
-       //createGlobalBehaviors();
+       createGlobalBehaviors();
+       ctx.cam              = mCamera;
 
-       //currentBehavior = globalBehaviors[CAMBEHAVIOR_FREE];
-       currentBehavior = new 
CameraBehaviorWheelChase();//CameraBehaviorVehicleOrbit();
+
+       switchBehavior(CAMBEHAVIOR_FREE);
 }
 
 CameraManager::~CameraManager()
@@ -86,6 +83,9 @@
 void CameraManager::createGlobalBehaviors()
 {
        globalBehaviors.insert( std::pair<int, 
CameraBehavior*>(CAMBEHAVIOR_FREE, new CameraBehaviorFree()) );
+       globalBehaviors.insert( std::pair<int, 
CameraBehavior*>(CAMBEHAVIOR_CHARACTER_ORBIT, new 
CameraBehaviorCharacterOrbit()) );
+       globalBehaviors.insert( std::pair<int, 
CameraBehavior*>(CAMBEHAVIOR_VEHICLE_ORBIT, new CameraBehaviorVehicleOrbit()) );
+       globalBehaviors.insert( std::pair<int, 
CameraBehavior*>(CAMBEHAVIOR_VEHICLE_WHEELCHASE, new 
CameraBehaviorWheelChase()) );
 }
 
 void CameraManager::updateInput()
@@ -231,6 +231,21 @@
 #endif // 0
 }
 
+void CameraManager::switchBehavior(int newBehavior)
+{
+       if(globalBehaviors.find(newBehavior) == globalBehaviors.end()) return;
+
+       // deactivate old
+       if(currentBehavior)
+               currentBehavior->deactivate(ctx);
+
+       // set new
+       currentBehavior = globalBehaviors[newBehavior];
+
+       // activate new
+       currentBehavior->activate(ctx);
+}
+
 void CameraManager::update(float dt)
 {
 
@@ -239,10 +254,6 @@
        {
                mMoveScale = 1;
                mRotScale = 0.1;
-
-               // HACKKK
-               if(currentBehavior)
-                       currentBehavior->activate();
        }
        // Otherwise scale movement units by time passed since last frame
        else
@@ -257,11 +268,9 @@
        if (SceneMouse::getSingleton().isMouseGrabbed()) return; //freeze camera
 #endif //MYGUI
 
-       cameraContext_t ctx;
        ctx.dt               = dt;
        ctx.translationScale = mMoveScale;
        ctx.rotationScale    = Ogre::Degree(mRotScale);
-       ctx.cam              = mCamera;
 
        if(!currentBehavior->allowInteraction())
        {
@@ -283,7 +292,7 @@
                }
        }
 
-       // hacky hack
+       // update current behavior
        if(currentBehavior)
                currentBehavior->update(ctx);
 

Modified: trunk/source/main/gfx/camera/CameraManager.h
===================================================================
--- trunk/source/main/gfx/camera/CameraManager.h        2012-03-15 22:03:08 UTC 
(rev 2469)
+++ trunk/source/main/gfx/camera/CameraManager.h        2012-03-16 06:46:40 UTC 
(rev 2470)
@@ -52,10 +52,16 @@
        DOFManager *mDOF;
        bool enforceCameraFOVUpdate;
        Ogre::Vector3 cdoppler;
+       cameraContext_t ctx;
 
        CameraBehavior *currentBehavior;
 
-       enum { CAMBEHAVIOR_FREE, CAMBEHAVIOR_TRUCK_EXT };
+       enum {   CAMBEHAVIOR_FREE
+                  , CAMBEHAVIOR_CHARACTER_ORBIT
+                  , CAMBEHAVIOR_VEHICLE_ORBIT
+                  , CAMBEHAVIOR_VEHICLE_WHEELCHASE
+                  , CAMBEHAVIOR_END
+       };
 
        std::map <int , CameraBehavior *> globalBehaviors;
 
@@ -68,6 +74,7 @@
        ~CameraManager();
 
        void updateInput();
+       void switchBehavior(int newBehavior);
 
        enum { CAMERA_EXT=0,
                CAMERA_FIX,

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Rigsofrods-devel mailing list
Rigsofrods-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to