From 265fe349e00b3ece59ec02e56f83bb7623e9d962 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 29 Nov 2014 00:12:11 +0000
Subject: Somewhat improve avatar region crossings by properly preserving
velocity when avatar enters the new region.
This commit addresses the following issues were causing velocity to be set to 0 on the new region, disrupting flight in particular
* Full avatar updates contained no velocity information, which does appear to have some effect in testing.
* BulletSim was always setting the velocity to 0 for the new BSCharacter. Now, physics engines take a velocity parameter when setting up characters so we can avoid this.
This patch applies to both Bullet and ODE.
---
.../BasicPhysicsPlugin/BasicPhysicsScene.cs | 3 +-
.../Physics/BulletSPlugin/BSActorAvatarMove.cs | 5 +++
.../Region/Physics/BulletSPlugin/BSCharacter.cs | 41 ++++++++++++++++------
.../Region/Physics/BulletSPlugin/BSPhysObject.cs | 2 +-
OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 6 ++--
OpenSim/Region/Physics/Manager/NullPhysicsScene.cs | 3 +-
OpenSim/Region/Physics/Manager/PhysicsScene.cs | 15 +++++---
OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 6 +++-
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 11 ++----
OpenSim/Region/Physics/POSPlugin/POSScene.cs | 3 +-
10 files changed, 65 insertions(+), 30 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs
index f53adcb..06a205e 100644
--- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs
@@ -80,10 +80,11 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
return prim;
}
- public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
+ public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
{
BasicActor act = new BasicActor(size);
act.Position = position;
+ act.Velocity = velocity;
act.Flying = isFlying;
_actors.Add(act);
return act;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs
index 14518e9..8e998ba 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs
@@ -30,6 +30,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
+using OpenSim.Framework;
using OpenSim.Region.Physics.Manager;
using OMV = OpenMetaverse;
@@ -109,6 +110,10 @@ public class BSActorAvatarMove : BSActor
{
if (m_velocityMotor != null)
{
+// if (targ == OMV.Vector3.Zero)
+// Util.PrintCallStack();
+//
+// Console.WriteLine("SetVelocityAndTarget, {0} {1}", vel, targ);
m_velocityMotor.Reset();
m_velocityMotor.SetTarget(targ);
m_velocityMotor.SetCurrent(vel);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 4c54f9f..f29784a 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -64,15 +64,25 @@ public sealed class BSCharacter : BSPhysObject
private bool _usePID;
private float _PIDTau;
- public BSCharacter(uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, bool isFlying)
+// public override OMV.Vector3 RawVelocity
+// { get { return base.RawVelocity; }
+// set {
+// if (value != base.RawVelocity)
+// Util.PrintCallStack();
+// Console.WriteLine("Set rawvel to {0}", value);
+// base.RawVelocity = value; }
+// }
+
+ public BSCharacter(
+ uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 vel, OMV.Vector3 size, bool isFlying)
: base(parent_scene, localID, avName, "BSCharacter")
{
_physicsActorType = (int)ActorTypes.Agent;
- RawPosition = pos;
+ RawPosition = pos;
_flying = isFlying;
RawOrientation = OMV.Quaternion.Identity;
- RawVelocity = OMV.Vector3.Zero;
+ RawVelocity = vel;
_buoyancy = ComputeBuoyancyFromFlying(isFlying);
Friction = BSParam.AvatarStandingFriction;
Density = BSParam.AvatarDensity;
@@ -89,13 +99,15 @@ public sealed class BSCharacter : BSPhysObject
// set _avatarVolume and _mass based on capsule size, _density and Scale
ComputeAvatarVolumeAndMass();
- DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5},pos={6}",
- LocalID, _size, Scale, Density, _avatarVolume, RawMass, pos);
+ DetailLog(
+ "{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5},pos={6},vel={7}",
+ LocalID, _size, Scale, Density, _avatarVolume, RawMass, pos, vel);
// do actual creation in taint time
PhysScene.TaintedObject(LocalID, "BSCharacter.create", delegate()
{
DetailLog("{0},BSCharacter.create,taint", LocalID);
+
// New body and shape into PhysBody and PhysShape
PhysScene.Shapes.GetBodyAndShape(true, PhysScene.World, this);
@@ -142,6 +154,7 @@ public sealed class BSCharacter : BSPhysObject
m_moveActor.SetVelocityAndTarget(RawVelocity, RawVelocity, false);
ForceVelocity = RawVelocity;
+ TargetVelocity = RawVelocity;
// This will enable or disable the flying buoyancy of the avatar.
// Needs to be reset especially when an avatar is recreated after crossing a region boundry.
@@ -256,7 +269,6 @@ public sealed class BSCharacter : BSPhysObject
// Called at taint time!
public override void ZeroMotion(bool inTaintTime)
{
- RawVelocity = OMV.Vector3.Zero;
_acceleration = OMV.Vector3.Zero;
_rotationalVelocity = OMV.Vector3.Zero;
@@ -267,6 +279,7 @@ public sealed class BSCharacter : BSPhysObject
PhysScene.PE.ClearAllForces(PhysBody);
});
}
+
public override void ZeroAngularMotion(bool inTaintTime)
{
_rotationalVelocity = OMV.Vector3.Zero;
@@ -441,32 +454,40 @@ public sealed class BSCharacter : BSPhysObject
get { return RawVelocity; }
set {
RawVelocity = value;
- // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, RawVelocity);
+ OMV.Vector3 vel = RawVelocity;
+
+ DetailLog("{0}: set Velocity = {1}", LogHeader, value);
+
PhysScene.TaintedObject(LocalID, "BSCharacter.setVelocity", delegate()
{
if (m_moveActor != null)
- m_moveActor.SetVelocityAndTarget(RawVelocity, RawVelocity, true /* inTaintTime */);
+ m_moveActor.SetVelocityAndTarget(vel, vel, true /* inTaintTime */);
- DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, RawVelocity);
- ForceVelocity = RawVelocity;
+ m_log.DebugFormat("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, vel);
+ ForceVelocity = vel;
});
}
}
+
public override OMV.Vector3 ForceVelocity {
get { return RawVelocity; }
set {
PhysScene.AssertInTaintTime("BSCharacter.ForceVelocity");
+// Util.PrintCallStack();
+ DetailLog("{0}: set ForceVelocity = {1}", LogHeader, value);
RawVelocity = value;
PhysScene.PE.SetLinearVelocity(PhysBody, RawVelocity);
PhysScene.PE.Activate(PhysBody, true);
}
}
+
public override OMV.Vector3 Torque {
get { return RawTorque; }
set { RawTorque = value;
}
}
+
public override float CollisionScore {
get { return _collisionScore; }
set { _collisionScore = value;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index f059322..e4d8df8 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -228,7 +228,7 @@ public abstract class BSPhysObject : PhysicsActor
public virtual OMV.Quaternion RawOrientation { get; set; }
public abstract OMV.Quaternion ForceOrientation { get; set; }
- public OMV.Vector3 RawVelocity { get; set; }
+ public virtual OMV.Vector3 RawVelocity { get; set; }
public abstract OMV.Vector3 ForceVelocity { get; set; }
public OMV.Vector3 RawForce { get; set; }
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 0f79a10..414bc92 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -461,19 +461,19 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
#region Prim and Avatar addition and removal
- public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
+ public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
{
m_log.ErrorFormat("{0}: CALL TO AddAvatar in BSScene. NOT IMPLEMENTED", LogHeader);
return null;
}
- public override PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 size, bool isFlying)
+ public override PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
{
// m_log.DebugFormat("{0}: AddAvatar: {1}", LogHeader, avName);
if (!m_initialized) return null;
- BSCharacter actor = new BSCharacter(localID, avName, this, position, size, isFlying);
+ BSCharacter actor = new BSCharacter(localID, avName, this, position, velocity, size, isFlying);
lock (PhysObjects)
PhysObjects.Add(localID, actor);
diff --git a/OpenSim/Region/Physics/Manager/NullPhysicsScene.cs b/OpenSim/Region/Physics/Manager/NullPhysicsScene.cs
index 1ccf46d..b52f1f6 100644
--- a/OpenSim/Region/Physics/Manager/NullPhysicsScene.cs
+++ b/OpenSim/Region/Physics/Manager/NullPhysicsScene.cs
@@ -45,7 +45,8 @@ namespace OpenSim.Region.Physics.Manager
// Does nothing right now
}
- public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
+ public override PhysicsActor AddAvatar(
+ string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
{
m_log.InfoFormat("[PHYSICS]: NullPhysicsScene : AddAvatar({0})", position);
return PhysicsActor.Null;
diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
index 71ad795..9cdedbf 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
@@ -142,10 +142,12 @@ namespace OpenSim.Region.Physics.Manager
///
///
///
+ ///
///
///
///
- public abstract PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying);
+ public abstract PhysicsActor AddAvatar(
+ string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying);
///
/// Add an avatar
@@ -153,13 +155,18 @@ namespace OpenSim.Region.Physics.Manager
///
///
///
+ ///
///
///
///
- public virtual PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 size, bool isFlying)
+ public virtual PhysicsActor AddAvatar(
+ uint localID, string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
{
- PhysicsActor ret = AddAvatar(avName, position, size, isFlying);
- if (ret != null) ret.LocalID = localID;
+ PhysicsActor ret = AddAvatar(avName, position, velocity, size, isFlying);
+
+ if (ret != null)
+ ret.LocalID = localID;
+
return ret;
}
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 67503df..05eaf2a 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -167,6 +167,7 @@ namespace OpenSim.Region.Physics.OdePlugin
///
///
///
+ ///
///
///
///
@@ -178,7 +179,7 @@ namespace OpenSim.Region.Physics.OdePlugin
///
///
public OdeCharacter(
- String avName, OdeScene parent_scene, Vector3 pos, Vector3 size, float pid_d, float pid_p,
+ String avName, OdeScene parent_scene, Vector3 pos, Vector3 vel, Vector3 size, float pid_d, float pid_p,
float capsule_radius, float tensor, float density,
float walk_divisor, float rundivisor)
{
@@ -210,6 +211,9 @@ namespace OpenSim.Region.Physics.OdePlugin
m_log.WarnFormat("[ODE CHARACTER]: Got NaN Position on Character Create for {0}", avName);
}
+ _velocity = vel;
+ m_taintTargetVelocity = vel;
+
_parent_scene = parent_scene;
PID_D = pid_d;
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 6d7f079..5953557 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -1969,16 +1969,11 @@ namespace OpenSim.Region.Physics.OdePlugin
#region Add/Remove Entities
- public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
- {
- Vector3 pos;
- pos.X = position.X;
- pos.Y = position.Y;
- pos.Z = position.Z;
-
+ public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
+ {
OdeCharacter newAv
= new OdeCharacter(
- avName, this, pos, size, avPIDD, avPIDP,
+ avName, this, position, velocity, size, avPIDD, avPIDP,
avCapRadius, avStandupTensor, avDensity,
avMovementDivisorWalk, avMovementDivisorRun);
diff --git a/OpenSim/Region/Physics/POSPlugin/POSScene.cs b/OpenSim/Region/Physics/POSPlugin/POSScene.cs
index d30d482..080c6ab 100644
--- a/OpenSim/Region/Physics/POSPlugin/POSScene.cs
+++ b/OpenSim/Region/Physics/POSPlugin/POSScene.cs
@@ -58,7 +58,8 @@ namespace OpenSim.Region.Physics.POSPlugin
{
}
- public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
+ public override PhysicsActor AddAvatar(
+ string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
{
POSCharacter act = new POSCharacter();
act.Position = position;
--
cgit v1.1