BulletSim: rename position and orientation variables to remove the

inconsistant use of Raw* and _* conventions.
cpu-performance
Robert Adams 2013-07-07 05:46:24 -07:00
parent 1286677352
commit 70d24a654b
3 changed files with 71 additions and 95 deletions

View File

@ -43,12 +43,10 @@ public sealed class BSCharacter : BSPhysObject
private OMV.Vector3 _size; private OMV.Vector3 _size;
private bool _grabbed; private bool _grabbed;
private bool _selected; private bool _selected;
private OMV.Vector3 _position;
private float _mass; private float _mass;
private float _avatarVolume; private float _avatarVolume;
private float _collisionScore; private float _collisionScore;
private OMV.Vector3 _acceleration; private OMV.Vector3 _acceleration;
private OMV.Quaternion _orientation;
private int _physicsActorType; private int _physicsActorType;
private bool _isPhysical; private bool _isPhysical;
private bool _flying; private bool _flying;
@ -70,10 +68,10 @@ public sealed class BSCharacter : BSPhysObject
: base(parent_scene, localID, avName, "BSCharacter") : base(parent_scene, localID, avName, "BSCharacter")
{ {
_physicsActorType = (int)ActorTypes.Agent; _physicsActorType = (int)ActorTypes.Agent;
_position = pos; RawPosition = pos;
_flying = isFlying; _flying = isFlying;
_orientation = OMV.Quaternion.Identity; RawOrientation = OMV.Quaternion.Identity;
RawVelocity = OMV.Vector3.Zero; RawVelocity = OMV.Vector3.Zero;
_buoyancy = ComputeBuoyancyFromFlying(isFlying); _buoyancy = ComputeBuoyancyFromFlying(isFlying);
Friction = BSParam.AvatarStandingFriction; Friction = BSParam.AvatarStandingFriction;
@ -133,7 +131,7 @@ public sealed class BSCharacter : BSPhysObject
PhysScene.PE.RemoveObjectFromWorld(PhysScene.World, PhysBody); PhysScene.PE.RemoveObjectFromWorld(PhysScene.World, PhysBody);
ZeroMotion(true); ZeroMotion(true);
ForcePosition = _position; ForcePosition = RawPosition;
// Set the velocity // Set the velocity
if (m_moveActor != null) if (m_moveActor != null)
@ -272,38 +270,33 @@ public sealed class BSCharacter : BSPhysObject
public override void LockAngularMotion(OMV.Vector3 axis) { return; } public override void LockAngularMotion(OMV.Vector3 axis) { return; }
public override OMV.Vector3 RawPosition
{
get { return _position; }
set { _position = value; }
}
public override OMV.Vector3 Position { public override OMV.Vector3 Position {
get { get {
// Don't refetch the position because this function is called a zillion times // Don't refetch the position because this function is called a zillion times
// _position = PhysicsScene.PE.GetObjectPosition(Scene.World, LocalID); // RawPosition = PhysicsScene.PE.GetObjectPosition(Scene.World, LocalID);
return _position; return RawPosition;
} }
set { set {
_position = value; RawPosition = value;
PhysScene.TaintedObject("BSCharacter.setPosition", delegate() PhysScene.TaintedObject("BSCharacter.setPosition", delegate()
{ {
DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, RawPosition, RawOrientation);
PositionSanityCheck(); PositionSanityCheck();
ForcePosition = _position; ForcePosition = RawPosition;
}); });
} }
} }
public override OMV.Vector3 ForcePosition { public override OMV.Vector3 ForcePosition {
get { get {
_position = PhysScene.PE.GetPosition(PhysBody); RawPosition = PhysScene.PE.GetPosition(PhysBody);
return _position; return RawPosition;
} }
set { set {
_position = value; RawPosition = value;
if (PhysBody.HasPhysicalBody) if (PhysBody.HasPhysicalBody)
{ {
PhysScene.PE.SetTranslation(PhysBody, _position, _orientation); PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation);
} }
} }
} }
@ -331,16 +324,16 @@ public sealed class BSCharacter : BSPhysObject
float terrainHeight = PhysScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition); float terrainHeight = PhysScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition);
if (Position.Z < terrainHeight) if (Position.Z < terrainHeight)
{ {
DetailLog("{0},BSCharacter.PositionSanityCheck,adjustForUnderGround,pos={1},terrain={2}", LocalID, _position, terrainHeight); DetailLog("{0},BSCharacter.PositionSanityCheck,adjustForUnderGround,pos={1},terrain={2}", LocalID, RawPosition, terrainHeight);
_position.Z = terrainHeight + BSParam.AvatarBelowGroundUpCorrectionMeters; RawPosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, terrainHeight + BSParam.AvatarBelowGroundUpCorrectionMeters);
ret = true; ret = true;
} }
if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0)
{ {
float waterHeight = PhysScene.TerrainManager.GetWaterLevelAtXYZ(_position); float waterHeight = PhysScene.TerrainManager.GetWaterLevelAtXYZ(RawPosition);
if (Position.Z < waterHeight) if (Position.Z < waterHeight)
{ {
_position.Z = waterHeight; RawPosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, waterHeight);
ret = true; ret = true;
} }
} }
@ -360,8 +353,8 @@ public sealed class BSCharacter : BSPhysObject
// just assign to "Position" because of potential call loops. // just assign to "Position" because of potential call loops.
PhysScene.TaintedObject(inTaintTime, "BSCharacter.PositionSanityCheck", delegate() PhysScene.TaintedObject(inTaintTime, "BSCharacter.PositionSanityCheck", delegate()
{ {
DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, RawPosition, RawOrientation);
ForcePosition = _position; ForcePosition = RawPosition;
}); });
ret = true; ret = true;
} }
@ -466,19 +459,14 @@ public sealed class BSCharacter : BSPhysObject
get { return _acceleration; } get { return _acceleration; }
set { _acceleration = value; } set { _acceleration = value; }
} }
public override OMV.Quaternion RawOrientation
{
get { return _orientation; }
set { _orientation = value; }
}
public override OMV.Quaternion Orientation { public override OMV.Quaternion Orientation {
get { return _orientation; } get { return RawOrientation; }
set { set {
// Orientation is set zillions of times when an avatar is walking. It's like // Orientation is set zillions of times when an avatar is walking. It's like
// the viewer doesn't trust us. // the viewer doesn't trust us.
if (_orientation != value) if (RawOrientation != value)
{ {
_orientation = value; RawOrientation = value;
PhysScene.TaintedObject("BSCharacter.setOrientation", delegate() PhysScene.TaintedObject("BSCharacter.setOrientation", delegate()
{ {
// Bullet assumes we know what we are doing when forcing orientation // Bullet assumes we know what we are doing when forcing orientation
@ -486,10 +474,10 @@ public sealed class BSCharacter : BSPhysObject
// This forces rotation to be only around the Z axis and doesn't change any of the other axis. // This forces rotation to be only around the Z axis and doesn't change any of the other axis.
// This keeps us from flipping the capsule over which the veiwer does not understand. // This keeps us from flipping the capsule over which the veiwer does not understand.
float oRoll, oPitch, oYaw; float oRoll, oPitch, oYaw;
_orientation.GetEulerAngles(out oRoll, out oPitch, out oYaw); RawOrientation.GetEulerAngles(out oRoll, out oPitch, out oYaw);
OMV.Quaternion trimmedOrientation = OMV.Quaternion.CreateFromEulers(0f, 0f, oYaw); OMV.Quaternion trimmedOrientation = OMV.Quaternion.CreateFromEulers(0f, 0f, oYaw);
// DetailLog("{0},BSCharacter.setOrientation,taint,val={1},valDir={2},conv={3},convDir={4}", // DetailLog("{0},BSCharacter.setOrientation,taint,val={1},valDir={2},conv={3},convDir={4}",
// LocalID, _orientation, OMV.Vector3.UnitX * _orientation, // LocalID, RawOrientation, OMV.Vector3.UnitX * RawOrientation,
// trimmedOrientation, OMV.Vector3.UnitX * trimmedOrientation); // trimmedOrientation, OMV.Vector3.UnitX * trimmedOrientation);
ForceOrientation = trimmedOrientation; ForceOrientation = trimmedOrientation;
}); });
@ -501,16 +489,16 @@ public sealed class BSCharacter : BSPhysObject
{ {
get get
{ {
_orientation = PhysScene.PE.GetOrientation(PhysBody); RawOrientation = PhysScene.PE.GetOrientation(PhysBody);
return _orientation; return RawOrientation;
} }
set set
{ {
_orientation = value; RawOrientation = value;
if (PhysBody.HasPhysicalBody) if (PhysBody.HasPhysicalBody)
{ {
// _position = PhysicsScene.PE.GetPosition(BSBody); // RawPosition = PhysicsScene.PE.GetPosition(BSBody);
PhysScene.PE.SetTranslation(PhysBody, _position, _orientation); PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation);
} }
} }
} }
@ -723,9 +711,9 @@ public sealed class BSCharacter : BSPhysObject
{ {
// Don't change position if standing on a stationary object. // Don't change position if standing on a stationary object.
if (!IsStationary) if (!IsStationary)
_position = entprop.Position; RawPosition = entprop.Position;
_orientation = entprop.Rotation; RawOrientation = entprop.Rotation;
// Smooth velocity. OpenSimulator is VERY sensitive to changes in velocity of the avatar // Smooth velocity. OpenSimulator is VERY sensitive to changes in velocity of the avatar
// and will send agent updates to the clients if velocity changes by more than // and will send agent updates to the clients if velocity changes by more than
@ -740,8 +728,8 @@ public sealed class BSCharacter : BSPhysObject
// Do some sanity checking for the avatar. Make sure it's above ground and inbounds. // Do some sanity checking for the avatar. Make sure it's above ground and inbounds.
if (PositionSanityCheck(true)) if (PositionSanityCheck(true))
{ {
DetailLog("{0},BSCharacter.UpdateProperties,updatePosForSanity,pos={1}", LocalID, _position); DetailLog("{0},BSCharacter.UpdateProperties,updatePosForSanity,pos={1}", LocalID, RawPosition);
entprop.Position = _position; entprop.Position = RawPosition;
} }
// remember the current and last set values // remember the current and last set values
@ -755,7 +743,7 @@ public sealed class BSCharacter : BSPhysObject
// base.RequestPhysicsterseUpdate(); // base.RequestPhysicsterseUpdate();
DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}",
LocalID, _position, _orientation, RawVelocity, _acceleration, _rotationalVelocity); LocalID, RawPosition, RawOrientation, RawVelocity, _acceleration, _rotationalVelocity);
} }
} }
} }

