removed useless unreal inworld movement vector estimation. Do animation state using movement control flags only, on avatar frame of reference. This will hold

valid until the up direction is allowed to be diferent from the world one.
avinationmerge
UbitUmarov 2014-10-01 04:32:19 +01:00
parent 49bf83ecb8
commit 4c8819a143
1 changed files with 95 additions and 68 deletions

View File

@ -299,29 +299,44 @@ namespace OpenSim.Region.Framework.Scenes.Animation
AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags;
PhysicsActor actor = m_scenePresence.PhysicsActor; PhysicsActor actor = m_scenePresence.PhysicsActor;
// there is no point on having this meaningless movement values, much less in world coordenates
// situation may change if vertical Axis of avatar is allowed to rotate.
// then jumping etc will need some care
// Create forward and left vectors from the current avatar rotation // Create forward and left vectors from the current avatar rotation
/* yes matrix are better, but getting it from the Quaternion will kill the advantage
Matrix4 rotMatrix = Matrix4.CreateFromQuaternion(m_scenePresence.Rotation); Matrix4 rotMatrix = Matrix4.CreateFromQuaternion(m_scenePresence.Rotation);
Vector3 fwd = Vector3.Transform(Vector3.UnitX, rotMatrix); Vector3 fwd = Vector3.Transform(Vector3.UnitX, rotMatrix);
Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix);
*/
// there is still a better way
// Vector3 fwd = Vector3.UnitX * m_scenePresence.Rotation;
// Vector3 left = Vector3.UnitY * m_scenePresence.Rotation;
// Check control flags // Check control flags
bool heldForward = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS); bool heldForward = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_AT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS)) != 0);
bool heldBack = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG); bool heldBack = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG)) != 0);
bool heldLeft = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS); bool heldLeft = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS)) != 0);
bool heldRight = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG); bool heldRight = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG)) != 0);
bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT; bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT;
bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT; bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT;
bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS; // bool heldUp = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_UP_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS)) != 0);
bool heldDown = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG; // excluded nudge up so it doesn't trigger jump state
bool heldUp = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_UP_POS)) != 0);
bool heldDown = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG)) != 0);
//bool flying = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) == AgentManager.ControlFlags.AGENT_CONTROL_FLY; //bool flying = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) == AgentManager.ControlFlags.AGENT_CONTROL_FLY;
//bool mouselook = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) == AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK; //bool mouselook = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) == AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK;
if (heldForward || heldBack || heldLeft || heldRight || heldUp || heldDown)
bool heldOnXY = (heldForward || heldBack || heldLeft || heldRight);
if (heldOnXY || heldUp || heldDown)
{ {
heldTurnLeft = false; heldTurnLeft = false;
heldTurnRight = false; heldTurnRight = false;
} }
// Direction in which the avatar is trying to move // Direction in which the avatar is trying to move
/*
Vector3 move = Vector3.Zero; Vector3 move = Vector3.Zero;
if (heldForward) { move.X += fwd.X; move.Y += fwd.Y; } if (heldForward) { move.X += fwd.X; move.Y += fwd.Y; }
if (heldBack) { move.X -= fwd.X; move.Y -= fwd.Y; } if (heldBack) { move.X -= fwd.X; move.Y -= fwd.Y; }
@ -329,6 +344,8 @@ namespace OpenSim.Region.Framework.Scenes.Animation
if (heldRight) { move.X -= left.X; move.Y -= left.Y; } if (heldRight) { move.X -= left.X; move.Y -= left.Y; }
if (heldUp) { move.Z += 1; } if (heldUp) { move.Z += 1; }
if (heldDown) { move.Z -= 1; } if (heldDown) { move.Z -= 1; }
*/
// Is the avatar trying to move? // Is the avatar trying to move?
// bool moving = (move != Vector3.Zero); // bool moving = (move != Vector3.Zero);
@ -340,13 +357,13 @@ namespace OpenSim.Region.Framework.Scenes.Animation
// well what to do? // well what to do?
currentControlState = motionControlStates.onsurface; currentControlState = motionControlStates.onsurface;
if (move.X != 0f || move.Y != 0f) // if (move.X != 0f || move.Y != 0f)
if (heldOnXY)
return "WALK"; return "WALK";
return "STAND"; return "STAND";
} }
#region Flying #region Flying
bool isColliding = actor.IsColliding; bool isColliding = actor.IsColliding;
@ -360,15 +377,19 @@ namespace OpenSim.Region.Framework.Scenes.Animation
currentControlState = motionControlStates.flying; currentControlState = motionControlStates.flying;
if (move.X != 0f || move.Y != 0f) // if (move.X != 0f || move.Y != 0f)
if (heldOnXY)
{ {
return (m_scenePresence.Scene.m_useFlySlow ? "FLYSLOW" : "FLY"); return (m_scenePresence.Scene.m_useFlySlow ? "FLYSLOW" : "FLY");
} }
else if (move.Z > 0f) // else if (move.Z > 0f)
else if (heldUp)
{ {
return "HOVER_UP"; return "HOVER_UP";
} }
else if (move.Z < 0f) // else if (move.Z < 0f)
else if (heldDown)
{ {
if (isColliding) if (isColliding)
{ {
@ -423,7 +444,8 @@ namespace OpenSim.Region.Framework.Scenes.Animation
} }
// Check if the user has stopped walking just now // Check if the user has stopped walking just now
if (CurrentMovementAnimation == "WALK" && (move == Vector3.Zero)) // if (CurrentMovementAnimation == "WALK" && move == Vector3.Zero))
if (CurrentMovementAnimation == "WALK" && !heldOnXY && !heldDown && !heldUp)
return "STAND"; return "STAND";
return CurrentMovementAnimation; return CurrentMovementAnimation;
@ -435,7 +457,8 @@ namespace OpenSim.Region.Framework.Scenes.Animation
#region Jumping // section added for jumping... #region Jumping // section added for jumping...
if (isColliding && move.Z > 0f && currentControlState != motionControlStates.jumping) // if (isColliding && move.Z > 0f && currentControlState != motionControlStates.jumping)
if (isColliding && heldUp && currentControlState != motionControlStates.jumping)
{ {
// Start jumping, prejump // Start jumping, prejump
currentControlState = motionControlStates.jumping; currentControlState = motionControlStates.jumping;
@ -514,12 +537,15 @@ namespace OpenSim.Region.Framework.Scenes.Animation
// next section moved outside paren. and realigned for jumping // next section moved outside paren. and realigned for jumping
if (move.X != 0f || move.Y != 0f)
// if (move.X != 0f || move.Y != 0f)
if (heldOnXY)
{ {
currentControlState = motionControlStates.onsurface; currentControlState = motionControlStates.onsurface;
Falling = false; Falling = false;
// Walking / crouchwalking / running // Walking / crouchwalking / running
if (move.Z < 0f) // if (move.Z < 0f)
if (heldDown)
{ {
return "CROUCHWALK"; return "CROUCHWALK";
} }
@ -538,7 +564,8 @@ namespace OpenSim.Region.Framework.Scenes.Animation
currentControlState = motionControlStates.onsurface; currentControlState = motionControlStates.onsurface;
Falling = false; Falling = false;
// Not walking // Not walking
if (move.Z < 0) // if (move.Z < 0)
if(heldDown)
return "CROUCH"; return "CROUCH";
else if (heldTurnLeft) else if (heldTurnLeft)
return "TURNLEFT"; return "TURNLEFT";