Revision: 2753
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2753&view=rev
Author:   ulteq
Date:     2012-05-29 04:18:01 +0000 (Tue, 29 May 2012)
Log Message:
-----------
implemented CameraBehaviorSpline

Modified Paths:
--------------
    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.h

Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.h 2012-05-29 
03:31:49 UTC (rev 2752)
+++ trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.h 2012-05-29 
04:18:01 UTC (rev 2753)
@@ -42,6 +42,7 @@
 
        Beam *currTruck;
        int lastCineCam;
+
        static const int DEFAULT_INTERNAL_CAM_PITCH = -15;
 };
 

Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp        
2012-05-29 03:31:49 UTC (rev 2752)
+++ trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp        
2012-05-29 04:18:01 UTC (rev 2753)
@@ -31,6 +31,8 @@
        , myManualObject(0)
        , mySceneNode(0)
        , spline(new SimpleSpline())
+       , splineClosed(false)
+       , splineLength(1.0f)
        , splinePos(0.5f)
 {
 }
@@ -38,31 +40,85 @@
 void CameraBehaviorVehicleSpline::update(const CameraManager::cameraContext_t 
&ctx)
 {
        Vector3 dir = 
(ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameranodepos[0]].smoothpos
-                                - 
ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameranodedir[0]].smoothpos).normalisedCopy();
+               - 
ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameranodedir[0]].smoothpos).normalisedCopy();
 
-       targetDirection = -atan2(dir.dotProduct(Vector3::UNIT_X), 
dir.dotProduct(-Vector3::UNIT_Z));
-       targetPitch     = 0.0f;
+       targetPitch = 0.0f;
 
-       camRatio = 1.0f / (ctx.mCurrTruck->tdt * 4.0f);
+       if ( camPitching )
+       {
+               targetPitch = -asin(dir.dotProduct(Vector3::UNIT_Y));
+       }
 
        if ( ctx.mCurrTruck->free_camerarail > 0 )
        {
-               spline->clear();
-               for (int i = 0; i < ctx.mCurrTruck->free_camerarail; i++)
+               updateSpline();
+               updateSplineDisplay();
+
+               camLookAt = spline->interpolate(splinePos);
+
+               if ( !INPUTENGINE.isKeyDown(OIS::KC_SPACE) )
                {
-                       
spline->addPoint(ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameraRail[i]].AbsPosition);
+                       Vector3 centerDir = ctx.mCurrTruck->getPosition() - 
camLookAt;
+                       if ( centerDir.length() > 1.0f )
+                       {
+                               centerDir.normalise();
+                               targetDirection = 
-atan2(centerDir.dotProduct(Vector3::UNIT_X), 
centerDir.dotProduct(-Vector3::UNIT_Z));
+                       } else
+                       {
+                               targetDirection = 
-atan2(dir.dotProduct(Vector3::UNIT_X), dir.dotProduct(-Vector3::UNIT_Z));
+                       }
                }
+       }
 
-               updateSplineDisplay();
+       CameraBehaviorOrbit::update(ctx);
+}
 
-               camLookAt = spline->interpolate(splinePos);
+bool CameraBehaviorVehicleSpline::mouseMoved(const 
CameraManager::cameraContext_t &ctx, const OIS::MouseEvent& _arg)
+{
+       const OIS::MouseState ms = _arg.state;
+
+       if ( INPUTENGINE.isKeyDown(OIS::KC_LCONTROL) && 
ms.buttonDown(OIS::MB_Right) )
+       {
+               if ( INPUTENGINE.isKeyDown(OIS::KC_LMENU) )
+               {
+                       splinePos += ms.X.rel * std::max(0.0001f, splineLength 
* 0.0000001f);
+               } else
+               {
+                       splinePos += ms.X.rel * std::max(0.00005f, splineLength 
* 0.0000005f);
+               }
+               
+               if ( ms.X.rel > 0 && splinePos > 0.99f )
+               {
+                       if ( splineClosed )
+                       {
+                               splinePos -= 1.0f;
+                       } else
+                       {
+                               // u - turn
+                       }
+               } else if ( ms.X.rel < 0 && splinePos < 0.01f )
+               {
+                       if ( splineClosed )
+                       {
+                               splinePos += 1.0f;
+                       } else
+                       {
+                               // u - turn
+                       }
+               }
+
+               splinePos  = std::max(0.0f, splinePos);
+               splinePos  = std::min(splinePos, 1.0f);
+
+               camRatio = 0.0f;
+
+               return true;
        } else
        {
-               // fallback :-/
-               camLookAt = ctx.mCurrTruck->getPosition();
+               camRatio = 5.0f;
+
+               return CameraBehaviorOrbit::mouseMoved(ctx, _arg);
        }
-
-       CameraBehaviorOrbit::update(ctx);
 }
 
 void CameraBehaviorVehicleSpline::activate(const 
CameraManager::cameraContext_t &ctx, bool reset /* = true */)
@@ -71,8 +127,68 @@
        {
                CameraManager::getSingleton().switchToNextBehavior();
                return;
+       } else if ( reset )
+       {
+               this->reset(ctx);
        }
+}
 
