From eb5c89a8802f523a782bf82786219c604a5e15dd Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Sun, 13 Jan 2013 11:27:56 +0100 Subject: [PATCH] GRIM: Use the right turn rate, and increase it only when necessary. --- engines/grim/actor.cpp | 17 ++++++++++------- engines/grim/actor.h | 8 ++++++-- engines/grim/lua_v1_actor.cpp | 7 ++----- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/engines/grim/actor.cpp b/engines/grim/actor.cpp index db3cc562da0..c3fa0058f50 100644 --- a/engines/grim/actor.cpp +++ b/engines/grim/actor.cpp @@ -473,7 +473,7 @@ Math::Vector3d Actor::actorUp() const { return Math::Vector3d(0.f, 1.f, 0.f); } -void Actor::turnTo(const Math::Vector3d &pos) { +void Actor::turnTo(const Math::Vector3d &pos, bool snap) { Math::Vector3d lookVector = pos - _pos; lookVector.normalize(); @@ -490,16 +490,17 @@ void Actor::turnTo(const Math::Vector3d &pos) { m.buildFromTargetDir(actorForward(), lookVector, actorUp(), up); if (_puckOrient) { - turnTo(m.getPitch(), m.getYaw(), m.getRoll()); + turnTo(m.getPitch(), m.getYaw(), m.getRoll(), snap); } else { - turnTo(_pitch, m.getYaw(), _roll); + turnTo(_pitch, m.getYaw(), _roll, snap); } } -void Actor::turnTo(const Math::Angle &pitchParam, const Math::Angle &yawParam, const Math::Angle &rollParam) { +void Actor::turnTo(const Math::Angle &pitchParam, const Math::Angle &yawParam, const Math::Angle &rollParam, bool snap) { _movePitch = pitchParam; _moveRoll = rollParam; _moveYaw = yawParam; + _turnRateMultiplier = (snap ? 5.f : 1.f); if (_yaw != yawParam || _pitch != pitchParam || _roll != rollParam) { _turning = true; } else @@ -802,7 +803,7 @@ void Actor::walkForward() { return; ei.angleWithEdge += (float)1.0f; - turnTo(0, _moveYaw + ei.angleWithEdge * turnDir, 0); + turnTo(0, _moveYaw + ei.angleWithEdge * turnDir, 0, true); if (oldDist <= dist + 0.001f) { // If we didn't move at all, keep trying a couple more times @@ -953,6 +954,7 @@ void Actor::turn(int dir) { float delta = g_grim->getPerSecond(_turnRate) * dir; _moveYaw = _moveYaw + delta; _turning = true; + _turnRateMultiplier = 5.f; _currTurnDir = dir; } @@ -1253,7 +1255,7 @@ void Actor::updateWalk() { } } - turnTo(destPos); + turnTo(destPos, true); dir = destPos - _pos; dir.normalize(); @@ -1289,12 +1291,13 @@ void Actor::update(uint frameTime) { } if (_turning) { - float turnAmt = g_grim->getPerSecond(_turnRate)*5; + float turnAmt = g_grim->getPerSecond(_turnRate) * _turnRateMultiplier; _currTurnDir = animTurn(turnAmt, _moveYaw, &_yaw); int p = animTurn(turnAmt, _movePitch, &_pitch); int r = animTurn(turnAmt, _moveRoll, &_roll); if (_currTurnDir == 0 && p == 0 && r == 0) { _turning = false; + _turnRateMultiplier = 1.f; } } diff --git a/engines/grim/actor.h b/engines/grim/actor.h index 311f30e6cf8..fa50366e8d0 100644 --- a/engines/grim/actor.h +++ b/engines/grim/actor.h @@ -175,6 +175,7 @@ public: * @param pitch The rotation of the x axis * @param yaw The rotation of the z axis * @param roll The rotation of the y axis + * @param snap If true tells the actor to increate its turn speed. * @see getPitch * @see getYaw * @see getRoll @@ -182,17 +183,18 @@ public: * @see turn * @see isTurning */ - void turnTo(const Math::Angle &pitch, const Math::Angle &yaw, const Math::Angle &roll); + void turnTo(const Math::Angle &pitch, const Math::Angle &yaw, const Math::Angle &roll, bool snap = false); /** * Turn the actor towards a point in space. * The effect is not immediate, the actor will slowly rotate * to the destination orientation. * * @param pos The position the actor should turn to. + * @param snap If true tells the actor to increate its turn speed. * @see turnTo * @see setRot */ - void turnTo(const Math::Vector3d &pos); + void turnTo(const Math::Vector3d &pos, bool snap = false); /** * Returns true if the actor is turning. * @@ -558,6 +560,8 @@ private: Math::Angle _moveYaw; Math::Angle _movePitch; Math::Angle _moveRoll; + // This is used to increase momentarily the turn rate when needed + float _turnRateMultiplier; // Variables for walking to a point bool _walking; diff --git a/engines/grim/lua_v1_actor.cpp b/engines/grim/lua_v1_actor.cpp index 25258ebd2fd..c87cf56b0ee 100644 --- a/engines/grim/lua_v1_actor.cpp +++ b/engines/grim/lua_v1_actor.cpp @@ -341,10 +341,7 @@ void Lua_V1::SetActorRot() { float pitch = lua_getnumber(p); float yaw = lua_getnumber(y); float roll = lua_getnumber(r); - if (getbool(5)) - actor->turnTo(pitch, yaw, roll); - else - actor->setRot(pitch, yaw, roll); + actor->turnTo(pitch, yaw, roll, getbool(5)); } void Lua_V1::GetActorRot() { @@ -1174,7 +1171,7 @@ void Lua_V1::TurnActorTo() { } Math::Vector3d turnToVector(x, y, z); - actor->turnTo(turnToVector); + actor->turnTo(turnToVector, false); // Return true if the actor is still turning // This allows manny to have the right yaw when he exits the elevator in the garage