Revision: 2754 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2754&view=rev Author: ulteq Date: 2012-05-29 17:33:46 +0000 (Tue, 29 May 2012) Log Message: ----------- -Feature: continue work on spline camera behavior +automatic add/remove of spline points when hooking/unhooking ~renamed CameraBehavior to CameraBehaviorOrbit ~used gameControlsEnabled() wherever possible
Modified Paths: -------------- trunk/source/main/gameplay/Character.cpp trunk/source/main/gameplay/RoRFrameListener.cpp trunk/source/main/gfx/camera/CameraBehaviorCharacter.h trunk/source/main/gfx/camera/CameraBehaviorFixed.h trunk/source/main/gfx/camera/CameraBehaviorFree.h trunk/source/main/gfx/camera/CameraBehaviorIsometric.h trunk/source/main/gfx/camera/CameraBehaviorStatic.h trunk/source/main/gfx/camera/CameraBehaviorVehicle.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/gfx/camera/ICameraBehavior.h trunk/source/main/physics/Beam.cpp Added Paths: ----------- trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp trunk/source/main/gfx/camera/CameraBehaviorOrbit.h Removed Paths: ------------- trunk/source/main/gfx/camera/CameraBehavior.cpp trunk/source/main/gfx/camera/CameraBehavior.h Modified: trunk/source/main/gameplay/Character.cpp =================================================================== --- trunk/source/main/gameplay/Character.cpp 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gameplay/Character.cpp 2012-05-29 17:33:46 UTC (rev 2754) @@ -275,7 +275,8 @@ if (physicsEnabled && !remote) { // disable character movement when using the free camera mode or when the menu is opened - if (CameraManager::singletonExists() && !CameraManager::getSingleton().getGameControlsEnabled()) return; + // TODO: check for menu being opened + if (CameraManager::singletonExists() && !CameraManager::getSingleton().gameControlsEnabled()) return; // small hack: if not visible do not apply physics Vector3 position = mCharacterNode->getPosition(); Modified: trunk/source/main/gameplay/RoRFrameListener.cpp =================================================================== --- trunk/source/main/gameplay/RoRFrameListener.cpp 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gameplay/RoRFrameListener.cpp 2012-05-29 17:33:46 UTC (rev 2754) @@ -1517,7 +1517,7 @@ if (loading_state==ALL_LOADED || loading_state == TERRAIN_EDITOR) { - if (CameraManager::getSingleton().getGameControlsEnabled()) + if (CameraManager::singletonExists() && CameraManager::getSingleton().gameControlsEnabled()) { if (!curr_truck) { @@ -2497,7 +2497,7 @@ surveyMapMode == SURVEY_MAP_BIG && CameraManager::singletonExists() && CameraManager::getSingleton().hasActiveBehavior() && - CameraManager::getSingleton().getGameControlsEnabled()) + CameraManager::getSingleton().gameControlsEnabled()) { if (velocity > 7.5f || CameraManager::getSingleton().getCameraBehavior() == CameraManager::CAMERA_BEHAVIOR_VEHICLE_CINECAM) { Deleted: trunk/source/main/gfx/camera/CameraBehavior.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehavior.cpp 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraBehavior.cpp 2012-05-29 17:33:46 UTC (rev 2754) @@ -1,158 +0,0 @@ -/* -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 "CameraBehavior.h" - -#include "Beam.h" -#include "Collisions.h" -#include "IHeightFinder.h" -#include "InputEngine.h" -#include "Ogre.h" -#include "TerrainManager.h" - -using namespace Ogre; - -CameraBehaviorOrbit::CameraBehaviorOrbit() : - camDist(5.0f) - , camDistMax(0.0f) - , camDistMin(0.0f) - , camLookAt(Vector3::ZERO) - , camRatio(11.0f) - , camRotX(0.0f) - , camRotY(0.3f) - , targetDirection(0.0f) - , targetPitch(0.0f) -{ -} - -void CameraBehaviorOrbit::update(const CameraManager::cameraContext_t &ctx) -{ - if ( INPUTENGINE.getEventBoolValueBounce(EV_CAMERA_LOOKBACK) ) - { - if ( camRotX > Degree(0) ) - { - camRotX = Degree(0); - } else - { - camRotX = Degree(180); - } - } - - if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_LEFT) ) - { - camRotX -= ctx.mRotScale; - } - if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_RIGHT) ) - { - camRotX += ctx.mRotScale; - } - if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_UP) && camRotY < Degree(88) ) - { - camRotY += ctx.mRotScale; - } - if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_DOWN) && camRotY > Degree(-80) ) - { - camRotY -= ctx.mRotScale; - } - - if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_IN) && camDist > 1 ) - { - camDist -= ctx.mTransScale; - } - if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_IN_FAST) && camDist > 1 ) - { - camDist -= ctx.mTransScale * 10; - } - if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_OUT) ) - { - camDist += ctx.mTransScale; - } - if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_OUT_FAST) ) - { - camDist += ctx.mTransScale * 10; - } - - if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_RESET) ) - { - reset(ctx); - } - - if ( camDistMin > 0.0f ) - { - camDist = std::max(camDistMin, camDist); - } - if ( camDistMax > 0.0f ) - { - camDist = std::min(camDist, camDistMax); - } - - Vector3 desiredPosition = camLookAt + camDist * 0.5f * Vector3( - sin(targetDirection.valueRadians() + camRotX.valueRadians()) * cos(targetPitch.valueRadians() + camRotY.valueRadians()) - , sin(targetPitch.valueRadians() + camRotY.valueRadians()) - , cos(targetDirection.valueRadians() + camRotX.valueRadians()) * cos(targetPitch.valueRadians() + camRotY.valueRadians()) - ); - - if ( gEnv->terrainManager && gEnv->terrainManager->getHeightFinder() ) - { - float h = gEnv->terrainManager->getHeightFinder()->getHeightAt(desiredPosition.x, desiredPosition.z) + 1.0f; - - desiredPosition.y = std::max(h, desiredPosition.y); - } - - Vector3 precedingPosition = gEnv->mainCamera->getPosition(); - - if ( ctx.mCurrTruck ) - { - precedingPosition += ctx.mCurrTruck->nodes[0].Velocity * ctx.mCurrTruck->ttdt; - } - - Vector3 camPosition = (1.0f / (camRatio + 1.0f)) * desiredPosition + (camRatio / (camRatio + 1.0f)) * precedingPosition; - - if ( gEnv->collisions && gEnv->collisions->forcecam ) - { - gEnv->mainCamera->setPosition(gEnv->collisions->forcecampos); - gEnv->collisions->forcecam = false; - } else - { - gEnv->mainCamera->setPosition(camPosition); - } - - gEnv->mainCamera->lookAt(camLookAt); -} - -bool CameraBehaviorOrbit::mouseMoved(const CameraManager::cameraContext_t &ctx, const OIS::MouseEvent& _arg) -{ - const OIS::MouseState ms = _arg.state; - - if ( ms.buttonDown(OIS::MB_Right) ) - { - camRotX += Degree( ms.X.rel * 0.13f); - camRotY += Degree(-ms.Y.rel * 0.13f); - camDist += -ms.Z.rel * 0.02f; - return true; - } - - return false; -} - -void CameraBehaviorOrbit::reset(const CameraManager::cameraContext_t &ctx) -{ - camRotX = 0.0f; - gEnv->mainCamera->setFOVy(ctx.fovExternal); -} Deleted: trunk/source/main/gfx/camera/CameraBehavior.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehavior.h 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraBehavior.h 2012-05-29 17:33:46 UTC (rev 2754) @@ -1,51 +0,0 @@ -/* -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_ORBIT_H_ -#define __CAMERA_BEHAVIOR_ORBIT_H_ - -#include "RoRPrerequisites.h" - -#include "ICameraBehavior.h" - -class CameraBehaviorOrbit : public ICameraBehavior, public ZeroedMemoryAllocator -{ -public: - - CameraBehaviorOrbit(); - - void update(const CameraManager::cameraContext_t &ctx); - - void activate(const CameraManager::cameraContext_t &ctx, bool reset = true) {}; - void deactivate(const CameraManager::cameraContext_t &ctx) {}; - void reset(const CameraManager::cameraContext_t &ctx); - - bool mouseMoved(const CameraManager::cameraContext_t &ctx, const OIS::MouseEvent& _arg); - bool mousePressed(const CameraManager::cameraContext_t &ctx, const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) { return false; }; - bool mouseReleased(const CameraManager::cameraContext_t &ctx, const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) { return false; }; - -protected: - - Ogre::Radian camRotX, camRotY; - Ogre::Radian targetDirection, targetPitch; - Ogre::Real camDist, camDistMin, camDistMax, camRatio; - Ogre::Vector3 camLookAt; -}; - -#endif // __CAMERA_BEHAVIOR_ORBIT_H_ Modified: trunk/source/main/gfx/camera/CameraBehaviorCharacter.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorCharacter.h 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraBehaviorCharacter.h 2012-05-29 17:33:46 UTC (rev 2754) @@ -22,7 +22,7 @@ #include "RoRPrerequisites.h" -#include "CameraBehavior.h" +#include "CameraBehaviorOrbit.h" class CameraBehaviorCharacter : public CameraBehaviorOrbit { Modified: trunk/source/main/gfx/camera/CameraBehaviorFixed.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorFixed.h 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraBehaviorFixed.h 2012-05-29 17:33:46 UTC (rev 2754) @@ -24,7 +24,7 @@ #include "ICameraBehavior.h" -class CameraBehaviorFixed : public ICameraBehavior, public ZeroedMemoryAllocator +class CameraBehaviorFixed : public ICameraBehavior { public: Modified: trunk/source/main/gfx/camera/CameraBehaviorFree.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorFree.h 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraBehaviorFree.h 2012-05-29 17:33:46 UTC (rev 2754) @@ -24,7 +24,7 @@ #include "ICameraBehavior.h" -class CameraBehaviorFree : public ICameraBehavior, public ZeroedMemoryAllocator +class CameraBehaviorFree : public ICameraBehavior { public: Modified: trunk/source/main/gfx/camera/CameraBehaviorIsometric.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorIsometric.h 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraBehaviorIsometric.h 2012-05-29 17:33:46 UTC (rev 2754) @@ -24,7 +24,7 @@ #include "ICameraBehavior.h" -class CameraBehaviorIsometric : public ICameraBehavior, public ZeroedMemoryAllocator +class CameraBehaviorIsometric : public ICameraBehavior { public: Copied: trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp (from rev 2753, trunk/source/main/gfx/camera/CameraBehavior.cpp) =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp (rev 0) +++ trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp 2012-05-29 17:33:46 UTC (rev 2754) @@ -0,0 +1,158 @@ +/* +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 "CameraBehaviorOrbit.h" + +#include "Beam.h" +#include "Collisions.h" +#include "IHeightFinder.h" +#include "InputEngine.h" +#include "Ogre.h" +#include "TerrainManager.h" + +using namespace Ogre; + +CameraBehaviorOrbit::CameraBehaviorOrbit() : + camDist(5.0f) + , camDistMax(0.0f) + , camDistMin(0.0f) + , camLookAt(Vector3::ZERO) + , camRatio(11.0f) + , camRotX(0.0f) + , camRotY(0.3f) + , targetDirection(0.0f) + , targetPitch(0.0f) +{ +} + +void CameraBehaviorOrbit::update(const CameraManager::cameraContext_t &ctx) +{ + if ( INPUTENGINE.getEventBoolValueBounce(EV_CAMERA_LOOKBACK) ) + { + if ( camRotX > Degree(0) ) + { + camRotX = Degree(0); + } else + { + camRotX = Degree(180); + } + } + + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_LEFT) ) + { + camRotX -= ctx.mRotScale; + } + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_RIGHT) ) + { + camRotX += ctx.mRotScale; + } + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_UP) && camRotY < Degree(88) ) + { + camRotY += ctx.mRotScale; + } + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_DOWN) && camRotY > Degree(-80) ) + { + camRotY -= ctx.mRotScale; + } + + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_IN) && camDist > 1 ) + { + camDist -= ctx.mTransScale; + } + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_IN_FAST) && camDist > 1 ) + { + camDist -= ctx.mTransScale * 10; + } + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_OUT) ) + { + camDist += ctx.mTransScale; + } + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_OUT_FAST) ) + { + camDist += ctx.mTransScale * 10; + } + + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_RESET) ) + { + reset(ctx); + } + + if ( camDistMin > 0.0f ) + { + camDist = std::max(camDistMin, camDist); + } + if ( camDistMax > 0.0f ) + { + camDist = std::min(camDist, camDistMax); + } + + Vector3 desiredPosition = camLookAt + camDist * 0.5f * Vector3( + sin(targetDirection.valueRadians() + camRotX.valueRadians()) * cos(targetPitch.valueRadians() + camRotY.valueRadians()) + , sin(targetPitch.valueRadians() + camRotY.valueRadians()) + , cos(targetDirection.valueRadians() + camRotX.valueRadians()) * cos(targetPitch.valueRadians() + camRotY.valueRadians()) + ); + + if ( gEnv->terrainManager && gEnv->terrainManager->getHeightFinder() ) + { + float h = gEnv->terrainManager->getHeightFinder()->getHeightAt(desiredPosition.x, desiredPosition.z) + 1.0f; + + desiredPosition.y = std::max(h, desiredPosition.y); + } + + Vector3 precedingPosition = gEnv->mainCamera->getPosition(); + + if ( ctx.mCurrTruck ) + { + precedingPosition += ctx.mCurrTruck->nodes[0].Velocity * ctx.mCurrTruck->ttdt; + } + + Vector3 camPosition = (1.0f / (camRatio + 1.0f)) * desiredPosition + (camRatio / (camRatio + 1.0f)) * precedingPosition; + + if ( gEnv->collisions && gEnv->collisions->forcecam ) + { + gEnv->mainCamera->setPosition(gEnv->collisions->forcecampos); + gEnv->collisions->forcecam = false; + } else + { + gEnv->mainCamera->setPosition(camPosition); + } + + gEnv->mainCamera->lookAt(camLookAt); +} + +bool CameraBehaviorOrbit::mouseMoved(const CameraManager::cameraContext_t &ctx, const OIS::MouseEvent& _arg) +{ + const OIS::MouseState ms = _arg.state; + + if ( ms.buttonDown(OIS::MB_Right) ) + { + camRotX += Degree( ms.X.rel * 0.13f); + camRotY += Degree(-ms.Y.rel * 0.13f); + camDist += -ms.Z.rel * 0.02f; + return true; + } + + return false; +} + +void CameraBehaviorOrbit::reset(const CameraManager::cameraContext_t &ctx) +{ + camRotX = 0.0f; + gEnv->mainCamera->setFOVy(ctx.fovExternal); +} Copied: trunk/source/main/gfx/camera/CameraBehaviorOrbit.h (from rev 2753, trunk/source/main/gfx/camera/CameraBehavior.h) =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorOrbit.h (rev 0) +++ trunk/source/main/gfx/camera/CameraBehaviorOrbit.h 2012-05-29 17:33:46 UTC (rev 2754) @@ -0,0 +1,51 @@ +/* +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_ORBIT_H_ +#define __CAMERA_BEHAVIOR_ORBIT_H_ + +#include "RoRPrerequisites.h" + +#include "ICameraBehavior.h" + +class CameraBehaviorOrbit : public ICameraBehavior +{ +public: + + CameraBehaviorOrbit(); + + void update(const CameraManager::cameraContext_t &ctx); + + void activate(const CameraManager::cameraContext_t &ctx, bool reset = true) {}; + void deactivate(const CameraManager::cameraContext_t &ctx) {}; + void reset(const CameraManager::cameraContext_t &ctx); + + bool mouseMoved(const CameraManager::cameraContext_t &ctx, const OIS::MouseEvent& _arg); + bool mousePressed(const CameraManager::cameraContext_t &ctx, const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) { return false; }; + bool mouseReleased(const CameraManager::cameraContext_t &ctx, const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) { return false; }; + +protected: + + Ogre::Radian camRotX, camRotY; + Ogre::Radian targetDirection, targetPitch; + Ogre::Real camDist, camDistMin, camDistMax, camRatio; + Ogre::Vector3 camLookAt; +}; + +#endif // __CAMERA_BEHAVIOR_ORBIT_H_ Modified: trunk/source/main/gfx/camera/CameraBehaviorStatic.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorStatic.h 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraBehaviorStatic.h 2012-05-29 17:33:46 UTC (rev 2754) @@ -24,7 +24,7 @@ #include "ICameraBehavior.h" -class CameraBehaviorStatic : public ICameraBehavior, public ZeroedMemoryAllocator +class CameraBehaviorStatic : public ICameraBehavior { public: Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicle.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicle.h 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicle.h 2012-05-29 17:33:46 UTC (rev 2754) @@ -22,7 +22,7 @@ #include "RoRPrerequisites.h" -#include "CameraBehavior.h" +#include "CameraBehaviorOrbit.h" class CameraBehaviorVehicle : public CameraBehaviorOrbit { Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp 2012-05-29 17:33:46 UTC (rev 2754) @@ -22,17 +22,16 @@ #include "Beam.h" #include "InputEngine.h" #include "Ogre.h" -#include "Settings.h" using namespace Ogre; CameraBehaviorVehicleSpline::CameraBehaviorVehicleSpline() : CameraBehaviorVehicle() - , myManualObject(0) - , mySceneNode(0) + , numLinkedBeams(0) , spline(new SimpleSpline()) , splineClosed(false) , splineLength(1.0f) + , splineObject(0) , splinePos(0.5f) { } @@ -51,6 +50,10 @@ if ( ctx.mCurrTruck->free_camerarail > 0 ) { + if ( ctx.mCurrTruck->getAllLinkedBeams().size() != numLinkedBeams ) + { + createSpline(ctx); + } updateSpline(); updateSplineDisplay(); @@ -130,6 +133,7 @@ } else if ( reset ) { this->reset(ctx); + createSpline(ctx); } } @@ -139,9 +143,13 @@ camDist = std::min(ctx.mCurrTruck->getMinimalCameraRadius() * 2.0f, 20.0f); + splinePos = 0.5f; +} + +void CameraBehaviorVehicleSpline::createSpline(const CameraManager::cameraContext_t &ctx) +{ splineClosed = false; splineLength = 1.0f; - splinePos = 0.5f; spline->clear(); splineNodes.clear(); @@ -154,7 +162,9 @@ std::list<Beam*> linkedBeams = ctx.mCurrTruck->getAllLinkedBeams(); - if (linkedBeams.size() > 0) + numLinkedBeams = linkedBeams.size(); + + if ( numLinkedBeams > 0 ) { for (std::list<Beam*>::iterator it = linkedBeams.begin(); it != linkedBeams.end(); ++it) { @@ -189,19 +199,19 @@ splineLength /= 2.0f; - if ( !myManualObject ) + if ( !splineObject ) { - myManualObject = gEnv->sceneManager->createManualObject(); - mySceneNode = gEnv->sceneManager->getRootSceneNode()->createChildSceneNode(); + splineObject = gEnv->sceneManager->createManualObject(); + SceneNode* splineNode = gEnv->sceneManager->getRootSceneNode()->createChildSceneNode(); - myManualObject->begin("tracks/transred", Ogre::RenderOperation::OT_LINE_STRIP); + splineObject->begin("tracks/transred", Ogre::RenderOperation::OT_LINE_STRIP); for (int i = 0; i < splineDrawResolution; i++) { - myManualObject->position(0, 0, 0); + splineObject->position(0, 0, 0); } - myManualObject->end(); + splineObject->end(); - mySceneNode->attachObject(myManualObject); + splineNode->attachObject(splineObject); } } @@ -215,12 +225,12 @@ void CameraBehaviorVehicleSpline::updateSplineDisplay() { - myManualObject->beginUpdate(0); + splineObject->beginUpdate(0); for (int i = 0; i < splineDrawResolution; i++) { - float pos1d = i / (float)splineDrawResolution; - Vector3 pos3d = spline->interpolate(pos1d); - myManualObject->position(pos3d); + Real parametricDist = i / (float)splineDrawResolution; + Vector3 position = spline->interpolate(parametricDist); + splineObject->position(position); } - myManualObject->end(); + splineObject->end(); } Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.h 2012-05-29 17:33:46 UTC (rev 2754) @@ -37,19 +37,20 @@ void activate(const CameraManager::cameraContext_t &ctx, bool reset = true); void reset(const CameraManager::cameraContext_t &ctx); + void createSpline(const CameraManager::cameraContext_t &ctx); void updateSpline(); void updateSplineDisplay(); protected: - Ogre::ManualObject* myManualObject; - Ogre::SceneNode* mySceneNode; + Ogre::ManualObject* splineObject; Ogre::SimpleSpline* spline; Ogre::Real splineLength; Ogre::Real splinePos; bool splineClosed; std::vector<node*> splineNodes; + int numLinkedBeams; static const int splineDrawResolution = 200; }; Modified: trunk/source/main/gfx/camera/CameraManager.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraManager.cpp 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraManager.cpp 2012-05-29 17:33:46 UTC (rev 2754) @@ -25,7 +25,7 @@ #include "RoRFrameListener.h" #include "Settings.h" -#include "CameraBehavior.h" +#include "CameraBehaviorOrbit.h" #include "CameraBehaviorCharacter.h" #include "CameraBehaviorFixed.h" #include "CameraBehaviorFree.h" @@ -235,8 +235,8 @@ return currentBehavior->mouseReleased(ctx, _arg, _id); } -bool CameraManager::getGameControlsEnabled() +bool CameraManager::gameControlsEnabled() { // game controls are only disabled in free camera mode for now - return (getCameraBehavior() != CAMERA_BEHAVIOR_FREE); + return (currentBehaviorID != CAMERA_BEHAVIOR_FREE); } Modified: trunk/source/main/gfx/camera/CameraManager.h =================================================================== --- trunk/source/main/gfx/camera/CameraManager.h 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/CameraManager.h 2012-05-29 17:33:46 UTC (rev 2754) @@ -63,14 +63,13 @@ void switchToNextBehavior(bool force = true); void toggleBehavior(int behavior); + bool gameControlsEnabled(); bool hasActiveBehavior(); bool hasActiveCharacterBehavior(); bool hasActiveVehicleBehavior(); int getCameraBehavior(); - bool getGameControlsEnabled(); - protected: cameraContext_t ctx; Modified: trunk/source/main/gfx/camera/ICameraBehavior.h =================================================================== --- trunk/source/main/gfx/camera/ICameraBehavior.h 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/gfx/camera/ICameraBehavior.h 2012-05-29 17:33:46 UTC (rev 2754) @@ -25,7 +25,7 @@ #include "CameraManager.h" #include <OIS.h> -class ICameraBehavior +class ICameraBehavior : public ZeroedMemoryAllocator { public: Modified: trunk/source/main/physics/Beam.cpp =================================================================== --- trunk/source/main/physics/Beam.cpp 2012-05-29 04:18:01 UTC (rev 2753) +++ trunk/source/main/physics/Beam.cpp 2012-05-29 17:33:46 UTC (rev 2754) @@ -5633,7 +5633,7 @@ if (driveable != TRUCK || !CameraManager::singletonExists() || !CameraManager::getSingleton().hasActiveBehavior() || - CameraManager::getSingleton().getCameraBehavior() != CameraManager::CAMERA_BEHAVIOR_FREE) + CameraManager::getSingleton().gameControlsEnabled()) { return; } 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