+void CameraBehaviorVehicleSpline::reset(const CameraManager::cameraContext_t 
&ctx)
+{
+       CameraBehaviorOrbit::reset(ctx);
+
+       camDist = std::min(ctx.mCurrTruck->getMinimalCameraRadius() * 2.0f, 
20.0f);
+       
+       splineClosed = false;
+       splineLength = 1.0f;
+       splinePos = 0.5f;
+
+       spline->clear();
+       splineNodes.clear();
+
+       for (int i = 0; i < ctx.mCurrTruck->free_camerarail; i++)
+       {
+               
spline->addPoint(ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameraRail[i]].AbsPosition);
+               
splineNodes.push_back(&ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameraRail[i]]);
+       }
+
+       std::list<Beam*> linkedBeams = ctx.mCurrTruck->getAllLinkedBeams();
+
+       if (linkedBeams.size() > 0)
+       {
+               for (std::list<Beam*>::iterator it = linkedBeams.begin(); it != 
linkedBeams.end(); ++it)
+               {
+                       if ( (*it)->free_camerarail <= 0 ) break;
+
+                       Vector3 lastPoint = 
spline->getPoint(spline->getNumPoints() - 1);
+                       Vector3 firstPoint = 
(*it)->nodes[(*it)->cameraRail[0]].AbsPosition;
+                       Vector3 secondPoint = 
(*it)->nodes[(*it)->cameraRail[1]].AbsPosition;
+
+                       if ( firstPoint.distance(lastPoint) > 5.0f ) break;
+
+                       for (int i = 1; i < (*it)->free_camerarail; i++)
+                       {
+                               
spline->addPoint((*it)->nodes[(*it)->cameraRail[i]].AbsPosition);
+                               
splineNodes.push_back(&(*it)->nodes[(*it)->cameraRail[i]]);
+                       }
+               }
+
+               Vector3 firstPoint = spline->getPoint(0);
+               Vector3 lastPoint  = spline->getPoint(spline->getNumPoints() - 
1);
+
+               if ( firstPoint.distance(lastPoint) < 1.0f )
+               {
+                       splineClosed = true;
+               }
+       }
+
+       for (int i = 1; i < spline->getNumPoints(); i++)
+       {
+               splineLength += spline->getPoint(i - 
1).distance(spline->getPoint(i));
+       }
+
+       splineLength /= 2.0f;
+
        if ( !myManualObject )
        {
                myManualObject = gEnv->sceneManager->createManualObject();
@@ -89,19 +205,11 @@
        }
 }
 
-bool CameraBehaviorVehicleSpline::mouseMoved(const 
CameraManager::cameraContext_t &ctx, const OIS::MouseEvent& _arg)
+void CameraBehaviorVehicleSpline::updateSpline()
 {
-       const OIS::MouseState ms = _arg.state;
-
-       if ( INPUTENGINE.isKeyDown(OIS::KC_LCONTROL) && 
ms.buttonDown(OIS::MB_Right) )
+       for (int i = 0; i < spline->getNumPoints(); i++)
        {
-               splinePos += ms.X.rel * 0.001f;
-               splinePos  = std::max(0.0f, splinePos);
-               splinePos  = std::min(splinePos, 1.0f);
-               return true;
-       } else
-       {
-               return CameraBehaviorOrbit::mouseMoved(ctx, _arg);
+               spline->updatePoint(i, splineNodes[i]->AbsPosition);
        }
 }
 

Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h  2012-05-29 
03:31:49 UTC (rev 2752)
+++ trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h  2012-05-29 
04:18:01 UTC (rev 2753)
@@ -35,17 +35,23 @@
        bool mouseMoved(const CameraManager::cameraContext_t &ctx, const 
OIS::MouseEvent& _arg);
 
        void activate(const CameraManager::cameraContext_t &ctx, bool reset = 
true);
+       void reset(const CameraManager::cameraContext_t &ctx);
 
-
+       void updateSpline();
        void updateSplineDisplay();
 
 protected:
 
-       Ogre::ManualObject *myManualObject;
+       Ogre::ManualObject* myManualObject;
        Ogre::SceneNode* mySceneNode;
-       Ogre::SimpleSpline *spline;
-       float splinePos;
-       static const int splineDrawResolution = 20;
+       Ogre::SimpleSpline* spline;
+       Ogre::Real splineLength;
+       Ogre::Real splinePos;
+       bool splineClosed;
+
+       std::vector<node*> splineNodes;
+
+       static const int splineDrawResolution = 200;
 };
 
 #endif // __CAMERA_BEHAVIOR_VEHICLE_SPLINE_H_

Modified: trunk/source/main/gfx/camera/CameraManager.h
===================================================================
--- trunk/source/main/gfx/camera/CameraManager.h        2012-05-29 03:31:49 UTC 
(rev 2752)
+++ trunk/source/main/gfx/camera/CameraManager.h        2012-05-29 04:18:01 UTC 
(rev 2753)
@@ -17,8 +17,8 @@
 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_MODE_H_
-#define __CAMERA_MODE_H_
+#ifndef __CAMERA_MANAGER_H_
+#define __CAMERA_MANAGER_H_
 
 #include "RoRPrerequisites.h"
 
@@ -90,4 +90,4 @@
        bool mouseReleased(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id);
 };
 
-#endif // __CAMERA_MODE_H_
+#endif // __CAMERA_MANAGER_H_

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