Revision: 2594 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2594&view=rev Author: ulteq Date: 2012-05-19 00:40:10 +0000 (Sat, 19 May 2012) Log Message: ----------- -Codechange: CameraSystem WIP (nearly done) fixed the awful camera stuttering in vehicle chase mode added console messages for free- and fixed mode improved the camera feeling in free mode
Modified Paths: -------------- trunk/source/main/gfx/camera/CameraBehavior.cpp trunk/source/main/gfx/camera/CameraBehavior.h trunk/source/main/gfx/camera/CameraBehaviorCharacter.cpp trunk/source/main/gfx/camera/CameraBehaviorFixed.h trunk/source/main/gfx/camera/CameraBehaviorFree.cpp trunk/source/main/gfx/camera/CameraBehaviorFree.h trunk/source/main/gfx/camera/CameraBehaviorStatic.cpp trunk/source/main/gfx/camera/CameraBehaviorVehicle.cpp trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp Added Paths: ----------- trunk/source/main/gfx/camera/CameraBehaviorFixed.cpp Modified: trunk/source/main/gfx/camera/CameraBehavior.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehavior.cpp 2012-05-18 22:52:02 UTC (rev 2593) +++ trunk/source/main/gfx/camera/CameraBehavior.cpp 2012-05-19 00:40:10 UTC (rev 2594) @@ -19,6 +19,7 @@ */ #include "CameraBehavior.h" +#include "Beam.h" #include "InputEngine.h" #include "heightfinder.h" #include "Ogre.h" @@ -30,7 +31,7 @@ , camDistMax(0.0f) , camDistMin(0.0f) , camLookAt(Vector3::ZERO) - , camIntertia(11.0f) + , camRatio(11.0f) , camRotX(0.0f) , camRotY(0.3f) , targetDirection(0.0f) @@ -112,9 +113,16 @@ desiredPosition.y = std::max(h, desiredPosition.y); } - Vector3 camTrans = (desiredPosition - ctx.mCamera->getPosition()) * 0.1f; + Vector3 precedingPosition = ctx.mCamera->getPosition(); + + if ( ctx.mCurrTruck ) + { + precedingPosition += ctx.mCurrTruck->nodes[0].Velocity * ctx.mCurrTruck->ttdt; + } - ctx.mCamera->move(camTrans); + Vector3 camPosition = (1.0f / (camRatio + 1.0f)) * desiredPosition + (camRatio / (camRatio + 1.0f)) * precedingPosition; + + ctx.mCamera->setPosition(camPosition); ctx.mCamera->lookAt(camLookAt); } Modified: trunk/source/main/gfx/camera/CameraBehavior.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehavior.h 2012-05-18 22:52:02 UTC (rev 2593) +++ trunk/source/main/gfx/camera/CameraBehavior.h 2012-05-19 00:40:10 UTC (rev 2594) @@ -43,7 +43,7 @@ Ogre::Vector3 camLookAt; Ogre::Radian camRotX, camRotY; - float camDist, camDistMin, camDistMax, camIntertia; + float camDist, camDistMin, camDistMax, camRatio; float targetDirection, targetPitch; }; Modified: trunk/source/main/gfx/camera/CameraBehaviorCharacter.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorCharacter.cpp 2012-05-18 22:52:02 UTC (rev 2593) +++ trunk/source/main/gfx/camera/CameraBehaviorCharacter.cpp 2012-05-19 00:40:10 UTC (rev 2594) @@ -64,7 +64,7 @@ return CameraBehavior::mouseMoved(ctx, _arg); } -void CameraBehaviorCharacter::activate(const CameraManager::cameraContext_t &ctx, bool reset) +void CameraBehaviorCharacter::activate(const CameraManager::cameraContext_t &ctx, bool reset /* = true */) { if ( reset ) { @@ -81,20 +81,23 @@ { camRotY = 0.1f; camDist = 0.1f; - camIntertia = 0.0f; + camRatio = 0.0f; camPositionOffset = Vector3(0.0f, 1.82f, 0.0f); } else if ( camMode == CHARACTER_THIRD_PERSON ) { camRotY = 0.3f; camDist = 5.0f; - camIntertia = 11.0f; + camRatio = 11.0f; camPositionOffset = Vector3(0.0f, 1.1f, 0.0f); } } bool CameraBehaviorCharacter::switchBehavior(const CameraManager::cameraContext_t &ctx) { - reset(ctx); - - return ++camMode >= CHARACTER_END; + if (++camMode < CHARACTER_END) + { + reset(ctx); + return false; + } + return true; } Added: trunk/source/main/gfx/camera/CameraBehaviorFixed.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorFixed.cpp (rev 0) +++ trunk/source/main/gfx/camera/CameraBehaviorFixed.cpp 2012-05-19 00:40:10 UTC (rev 2594) @@ -0,0 +1,32 @@ +/* +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 "CameraBehaviorFixed.h" + +#include "Console.h" +#include "language.h" + +using namespace Ogre; + +void CameraBehaviorFixed::activate(const CameraManager::cameraContext_t &ctx, bool reset /* = true */) +{ +#ifdef USE_MYGUI + Console::getSingleton().putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, _L("fixed free camera"), "camera_link.png", 3000); +#endif // USE_MYGUI +} Modified: trunk/source/main/gfx/camera/CameraBehaviorFixed.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorFixed.h 2012-05-18 22:52:02 UTC (rev 2593) +++ trunk/source/main/gfx/camera/CameraBehaviorFixed.h 2012-05-19 00:40:10 UTC (rev 2594) @@ -34,7 +34,7 @@ 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; }; - void activate(const CameraManager::cameraContext_t &ctx, bool reset = true) {}; + void activate(const CameraManager::cameraContext_t &ctx, bool reset = true); void deactivate(const CameraManager::cameraContext_t &ctx) {}; void reset(const CameraManager::cameraContext_t &ctx) {}; Modified: trunk/source/main/gfx/camera/CameraBehaviorFree.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorFree.cpp 2012-05-18 22:52:02 UTC (rev 2593) +++ trunk/source/main/gfx/camera/CameraBehaviorFree.cpp 2012-05-19 00:40:10 UTC (rev 2594) @@ -19,8 +19,10 @@ */ #include "CameraBehaviorFree.h" +#include "Console.h" #include "heightfinder.h" #include "InputEngine.h" +#include "language.h" #include "mygui/BaseLayout.h" #include "Ogre.h" @@ -28,53 +30,69 @@ void CameraBehaviorFree::update(const CameraManager::cameraContext_t &ctx) { - Vector3 mTrans(Vector3::ZERO); Degree mRotX(0.0f); Degree mRotY(0.0f); + Degree mRotScale(ctx.mRotScale * 0.5f); + Vector3 mTrans(Vector3::ZERO); + Real mTransScale(ctx.mTransScale * 0.5f); - if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_SIDESTEP_LEFT) ) + if(INPUTENGINE.isKeyDown(OIS::KC_LSHIFT) || INPUTENGINE.isKeyDown(OIS::KC_RSHIFT)) { - mTrans.x -= ctx.mTransScale; + mRotScale *= 3.0f; + mTransScale *= 3.0f; } - if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_SIDESTEP_RIGHT) ) + if(INPUTENGINE.isKeyDown(OIS::KC_LCONTROL)) { - mTrans.x += ctx.mTransScale; + mRotScale *= 30.0f; + mTransScale *= 30.0f; } + if(INPUTENGINE.isKeyDown(OIS::KC_LMENU)) + { + mRotScale *= 0.05f; + mTransScale *= 0.05f; + } - if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_FORWARD) ) + if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_SIDESTEP_LEFT) ) { - mTrans.z -= ctx.mTransScale; + mTrans.x -= mTransScale; } - if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_BACKWARDS) ) + if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_SIDESTEP_RIGHT) ) { - mTrans.z += ctx.mTransScale; + mTrans.x += mTransScale; } - - if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_ROT_UP) ) + if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_FORWARD) ) { - mRotY += ctx.mRotScale; + mTrans.z -= mTransScale; } - if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_ROT_DOWN) ) + if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_BACKWARDS) ) { - mRotY -= ctx.mRotScale; + mTrans.z += mTransScale; } - if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_UP) ) { - mTrans.y += ctx.mTransScale; + mTrans.y += mTransScale; } if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_DOWN) ) { - mTrans.y -= ctx.mTransScale; + mTrans.y -= mTransScale; } + if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_RIGHT) ) { - mRotX -= ctx.mRotScale; + mRotX -= mRotScale; } if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_LEFT) ) { - mRotX += ctx.mRotScale; + mRotX += mRotScale; } + if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_ROT_UP) ) + { + mRotY += mRotScale; + } + if ( INPUTENGINE.getEventBoolValue(EV_CHARACTER_ROT_DOWN) ) + { + mRotY -= mRotScale; + } ctx.mCamera->yaw(mRotX); ctx.mCamera->pitch(mRotY); @@ -100,7 +118,14 @@ #ifdef USE_MYGUI MyGUI::PointerManager::getInstance().setVisible(false); +#endif // USE_MYGUI -#endif // USE_MYGUI return true; } + +void CameraBehaviorFree::activate(const CameraManager::cameraContext_t &ctx, bool reset /* = true */) +{ +#ifdef USE_MYGUI + Console::getSingleton().putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, _L("free camera"), "camera_go.png", 3000); +#endif // USE_MYGUI +} Modified: trunk/source/main/gfx/camera/CameraBehaviorFree.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorFree.h 2012-05-18 22:52:02 UTC (rev 2593) +++ trunk/source/main/gfx/camera/CameraBehaviorFree.h 2012-05-19 00:40:10 UTC (rev 2594) @@ -34,7 +34,7 @@ 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; }; - void activate(const CameraManager::cameraContext_t &ctx, bool reset = true) {}; + void activate(const CameraManager::cameraContext_t &ctx, bool reset = true); void deactivate(const CameraManager::cameraContext_t &ctx) {}; void reset(const CameraManager::cameraContext_t &ctx) {}; Modified: trunk/source/main/gfx/camera/CameraBehaviorStatic.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorStatic.cpp 2012-05-18 22:52:02 UTC (rev 2593) +++ trunk/source/main/gfx/camera/CameraBehaviorStatic.cpp 2012-05-19 00:40:10 UTC (rev 2594) @@ -21,8 +21,10 @@ #include "Beam.h" #include "Character.h" +#include "Console.h" #include "DepthOfFieldEffect.h" #include "heightfinder.h" +#include "language.h" #include "Ogre.h" using namespace Ogre; @@ -68,7 +70,7 @@ } } -void CameraBehaviorStatic::activate(const CameraManager::cameraContext_t &ctx, bool reset) +void CameraBehaviorStatic::activate(const CameraManager::cameraContext_t &ctx, bool reset /* = true */) { fovPreviously = ctx.mCamera->getFOVy(); } @@ -76,4 +78,9 @@ void CameraBehaviorStatic::deactivate(const CameraManager::cameraContext_t &ctx) { ctx.mCamera->setFOVy(fovPreviously); + + if ( ctx.mDof ) + { + ctx.mDof->setFocusMode(DOFManager::Auto); + } } Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicle.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicle.cpp 2012-05-18 22:52:02 UTC (rev 2593) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicle.cpp 2012-05-19 00:40:10 UTC (rev 2594) @@ -47,7 +47,7 @@ targetPitch = -asin(dir.dotProduct(Vector3::UNIT_Y)); } - camIntertia = 1.0f / (ctx.mDt * 4.0f); + camRatio = 1.0f / (ctx.mCurrTruck->tdt * 4.0f); camDistMin = ctx.mCurrTruck->getMinimalCameraRadius() * 2.0f; @@ -56,7 +56,7 @@ CameraBehavior::update(ctx); } -void CameraBehaviorVehicle::activate(const CameraManager::cameraContext_t &ctx, bool reset) +void CameraBehaviorVehicle::activate(const CameraManager::cameraContext_t &ctx, bool reset /* = true */) { if ( !ctx.mCurrTruck ) { @@ -71,6 +71,6 @@ { camRotX = 0.0f; camRotY = 0.5f; - camDist = ctx.mCurrTruck->getMinimalCameraRadius() * 3.0f; + camDist = ctx.mCurrTruck->getMinimalCameraRadius() * 3.0f + 2.0f; camDistMin = ctx.mCurrTruck->getMinimalCameraRadius() * 2.0f; } Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp 2012-05-18 22:52:02 UTC (rev 2593) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp 2012-05-19 00:40:10 UTC (rev 2594) @@ -59,7 +59,7 @@ ctx.mCamera->setOrientation(orientation); } -void CameraBehaviorVehicleCineCam::activate(const CameraManager::cameraContext_t &ctx, bool reset) +void CameraBehaviorVehicleCineCam::activate(const CameraManager::cameraContext_t &ctx, bool reset /* = true */) { if ( !ctx.mCurrTruck || ctx.mCurrTruck->freecinecamera <= 0 ) { Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp 2012-05-18 22:52:02 UTC (rev 2593) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp 2012-05-19 00:40:10 UTC (rev 2594) @@ -21,7 +21,6 @@ #include "Beam.h" #include "InputEngine.h" -#include "language.h" #include "Ogre.h" #include "Settings.h" @@ -38,12 +37,14 @@ 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; - dir.normalise(); + Vector3 dir = (ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameranodepos[0]].smoothpos + - ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameranodedir[0]].smoothpos).normalisedCopy(); + targetDirection = -atan2(dir.dotProduct(Vector3::UNIT_X), dir.dotProduct(-Vector3::UNIT_Z)); - targetPitch = 0; - camIntertia = 1.0f / (ctx.mDt * 4.0f); + targetPitch = 0.0f; + camRatio = 1.0f / (ctx.mCurrTruck->tdt * 4.0f); + if ( ctx.mCurrTruck->free_camerarail > 0 ) { spline->clear(); @@ -64,7 +65,7 @@ CameraBehavior::update(ctx); } -void CameraBehaviorVehicleSpline::activate(const CameraManager::cameraContext_t &ctx, bool reset) +void CameraBehaviorVehicleSpline::activate(const CameraManager::cameraContext_t &ctx, bool reset /* = true */) { if ( !ctx.mCurrTruck || ctx.mCurrTruck->free_camerarail <= 0 ) { 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