mirror of
https://github.com/opensim/opensim.git
synced 2026-08-09 18:55:58 +08:00
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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user