View File

@ -197,10 +197,10 @@ public abstract class BSPhysObject : PhysicsActor
// Update the physical location and motion of the object. Called with data from Bullet. // Update the physical location and motion of the object. Called with data from Bullet.
public abstract void UpdateProperties(EntityProperties entprop); public abstract void UpdateProperties(EntityProperties entprop);
public abstract OMV.Vector3 RawPosition { get; set; } public virtual OMV.Vector3 RawPosition { get; set; }
public abstract OMV.Vector3 ForcePosition { get; set; } public abstract OMV.Vector3 ForcePosition { get; set; }
public abstract OMV.Quaternion RawOrientation { get; set; } public virtual OMV.Quaternion RawOrientation { get; set; }
public abstract OMV.Quaternion ForceOrientation { get; set; } public abstract OMV.Quaternion ForceOrientation { get; set; }
public OMV.Vector3 RawVelocity { get; set; } public OMV.Vector3 RawVelocity { get; set; }

View File

@ -51,12 +51,8 @@ public class BSPrim : BSPhysObject
private bool _isSelected; private bool _isSelected;
private bool _isVolumeDetect; private bool _isVolumeDetect;
// _position is what the simulator thinks the positions of the prim is.
private OMV.Vector3 _position;
private float _mass; // the mass of this object private float _mass; // the mass of this object
private OMV.Vector3 _acceleration; private OMV.Vector3 _acceleration;
private OMV.Quaternion _orientation;
private int _physicsActorType; private int _physicsActorType;
private bool _isPhysical; private bool _isPhysical;
private bool _flying; private bool _flying;
@ -88,10 +84,10 @@ public class BSPrim : BSPhysObject
{ {
// m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID); // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID);
_physicsActorType = (int)ActorTypes.Prim; _physicsActorType = (int)ActorTypes.Prim;
_position = pos; RawPosition = pos;
_size = size; _size = size;
Scale = size; // prims are the size the user wants them to be (different for BSCharactes). Scale = size; // prims are the size the user wants them to be (different for BSCharactes).
_orientation = rotation; RawOrientation = rotation;
_buoyancy = 0f; _buoyancy = 0f;
RawVelocity = OMV.Vector3.Zero; RawVelocity = OMV.Vector3.Zero;
_rotationalVelocity = OMV.Vector3.Zero; _rotationalVelocity = OMV.Vector3.Zero;
@ -270,46 +266,42 @@ public class BSPrim : BSPhysObject
return; return;
} }
public override OMV.Vector3 RawPosition
{
get { return _position; }
set { _position = value; }
}
public override OMV.Vector3 Position { public override OMV.Vector3 Position {
get { get {
// don't do the GetObjectPosition for root elements because this function is called a zillion times. // don't do the GetObjectPosition for root elements because this function is called a zillion times.
// _position = ForcePosition; // RawPosition = ForcePosition;
return _position; return RawPosition;
} }
set { set {
// If the position must be forced into the physics engine, use ForcePosition. // If the position must be forced into the physics engine, use ForcePosition.
// All positions are given in world positions. // All positions are given in world positions.
if (_position == value) if (RawPosition == value)
{ {
DetailLog("{0},BSPrim.setPosition,call,positionNotChanging,pos={1},orient={2}", LocalID, _position, _orientation); DetailLog("{0},BSPrim.setPosition,call,positionNotChanging,pos={1},orient={2}", LocalID, RawPosition, RawOrientation);
return; return;
} }
_position = value; RawPosition = value;
PositionSanityCheck(false); PositionSanityCheck(false);
PhysScene.TaintedObject("BSPrim.setPosition", delegate() PhysScene.TaintedObject("BSPrim.setPosition", delegate()
{ {
DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, RawPosition, RawOrientation);
ForcePosition = _position; ForcePosition = RawPosition;
}); });
} }
} }
// NOTE: overloaded by BSPrimDisplaced to handle offset for center-of-gravity.
public override OMV.Vector3 ForcePosition { public override OMV.Vector3 ForcePosition {
get { get {
_position = PhysScene.PE.GetPosition(PhysBody); RawPosition = PhysScene.PE.GetPosition(PhysBody);
return _position; return RawPosition;
} }
set { set {
_position = value; RawPosition = value;
if (PhysBody.HasPhysicalBody) if (PhysBody.HasPhysicalBody)
{ {
PhysScene.PE.SetTranslation(PhysBody, _position, _orientation); PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation);
ActivateIfPhysical(false); ActivateIfPhysical(false);
} }
} }
@ -343,10 +335,10 @@ public class BSPrim : BSPhysObject
float targetHeight = terrainHeight + (Size.Z / 2f); float targetHeight = terrainHeight + (Size.Z / 2f);
// If the object is below ground it just has to be moved up because pushing will // If the object is below ground it just has to be moved up because pushing will
// not get it through the terrain // not get it through the terrain
_position.Z = targetHeight; RawPosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, targetHeight);
if (inTaintTime) if (inTaintTime)
{ {
ForcePosition = _position; ForcePosition = RawPosition;
} }
// If we are throwing the object around, zero its other forces // If we are throwing the object around, zero its other forces
ZeroMotion(inTaintTime); ZeroMotion(inTaintTime);
@ -355,7 +347,7 @@ public class BSPrim : BSPhysObject
if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0)
{ {
float waterHeight = PhysScene.TerrainManager.GetWaterLevelAtXYZ(_position); float waterHeight = PhysScene.TerrainManager.GetWaterLevelAtXYZ(RawPosition);
// TODO: a floating motor so object will bob in the water // TODO: a floating motor so object will bob in the water
if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f) if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f)
{ {
@ -364,7 +356,7 @@ public class BSPrim : BSPhysObject
// Apply upforce and overcome gravity. // Apply upforce and overcome gravity.
OMV.Vector3 correctionForce = upForce - PhysScene.DefaultGravity; OMV.Vector3 correctionForce = upForce - PhysScene.DefaultGravity;
DetailLog("{0},BSPrim.PositionSanityCheck,applyForce,pos={1},upForce={2},correctionForce={3}", LocalID, _position, upForce, correctionForce); DetailLog("{0},BSPrim.PositionSanityCheck,applyForce,pos={1},upForce={2},correctionForce={3}", LocalID, RawPosition, upForce, correctionForce);
AddForce(correctionForce, false, inTaintTime); AddForce(correctionForce, false, inTaintTime);
ret = true; ret = true;
} }
@ -383,11 +375,11 @@ public class BSPrim : BSPhysObject
uint wayOutThere = Constants.RegionSize * Constants.RegionSize; uint wayOutThere = Constants.RegionSize * Constants.RegionSize;
// There have been instances of objects getting thrown way out of bounds and crashing // There have been instances of objects getting thrown way out of bounds and crashing
// the border crossing code. // the border crossing code.
if ( _position.X < -Constants.RegionSize || _position.X > wayOutThere if ( RawPosition.X < -Constants.RegionSize || RawPosition.X > wayOutThere
|| _position.Y < -Constants.RegionSize || _position.Y > wayOutThere || RawPosition.Y < -Constants.RegionSize || RawPosition.Y > wayOutThere
|| _position.Z < -Constants.RegionSize || _position.Z > wayOutThere) || RawPosition.Z < -Constants.RegionSize || RawPosition.Z > wayOutThere)
{ {
_position = new OMV.Vector3(10, 10, 50); RawPosition = new OMV.Vector3(10, 10, 50);
ZeroMotion(inTaintTime); ZeroMotion(inTaintTime);
ret = true; ret = true;
} }
@ -713,23 +705,19 @@ public class BSPrim : BSPhysObject
get { return _acceleration; } get { return _acceleration; }
set { _acceleration = value; } set { _acceleration = value; }
} }
public override OMV.Quaternion RawOrientation
{
get { return _orientation; }
set { _orientation = value; }
}
public override OMV.Quaternion Orientation { public override OMV.Quaternion Orientation {
get { get {
return _orientation; return RawOrientation;
} }
set { set {
if (_orientation == value) if (RawOrientation == value)
return; return;
_orientation = value; RawOrientation = value;
PhysScene.TaintedObject("BSPrim.setOrientation", delegate() PhysScene.TaintedObject("BSPrim.setOrientation", delegate()
{ {
ForceOrientation = _orientation; ForceOrientation = RawOrientation;
}); });
} }
} }
@ -738,14 +726,14 @@ public class BSPrim : BSPhysObject
{ {
get get
{ {
_orientation = PhysScene.PE.GetOrientation(PhysBody); RawOrientation = PhysScene.PE.GetOrientation(PhysBody);
return _orientation; return RawOrientation;
} }
set set
{ {
_orientation = value; RawOrientation = value;
if (PhysBody.HasPhysicalBody) if (PhysBody.HasPhysicalBody)
PhysScene.PE.SetTranslation(PhysBody, _position, _orientation); PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation);
} }
} }
public override int PhysicsActorType { public override int PhysicsActorType {
@ -889,7 +877,7 @@ public class BSPrim : BSPhysObject
// PhysicsScene.PE.ClearAllForces(BSBody); // PhysicsScene.PE.ClearAllForces(BSBody);
// For good measure, make sure the transform is set through to the motion state // For good measure, make sure the transform is set through to the motion state
ForcePosition = _position; ForcePosition = RawPosition;
ForceVelocity = RawVelocity; ForceVelocity = RawVelocity;
ForceRotationalVelocity = _rotationalVelocity; ForceRotationalVelocity = _rotationalVelocity;
@ -1543,8 +1531,8 @@ public class BSPrim : BSPhysObject
// DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG
// Assign directly to the local variables so the normal set actions do not happen // Assign directly to the local variables so the normal set actions do not happen
_position = entprop.Position; RawPosition = entprop.Position;
_orientation = entprop.Rotation; RawOrientation = entprop.Rotation;
// DEBUG DEBUG DEBUG -- smooth velocity changes a bit. The simulator seems to be // DEBUG DEBUG DEBUG -- smooth velocity changes a bit. The simulator seems to be
// very sensitive to velocity changes. // very sensitive to velocity changes.
if (entprop.Velocity == OMV.Vector3.Zero || !entprop.Velocity.ApproxEquals(RawVelocity, BSParam.UpdateVelocityChangeThreshold)) if (entprop.Velocity == OMV.Vector3.Zero || !entprop.Velocity.ApproxEquals(RawVelocity, BSParam.UpdateVelocityChangeThreshold))
@ -1557,13 +1545,13 @@ public class BSPrim : BSPhysObject
// The sanity check can change the velocity and/or position. // The sanity check can change the velocity and/or position.
if (PositionSanityCheck(true /* inTaintTime */ )) if (PositionSanityCheck(true /* inTaintTime */ ))
{ {
entprop.Position = _position; entprop.Position = RawPosition;
entprop.Velocity = RawVelocity; entprop.Velocity = RawVelocity;
entprop.RotationalVelocity = _rotationalVelocity; entprop.RotationalVelocity = _rotationalVelocity;
entprop.Acceleration = _acceleration; entprop.Acceleration = _acceleration;
} }
OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG OMV.Vector3 direction = OMV.Vector3.UnitX * RawOrientation; // DEBUG DEBUG DEBUG
DetailLog("{0},BSPrim.UpdateProperties,call,entProp={1},dir={2}", LocalID, entprop, direction); DetailLog("{0},BSPrim.UpdateProperties,call,entProp={1},dir={2}", LocalID, entprop, direction);
// remember the current and last set values // remember the current and last set values