Revision: 2469 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2469&view=rev Author: rorthomas Date: 2012-03-15 22:03:08 +0000 (Thu, 15 Mar 2012) Log Message: ----------- added silly wheel cam, WIP
Modified Paths: -------------- trunk/source/main/gameplay/SceneMouse.cpp trunk/source/main/gfx/camera/CameraBehaviorFree.cpp trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.cpp trunk/source/main/gfx/camera/CameraManager.cpp Added Paths: ----------- trunk/source/main/gfx/camera/CameraBehaviorWheelChase.cpp trunk/source/main/gfx/camera/CameraBehaviorWheelChase.h Modified: trunk/source/main/gameplay/SceneMouse.cpp =================================================================== --- trunk/source/main/gameplay/SceneMouse.cpp 2012-03-15 20:44:51 UTC (rev 2468) +++ trunk/source/main/gameplay/SceneMouse.cpp 2012-03-15 22:03:08 UTC (rev 2469) @@ -163,27 +163,6 @@ return false; } - /* - if(ms.buttonDown(OIS::MB_Right)) - { - rfl->camRotX += Degree( (float)ms.X.rel * 0.13f); - rfl->camRotY += Degree(-(float)ms.Y.rel * 0.13f); - rfl->camDist += -(float)ms.Z.rel * 0.02f; -#ifdef USE_MYGUI - MyGUI::PointerManager::getInstance().setPointer("hand"); -#endif // USE_MYGUI - return true; - } else if(rfl->cameramode == CAMERA_FREE) - { - rfl->getCamera()->yaw(Degree(-(float)ms.X.rel * 0.13f)); - rfl->getCamera()->pitch(Degree(-(float)ms.Y.rel * 0.13f)); -#ifdef USE_MYGUI - MyGUI::PointerManager::getInstance().setPointer("hand"); -#endif // USE_MYGUI - return true; - } - */ - return false; } Modified: trunk/source/main/gfx/camera/CameraBehaviorFree.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorFree.cpp 2012-03-15 20:44:51 UTC (rev 2468) +++ trunk/source/main/gfx/camera/CameraBehaviorFree.cpp 2012-03-15 22:03:08 UTC (rev 2469) @@ -96,13 +96,13 @@ if(INPUTENGINE.getEventBoolValue(EV_CHARACTER_LEFT)) mRotX += ctx.rotationScale; - Camera *cam = CameraManager::getSingleton().getCamera(); + ctx.cam->yaw(mRotX); + ctx.cam->pitch(mRotY); - cam->yaw(mRotX); - cam->pitch(mRotY); + ctx.cam->setFixedYawAxis(false); - Vector3 trans = cam->getOrientation() * mTranslateVector; - cam->setPosition(cam->getPosition() + trans); + Vector3 trans = ctx.cam->getOrientation() * mTranslateVector; + ctx.cam->setPosition(ctx.cam->getPosition() + trans); } bool CameraBehaviorFree::mouseMoved(const OIS::MouseEvent& _arg) Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.cpp 2012-03-15 20:44:51 UTC (rev 2468) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicleOrbit.cpp 2012-03-15 22:03:08 UTC (rev 2469) @@ -53,5 +53,7 @@ camRatio = 1.0f / (curr_truck->tdt * 4.0f); + camCenterPoint = curr_truck->getPosition(); + CameraBehaviorOrbit::update(ctx); } Added: trunk/source/main/gfx/camera/CameraBehaviorWheelChase.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorWheelChase.cpp (rev 0) +++ trunk/source/main/gfx/camera/CameraBehaviorWheelChase.cpp 2012-03-15 22:03:08 UTC (rev 2469) @@ -0,0 +1,76 @@ +/* +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 "CameraBehaviorWheelChase.h" + +#include <Ogre.h> +#include "CameraManager.h" +#include "Console.h" +#include "InputEngine.h" +#include "language.h" + +#include "BeamFactory.h" + +using namespace Ogre; + +void CameraBehaviorWheelChase::activate() +{ +} + +void CameraBehaviorWheelChase::deactivate() +{ +} + +void CameraBehaviorWheelChase::update(cameraContext_t &ctx) +{ + Beam *curr_truck = BeamFactory::getSingleton().getCurrentTruck(); + if(!curr_truck) return; + + //ctx.cam->setFixedYawAxis(false); + + int i = 0; + + Vector3 axis = curr_truck->wheels[i].refnode1->smoothpos - curr_truck->wheels[i].refnode0->smoothpos; + Vector3 cpos = curr_truck->wheels[i].refnode0->smoothpos - axis * 3; + Vector3 clook = curr_truck->wheels[i].refnode1->smoothpos; + + //ctx.cam->setFixedYawAxis(false); + + ctx.cam->lookAt(clook); + + // TODO: FIX + //ctx.cam->roll(Ogre::Degree(-curr_truck->wheels[i].speed)); + + ctx.cam->setPosition(cpos); +} + +bool CameraBehaviorWheelChase::mouseMoved(const OIS::MouseEvent& _arg) +{ + return false; +} + +bool CameraBehaviorWheelChase::mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) +{ + return false; +} + +bool CameraBehaviorWheelChase::mouseReleased(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id) +{ + return false; +} Added: trunk/source/main/gfx/camera/CameraBehaviorWheelChase.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorWheelChase.h (rev 0) +++ trunk/source/main/gfx/camera/CameraBehaviorWheelChase.h 2012-03-15 22:03:08 UTC (rev 2469) @@ -0,0 +1,43 @@ +/* +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 CAMERABEHAVIORWHEELCHASE_H__ +#define CAMERABEHAVIORWHEELCHASE_H__ + +#include "RoRPrerequisites.h" +#include "CameraBehavior.h" + +class CameraBehaviorWheelChase : public CameraBehavior +{ +public: + void activate(); + void deactivate(); + + void update(cameraContext_t &ctx); + + bool mouseMoved(const OIS::MouseEvent& _arg); + bool mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id); + bool mouseReleased(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id); + + bool allowInteraction() { return false; }; +}; + +#endif // CAMERABEHAVIORWHEELCHASE_H__ + + Modified: trunk/source/main/gfx/camera/CameraManager.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraManager.cpp 2012-03-15 20:44:51 UTC (rev 2468) +++ trunk/source/main/gfx/camera/CameraManager.cpp 2012-03-15 22:03:08 UTC (rev 2469) @@ -32,6 +32,7 @@ #include "CameraBehaviorOrbit.h" #include "CameraBehaviorCharacterOrbit.h" #include "CameraBehaviorVehicleOrbit.h" +#include "CameraBehaviorWheelChase.h" #include "RoRFrameListener.h" @@ -74,7 +75,7 @@ //createGlobalBehaviors(); //currentBehavior = globalBehaviors[CAMBEHAVIOR_FREE]; - currentBehavior = new CameraBehaviorVehicleOrbit(); + currentBehavior = new CameraBehaviorWheelChase();//CameraBehaviorVehicleOrbit(); } CameraManager::~CameraManager() @@ -262,6 +263,26 @@ ctx.rotationScale = Ogre::Degree(mRotScale); ctx.cam = mCamera; + if(!currentBehavior->allowInteraction()) + { + if(INPUTENGINE.isKeyDown(OIS::KC_LSHIFT) || INPUTENGINE.isKeyDown(OIS::KC_RSHIFT)) + { + ctx.rotationScale *= 3; + ctx.translationScale *= 3; + } + + if(INPUTENGINE.isKeyDown(OIS::KC_LCONTROL)) + { + ctx.rotationScale *= 30; + ctx.translationScale *= 30; + } + if(INPUTENGINE.isKeyDown(OIS::KC_LMENU)) + { + ctx.rotationScale *= 0.05; + ctx.translationScale *= 0.05; + } + } + // hacky hack if(currentBehavior) currentBehavior->update(ctx); @@ -289,50 +310,6 @@ collisions->forcecam=false; if(mDOF) mDOF->setFocusMode(DOFManager::Auto); } - else - { - // Make all the changes to the camera - //Vector3 delta=lastPosition-personode->getPosition(); - //delta.y=0.0; - float angle=-person->getAngle()-(3.14159/2.0); - // float angle2; - //if (delta.length()>0.01) angle=atan2(delta.x,delta.z); else angle=lastangle; - - // fix camera distance a bit - if(camDist < 3) camDist = 3.0f; - - camIdealPosition=camDist/2.0*Vector3(sin(angle+camRotX.valueRadians())*cos(camRotY.valueRadians()),sin(camRotY.valueRadians()),cos(angle+camRotX.valueRadians())*cos(camRotY.valueRadians())); - - float real_camdist = camIdealPosition.length(); - - camIdealPosition=camIdealPosition+person->getPosition(); - Vector3 newposition=(camIdealPosition+10.0*mCamera->getPosition())/11.0; - Real h=hfinder->getHeightAt(newposition.x,newposition.z); - - if (w && !w->allowUnderWater() && w->getHeightWaves(newposition) > h) - h=w->getHeightWaves(newposition); - - h+=1.0; - if (newposition.y<h) newposition.y=h; - setCameraPositionWithCollision(newposition); - mCamera->lookAt(person->getPosition()+Vector3(0.0,1.1f,0.0)); - - float fov = FSETTING("FOV External", 60); - - if(changeCamMode) - mCamera->setFOVy(Degree(fov)); - - lastPosition=person->getPosition(); - - if(mDOF) - { - mDOF->setFocusMode(DOFManager::Manual); - mDOF->setFocus(real_camdist); - mDOF->setLensFOV(Degree(fov)); - } - - //lastangle=angle; - } } else if (cameramode==CAMERA_FIX) { @@ -407,61 +384,6 @@ mDOF->setLensFOV(Degree(80)); } } - else - { - // Make all the changes to the camera - //Vector3 delta=lastPosition-trucks[current_truck]->position; - //delta.y=0.0; - float angle; - // float angle2; - // if (delta.length()>0.05) angle=atan2(delta.x,delta.z); else angle=lastangle; - Vector3 dir=curr_truck->nodes[curr_truck->cameranodepos[0]].smoothpos-curr_truck->nodes[curr_truck->cameranodedir[0]].smoothpos; - dir.normalise(); - angle=-atan2(dir.dotProduct(Vector3::UNIT_X), dir.dotProduct(-Vector3::UNIT_Z)); - - if(externalCameraMode==0) - { - float pitch=-asin(dir.dotProduct(Vector3::UNIT_Y)); - camIdealPosition=camDist*Vector3(sin(angle+camRotX.valueRadians())*cos(pitch+camRotY.valueRadians()),sin(pitch+camRotY.valueRadians()),cos(angle+camRotX.valueRadians())*cos(pitch+camRotY.valueRadians())); - } else if(externalCameraMode==1) - { - camIdealPosition=camDist*Vector3(sin(angle+camRotX.valueRadians())*cos(camRotY.valueRadians()),sin(camRotY.valueRadians()),cos(angle+camRotX.valueRadians())*cos(camRotY.valueRadians())); - } - - float cam_realdist = camIdealPosition.length(); - camIdealPosition=camIdealPosition+curr_truck->getPosition(); - Vector3 oldposition=mCamera->getPosition()+curr_truck->nodes[0].Velocity*curr_truck->ttdt; - float ratio=1.0/(curr_truck->tdt*4.0); - //float ratio=0.001; - //Vector3 newposition=(camIdealPosition+ratio*mCamera->getPosition())/(ratio+1.0); - //Vector3 newposition=camIdealPosition; - Vector3 newposition=(1/(ratio+1.0))*camIdealPosition+(ratio/(ratio+1.0))*oldposition; - - Real h=hfinder->getHeightAt(newposition.x,newposition.z); - if (w && !w->allowUnderWater() && w->getHeightWaves(newposition)>h) - h=w->getHeightWaves(newposition); - h+=1.0; - if (newposition.y<h) newposition.y=h; - setCameraPositionWithCollision(newposition); - mCamera->lookAt(curr_truck->getPosition()); - - float fov = FSETTING("FOV External", 60); - - if(changeCamMode) - mCamera->setFOVy(Degree(fov)); - - lastPosition=curr_truck->getPosition(); - - if(mDOF) - { - mDOF->setFocusMode(DOFManager::Manual); - mDOF->setFocus(cam_realdist); - mDOF->setLensFOV(Degree(80)); - } - - - //lastangle=angle; - } } if (cameramode==CAMERA_FIX) { 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