Revision: 2579 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2579&view=rev Author: ulteq Date: 2012-05-17 10:09:50 +0000 (Thu, 17 May 2012) Log Message: ----------- improved code readability
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/CameraBehaviorVehicle.cpp trunk/source/main/gfx/camera/CameraBehaviorVehicle.h trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp trunk/source/main/physics/Beam.cpp trunk/source/main/physics/input_output/SerializedRig.cpp Modified: trunk/source/main/gfx/camera/CameraBehavior.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehavior.cpp 2012-05-17 08:45:12 UTC (rev 2578) +++ trunk/source/main/gfx/camera/CameraBehavior.cpp 2012-05-17 10:09:50 UTC (rev 2579) @@ -25,15 +25,13 @@ using namespace Ogre; CameraBehavior::CameraBehavior() : - camRotX(0.0f) + camDist(5.0f) + , camDistMax(0.0f) + , camDistMin(0.0f) + , camLookAt(Vector3::ZERO) + , camIntertia(11.0f) + , camRotX(0.0f) , camRotY(0.3f) - , camDist(5.0f) - , minCamDist(0.0f) - , maxCamDist(0.0f) - , camRatio(11.0f) - , camIdealPosition(Vector3::ZERO) - , camCenterPosition(Vector3::ZERO) - , camTranslation(Vector3::ZERO) , targetDirection(0.0f) , targetPitch(0.0f) { @@ -41,81 +39,77 @@ void CameraBehavior::update(const CameraManager::cameraContext_t &ctx) { - if (INPUTENGINE.getEventBoolValueBounce(EV_CAMERA_LOOKBACK)) + if ( INPUTENGINE.getEventBoolValueBounce(EV_CAMERA_LOOKBACK) ) { if ( camRotX > Degree(0) ) + { camRotX = Degree(0); - else + } else + { camRotX = Degree(180); + } } - if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_LEFT)) + + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_LEFT) ) { - // Move camera left camRotX -= ctx.mRotScale; } - - if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_RIGHT)) + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_RIGHT) ) { - // Move camera right camRotX += ctx.mRotScale; } - if ((INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_UP)) && camRotY<Degree(88)) + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_UP) && camRotY < Degree(88) ) { - // Move camera up camRotY += ctx.mRotScale; } - - if ((INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_DOWN)) && camRotY>Degree(-80)) + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ROTATE_DOWN) && camRotY > Degree(-80) ) { - // Move camera down camRotY -= ctx.mRotScale; } - if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_IN) && camDist>1) + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_IN) && camDist > 1 ) { - // Move camera near camDist -= ctx.mTransScale; } - if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_IN_FAST) && camDist>1) + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_IN_FAST) && camDist > 1 ) { - // Move camera near camDist -= ctx.mTransScale * 10; } - if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_OUT)) + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_OUT) ) { - // Move camera far camDist += ctx.mTransScale; } - if (INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_OUT_FAST)) + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_ZOOM_OUT_FAST) ) { - // Move camera far camDist += ctx.mTransScale * 10; } - if (INPUTENGINE.getEventBoolValue(EV_CAMERA_RESET)) + + if ( INPUTENGINE.getEventBoolValue(EV_CAMERA_RESET) ) { - camRotX = 0.0f; - camRotY = 0.0f; - camDist = 20.0f; + camRotX = 0.0f; + camRotY = 0.0f; + camDist = 5.0f; } - if ( minCamDist > 0.0f ) - camDist = std::max(minCamDist, camDist); - if ( maxCamDist > 0.0f ) - camDist = std::min(camDist, maxCamDist); + if ( camDistMin > 0.0f ) + { + camDist = std::max(camDistMin, camDist); + } + if ( camDistMax > 0.0f ) + { + camDist = std::min(camDist, camDistMax); + } - camIdealPosition = camDist * 0.5f * Vector3( \ + Vector3 desiredPosition = camLookAt + camDist * 0.5f * Vector3( \ sin(targetDirection + camRotX.valueRadians()) * cos(targetPitch + camRotY.valueRadians()) \ , sin(targetPitch + camRotY.valueRadians()) \ , cos(targetDirection + camRotX.valueRadians()) * cos(targetPitch + camRotY.valueRadians()) \ ); - float real_camdist = camIdealPosition.length(); + Vector3 position = (desiredPosition + ctx.mCamera->getPosition() * camIntertia) / (1.0f + camIntertia); - camIdealPosition = camIdealPosition + camCenterPosition + camTranslation; - Vector3 newPosition = (camIdealPosition + camRatio * ctx.mCamera->getPosition()) / (camRatio + 1.0f); - - ctx.mCamera->setPosition(newPosition); - ctx.mCamera->lookAt(camCenterPosition); + ctx.mCamera->setPosition(position); + ctx.mCamera->lookAt(camLookAt); } bool CameraBehavior::mouseMoved(const CameraManager::cameraContext_t &ctx, const OIS::MouseEvent& _arg) @@ -124,9 +118,9 @@ 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; + camRotX += Degree( ms.X.rel * 0.13f); + camRotY += Degree(-ms.Y.rel * 0.13f); + camDist += -ms.Z.rel * 0.02f; return true; } Modified: trunk/source/main/gfx/camera/CameraBehavior.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehavior.h 2012-05-17 08:45:12 UTC (rev 2578) +++ trunk/source/main/gfx/camera/CameraBehavior.h 2012-05-17 10:09:50 UTC (rev 2579) @@ -41,9 +41,9 @@ protected: + Ogre::Vector3 camLookAt; Ogre::Radian camRotX, camRotY; - Ogre::Vector3 camIdealPosition, camCenterPosition, camTranslation; - float camDist, minCamDist, maxCamDist, camRatio; + float camDist, camDistMin, camDistMax, camIntertia; float targetDirection, targetPitch; }; Modified: trunk/source/main/gfx/camera/CameraBehaviorCharacter.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorCharacter.cpp 2012-05-17 08:45:12 UTC (rev 2578) +++ trunk/source/main/gfx/camera/CameraBehaviorCharacter.cpp 2012-05-17 10:09:50 UTC (rev 2579) @@ -32,8 +32,8 @@ void CameraBehaviorCharacter::update(const CameraManager::cameraContext_t &ctx) { - targetDirection = -ctx.mCharacter->getAngle() - Math::HALF_PI; - camCenterPosition = ctx.mCharacter->getPosition() + camPositionOffset; + targetDirection = -ctx.mCharacter->getAngle() - Math::HALF_PI; + camLookAt = ctx.mCharacter->getPosition() + camPositionOffset; CameraBehavior::update(ctx); } @@ -45,8 +45,8 @@ const OIS::MouseState ms = _arg.state; float angle = ctx.mCharacter->getAngle(); - camRotY += Degree((float)ms.Y.rel * 0.13f); - angle += ms.X.rel * 0.01f; + camRotY += Degree(ms.Y.rel * 0.13f); + angle += ms.X.rel * 0.01f; ctx.mCharacter->setAngle(angle); @@ -59,18 +59,19 @@ bool CameraBehaviorCharacter::switchBehavior(const CameraManager::cameraContext_t &ctx) { camMode = (camMode + 1) % CHARACTER_END; + camRotX = 0.0f; if ( camMode == CHARACTER_FIRST_PERSON ) { camRotY = 0.1f; camDist = 0.1f; - camRatio = 0.0f; - camPositionOffset = Vector3(0.1f, 1.82f, 0.0f); + camIntertia = 0.0f; + camPositionOffset = Vector3(0.0f, 1.82f, 0.0f); } else if ( camMode == CHARACTER_THIRD_PERSON ) { camRotY = 0.3f; camDist = 5.0f; - camRatio = 11.0f; + camIntertia = 11.0f; camPositionOffset = Vector3(0.0f, 1.1f, 0.0f); } Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicle.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicle.cpp 2012-05-17 08:45:12 UTC (rev 2578) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicle.cpp 2012-05-17 10:09:50 UTC (rev 2579) @@ -28,9 +28,8 @@ CameraBehavior() , camPitching(true) { - camRotY = 0.6f; - minCamDist = 8.0f; - maxCamDist = 0.0f; + camRotY = 0.5f; + camDistMin = 8.0f; if ( SSETTING("External Camera Mode", "Pitching") == "Static" ) camPitching = false; @@ -48,16 +47,13 @@ { targetPitch = -asin(dir.dotProduct(Vector3::UNIT_Y)); } + + camLookAt = ctx.mCurrTruck->getPosition(); - camRatio = 1.0f / (ctx.mCurrTruck->tdt * 4.0f); - - camCenterPosition = ctx.mCurrTruck->getPosition(); - CameraBehavior::update(ctx); } -bool CameraBehaviorVehicle::switchBehavior(const CameraManager::cameraContext_t &ctx) +void CameraBehaviorVehicle::activate(const CameraManager::cameraContext_t &ctx) { - // TODO: rear chase, front chase, ... - return true; + // initialize camDistMin based on the vehicle bounding box } Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicle.h =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicle.h 2012-05-17 08:45:12 UTC (rev 2578) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicle.h 2012-05-17 10:09:50 UTC (rev 2579) @@ -32,8 +32,10 @@ void update(const CameraManager::cameraContext_t &ctx); - bool switchBehavior(const CameraManager::cameraContext_t &ctx); + void activate(const CameraManager::cameraContext_t &ctx); + bool switchBehavior(const CameraManager::cameraContext_t &ctx) { return true; }; + protected: bool camPitching; Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp 2012-05-17 08:45:12 UTC (rev 2578) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicleCineCam.cpp 2012-05-17 10:09:50 UTC (rev 2579) @@ -34,6 +34,8 @@ void CameraBehaviorVehicleCineCam::update(const CameraManager::cameraContext_t &ctx) { + CameraBehavior::update(ctx); + Vector3 dir = (ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameranodepos[ctx.mCurrTruck->currentcamera]].smoothpos - ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameranodedir[ctx.mCurrTruck->currentcamera]].smoothpos).normalisedCopy(); @@ -44,10 +46,8 @@ roll = up.crossProduct(dir); - CameraBehavior::update(ctx); + Quaternion orientation = Quaternion(camRotX, up) * Quaternion(Degree(180.0) + camRotY, roll) * Quaternion(roll, up, dir); - Quaternion orientation = Quaternion(camRotX, up) * Quaternion(Degree(180.0) + camRotY, roll) * Quaternion(roll, up, dir); - ctx.mCamera->setPosition(ctx.mCurrTruck->nodes[ctx.mCurrTruck->cinecameranodepos[ctx.mCurrTruck->currentcamera]].smoothpos); ctx.mCamera->setOrientation(orientation); } Modified: trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp =================================================================== --- trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp 2012-05-17 08:45:12 UTC (rev 2578) +++ trunk/source/main/gfx/camera/CameraBehaviorVehicleSpline.cpp 2012-05-17 10:09:50 UTC (rev 2579) @@ -40,9 +40,9 @@ { Vector3 dir = ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameranodepos[0]].smoothpos - ctx.mCurrTruck->nodes[ctx.mCurrTruck->cameranodedir[0]].smoothpos; dir.normalise(); - targetDirection = -atan2(dir.dotProduct(Vector3::UNIT_X), dir.dotProduct(-Vector3::UNIT_Z)); - targetPitch = 0; - camRatio = 1.0f / (ctx.mCurrTruck->tdt * 4.0f); + //targetDirection = -atan2(dir.dotProduct(Vector3::UNIT_X), dir.dotProduct(-Vector3::UNIT_Z)); + //targetPitch = 0; + //camRatio = 1.0f / (ctx.mCurrTruck->tdt * 4.0f); if ( ctx.mCurrTruck->free_camerarail > 0 ) { @@ -54,11 +54,11 @@ updateSplineDisplay(); - camCenterPosition = spline->interpolate(splinePos); + //camCenterPosition = spline->interpolate(splinePos); } else { // fallback :-/ - camCenterPosition = ctx.mCurrTruck->getPosition(); + //camCenterPosition = ctx.mCurrTruck->getPosition(); } CameraBehavior::update(ctx); Modified: trunk/source/main/physics/Beam.cpp =================================================================== --- trunk/source/main/physics/Beam.cpp 2012-05-17 08:45:12 UTC (rev 2578) +++ trunk/source/main/physics/Beam.cpp 2012-05-17 10:09:50 UTC (rev 2579) @@ -1882,7 +1882,7 @@ origin=Vector3::ZERO; //to fix if(pointCD) pointCD->reset(); - float yPos = lowestnode != -1 ? nodes[lowestnode].AbsPosition.y : 0; + float yPos = nodes[lowestnode].AbsPosition.y; Vector3 cur_position = nodes[0].AbsPosition; Vector3 cur_dir = nodes[0].AbsPosition; Modified: trunk/source/main/physics/input_output/SerializedRig.cpp =================================================================== --- trunk/source/main/physics/input_output/SerializedRig.cpp 2012-05-17 08:45:12 UTC (rev 2578) +++ trunk/source/main/physics/input_output/SerializedRig.cpp 2012-05-17 10:09:50 UTC (rev 2579) @@ -318,13 +318,13 @@ advanced_total_drag=0; freecamera=0; hasEmissivePass=0; - cabMesh = 0; - cabNode = 0; + cabMesh=0; + cabNode=0; cameranodepos[0]=-1; cameranodedir[0]=-1; cameranoderoll[0]=-1; freePositioned=false; - lowestnode = -1; + lowestnode=0; beamsRoot=0; virtuallyLoaded=false; @@ -6618,9 +6618,8 @@ maxy=nodes[0].AbsPosition.y; minz=nodes[0].AbsPosition.z; maxz=nodes[0].AbsPosition.z; - lowestnode=-1; - int i; - for (i=1; i<free_node; i++) + lowestnode=0; + for (int i=1; i < free_node; i++) { if (nodes[i].AbsPosition.x>maxx) maxx=nodes[i].AbsPosition.x; if (nodes[i].AbsPosition.x<minx) minx=nodes[i].AbsPosition.x; 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