Revision: 2467 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2467&view=rev Author: rorthomas Date: 2012-03-15 20:44:10 +0000 (Thu, 15 Mar 2012) Log Message: ----------- improved camera system
Modified Paths: -------------- trunk/source/main/gfx/camera/CameraBehavior.h trunk/source/main/gfx/camera/CameraBehaviorCharacterOrbit.cpp trunk/source/main/gfx/camera/CameraBehaviorCharacterOrbit.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/CameraManager.cpp trunk/source/main/gfx/camera/CameraManager.h Added Paths: ----------- trunk/source/main/gfx/camera/CameraBehavior.cpp trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.cpp trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.h Added: trunk/source/main/gfx/camera/CameraBehavior.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehavior.cpp (rev 0) +++ trunk/source/main/gfx/camera/CameraBehavior.cpp 2012-03-15 20:44:10 UTC (rev 2467) @@ -0,0 +1,30 @@ +/* +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 <Ogre.h> +#include "CameraManager.h" +#include "Console.h" +#include "InputEngine.h" +#include "language.h" +#include "Settings.h" + +using namespace Ogre; + Modified: trunk/source/main/gfx/camera/CameraBehavior.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehavior.h 2012-03-15 18:11:33 UTC (rev 2466) +++ trunk/source/main/gfx/camera/CameraBehavior.h 2012-03-15 20:44:10 UTC (rev 2467) @@ -23,13 +23,22 @@ #include "RoRPrerequisites.h" #include <OIS.h> +typedef struct cameraContext_t { + float dt; + Ogre::Degree rotationScale; + float translationScale; + Ogre::Camera *cam; +} cameraContext_t; class CameraBehavior { +protected: + float mMoveScale, mRotScale, mMoveSpeed, mRotateSpeed; +; public: virtual ~CameraBehavior() {}; - virtual void update(float dt) {}; + virtual void update(cameraContext_t &ctx) = 0; virtual bool mouseMoved(const OIS::MouseEvent& _arg) = 0; virtual bool mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) = 0; Modified: trunk/source/main/gfx/camera/CameraBehaviorCharacterOrbit.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorCharacterOrbit.cpp 2012-03-15 18:11:33 UTC (rev 2466) +++ trunk/source/main/gfx/camera/CameraBehaviorCharacterOrbit.cpp 2012-03-15 20:44:10 UTC (rev 2467) @@ -26,11 +26,17 @@ #include "language.h" #include "Settings.h" +#include "Character.h" +#include "RoRFrameListener.h" + using namespace Ogre; -void CameraBehaviorCharacterOrbit::update(float dt, Character *person) +void CameraBehaviorCharacterOrbit::update(cameraContext_t &ctx) { + Character *person = RoRFrameListener::eflsingleton->person; + targetDirection = -person->getAngle() - Math::HALF_PI; camCenterPoint = person->getPosition() + Vector3(0, 1.1f, 0); - CameraBehaviorOrbit::update(dt); + + CameraBehaviorOrbit::update(ctx); } Modified: trunk/source/main/gfx/camera/CameraBehaviorCharacterOrbit.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorCharacterOrbit.h 2012-03-15 18:11:33 UTC (rev 2466) +++ trunk/source/main/gfx/camera/CameraBehaviorCharacterOrbit.h 2012-03-15 20:44:10 UTC (rev 2467) @@ -23,12 +23,10 @@ #include "RoRPrerequisites.h" #include "CameraBehaviorOrbit.h" -#include "Character.h" - class CameraBehaviorCharacterOrbit : public CameraBehaviorOrbit { public: - void update(float dt, Character *chr); + void update(cameraContext_t &ctx); }; #endif // CAMERABEHAVIORPERSONORBIT_H__ Modified: trunk/source/main/gfx/camera/CameraBehaviorFree.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorFree.cpp 2012-03-15 18:11:33 UTC (rev 2466) +++ trunk/source/main/gfx/camera/CameraBehaviorFree.cpp 2012-03-15 20:44:10 UTC (rev 2467) @@ -58,62 +58,43 @@ #endif // USE_MYGUI } -void CameraBehaviorFree::update(float dt) +void CameraBehaviorFree::update(cameraContext_t &ctx) { - Real mMoveScale = 0.1; - Ogre::Degree mRotScale(0.1f); Ogre::Degree mRotX(0); Ogre::Degree mRotY(0); Vector3 mTranslateVector = Vector3::ZERO; - if(INPUTENGINE.isKeyDown(OIS::KC_LSHIFT) || INPUTENGINE.isKeyDown(OIS::KC_RSHIFT)) - { - mRotScale *= 3; - mMoveScale *= 3; - } - if(INPUTENGINE.isKeyDown(OIS::KC_LCONTROL)) - { - mRotScale *= 30; - mMoveScale *= 30; - } - if(INPUTENGINE.isKeyDown(OIS::KC_LMENU)) - { - mRotScale *= 0.05; - mMoveScale *= 0.05; - } - - if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_SIDESTEP_LEFT)) - mTranslateVector.x = -mMoveScale; // Move camera left + mTranslateVector.x -= ctx.translationScale; // Move camera left if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_SIDESTEP_RIGHT)) - mTranslateVector.x = mMoveScale; // Move camera RIGHT + mTranslateVector.x += ctx.translationScale; // Move camera RIGHT if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_FORWARD)) - mTranslateVector.z = -mMoveScale; // Move camera forward + mTranslateVector.z -= ctx.translationScale; // Move camera forward if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_BACKWARDS)) - mTranslateVector.z = mMoveScale; // Move camera backward + mTranslateVector.z += ctx.translationScale; // Move camera backward if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_ROT_UP)) - mRotY += mRotScale; + mRotY += ctx.rotationScale; if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_ROT_DOWN)) - mRotY += -mRotScale; + mRotY -= ctx.rotationScale; if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_UP)) - mTranslateVector.y = mMoveScale; // Move camera up + mTranslateVector.y += ctx.translationScale; // Move camera up if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_DOWN)) - mTranslateVector.y = -mMoveScale; // Move camera down + mTranslateVector.y -= ctx.translationScale; // Move camera down if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_RIGHT)) - mRotX += -mRotScale; + mRotX -= ctx.rotationScale; if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_LEFT)) - mRotX += mRotScale; + mRotX += ctx.rotationScale; Camera *cam = CameraManager::getSingleton().getCamera(); Modified: trunk/source/main/gfx/camera/CameraBehaviorFree.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorFree.h 2012-03-15 18:11:33 UTC (rev 2466) +++ trunk/source/main/gfx/camera/CameraBehaviorFree.h 2012-03-15 20:44:10 UTC (rev 2467) @@ -29,7 +29,7 @@ void activate(); void deactivate(); - void update(float dt); + void update(cameraContext_t &ctx); bool mouseMoved(const OIS::MouseEvent& _arg); bool mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id); Modified: trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp 2012-03-15 18:11:33 UTC (rev 2466) +++ trunk/source/main/gfx/camera/CameraBehaviorOrbit.cpp 2012-03-15 20:44:10 UTC (rev 2467) @@ -32,8 +32,11 @@ camRotX(0) , camRotY(0) , camDist(5) + , minCamDist(3) + , camRatio(11) , camIdealPosition(Vector3::ZERO) , camCenterPoint(Vector3::ZERO) + , camTranslation(Vector3::ZERO) , targetDirection(0) , targetPitch(0) { @@ -62,12 +65,106 @@ { } -void CameraBehaviorOrbit::update(float dt) +void CameraBehaviorOrbit::update(cameraContext_t &ctx) { Camera *cam = CameraManager::getSingleton().getCamera(); + /* + if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_SIDESTEP_LEFT)) + camTranslation.x -= mMoveScale; // Move camera left + + if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_SIDESTEP_RIGHT)) + camTranslation.x += mMoveScale; // Move camera RIGHT + + if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_FORWARD)) + camTranslation.z -= mMoveScale; // Move camera forward + + if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_BACKWARDS)) + camTranslation.z += mMoveScale; // Move camera backward + + if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_UP)) + camTranslation.y += mMoveScale; // Move camera up + + if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_DOWN)) + camTranslation.y -= mMoveScale; // Move camera down + + if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_ROT_UP)) + camRotY += mRotScale; + + if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_ROT_DOWN)) + camRotY -= mRotScale; + + if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_RIGHT)) + camRotX -= mRotScale; + + if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_LEFT)) + camRotX += mRotScale; +*/ + + if (INPUTENGINE.getEventBoolValueBounce(EV_CAMERA_LOOKBACK)) + { + if(camRotX > Degree(0)) + camRotX=Degree(0); + else + camRotX=Degree(180); + } + if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_LEFT)) + { + // Move camera left + camRotX -= ctx.rotationScale; + } + + if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_RIGHT)) + { + // Move camera RIGHT + camRotX += ctx.rotationScale; + } + if ((INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_UP)) && camRotY<Degree(88)) + { + // Move camera up + camRotY += ctx.rotationScale; + } + + if ((INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_DOWN)) && camRotY>Degree(-80)) + { + // Move camera down + camRotY -= ctx.rotationScale; + } + + if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_IN) && camDist>1) + { + // Move camera near + camDist -= ctx.translationScale; + } + if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_IN_FAST) && camDist>1) + { + // Move camera near + camDist -= ctx.translationScale * 10; + } + if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_OUT)) + { + // Move camera far + camDist += ctx.translationScale; + } + if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_OUT_FAST)) + { + // Move camera far + camDist += ctx.translationScale * 10; + } + if (INPUTENGINE.getEventBoolValue(EV_CAMERA_RESET)) + { + camRotX=0; + //if (cameramode!=CAMERA_INT) + // camRotY=Degree(12); + //else + camRotY = DEFAULT_INTERNAL_CAM_PITCH; + camDist=20; + } + + + // set Minimal Cam distance - if(camDist < 3) camDist = 3.0f; + if(camDist < minCamDist) camDist = minCamDist; camIdealPosition = camDist * 0.5f * Vector3( \ sin(targetDirection + camRotX.valueRadians()) * cos(targetPitch + camRotY.valueRadians()) \ @@ -77,8 +174,8 @@ float real_camdist = camIdealPosition.length(); - camIdealPosition = camIdealPosition + camCenterPoint; - Vector3 newposition = ( camIdealPosition + 10.0f * cam->getPosition() ) / 11.0f; + camIdealPosition = camIdealPosition + camCenterPoint + camTranslation; + Vector3 newposition = ( camIdealPosition + camRatio * cam->getPosition() ) / (camRatio+1.0f); /* Real h=hfinder->getHeightAt(newposition.x,newposition.z); @@ -108,12 +205,14 @@ const OIS::MouseState ms = _arg.state; Camera *cam = CameraManager::getSingleton().getCamera(); - - camRotX += Degree( (float)ms.X.rel * 0.13f); - camRotY += Degree(-(float)ms.Y.rel * 0.13f); - camDist += -(float)ms.Z.rel * 0.02f; - - return true; + if(ms.buttonDown(OIS::MB_Right)) + { + camRotX += Degree( (float)ms.X.rel * 0.13f); + camRotY += Degree(-(float)ms.Y.rel * 0.13f); + camDist += -(float)ms.Z.rel * 0.02f; + return true; + } + return false; } bool CameraBehaviorOrbit::mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) Modified: trunk/source/main/gfx/camera/CameraBehaviorOrbit.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorOrbit.h 2012-03-15 18:11:33 UTC (rev 2466) +++ trunk/source/main/gfx/camera/CameraBehaviorOrbit.h 2012-03-15 20:44:10 UTC (rev 2467) @@ -27,8 +27,8 @@ { protected: Ogre::Radian camRotX, camRotY; - float camDist; - Ogre::Vector3 camIdealPosition, camCenterPoint, lastPosition; + float camDist, minCamDist, camRatio; + Ogre::Vector3 camIdealPosition, camCenterPoint, lastPosition, camTranslation; float targetDirection, targetPitch; public: @@ -38,7 +38,7 @@ void activate(); void deactivate(); - void update(float dt); + void update(cameraContext_t &ctx); bool mouseMoved(const OIS::MouseEvent& _arg); bool mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id); Added: trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.cpp (rev 0) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.cpp 2012-03-15 20:44:10 UTC (rev 2467) @@ -0,0 +1,57 @@ +/* +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 "CameraBehaviorVehicleOrbit.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; + +CameraBehaviorVehicleOrbit::CameraBehaviorVehicleOrbit() : + externalCameraMode(0) +{ + externalCameraMode = (SSETTING("External Camera Mode", "Pitching") == "Static")? 1 : 0; +} + +void CameraBehaviorVehicleOrbit::update(cameraContext_t &ctx) +{ + Beam *curr_truck = BeamFactory::getSingleton().getCurrentTruck(); + if(!curr_truck) return; + + // 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)); + + if(!externalCameraMode) + targetPitch = -asin(dir.dotProduct(Vector3::UNIT_Y)); + else + targetPitch = 0; + { + camRatio = 1.0f / (curr_truck->tdt * 4.0f); + + CameraBehaviorOrbit::update(ctx); +} Added: trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.h (rev 0) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.h 2012-03-15 20:44:10 UTC (rev 2467) @@ -0,0 +1,37 @@ +/* +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 CAMERABEHAVIORVEHICLEORBIT_H__ +#define CAMERABEHAVIORVEHICLEORBIT_H__ + +#include "RoRPrerequisites.h" +#include "CameraBehaviorOrbit.h" + +class CameraBehaviorVehicleOrbit : public CameraBehaviorOrbit +{ +protected: + int externalCameraMode; +public: + CameraBehaviorVehicleOrbit(); + void update(cameraContext_t &ctx); +}; + +#endif // CAMERABEHAVIORVEHICLEORBIT_H__ + + Modified: trunk/source/main/gfx/camera/CameraManager.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraManager.cpp 2012-03-15 18:11:33 UTC (rev 2466) +++ trunk/source/main/gfx/camera/CameraManager.cpp 2012-03-15 20:44:10 UTC (rev 2467) @@ -31,12 +31,12 @@ #include "CameraBehaviorFree.h" #include "CameraBehaviorOrbit.h" #include "CameraBehaviorCharacterOrbit.h" +#include "CameraBehaviorVehicleOrbit.h" #include "RoRFrameListener.h" using namespace Ogre; -#define DEFAULT_INTERNAL_CAM_PITCH Degree(-15) CameraManager::CameraManager(Ogre::SceneManager *scm, Ogre::Camera *cam) : mSceneMgr(scm) @@ -46,10 +46,8 @@ { setSingleton(this); - externalCameraMode=0; lastcameramode=CAMERA_EXT; cameramode=CAMERA_EXT; - externalCameraMode = (SSETTING("External Camera Mode", "Pitching") == "Static")? 1 : 0; mMoveScale = 0.0f; mRotScale = 0.0f; //camIdealPosition = Vector3::ZERO; @@ -76,7 +74,7 @@ //createGlobalBehaviors(); //currentBehavior = globalBehaviors[CAMBEHAVIOR_FREE]; - currentBehavior = new CameraBehaviorCharacterOrbit(); + currentBehavior = new CameraBehaviorVehicleOrbit(); } CameraManager::~CameraManager() @@ -258,11 +256,15 @@ 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; - // hacky hack if(currentBehavior) - ((CameraBehaviorCharacterOrbit *)currentBehavior)->update(dt, RoRFrameListener::eflsingleton->person); + currentBehavior->update(ctx); #if 0 Modified: trunk/source/main/gfx/camera/CameraManager.h =================================================================== --- trunk/source/main/gfx/camera/CameraManager.h 2012-03-15 18:11:33 UTC (rev 2466) +++ trunk/source/main/gfx/camera/CameraManager.h 2012-03-15 20:44:10 UTC (rev 2467) @@ -32,6 +32,7 @@ #define MAIN_CAMERA CameraManager::getSingleton().getCamera() #define CAMERA_MODE CameraManager::getSingleton().getCameraMode() +#define DEFAULT_INTERNAL_CAM_PITCH Degree(-15) class CameraManager : public RoRSingletonNoCreation < CameraManager > { @@ -43,14 +44,11 @@ bool camCollided; Ogre::Vector3 camPosColl; Ogre::Radian pushcamRotX, pushcamRotY; - float mMoveScale; - Ogre::Degree mRotScale; + float mMoveScale, mRotScale; Ogre::Vector3 lastPosition; - int externalCameraMode; int mSceneDetailIndex; // Real dirSpeed; - float mMoveSpeed; - Ogre::Degree mRotateSpeed; + float mMoveSpeed, mRotateSpeed; DOFManager *mDOF; bool enforceCameraFOVUpdate; Ogre::Vector3 cdoppler; 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