BulletSim: rename position and orientation variables to remove the
inconsistant use of Raw* and _* conventions.cpu-performance
parent
1286677352
commit
70d24a654b
|
@ -43,12 +43,10 @@ public sealed class BSCharacter : BSPhysObject
|
|||
private OMV.Vector3 _size;
|
||||
private bool _grabbed;
|
||||
private bool _selected;
|
||||
private OMV.Vector3 _position;
|
||||
private float _mass;
|
||||
private float _avatarVolume;
|
||||
private float _collisionScore;
|
||||
private OMV.Vector3 _acceleration;
|
||||
private OMV.Quaternion _orientation;
|
||||
private int _physicsActorType;
|
||||
private bool _isPhysical;
|
||||
private bool _flying;
|
||||
|
@ -70,10 +68,10 @@ public sealed class BSCharacter : BSPhysObject
|
|||
: base(parent_scene, localID, avName, "BSCharacter")
|
||||
{
|
||||
_physicsActorType = (int)ActorTypes.Agent;
|
||||
_position = pos;
|
||||
RawPosition = pos;
|
||||
|
||||
_flying = isFlying;
|
||||
_orientation = OMV.Quaternion.Identity;
|
||||
RawOrientation = OMV.Quaternion.Identity;
|
||||
RawVelocity = OMV.Vector3.Zero;
|
||||
_buoyancy = ComputeBuoyancyFromFlying(isFlying);
|
||||
Friction = BSParam.AvatarStandingFriction;
|
||||
|
@ -133,7 +131,7 @@ public sealed class BSCharacter : BSPhysObject
|
|||
PhysScene.PE.RemoveObjectFromWorld(PhysScene.World, PhysBody);
|
||||
|
||||
ZeroMotion(true);
|
||||
ForcePosition = _position;
|
||||
ForcePosition = RawPosition;
|
||||
|
||||
// Set the velocity
|
||||
if (m_moveActor != null)
|
||||
|
@ -272,38 +270,33 @@ public sealed class BSCharacter : BSPhysObject
|
|||
|
||||
public override void LockAngularMotion(OMV.Vector3 axis) { return; }
|
||||
|
||||
public override OMV.Vector3 RawPosition
|
||||
{
|
||||
get { return _position; }
|
||||
set { _position = value; }
|
||||
}
|
||||
public override OMV.Vector3 Position {
|
||||
get {
|
||||
// Don't refetch the position because this function is called a zillion times
|
||||
// _position = PhysicsScene.PE.GetObjectPosition(Scene.World, LocalID);
|
||||
return _position;
|
||||
// RawPosition = PhysicsScene.PE.GetObjectPosition(Scene.World, LocalID);
|
||||
return RawPosition;
|
||||
}
|
||||
set {
|
||||
_position = value;
|
||||
RawPosition = value;
|
||||
|
||||
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();
|
||||
ForcePosition = _position;
|
||||
ForcePosition = RawPosition;
|
||||
});
|
||||
}
|
||||
}
|
||||
public override OMV.Vector3 ForcePosition {
|
||||
get {
|
||||
_position = PhysScene.PE.GetPosition(PhysBody);
|
||||
return _position;
|
||||
RawPosition = PhysScene.PE.GetPosition(PhysBody);
|
||||
return RawPosition;
|
||||
}
|
||||
set {
|
||||
_position = value;
|
||||
RawPosition = value;
|
||||
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);
|
||||
if (Position.Z < terrainHeight)
|
||||
{
|
||||
DetailLog("{0},BSCharacter.PositionSanityCheck,adjustForUnderGround,pos={1},terrain={2}", LocalID, _position, terrainHeight);
|
||||
_position.Z = terrainHeight + BSParam.AvatarBelowGroundUpCorrectionMeters;
|
||||
DetailLog("{0},BSCharacter.PositionSanityCheck,adjustForUnderGround,pos={1},terrain={2}", LocalID, RawPosition, terrainHeight);
|
||||
RawPosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, terrainHeight + BSParam.AvatarBelowGroundUpCorrectionMeters);
|
||||
ret = true;
|
||||
}
|
||||
if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0)
|
||||
{
|
||||
float waterHeight = PhysScene.TerrainManager.GetWaterLevelAtXYZ(_position);
|
||||
float waterHeight = PhysScene.TerrainManager.GetWaterLevelAtXYZ(RawPosition);
|
||||
if (Position.Z < waterHeight)
|
||||
{
|
||||
_position.Z = waterHeight;
|
||||
RawPosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, waterHeight);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
@ -360,8 +353,8 @@ public sealed class BSCharacter : BSPhysObject
|
|||
// just assign to "Position" because of potential call loops.
|
||||
PhysScene.TaintedObject(inTaintTime, "BSCharacter.PositionSanityCheck", delegate()
|
||||
{
|
||||
DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation);
|
||||
ForcePosition = _position;
|
||||
DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, RawPosition, RawOrientation);
|
||||
ForcePosition = RawPosition;
|
||||
});
|
||||
ret = true;
|
||||
}
|
||||
|
@ -466,19 +459,14 @@ public sealed class BSCharacter : BSPhysObject
|
|||
get { return _acceleration; }
|
||||
set { _acceleration = value; }
|
||||
}
|
||||
public override OMV.Quaternion RawOrientation
|
||||
{
|
||||
get { return _orientation; }
|
||||
set { _orientation = value; }
|
||||
}
|
||||
public override OMV.Quaternion Orientation {
|
||||
get { return _orientation; }
|
||||
get { return RawOrientation; }
|
||||
set {
|
||||
// Orientation is set zillions of times when an avatar is walking. It's like
|
||||
// the viewer doesn't trust us.
|
||||
if (_orientation != value)
|
||||
if (RawOrientation != value)
|
||||
{
|
||||
_orientation = value;
|
||||
RawOrientation = value;
|
||||
PhysScene.TaintedObject("BSCharacter.setOrientation", delegate()
|
||||
{
|
||||
// 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 keeps us from flipping the capsule over which the veiwer does not understand.
|
||||
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);
|
||||
// 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);
|
||||
ForceOrientation = trimmedOrientation;
|
||||
});
|
||||
|
@ -501,16 +489,16 @@ public sealed class BSCharacter : BSPhysObject
|
|||
{
|
||||
get
|
||||
{
|
||||
_orientation = PhysScene.PE.GetOrientation(PhysBody);
|
||||
return _orientation;
|
||||
RawOrientation = PhysScene.PE.GetOrientation(PhysBody);
|
||||
return RawOrientation;
|
||||
}
|
||||
set
|
||||
{
|
||||
_orientation = value;
|
||||
RawOrientation = value;
|
||||
if (PhysBody.HasPhysicalBody)
|
||||
{
|
||||
// _position = PhysicsScene.PE.GetPosition(BSBody);
|
||||
PhysScene.PE.SetTranslation(PhysBody, _position, _orientation);
|
||||
// RawPosition = PhysicsScene.PE.GetPosition(BSBody);
|
||||
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.
|
||||
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
|
||||
// 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.
|
||||
if (PositionSanityCheck(true))
|
||||
{
|
||||
DetailLog("{0},BSCharacter.UpdateProperties,updatePosForSanity,pos={1}", LocalID, _position);
|
||||
entprop.Position = _position;
|
||||
DetailLog("{0},BSCharacter.UpdateProperties,updatePosForSanity,pos={1}", LocalID, RawPosition);
|
||||
entprop.Position = RawPosition;
|
||||
}
|
||||
|
||||
// remember the current and last set values
|
||||
|
@ -755,7 +743,7 @@ public sealed class BSCharacter : BSPhysObject
|
|||
// base.RequestPhysicsterseUpdate();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,10 +197,10 @@ public abstract class BSPhysObject : PhysicsActor
|
|||
// Update the physical location and motion of the object. Called with data from Bullet.
|
||||
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.Quaternion RawOrientation { get; set; }
|
||||
public virtual OMV.Quaternion RawOrientation { get; set; }
|
||||
public abstract OMV.Quaternion ForceOrientation { get; set; }
|
||||
|
||||
public OMV.Vector3 RawVelocity { get; set; }
|
||||
|
|
|
@ -51,12 +51,8 @@ public class BSPrim : BSPhysObject
|
|||
private bool _isSelected;
|
||||
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 OMV.Vector3 _acceleration;
|
||||
private OMV.Quaternion _orientation;
|
||||
private int _physicsActorType;
|
||||
private bool _isPhysical;
|
||||
private bool _flying;
|
||||
|
@ -88,10 +84,10 @@ public class BSPrim : BSPhysObject
|
|||
{
|
||||
// m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID);
|
||||
_physicsActorType = (int)ActorTypes.Prim;
|
||||
_position = pos;
|
||||
RawPosition = pos;
|
||||
_size = size;
|
||||
Scale = size; // prims are the size the user wants them to be (different for BSCharactes).
|
||||
_orientation = rotation;
|
||||
RawOrientation = rotation;
|
||||
_buoyancy = 0f;
|
||||
RawVelocity = OMV.Vector3.Zero;
|
||||
_rotationalVelocity = OMV.Vector3.Zero;
|
||||
|
@ -270,46 +266,42 @@ public class BSPrim : BSPhysObject
|
|||
return;
|
||||
}
|
||||
|
||||
public override OMV.Vector3 RawPosition
|
||||
{
|
||||
get { return _position; }
|
||||
set { _position = value; }
|
||||
}
|
||||
public override OMV.Vector3 Position {
|
||||
get {
|
||||
// don't do the GetObjectPosition for root elements because this function is called a zillion times.
|
||||
// _position = ForcePosition;
|
||||
return _position;
|
||||
// RawPosition = ForcePosition;
|
||||
return RawPosition;
|
||||
}
|
||||
set {
|
||||
// If the position must be forced into the physics engine, use ForcePosition.
|
||||
// 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;
|
||||
}
|
||||
_position = value;
|
||||
RawPosition = value;
|
||||
PositionSanityCheck(false);
|
||||
|
||||
PhysScene.TaintedObject("BSPrim.setPosition", delegate()
|
||||
{
|
||||
DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
|
||||
ForcePosition = _position;
|
||||
DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, RawPosition, RawOrientation);
|
||||
ForcePosition = RawPosition;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: overloaded by BSPrimDisplaced to handle offset for center-of-gravity.
|
||||
public override OMV.Vector3 ForcePosition {
|
||||
get {
|
||||
_position = PhysScene.PE.GetPosition(PhysBody);
|
||||
return _position;
|
||||
RawPosition = PhysScene.PE.GetPosition(PhysBody);
|
||||
return RawPosition;
|
||||
}
|
||||
set {
|
||||
_position = value;
|
||||
RawPosition = value;
|
||||
if (PhysBody.HasPhysicalBody)
|
||||
{
|
||||
PhysScene.PE.SetTranslation(PhysBody, _position, _orientation);
|
||||
PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation);
|
||||
ActivateIfPhysical(false);
|
||||
}
|
||||
}
|
||||
|
@ -343,10 +335,10 @@ public class BSPrim : BSPhysObject
|
|||
float targetHeight = terrainHeight + (Size.Z / 2f);
|
||||
// If the object is below ground it just has to be moved up because pushing will
|
||||
// not get it through the terrain
|
||||
_position.Z = targetHeight;
|
||||
RawPosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, targetHeight);
|
||||
if (inTaintTime)
|
||||
{
|
||||
ForcePosition = _position;
|
||||
ForcePosition = RawPosition;
|
||||
}
|
||||
// If we are throwing the object around, zero its other forces
|
||||
ZeroMotion(inTaintTime);
|
||||
|
@ -355,7 +347,7 @@ public class BSPrim : BSPhysObject
|
|||
|
||||
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
|
||||
if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f)
|
||||
{
|
||||
|
@ -364,7 +356,7 @@ public class BSPrim : BSPhysObject
|
|||
|
||||
// Apply upforce and overcome gravity.
|
||||
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);
|
||||
ret = true;
|
||||
}
|
||||
|
@ -383,11 +375,11 @@ public class BSPrim : BSPhysObject
|
|||
uint wayOutThere = Constants.RegionSize * Constants.RegionSize;
|
||||
// There have been instances of objects getting thrown way out of bounds and crashing
|
||||
// the border crossing code.
|
||||
if ( _position.X < -Constants.RegionSize || _position.X > wayOutThere
|
||||
|| _position.Y < -Constants.RegionSize || _position.Y > wayOutThere
|
||||
|| _position.Z < -Constants.RegionSize || _position.Z > wayOutThere)
|
||||
if ( RawPosition.X < -Constants.RegionSize || RawPosition.X > wayOutThere
|
||||
|| RawPosition.Y < -Constants.RegionSize || RawPosition.Y > wayOutThere
|
||||
|| RawPosition.Z < -Constants.RegionSize || RawPosition.Z > wayOutThere)
|
||||
{
|
||||
_position = new OMV.Vector3(10, 10, 50);
|
||||
RawPosition = new OMV.Vector3(10, 10, 50);
|
||||
ZeroMotion(inTaintTime);
|
||||
ret = true;
|
||||
}
|
||||
|
@ -713,23 +705,19 @@ public class BSPrim : BSPhysObject
|
|||
get { return _acceleration; }
|
||||
set { _acceleration = value; }
|
||||
}
|
||||
public override OMV.Quaternion RawOrientation
|
||||
{
|
||||
get { return _orientation; }
|
||||
set { _orientation = value; }
|
||||
}
|
||||
|
||||
public override OMV.Quaternion Orientation {
|
||||
get {
|
||||
return _orientation;
|
||||
return RawOrientation;
|
||||
}
|
||||
set {
|
||||
if (_orientation == value)
|
||||
if (RawOrientation == value)
|
||||
return;
|
||||
_orientation = value;
|
||||
RawOrientation = value;
|
||||
|
||||
PhysScene.TaintedObject("BSPrim.setOrientation", delegate()
|
||||
{
|
||||
ForceOrientation = _orientation;
|
||||
ForceOrientation = RawOrientation;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -738,14 +726,14 @@ public class BSPrim : BSPhysObject
|
|||
{
|
||||
get
|
||||
{
|
||||
_orientation = PhysScene.PE.GetOrientation(PhysBody);
|
||||
return _orientation;
|
||||
RawOrientation = PhysScene.PE.GetOrientation(PhysBody);
|
||||
return RawOrientation;
|
||||
}
|
||||
set
|
||||
{
|
||||
_orientation = value;
|
||||
RawOrientation = value;
|
||||
if (PhysBody.HasPhysicalBody)
|
||||
PhysScene.PE.SetTranslation(PhysBody, _position, _orientation);
|
||||
PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation);
|
||||
}
|
||||
}
|
||||
public override int PhysicsActorType {
|
||||
|
@ -889,7 +877,7 @@ public class BSPrim : BSPhysObject
|
|||
// PhysicsScene.PE.ClearAllForces(BSBody);
|
||||
|
||||
// For good measure, make sure the transform is set through to the motion state
|
||||
ForcePosition = _position;
|
||||
ForcePosition = RawPosition;
|
||||
ForceVelocity = RawVelocity;
|
||||
ForceRotationalVelocity = _rotationalVelocity;
|
||||
|
||||
|
@ -1543,8 +1531,8 @@ public class BSPrim : BSPhysObject
|
|||
// 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
|
||||
_position = entprop.Position;
|
||||
_orientation = entprop.Rotation;
|
||||
RawPosition = entprop.Position;
|
||||
RawOrientation = entprop.Rotation;
|
||||
// DEBUG DEBUG DEBUG -- smooth velocity changes a bit. The simulator seems to be
|
||||
// very sensitive to velocity changes.
|
||||
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.
|
||||
if (PositionSanityCheck(true /* inTaintTime */ ))
|
||||
{
|
||||
entprop.Position = _position;
|
||||
entprop.Position = RawPosition;
|
||||
entprop.Velocity = RawVelocity;
|
||||
entprop.RotationalVelocity = _rotationalVelocity;
|
||||
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);
|
||||
|
||||
// remember the current and last set values
|
||||
|
|
Loading…
Reference in New Issue