aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs239
1 files changed, 203 insertions, 36 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 7420134..c4f4021 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -130,12 +130,14 @@ namespace OpenSim.Region.Framework.Scenes
130 private bool m_setAlwaysRun; 130 private bool m_setAlwaysRun;
131 131
132 private string m_movementAnimation = "DEFAULT"; 132 private string m_movementAnimation = "DEFAULT";
133 private long m_animPersistUntil = 0; 133 private long m_animPersistUntil;
134 private bool m_allowFalling = false; 134 private int m_animTickFall;
135 private bool m_useFlySlow = false; 135 private int m_animTickJump;
136 private bool m_usePreJump = false; 136 private bool m_allowFalling;
137 private bool m_forceFly = false; 137 private bool m_useFlySlow;
138 private bool m_flyDisabled = false; 138 private bool m_usePreJump;
139 private bool m_forceFly;
140 private bool m_flyDisabled;
139 141
140 private float m_speedModifier = 1.0f; 142 private float m_speedModifier = 1.0f;
141 143
@@ -143,7 +145,7 @@ namespace OpenSim.Region.Framework.Scenes
143 145
144 public bool IsRestrictedToRegion; 146 public bool IsRestrictedToRegion;
145 147
146 public string JID = string.Empty; 148 public string JID = String.Empty;
147 149
148 // Agent moves with a PID controller causing a force to be exerted. 150 // Agent moves with a PID controller causing a force to be exerted.
149 private bool m_newCoarseLocations = true; 151 private bool m_newCoarseLocations = true;
@@ -158,43 +160,43 @@ namespace OpenSim.Region.Framework.Scenes
158 private readonly Vector3[] Dir_Vectors = new Vector3[6]; 160 private readonly Vector3[] Dir_Vectors = new Vector3[6];
159 161
160 // Position of agent's camera in world (region cordinates) 162 // Position of agent's camera in world (region cordinates)
161 protected Vector3 m_CameraCenter = Vector3.Zero; 163 protected Vector3 m_CameraCenter;
162 protected Vector3 m_lastCameraCenter = Vector3.Zero; 164 protected Vector3 m_lastCameraCenter;
163 165
164 protected Timer m_reprioritization_timer; 166 protected Timer m_reprioritization_timer;
165 protected bool m_reprioritizing = false; 167 protected bool m_reprioritizing;
166 protected bool m_reprioritization_called = false; 168 protected bool m_reprioritization_called;
167 169
168 // Use these three vectors to figure out what the agent is looking at 170 // Use these three vectors to figure out what the agent is looking at
169 // Convert it to a Matrix and/or Quaternion 171 // Convert it to a Matrix and/or Quaternion
170 protected Vector3 m_CameraAtAxis = Vector3.Zero; 172 protected Vector3 m_CameraAtAxis;
171 protected Vector3 m_CameraLeftAxis = Vector3.Zero; 173 protected Vector3 m_CameraLeftAxis;
172 protected Vector3 m_CameraUpAxis = Vector3.Zero; 174 protected Vector3 m_CameraUpAxis;
173 private uint m_AgentControlFlags; 175 private uint m_AgentControlFlags;
174 private Quaternion m_headrotation = Quaternion.Identity; 176 private Quaternion m_headrotation = Quaternion.Identity;
175 private byte m_state; 177 private byte m_state;
176 178
177 //Reuse the Vector3 instead of creating a new one on the UpdateMovement method 179 //Reuse the Vector3 instead of creating a new one on the UpdateMovement method
178 private Vector3 movementvector = Vector3.Zero; 180 private Vector3 movementvector;
179 181
180 private bool m_autopilotMoving; 182 private bool m_autopilotMoving;
181 private Vector3 m_autoPilotTarget = Vector3.Zero; 183 private Vector3 m_autoPilotTarget;
182 private bool m_sitAtAutoTarget; 184 private bool m_sitAtAutoTarget;
183 185
184 private string m_nextSitAnimation = String.Empty; 186 private string m_nextSitAnimation = String.Empty;
185 187
186 //PauPaw:Proper PID Controler for autopilot************ 188 //PauPaw:Proper PID Controler for autopilot************
187 private bool m_moveToPositionInProgress; 189 private bool m_moveToPositionInProgress;
188 private Vector3 m_moveToPositionTarget = Vector3.Zero; 190 private Vector3 m_moveToPositionTarget;
189 191
190 private bool m_followCamAuto = false; 192 private bool m_followCamAuto;
191 193
192 private int m_movementUpdateCount = 0; 194 private int m_movementUpdateCount;
193 195
194 private const int NumMovementsBetweenRayCast = 5; 196 private const int NumMovementsBetweenRayCast = 5;
195 197
196 private bool CameraConstraintActive = false; 198 private bool CameraConstraintActive;
197 //private int m_moveToPositionStateStatus = 0; 199 //private int m_moveToPositionStateStatus;
198 //***************************************************** 200 //*****************************************************
199 201
200 // Agent's Draw distance. 202 // Agent's Draw distance.
@@ -444,7 +446,7 @@ namespace OpenSim.Region.Framework.Scenes
444 } 446 }
445 447
446 m_pos = value; 448 m_pos = value;
447 m_parentPosition = new Vector3(0, 0, 0); 449 m_parentPosition = Vector3.Zero;
448 } 450 }
449 } 451 }
450 452
@@ -457,22 +459,21 @@ namespace OpenSim.Region.Framework.Scenes
457 { 459 {
458 PhysicsActor actor = m_physicsActor; 460 PhysicsActor actor = m_physicsActor;
459 if (actor != null) 461 if (actor != null)
460 m_velocity = m_physicsActor.Velocity; 462 m_velocity = actor.Velocity;
461 463
462 return m_velocity; 464 return m_velocity;
463 } 465 }
464 set 466 set
465 { 467 {
466 //m_log.DebugFormat("In {0} setting velocity of {1} to {2}", m_scene.RegionInfo.RegionName, Name, value); 468 //m_log.DebugFormat("In {0} setting velocity of {1} to {2}", m_scene.RegionInfo.RegionName, Name, value);
467 469
468 if (m_physicsActor != null) 470 PhysicsActor actor = m_physicsActor;
471 if (actor != null)
469 { 472 {
470 try 473 try
471 { 474 {
472 lock (m_scene.SyncRoot) 475 lock (m_scene.SyncRoot)
473 { 476 actor.Velocity = value;
474 m_physicsActor.Velocity = value;
475 }
476 } 477 }
477 catch (Exception e) 478 catch (Exception e)
478 { 479 {
@@ -934,7 +935,7 @@ namespace OpenSim.Region.Framework.Scenes
934 isFlying = m_physicsActor.Flying; 935 isFlying = m_physicsActor.Flying;
935 936
936 RemoveFromPhysicalScene(); 937 RemoveFromPhysicalScene();
937 Velocity = new Vector3(0, 0, 0); 938 Velocity = Vector3.Zero;
938 AbsolutePosition = pos; 939 AbsolutePosition = pos;
939 AddToPhysicalScene(isFlying); 940 AddToPhysicalScene(isFlying);
940 if (m_appearance != null) 941 if (m_appearance != null)
@@ -982,12 +983,13 @@ namespace OpenSim.Region.Framework.Scenes
982 983
983 if (m_avHeight != 127.0f) 984 if (m_avHeight != 127.0f)
984 { 985 {
985 AbsolutePosition = AbsolutePosition + new Vector3(0, 0, (m_avHeight / 6f)); 986 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (m_avHeight / 6f));
986 } 987 }
987 else 988 else
988 { 989 {
989 AbsolutePosition = AbsolutePosition + new Vector3(0, 0, (1.56f / 6f)); 990 AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f));
990 } 991 }
992
991 TrySetMovementAnimation("LAND"); 993 TrySetMovementAnimation("LAND");
992 SendFullUpdateToAllClients(); 994 SendFullUpdateToAllClients();
993 } 995 }
@@ -1534,7 +1536,7 @@ namespace OpenSim.Region.Framework.Scenes
1534 if (part != null) 1536 if (part != null)
1535 { 1537 {
1536 AbsolutePosition = part.AbsolutePosition; 1538 AbsolutePosition = part.AbsolutePosition;
1537 Velocity = new Vector3(0, 0, 0); 1539 Velocity = Vector3.Zero;
1538 SendFullUpdateToAllClients(); 1540 SendFullUpdateToAllClients();
1539 1541
1540 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); 1542 //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID);
@@ -1851,7 +1853,7 @@ namespace OpenSim.Region.Framework.Scenes
1851 } 1853 }
1852 m_parentID = m_requestedSitTargetID; 1854 m_parentID = m_requestedSitTargetID;
1853 1855
1854 Velocity = new Vector3(0, 0, 0); 1856 Velocity = Vector3.Zero;
1855 RemoveFromPhysicalScene(); 1857 RemoveFromPhysicalScene();
1856 1858
1857 TrySetMovementAnimation(sitAnimation); 1859 TrySetMovementAnimation(sitAnimation);
@@ -2008,7 +2010,7 @@ namespace OpenSim.Region.Framework.Scenes
2008 protected void TrySetMovementAnimation(string anim) 2010 protected void TrySetMovementAnimation(string anim)
2009 { 2011 {
2010 //m_log.DebugFormat("Updating movement animation to {0}", anim); 2012 //m_log.DebugFormat("Updating movement animation to {0}", anim);
2011 2013
2012 if (!m_isChildAgent) 2014 if (!m_isChildAgent)
2013 { 2015 {
2014 if (m_animations.TrySetDefaultAnimation(anim, m_controllingClient.NextAnimationSequenceNumber, UUID.Zero)) 2016 if (m_animations.TrySetDefaultAnimation(anim, m_controllingClient.NextAnimationSequenceNumber, UUID.Zero))
@@ -2239,12 +2241,176 @@ namespace OpenSim.Region.Framework.Scenes
2239 } 2241 }
2240 } 2242 }
2241 2243
2244 public string GetMovementAnimation2()
2245 {
2246 const float FALL_DELAY = 0.33f;
2247 const float PREJUMP_DELAY = 0.25f;
2248
2249 m_allowFalling = true;
2250
2251 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_AgentControlFlags;
2252 PhysicsActor actor = m_physicsActor;
2253
2254 // Create forward and left vectors from the current avatar rotation
2255 Matrix4 rotMatrix = Matrix4.CreateFromQuaternion(m_bodyRot);
2256 Vector3 fwd = Vector3.Transform(Vector3.UnitX, rotMatrix);
2257 Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix);
2258
2259 // Check control flags
2260 bool heldForward = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS;
2261 bool heldBack = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG;
2262 bool heldLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS;
2263 bool heldRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG;
2264 //bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT;
2265 //bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT;
2266 bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS;
2267 bool heldDown = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG;
2268 //bool flying = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) == AgentManager.ControlFlags.AGENT_CONTROL_FLY;
2269 //bool mouselook = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) == AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK;
2270
2271 // Direction in which the avatar is trying to move
2272 Vector3 move = Vector3.Zero;
2273 if (heldForward) { move.X += fwd.X; move.Y += fwd.Y; }
2274 if (heldBack) { move.X -= fwd.X; move.Y -= fwd.Y; }
2275 if (heldLeft) { move.X += left.X; move.Y += left.Y; }
2276 if (heldRight) { move.X -= left.X; move.Y -= left.Y; }
2277 if (heldUp) { move.Z += 1; }
2278 if (heldDown) { move.Z -= 1; }
2279
2280 // Is the avatar trying to move?
2281 bool moving = (move != Vector3.Zero);
2282 bool jumping = m_animTickJump != 0;
2283
2284 #region Flying
2285
2286 if (actor != null && actor.Flying)
2287 {
2288 m_animTickFall = 0;
2289 m_animTickJump = 0;
2290
2291 if (move.X != 0f || move.Y != 0f)
2292 {
2293 return (m_useFlySlow ? "FLYSLOW" : "FLY");
2294 }
2295 else if (move.Z > 0f)
2296 {
2297 return "HOVER_UP";
2298 }
2299 else if (move.Z < 0f)
2300 {
2301 if (actor != null && actor.IsColliding)
2302 return "LAND";
2303 else
2304 return "HOVER_DOWN";
2305 }
2306 else
2307 {
2308 return "HOVER";
2309 }
2310 }
2311
2312 #endregion Flying
2313
2314 #region Falling/Floating/Landing
2315
2316 if (actor == null || !actor.IsColliding)
2317 {
2318 float fallElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f;
2319
2320 if (m_animTickFall == 0 || (fallElapsed > FALL_DELAY && actor.Velocity.Z >= 0.0f))
2321 {
2322 // Just started falling
2323 m_animTickFall = Environment.TickCount;
2324 }
2325 else if (!jumping && fallElapsed > FALL_DELAY)
2326 {
2327 // Falling long enough to trigger the animation
2328 return "FALLDOWN";
2329 }
2330
2331 return m_movementAnimation;
2332 }
2333
2334 #endregion Falling/Floating/Landing
2335
2336 #region Ground Movement
2337
2338 if (m_movementAnimation == "FALLDOWN")
2339 {
2340 m_animTickFall = Environment.TickCount;
2341
2342 // TODO: SOFT_LAND support
2343 return "LAND";
2344 }
2345 else if (m_movementAnimation == "LAND")
2346 {
2347 float landElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f;
2348
2349 if (landElapsed <= FALL_DELAY)
2350 return "LAND";
2351 }
2352
2353 m_animTickFall = 0;
2354
2355 if (move.Z > 0f)
2356 {
2357 // Jumping
2358 if (!jumping)
2359 {
2360 // Begin prejump
2361 m_animTickJump = Environment.TickCount;
2362 return "PREJUMP";
2363 }
2364 else if (Environment.TickCount - m_animTickJump > PREJUMP_DELAY * 1000.0f)
2365 {
2366 // Start actual jump
2367 if (m_animTickJump == -1)
2368 {
2369 // Already jumping! End the current jump
2370 m_animTickJump = 0;
2371 return "JUMP";
2372 }
2373
2374 m_animTickJump = -1;
2375 return "JUMP";
2376 }
2377 }
2378 else
2379 {
2380 // Not jumping
2381 m_animTickJump = 0;
2382
2383 if (move.X != 0f || move.Y != 0f)
2384 {
2385 // Walking / crouchwalking / running
2386 if (move.Z < 0f)
2387 return "CROUCHWALK";
2388 else if (m_setAlwaysRun)
2389 return "RUN";
2390 else
2391 return "WALK";
2392 }
2393 else
2394 {
2395 // Not walking
2396 if (move.Z < 0f)
2397 return "CROUCH";
2398 else
2399 return "STAND";
2400 }
2401 }
2402
2403 #endregion Ground Movement
2404
2405 return m_movementAnimation;
2406 }
2407
2242 /// <summary> 2408 /// <summary>
2243 /// Update the movement animation of this avatar according to its current state 2409 /// Update the movement animation of this avatar according to its current state
2244 /// </summary> 2410 /// </summary>
2245 protected void UpdateMovementAnimations() 2411 protected void UpdateMovementAnimations()
2246 { 2412 {
2247 string movementAnimation = GetMovementAnimation(); 2413 string movementAnimation = GetMovementAnimation2();
2248 2414
2249 if (movementAnimation == "FALLDOWN" && m_allowFalling == false) 2415 if (movementAnimation == "FALLDOWN" && m_allowFalling == false)
2250 { 2416 {
@@ -2367,7 +2533,8 @@ namespace OpenSim.Region.Framework.Scenes
2367 2533
2368 if (m_isChildAgent == false) 2534 if (m_isChildAgent == false)
2369 { 2535 {
2370 Vector3 velocity = (m_physicsActor != null) ? m_physicsActor.Velocity : Vector3.Zero; 2536 PhysicsActor actor = m_physicsActor;
2537 Vector3 velocity = (actor != null) ? actor.Velocity : Vector3.Zero;
2371 2538
2372 // Throw away duplicate or insignificant updates 2539 // Throw away duplicate or insignificant updates
2373 if (!m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) || 2540 if (!m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||