From: Oliver O. <fr...@us...> - 2007-06-17 08:03:40
|
Update of /cvsroot/simspark/simspark/spark/oxygen/sceneserver In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv28400 Modified Files: Tag: projectx fpscontroller.cpp Log Message: merge from HEAD Index: fpscontroller.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/sceneserver/fpscontroller.cpp,v retrieving revision 1.1.2.1.2.1 retrieving revision 1.1.2.1.2.2 diff -C2 -d -r1.1.2.1.2.1 -r1.1.2.1.2.2 *** fpscontroller.cpp 1 Jun 2007 06:57:10 -0000 1.1.2.1.2.1 --- fpscontroller.cpp 17 Jun 2007 08:03:26 -0000 1.1.2.1.2.2 *************** *** 27,34 **** --- 27,44 ---- using namespace salt; + // define some magic number here for the static fps controller update + // (while the simulation is paused). These should be made + // configurable.n + static const float STATIC_MIN_ANGLE_DELTA = 0.1f; + static const float STATIC_MIN_VELOCITY = 1e-3; + static const float STATIC_VELOCITY_DECAY = 0.8f; + static const float STATIC_ACCELERATION = 0.01f; + FPSController::FPSController() : BodyController() { mHAngle = 0.0f; + mHAngleDelta = 0.0f; mVAngle = 0.0f; + mVAngleDelta = 0.0f; mForward = false; mBackward = false; *************** *** 45,57 **** void ! FPSController::PrePhysicsUpdateInternal(float /*deltaTime*/) { - if (mBody.get() == 0) - { - return; - } - // determine force direction ! Vector3f vec(0.0f,0.0f,0.0f); if (mForward) vec.y() += 1.0f; --- 55,62 ---- void ! FPSController::PrepareUpdate(Matrix& matrix, Matrix& fwd, Vector3f& vec) { // determine force direction ! vec = Vector3f(0.0f,0.0f,0.0f); if (mForward) vec.y() += 1.0f; *************** *** 71,79 **** } ! Matrix matrix; float hAngle = gDegToRad(-mHAngle); float vAngle = gDegToRad(-mVAngle); matrix.RotationZ(hAngle); matrix.RotateX(vAngle); mBody->SetRotation(matrix); --- 76,101 ---- } ! matrix.Identity(); float hAngle = gDegToRad(-mHAngle); float vAngle = gDegToRad(-mVAngle); matrix.RotationZ(hAngle); matrix.RotateX(vAngle); + + fwd.Identity(); + fwd.RotationZ(hAngle); + } + + void FPSController::PrePhysicsUpdateInternal(float /*deltaTime*/) + { + if (mBody.get() == 0) + { + return; + } + + Matrix matrix; + Matrix fwd; + Vector3f vec; + PrepareUpdate(matrix, fwd, vec); + mBody->SetRotation(matrix); *************** *** 83,96 **** vec *= force; - Matrix fwd; - fwd.RotationZ(hAngle); mBody->AddForce(vec.y() * fwd.Up()); - - Matrix side; - side.RotationX(vAngle); mBody->AddForce(vec.x() * fwd.Right()); - mBody->AddForce(vec.z() * Vector3f(0,0,1)); } } --- 105,175 ---- vec *= force; mBody->AddForce(vec.y() * fwd.Up()); mBody->AddForce(vec.x() * fwd.Right()); mBody->AddForce(vec.z() * Vector3f(0,0,1)); } + + mHAngleDelta = 0.0; + mVAngleDelta = 0.0; + } + + bool FPSController::NeedStaticUpdate() const + { + if (mBody.get() == 0) + { + return false; + } + + return ( + (mForward) || + (mBackward) || + (mRight) || + (mLeft) || + (mUp) || + (mDown) || + (gAbs(mHAngleDelta) >= STATIC_MIN_ANGLE_DELTA) || + (gAbs(mVAngleDelta) >= STATIC_MIN_ANGLE_DELTA) || + (mBody->GetVelocity().Length() > STATIC_MIN_VELOCITY) + ); + } + + void FPSController::UpdateStatic(float deltaTime) + { + if (mBody.get() == 0) + { + return; + } + + Matrix matrix; + Matrix fwd; + Vector3f vec; + PrepareUpdate(matrix, fwd, vec); + + mBody->SetRotation(matrix); + + Vector3f bodyVel = mBody->GetVelocity() + (deltaTime * vec * STATIC_ACCELERATION); + bodyVel *= STATIC_VELOCITY_DECAY; + + Vector3f velocity = + vec.y() * fwd.Up() + + vec.x() * fwd.Right() + + vec.z() * Vector3f(0,0,1); + + matrix.Pos() = mBody->GetPosition() + velocity * bodyVel.Length(); + + mBody->SetPosition(matrix.Pos()); + mBody->SetVelocity(velocity); + + shared_ptr<BaseNode> bodyParent = shared_static_cast<BaseNode> + (make_shared(mBody->GetParent())); + + if (bodyParent.get() != 0) + { + mBody->SynchronizeParent(); + bodyParent->UpdateHierarchy(); + } + + mHAngleDelta = 0.0; + mVAngleDelta = 0.0; } *************** *** 98,101 **** --- 177,181 ---- { mHAngle += delta; + mHAngleDelta += delta; } *************** *** 103,106 **** --- 183,187 ---- { mVAngle += delta; + mVAngleDelta += delta; } *************** *** 108,111 **** --- 189,193 ---- { mHAngle = angleDeg; + mHAngleDelta = 0.0; } *************** *** 113,116 **** --- 195,199 ---- { mVAngle = angleDeg; + mVAngleDelta = 0.0; } |