Revision: 2472
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2472&view=rev
Author:   rorthomas
Date:     2012-03-16 10:44:54 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
working on new camera system

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

Added Paths:
-----------
    trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp
    trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h

Modified: trunk/source/main/gfx/camera/CameraBehavior.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehavior.h       2012-03-16 09:35:24 UTC 
(rev 2471)
+++ trunk/source/main/gfx/camera/CameraBehavior.h       2012-03-16 10:44:54 UTC 
(rev 2472)
@@ -28,6 +28,7 @@
        Ogre::Degree rotationScale;
        float translationScale;
        Ogre::Camera *cam;
+       Ogre::SceneManager *scm;
 } cameraContext_t;
 
 class CameraBehavior

Added: trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp                
                (rev 0)
+++ trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp        
2012-03-16 10:44:54 UTC (rev 2472)
@@ -0,0 +1,103 @@
+/*
+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/>.
+*/
+#include "CameraBehaviorVehicleSpline.h"
+
+#include <Ogre.h>
+#include "CameraManager.h"
+#include "Console.h"
+#include "InputEngine.h"
+#include "language.h"
+#include "Settings.h"
+
+#include "BeamFactory.h"
+
+using namespace Ogre;
+
+CameraBehaviorVehicleSpline::CameraBehaviorVehicleSpline() :
+         splinePos(0)
+       , myManualObject(0)
+       , myManualObjectNode(0)
+       , spline(new SimpleSpline())
+{
+}
+
+void CameraBehaviorVehicleSpline::activate(cameraContext_t &ctx)
+{
+       if(!myManualObject)
+       {
+               myManualObject =  ctx.scm->createManualObject();
+               myManualObjectNode = 
ctx.scm->getRootSceneNode()->createChildSceneNode();
+
+               myManualObject->begin("tracks/transred", 
Ogre::RenderOperation::OT_LINE_STRIP);
+               for(int i=0; i < splineDrawResolution; i++)
+                       myManualObject->position(0, 0, 0);
+               myManualObject->end();
+
+               myManualObjectNode->attachObject(myManualObject);
+       }
+
+}
+
+void CameraBehaviorVehicleSpline::updateSplineDisplay()
+{
+       myManualObject->beginUpdate(0);
+       for(int i = 0; i < splineDrawResolution; i++)
+       {
+               float pos1d = i/(float)splineDrawResolution;
+               Vector3 pos3d = spline->interpolate(pos1d);
+               //printf(">pos3d> %d >%f,%f,%f\n", i, pos3d.x, pos3d.y, 
pos3d.z);
+               myManualObject->position(pos3d);
+
+       }
+       myManualObject->end();
+}
+
+void CameraBehaviorVehicleSpline::update(cameraContext_t &ctx)
+{
+       Beam *curr_truck = BeamFactory::getSingleton().getCurrentTruck();
+       if(!curr_truck) return;
+
+       // create a simple spline
+       float x = curr_truck->minx + (curr_truck->maxx - curr_truck->minx) * 
0.5f;
+       float y = curr_truck->miny + (curr_truck->maxy - curr_truck->miny) * 
0.5f;
+
+       Vector3 pos1 = Vector3(x, y, curr_truck->minz);
+       Vector3 pos2 = pos1+Vector3(10,0,0); //Vector3(x, y, curr_truck->maxz);
+       Vector3 pos3 = pos2+Vector3(-10,10,0); //Vector3(x, y, 
curr_truck->maxz);
+
+       spline->clear();
+       spline->addPoint(pos1);
+       spline->addPoint(pos2);
+       spline->addPoint(pos3);
+
+       updateSplineDisplay();
+
+       // Make all the changes to the camera
+       Vector3 dir = curr_truck->nodes[curr_truck->cameranodepos[0]].smoothpos 
- curr_truck->nodes[curr_truck->cameranodedir[0]].smoothpos;
+       dir.normalise();
+       targetDirection = -atan2(dir.dotProduct(Vector3::UNIT_X), 
dir.dotProduct(-Vector3::UNIT_Z));
+       targetPitch = 0;
+
+       camRatio = 1.0f / (curr_truck->tdt * 4.0f);
+
+       camCenterPoint = curr_truck->getPosition();
+
+       CameraBehaviorOrbit::update(ctx);
+}

Added: trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h
===================================================================
--- trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h                  
        (rev 0)
+++ trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h  2012-03-16 
10:44:54 UTC (rev 2472)
@@ -0,0 +1,46 @@
+/*
+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 CAMERABEHAVIORVEHICLESPLINE_H__
+#define CAMERABEHAVIORVEHICLESPLINE_H__
+
+#include "RoRPrerequisites.h"
+#include "CameraBehaviorOrbit.h"
+
+class CameraBehaviorVehicleSpline : public CameraBehaviorOrbit
+{
+protected:
+       float splinePos;
+       Ogre::ManualObject *myManualObject;
+       Ogre::SceneNode* myManualObjectNode;
+       Ogre::SimpleSpline *spline;
+       static const int splineDrawResolution = 20;
+
+public:
+       CameraBehaviorVehicleSpline();
+
+       void activate(cameraContext_t &ctx);
+       void update(cameraContext_t &ctx);
+
+       void updateSplineDisplay();
+};
+
+#endif // CAMERABEHAVIORVEHICLESPLINE_H__
+
+

Modified: trunk/source/main/gfx/camera/CameraManager.cpp
===================================================================
--- trunk/source/main/gfx/camera/CameraManager.cpp      2012-03-16 09:35:24 UTC 
(rev 2471)
+++ trunk/source/main/gfx/camera/CameraManager.cpp      2012-03-16 10:44:54 UTC 
(rev 2472)
@@ -33,6 +33,7 @@
 #include "CameraBehaviorCharacterOrbit.h"
 #include "CameraBehaviorVehicleOrbit.h"
 #include "CameraBehaviorWheelChase.h"
+#include "CameraBehaviorVehicleSpline.h"
 
 #include "RoRFrameListener.h"
 
@@ -69,10 +70,12 @@
        }
 
        createGlobalBehaviors();
-       ctx.cam              = mCamera;
+       ctx.cam = mCamera;
+       ctx.scm = mSceneMgr;
 
 
-       switchBehavior(CAMBEHAVIOR_CHARACTER_ORBIT);
+       //switchBehavior(CAMBEHAVIOR_CHARACTER_ORBIT);
+       switchBehavior(CAMBEHAVIOR_VEHICLE_SPLINE);
 }
 
 CameraManager::~CameraManager()
@@ -86,6 +89,8 @@
        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()) );
+       globalBehaviors.insert( std::pair<int, 
CameraBehavior*>(CAMBEHAVIOR_VEHICLE_SPLINE, new CameraBehaviorVehicleSpline()) 
);
+
 }
 
 void CameraManager::updateInput()

Modified: trunk/source/main/gfx/camera/CameraManager.h
===================================================================
--- trunk/source/main/gfx/camera/CameraManager.h        2012-03-16 09:35:24 UTC 
(rev 2471)
+++ trunk/source/main/gfx/camera/CameraManager.h        2012-03-16 10:44:54 UTC 
(rev 2472)
@@ -60,6 +60,7 @@
                   , CAMBEHAVIOR_CHARACTER_ORBIT
                   , CAMBEHAVIOR_VEHICLE_ORBIT
                   , CAMBEHAVIOR_VEHICLE_WHEELCHASE
+                  , CAMBEHAVIOR_VEHICLE_SPLINE
                   , CAMBEHAVIOR_END
        };
 

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