Revision: 2550
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2550&view=rev
Author:   ulteq
Date:     2012-05-13 10:03:30 +0000 (Sun, 13 May 2012)
Log Message:
-----------
-Codechange: CameraSystem WIP (functional)

Modified Paths:
--------------
    trunk/source/main/gameplay/RoRFrameListener.cpp
    trunk/source/main/gfx/camera/CameraBehaviorCharacter.cpp
    trunk/source/main/gfx/camera/CameraBehaviorCharacter.h
    trunk/source/main/gfx/camera/CameraBehaviorFixed.cpp
    trunk/source/main/gfx/camera/CameraBehaviorFree.cpp
    trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp
    trunk/source/main/gfx/camera/CameraBehaviorOrbit.h
    trunk/source/main/gfx/camera/CameraBehaviorVehicle.cpp
    trunk/source/main/gfx/camera/CameraBehaviorVehicle.h
    trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp
    trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.h
    trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp
    trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h
    trunk/source/main/gfx/camera/CameraManager.cpp
    trunk/source/main/gfx/camera/CameraManager.h
    trunk/source/main/physics/Beam.cpp

Modified: trunk/source/main/gameplay/RoRFrameListener.cpp
===================================================================
--- trunk/source/main/gameplay/RoRFrameListener.cpp     2012-05-13 06:19:27 UTC 
(rev 2549)
+++ trunk/source/main/gameplay/RoRFrameListener.cpp     2012-05-13 10:03:30 UTC 
(rev 2550)
@@ -2115,7 +2115,7 @@
 
        if (loading_state==ALL_LOADED)
        {
-               if (CameraManager::getSingleton().getCameraMode() != 
CameraManager::CAMERA_FREE)
+               if (CameraManager::getSingleton().getCameraMode() != 
CameraManager::CAMERA_BEHAVIOR_FREE)
                {
                        if (!curr_truck)
                        {
@@ -3041,7 +3041,7 @@
                                if (mapMode==0)
                                {
                                        bigMap->setVisibility(true);
-                                       if 
(CameraManager::getSingleton().getCameraMode() != 
CameraManager::CAMERA_VEHICLE_CINECAM)
+                                       if 
(CameraManager::getSingleton().getCameraMode() != 
CameraManager::CAMERA_BEHAVIOR_VEHICLE_CINECAM)
                                        {
                                                //make it small again
                                                
bigMap->updateRenderMetrics(mWindow);
@@ -5119,7 +5119,7 @@
 
 void RoRFrameListener::changedCurrentTruck(Beam *previousTruck, Beam 
*currentTruck)
 {
-       if (CameraManager::getSingleton().getCameraMode() == 
CameraManager::CAMERA_FREE) return;
+       if (CameraManager::getSingleton().getCameraMode() == 
CameraManager::CAMERA_BEHAVIOR_FREE) return;
 
        // hide any old dashes
        if (previousTruck && previousTruck->dash)
@@ -5667,7 +5667,7 @@
        }
        else
        {
-               if (curr_truck && CameraManager::getSingleton().getCameraMode() 
!= CameraManager::CAMERA_VEHICLE_CINECAM)
+               if (curr_truck && CameraManager::getSingleton().getCameraMode() 
!= CameraManager::CAMERA_BEHAVIOR_VEHICLE_CINECAM)
                {
                        if (ow) ow->showDashboardOverlays(true, curr_truck);
                        //if (bigMap) bigMap->setVisibility(true);

Modified: trunk/source/main/gfx/camera/CameraBehaviorCharacter.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorCharacter.cpp    2012-05-13 
06:19:27 UTC (rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorCharacter.cpp    2012-05-13 
10:03:30 UTC (rev 2550)
@@ -23,12 +23,41 @@
 
 using namespace Ogre;
 
+CameraBehaviorCharacter::CameraBehaviorCharacter() :
+         camMode(THIRD_PERSON)
+{
+}
+
 void CameraBehaviorCharacter::update(const CameraManager::cameraContext_t &ctx)
 {
        Character *person = ctx.mEfl->person;
 
        targetDirection   = -person->getAngle() - Math::HALF_PI;
-       camCenterPosition =  person->getPosition() + Vector3(0.0f, 1.1f, 0.0f);
 
+       if ( camMode == FIRST_PERSON )
+       {
+               camRotY = 0.1f;
+               camRatio = 0.0f;
+               maxCamDist = 0.2f;
+               camCenterPosition =  person->getPosition() + Vector3(0.1f, 
1.82f, 0.0f);
+       } else if ( camMode == THIRD_PERSON )
+       {
+               camRotY = 0.3f;
+               camDist = 5.0f;
+               camRatio = 11.0f;
+               minCamDist = 3.0f;
+               maxCamDist = 6.0f;
+               camCenterPosition =  person->getPosition() + Vector3(0.0f, 
1.1f, 0.0f);
+       }
+
        CameraBehaviorOrbit::update(ctx);
 }
+
+// TODO: First-person mouse interaction
+
+bool CameraBehaviorCharacter::switchBehavior(const 
CameraManager::cameraContext_t &ctx)
+{
+       camMode = !camMode;
+
+       return false;
+}
\ No newline at end of file

Modified: trunk/source/main/gfx/camera/CameraBehaviorCharacter.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorCharacter.h      2012-05-13 
06:19:27 UTC (rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorCharacter.h      2012-05-13 
10:03:30 UTC (rev 2550)
@@ -1,34 +1,47 @@
-/*
-This source file is part of Rigs of Rods
-Copyright 2005-2012 Pierre-Michel Ricordel
-Copyright 2007-2012 Thomas Fischer
-
-For more information, see http://www.rigsofrods.com/
-
-Rigs of Rods is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License version 3, as
-published by the Free Software Foundation.
-
-Rigs of Rods is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#ifndef __CAMERA_BEHAVIOR_CHARACTER_ORBIT_H_
-#define __CAMERA_BEHAVIOR_CHARACTER_ORBIT_H_
-
-#include "RoRPrerequisites.h"
-
-#include "CameraBehaviorOrbit.h"
-
-class CameraBehaviorCharacter : public CameraBehaviorOrbit
-{
-public:
-
-       void update(const CameraManager::cameraContext_t &ctx);
-};
-
-#endif // __CAMERA_BEHAVIOR_CHARACTER_ORBIT_H_
+/*
+This source file is part of Rigs of Rods
+Copyright 2005-2012 Pierre-Michel Ricordel
+Copyright 2007-2012 Thomas Fischer
+
+For more information, see http://www.rigsofrods.com/
+
+Rigs of Rods is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 3, as
+published by the Free Software Foundation.
+
+Rigs of Rods is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef __CAMERA_BEHAVIOR_CHARACTER_ORBIT_H_
+#define __CAMERA_BEHAVIOR_CHARACTER_ORBIT_H_
+
+#include "RoRPrerequisites.h"
+
+#include "CameraBehaviorOrbit.h"
+
+class CameraBehaviorCharacter : public CameraBehaviorOrbit
+{
+public:
+
+       CameraBehaviorCharacter();
+
+       void update(const CameraManager::cameraContext_t &ctx);
+
+       bool switchBehavior(const CameraManager::cameraContext_t &ctx);
+
+protected:
+
+       enum CameraModes {
+               FIRST_PERSON=0,
+               THIRD_PERSON=1
+       };
+
+       bool camMode;
+};
+
+#endif // __CAMERA_BEHAVIOR_CHARACTER_ORBIT_H_

Modified: trunk/source/main/gfx/camera/CameraBehaviorFixed.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorFixed.cpp        2012-05-13 
06:19:27 UTC (rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorFixed.cpp        2012-05-13 
10:03:30 UTC (rev 2550)
@@ -23,4 +23,5 @@
 
 void CameraBehaviorFixed::update(const CameraManager::cameraContext_t &ctx)
 {
+       // TODO
 }

Modified: trunk/source/main/gfx/camera/CameraBehaviorFree.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorFree.cpp 2012-05-13 06:19:27 UTC 
(rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorFree.cpp 2012-05-13 10:03:30 UTC 
(rev 2550)
@@ -30,11 +30,6 @@
 
 void CameraBehaviorFree::activate(const CameraManager::cameraContext_t &ctx)
 {
-       if ( ctx.mDOF )
-       {
-               ctx.mDOF->setFocusMode(DOFManager::Auto);
-       }
-
        ctx.mCamera->setFixedYawAxis(true, Vector3::UNIT_Y);
 
        LOG("entering free camera mode");
@@ -48,11 +43,6 @@
 
 void CameraBehaviorFree::deactivate(const CameraManager::cameraContext_t &ctx)
 {
-       if ( ctx.mDOF)
-       {
-               ctx.mDOF->setFocusMode(DOFManager::Manual);
-       }
-
        LOG("exiting free camera mode");
 
        CONSOLE_PUTMESSAGE(Console::CONSOLE_MSGTYPE_INFO, 
Console::CONSOLE_SYSTEM_NOTICE, _L("normal camera"), "camera.png", 3000, false);

Modified: trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp        2012-05-13 
06:19:27 UTC (rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp        2012-05-13 
10:03:30 UTC (rev 2550)
@@ -28,9 +28,10 @@
 
 CameraBehaviorOrbit::CameraBehaviorOrbit() :
          camRotX(0.0f)
-       , camRotY(0.6f)
+       , camRotY(0.3f)
        , camDist(5.0f)
        , minCamDist(3.0f)
+       , maxCamDist(6.0f)
        , camRatio(11.0f)
        , camIdealPosition(Vector3::ZERO)
        , camCenterPosition(Vector3::ZERO)
@@ -42,17 +43,7 @@
 
 void CameraBehaviorOrbit::activate(const CameraManager::cameraContext_t &ctx)
 {
-#if 0
-       float fov = FSETTING("FOV External", 60);
-
-       if ( ctx.mDOF )
-       {
-               ctx.mDOF->setFocusMode(DOFManager::Manual);
-               ctx.mDOF->setLensFOV(Degree(fov));
-       }
-
        camCenterPosition = Vector3(0.0f, 3.0f, 0.0f);
-#endif
 }
 
 void CameraBehaviorOrbit::deactivate(const CameraManager::cameraContext_t &ctx)
@@ -118,9 +109,9 @@
                camDist = 20;
        }
 
-       // set minimum distance
-       camDist = std::max(camDist, minCamDist);
-       
+       camDist = std::max(minCamDist, camDist);
+       camDist = std::min(camDist, maxCamDist);
+
        camIdealPosition = camDist * 0.5f * Vector3( \
                          sin(targetDirection + camRotX.valueRadians()) * 
cos(targetPitch + camRotY.valueRadians()) \
                        , sin(targetPitch     + camRotY.valueRadians()) \
@@ -134,18 +125,12 @@
 
        ctx.mCamera->setPosition(newPosition);
        ctx.mCamera->lookAt(camCenterPosition);
-
-       if ( ctx.mDOF )
-       {
-               ctx.mDOF->setFocusMode(DOFManager::Manual);
-               ctx.mDOF->setLensFOV(Degree(real_camdist));
-       }
 }
 
 bool CameraBehaviorOrbit::mouseMoved(const OIS::MouseEvent& _arg)
 {
        const OIS::MouseState ms = _arg.state;
-       if(ms.buttonDown(OIS::MB_Right))
+       if ( ms.buttonDown(OIS::MB_Right) )
        {
                camRotX += Degree( (float)ms.X.rel * 0.13f);
                camRotY += Degree(-(float)ms.Y.rel * 0.13f);

Modified: trunk/source/main/gfx/camera/CameraBehaviorOrbit.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorOrbit.h  2012-05-13 06:19:27 UTC 
(rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorOrbit.h  2012-05-13 10:03:30 UTC 
(rev 2550)
@@ -28,8 +28,6 @@
 {
 public:
 
-       CameraBehaviorOrbit();
-
        void update(const CameraManager::cameraContext_t &ctx);
 
        bool mouseMoved(const OIS::MouseEvent& _arg);
@@ -43,9 +41,11 @@
 
 protected:
 
+       CameraBehaviorOrbit();
+
        Ogre::Radian camRotX, camRotY;
        Ogre::Vector3 camIdealPosition, camCenterPosition, camTranslation;
-       float camDist, minCamDist, camRatio;
+       float camDist, minCamDist, maxCamDist, camRatio;
        float targetDirection, targetPitch;
 };
 

Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicle.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorVehicle.cpp      2012-05-13 
06:19:27 UTC (rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorVehicle.cpp      2012-05-13 
10:03:30 UTC (rev 2550)
@@ -25,12 +25,14 @@
 using namespace Ogre;
 
 CameraBehaviorVehicle::CameraBehaviorVehicle() :
-       externalCameraMode(false)
+         camPitching(true)
 {
+       camRotY = 0.6f;
        minCamDist = 8.0f;
+       maxCamDist = 20.0f;
 
-       if (SSETTING("External Camera Mode", "Pitching") == "Static")
-               externalCameraMode = true;
+       if ( SSETTING("External Camera Mode", "Pitching") == "Static" )
+               camPitching = false;
 }
 
 void CameraBehaviorVehicle::update(const CameraManager::cameraContext_t &ctx)
@@ -41,7 +43,7 @@
        targetDirection = -atan2(dir.dotProduct(Vector3::UNIT_X), 
dir.dotProduct(-Vector3::UNIT_Z));
        targetPitch     = 0.0f;
 
-       if(!externalCameraMode)
+       if ( camPitching )
        {
                targetPitch = -asin(dir.dotProduct(Vector3::UNIT_Y));
        }
@@ -49,4 +51,6 @@
        camRatio = 1.0f / (ctx.mCurrTruck->tdt * 5.0f);
 
        camCenterPosition = ctx.mCurrTruck->getPosition();
+
+       CameraBehaviorOrbit::update(ctx);
 }

Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicle.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorVehicle.h        2012-05-13 
06:19:27 UTC (rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorVehicle.h        2012-05-13 
10:03:30 UTC (rev 2550)
@@ -34,7 +34,7 @@
 
 protected:
 
-       bool externalCameraMode;
+       bool camPitching;
 };
 
 #endif // __CAMERA_BEHAVIOR_VEHICLE_ORBIT_H_

Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp       
2012-05-13 06:19:27 UTC (rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp       
2012-05-13 10:03:30 UTC (rev 2550)
@@ -25,30 +25,30 @@
 
 using namespace Ogre;
 
-void CameraBehaviorVehicleCineCam::activate(const 
CameraManager::cameraContext_t &ctx)
+CameraBehaviorVehicleCineCam::CameraBehaviorVehicleCineCam()
 {
-       float fov = FSETTING("FOV Internal", 75);
-
-       if ( ctx.mDOF )
-       {
-               ctx.mDOF->setFocusMode(DOFManager::Manual);
-               ctx.mDOF->setLensFOV(Degree(fov));
-       }
-
-       ctx.mCamera->setFOVy(Degree(fov));
+       camRatio = 0.0f;
 }
 
-void CameraBehaviorVehicleCineCam::deactivate(const 
CameraManager::cameraContext_t &ctx)
+bool CameraBehaviorVehicleCineCam::switchBehavior(const 
CameraManager::cameraContext_t &ctx)
 {
+       if ( ctx.mCurrTruck->currentcamera < ctx.mCurrTruck->freecinecamera-1 )
+       {
+               ctx.mCurrTruck->currentcamera++;
+
+               // TODO
+
+               return false;
+       }
+       
+       // TODO
 
-}
+       ctx.mCurrTruck->currentcamera = -1;
 
-bool CameraBehaviorVehicleCineCam::switchBehavior(const 
CameraManager::cameraContext_t &ctx)
-{
        return true;
 }
 
 void CameraBehaviorVehicleCineCam::update(const CameraManager::cameraContext_t 
&ctx)
 {
-
+       // TODO
 }

Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.h 2012-05-13 
06:19:27 UTC (rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.h 2012-05-13 
10:03:30 UTC (rev 2550)
@@ -27,12 +27,11 @@
 class CameraBehaviorVehicleCineCam : public CameraBehaviorVehicle
 {
 public:
+
+       CameraBehaviorVehicleCineCam();
        
        void update(const CameraManager::cameraContext_t &ctx);
 
-       void activate(const CameraManager::cameraContext_t &ctx);
-       void deactivate(const CameraManager::cameraContext_t &ctx);
-
        bool switchBehavior(const CameraManager::cameraContext_t &ctx);
 };
 

Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp        
2012-05-13 06:19:27 UTC (rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp        
2012-05-13 10:03:30 UTC (rev 2550)
@@ -92,9 +92,11 @@
                // fallback :-/
                camCenterPosition = ctx.mCurrTruck->getPosition();
        }
+
+       CameraBehaviorOrbit::update(ctx);
 }
 
-bool CameraBehaviorVehicleSpline::mouseMoved(const OIS::MouseEvent& _arg)
+bool CameraBehaviorVehicleSpline::mouseMoved(const OIS::MouseEvent& _arg, 
const CameraManager::cameraContext_t &ctx)
 {
        const OIS::MouseState ms = _arg.state;
 

Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h  2012-05-13 
06:19:27 UTC (rev 2549)
+++ trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h  2012-05-13 
10:03:30 UTC (rev 2550)
@@ -35,7 +35,7 @@
 
        void updateSplineDisplay();
 
-       bool mouseMoved(const OIS::MouseEvent& _arg);
+       bool mouseMoved(const OIS::MouseEvent& _arg, const 
CameraManager::cameraContext_t &ctx);
 
 protected:
 

Modified: trunk/source/main/gfx/camera/CameraManager.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraManager.cpp      2012-05-13 06:19:27 UTC 
(rev 2549)
+++ trunk/source/main/gfx/camera/CameraManager.cpp      2012-05-13 10:03:30 UTC 
(rev 2550)
@@ -59,18 +59,13 @@
        createGlobalBehaviors();
 
        ctx.mCamera = cam;
+       ctx.mCurrTruck = 0;
        ctx.mEfl = efl;
        ctx.mHfinder = hf;
        ctx.mLastPosition = Vector3::ZERO;
        ctx.mSceneMgr = scm;
-       
-       if ( BSETTING("DOF", false) )
-       {
-               ctx.mDOF = new DOFManager(scm, cam->getViewport(), 
Root::getSingletonPtr(), cam);
-               ctx.mDOF->setEnabled(true);
-       }
 
-       //switchBehavior(CAMERA_CHARACTER);
+       switchBehavior(CAMERA_BEHAVIOR_CHARACTER);
 }
 
 CameraManager::~CameraManager()
@@ -85,31 +80,35 @@
 
 void CameraManager::createGlobalBehaviors()
 {
-       globalBehaviors.insert(std::pair<int, 
ICameraBehavior*>(CAMERA_CHARACTER, new CameraBehaviorCharacter()));
-       globalBehaviors.insert(std::pair<int, 
ICameraBehavior*>(CAMERA_CHARACTER, new CameraBehaviorCharacter()));
-       globalBehaviors.insert(std::pair<int, ICameraBehavior*>(CAMERA_VEHICLE, 
new CameraBehaviorVehicle()));
-       globalBehaviors.insert(std::pair<int, 
ICameraBehavior*>(CAMERA_VEHICLE_FIXED, new CameraBehaviorFixed()));
-       globalBehaviors.insert(std::pair<int, 
ICameraBehavior*>(CAMERA_VEHICLE_SPLINE, new CameraBehaviorVehicleSpline()));
-       globalBehaviors.insert(std::pair<int, 
ICameraBehavior*>(CAMERA_VEHICLE_CINECAM, new CameraBehaviorVehicleCineCam()));
-       globalBehaviors.insert(std::pair<int, ICameraBehavior*>(CAMERA_FREE, 
new CameraBehaviorFree()));
+       globalBehaviors.insert(std::pair<int, 
ICameraBehavior*>(CAMERA_BEHAVIOR_CHARACTER, new CameraBehaviorCharacter()));
+       globalBehaviors.insert(std::pair<int, 
ICameraBehavior*>(CAMERA_BEHAVIOR_VEHICLE, new CameraBehaviorVehicle()));
+       globalBehaviors.insert(std::pair<int, 
ICameraBehavior*>(CAMERA_BEHAVIOR_VEHICLE_FIXED, new CameraBehaviorFixed()));
+       globalBehaviors.insert(std::pair<int, 
ICameraBehavior*>(CAMERA_BEHAVIOR_VEHICLE_SPLINE, new 
CameraBehaviorVehicleSpline()));
+       globalBehaviors.insert(std::pair<int, 
ICameraBehavior*>(CAMERA_BEHAVIOR_VEHICLE_CINECAM, new 
CameraBehaviorVehicleCineCam()));
+       globalBehaviors.insert(std::pair<int, 
ICameraBehavior*>(CAMERA_BEHAVIOR_FREE, new CameraBehaviorFree()));
 }
 
 void CameraManager::switchToNextBehavior()
 {
        if ( !currentBehavior || currentBehavior->switchBehavior(ctx) )
        {
-               int i = (currentBehaviorID + 1) % CAMERA_END;
+               int i = (currentBehaviorID + 1) % CAMERA_BEHAVIOR_END;
                switchBehavior(i);
        }
 }
 
-void CameraManager::switchBehavior(int newBehavior)
+void CameraManager::switchBehavior(int newBehaviorID)
 {
-       if ( globalBehaviors.find(newBehavior) == globalBehaviors.end() )
+       if (newBehaviorID == currentBehaviorID)
        {
                return;
        }
 
+       if ( globalBehaviors.find(newBehaviorID) == globalBehaviors.end() )
+       {
+               return;
+       }
+
        // deactivate old
        if ( currentBehavior )
        {
@@ -117,8 +116,8 @@
        }
 
        // set new
-       currentBehavior = globalBehaviors[newBehavior];
-       currentBehaviorID = newBehavior;
+       currentBehavior = globalBehaviors[newBehaviorID];
+       currentBehaviorID = newBehaviorID;
 
        // activate new
        currentBehavior->activate(ctx);
@@ -144,6 +143,14 @@
        ctx.mRotScale   = Degree(mRotScale);
        ctx.mTransScale = mTransScale;
 
+       if ( !ctx.mCurrTruck && currentBehaviorID != CAMERA_BEHAVIOR_CHARACTER )
+       {
+               switchBehavior(CAMERA_BEHAVIOR_CHARACTER);
+       } else if (ctx.mCurrTruck && currentBehaviorID == 
CAMERA_BEHAVIOR_CHARACTER)
+       {
+               switchBehavior(CAMERA_BEHAVIOR_VEHICLE);
+       }
+
        if ( currentBehavior )
        {
                currentBehavior->update(ctx);
@@ -160,15 +167,18 @@
 
 bool CameraManager::mouseMoved(const OIS::MouseEvent& _arg)
 {
+       if ( !currentBehavior ) return false;
        return currentBehavior->mouseMoved(_arg);
 }
 
 bool CameraManager::mousePressed(const OIS::MouseEvent& _arg, 
OIS::MouseButtonID _id)
 {
+       if ( !currentBehavior ) return false;
        return currentBehavior->mousePressed(_arg, _id);
 }
 
 bool CameraManager::mouseReleased(const OIS::MouseEvent& _arg, 
OIS::MouseButtonID _id)
 {
+       if ( !currentBehavior ) return false;
        return currentBehavior->mouseReleased(_arg, _id);
 }
\ No newline at end of file

Modified: trunk/source/main/gfx/camera/CameraManager.h
===================================================================
--- trunk/source/main/gfx/camera/CameraManager.h        2012-05-13 06:19:27 UTC 
(rev 2549)
+++ trunk/source/main/gfx/camera/CameraManager.h        2012-05-13 10:03:30 UTC 
(rev 2550)
@@ -38,7 +38,6 @@
 
        typedef struct cameraContext {
                Beam *mCurrTruck;
-               DOFManager *mDOF;
                HeightFinder *mHfinder;
                Ogre::Camera *mCamera;
                Ogre::Degree mRotScale;
@@ -50,15 +49,15 @@
        } cameraContext_t;
 
        enum CameraBehaviors {
-               CAMERA_CHARACTER=0
-         , CAMERA_VEHICLE
-         , CAMERA_VEHICLE_FIXED
-         , CAMERA_VEHICLE_SPLINE
-         , CAMERA_VEHICLE_CINECAM
-         , CAMERA_END
-         , CAMERA_FREE
+               CAMERA_BEHAVIOR_CHARACTER=0,
+               CAMERA_BEHAVIOR_VEHICLE,
+               CAMERA_BEHAVIOR_VEHICLE_FIXED,
+               CAMERA_BEHAVIOR_VEHICLE_SPLINE,
+               CAMERA_BEHAVIOR_VEHICLE_CINECAM,
+               CAMERA_BEHAVIOR_END,
+               CAMERA_BEHAVIOR_FREE
        };
-       
+
        void update(float dt);
 
        Ogre::Camera *getCamera() { return ctx.mCamera; };

Modified: trunk/source/main/physics/Beam.cpp
===================================================================
--- trunk/source/main/physics/Beam.cpp  2012-05-13 06:19:27 UTC (rev 2549)
+++ trunk/source/main/physics/Beam.cpp  2012-05-13 10:03:30 UTC (rev 2550)
@@ -5563,7 +5563,7 @@
 
 void Beam::updateAI(float dt)
 {
-       if(driveable != TRUCK || CameraManager::getSingleton().getCameraMode() 
!= CameraManager::CAMERA_FREE)
+       if(driveable != TRUCK || CameraManager::getSingleton().getCameraMode() 
!= CameraManager::CAMERA_BEHAVIOR_FREE)
                return;
 
        // start engine if not running

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


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Rigsofrods-devel mailing list
Rigsofrods-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to