aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs109
1 files changed, 65 insertions, 44 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
index f5ee671..35d5a08 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
@@ -44,14 +44,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin
44{ 44{
45public class BSPrimDisplaced : BSPrim 45public class BSPrimDisplaced : BSPrim
46{ 46{
47 // The purpose of this module is to do any mapping between what the simulator thinks 47 // The purpose of this subclass is to do any mapping between what the simulator thinks
48 // the prim position and orientation is and what the physical position/orientation. 48 // the prim position and orientation is and what the physical position/orientation.
49 // This difference happens because Bullet assumes the center-of-mass is the <0,0,0> 49 // This difference happens because Bullet assumes the center-of-mass is the <0,0,0>
50 // of the prim/linkset. The simulator tracks the location of the prim/linkset by 50 // of the prim/linkset. The simulator, on the other hand, tracks the location of
51 // the location of the root prim. So, if center-of-mass is anywhere but the origin 51 // the prim/linkset by the location of the root prim. So, if center-of-mass is anywhere
52 // of the root prim, the physical origin is displaced from the simulator origin. 52 // but the origin of the root prim, the physical origin is displaced from the simulator origin.
53 // 53 //
54 // This routine works by capturing the Force* setting of position/orientation/... and 54 // This routine works by capturing ForcePosition and
55 // adjusting the simulator values (being set) into the physical values. 55 // adjusting the simulator values (being set) into the physical values.
56 // The conversion is also done in the opposite direction (physical origin -> simulator origin). 56 // The conversion is also done in the opposite direction (physical origin -> simulator origin).
57 // 57 //
@@ -59,8 +59,8 @@ public class BSPrimDisplaced : BSPrim
59 // are converted into simulator origin values before being passed to the base 59 // are converted into simulator origin values before being passed to the base
60 // class. 60 // class.
61 61
62 // PositionDisplacement is the vehicle relative distance from the root prim position to the center-of-mass.
62 public virtual OMV.Vector3 PositionDisplacement { get; set; } 63 public virtual OMV.Vector3 PositionDisplacement { get; set; }
63 public virtual OMV.Quaternion OrientationDisplacement { get; set; }
64 64
65 public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, 65 public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size,
66 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) 66 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
@@ -69,50 +69,81 @@ public class BSPrimDisplaced : BSPrim
69 ClearDisplacement(); 69 ClearDisplacement();
70 } 70 }
71 71
72 // Clears any center-of-mass displacement introduced by linksets, etc.
73 // Does not clear the displacement set by the user.
72 public void ClearDisplacement() 74 public void ClearDisplacement()
73 { 75 {
74 PositionDisplacement = OMV.Vector3.Zero; 76 if (UserSetCenterOfMassDisplacement.HasValue)
75 OrientationDisplacement = OMV.Quaternion.Identity; 77 PositionDisplacement = (OMV.Vector3)UserSetCenterOfMassDisplacement;
78 else
79 PositionDisplacement = OMV.Vector3.Zero;
76 } 80 }
77 81
78 // Set this sets and computes the displacement from the passed prim to the center-of-mass. 82 // Set this sets and computes the displacement from the passed prim to the center-of-mass.
79 // A user set value for center-of-mass overrides whatever might be passed in here. 83 // A user set value for center-of-mass overrides whatever might be passed in here.
80 // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates). 84 // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates).
81 public virtual void SetEffectiveCenterOfMassDisplacement(Vector3 centerOfMassDisplacement) 85 // Returns the relative offset from the root position to the center-of-mass.
86 // Called at taint time.
87 public virtual Vector3 SetEffectiveCenterOfMassDisplacement(Vector3 centerOfMassDisplacement)
82 { 88 {
89 PhysScene.AssertInTaintTime("BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement");
83 Vector3 comDisp; 90 Vector3 comDisp;
84 if (UserSetCenterOfMassDisplacement.HasValue) 91 if (UserSetCenterOfMassDisplacement.HasValue)
85 comDisp = (OMV.Vector3)UserSetCenterOfMassDisplacement; 92 comDisp = (OMV.Vector3)UserSetCenterOfMassDisplacement;
86 else 93 else
87 comDisp = centerOfMassDisplacement; 94 comDisp = centerOfMassDisplacement;
88 95
96 // Eliminate any jitter caused be very slight differences in masses and positions
97 if (comDisp.ApproxEquals(Vector3.Zero, 0.01f) )
98 comDisp = Vector3.Zero;
99
89 DetailLog("{0},BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement,userSet={1},comDisp={2}", 100 DetailLog("{0},BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement,userSet={1},comDisp={2}",
90 LocalID, UserSetCenterOfMassDisplacement.HasValue, comDisp); 101 LocalID, UserSetCenterOfMassDisplacement.HasValue, comDisp);
91 if (comDisp == Vector3.Zero) 102 if ( !comDisp.ApproxEquals(PositionDisplacement, 0.01f) )
92 { 103 {
93 // If there is no diplacement. Things get reset. 104 // Displacement setting is changing.
94 PositionDisplacement = OMV.Vector3.Zero; 105 // The relationship between the physical object and simulated object must be aligned.
95 OrientationDisplacement = OMV.Quaternion.Identity;
96 }
97 else
98 {
99 // Remember the displacement from root as well as the origional rotation of the
100 // new center-of-mass.
101 PositionDisplacement = comDisp; 106 PositionDisplacement = comDisp;
102 OrientationDisplacement = OMV.Quaternion.Identity; 107 this.ForcePosition = RawPosition;
103 } 108 }
109
110 return PositionDisplacement;
104 } 111 }
105 112
113 // 'ForcePosition' is the one way to set the physical position of the body in the physics engine.
114 // Displace the simulator idea of position (center of root prim) to the physical position.
106 public override Vector3 ForcePosition 115 public override Vector3 ForcePosition
107 { 116 {
108 get { return base.ForcePosition; } 117 get {
118 OMV.Vector3 physPosition = base.ForcePosition;
119 if (PositionDisplacement != OMV.Vector3.Zero)
120 {
121 // If there is some displacement, return the physical position (center-of-mass)
122 // location minus the displacement to give the center of the root prim.
123 OMV.Vector3 displacement = PositionDisplacement * ForceOrientation;
124 DetailLog("{0},BSPrimDisplaced.ForcePosition,get,physPos={1},disp={2},simPos={3}",
125 LocalID, physPosition, displacement, physPosition - displacement);
126 physPosition -= displacement;
127 }
128 return physPosition;
129 }
109 set 130 set
110 { 131 {
111 if (PositionDisplacement != OMV.Vector3.Zero) 132 if (PositionDisplacement != OMV.Vector3.Zero)
112 { 133 {
113 OMV.Vector3 displacedPos = value - (PositionDisplacement * RawOrientation); 134 // This value is the simulator's idea of where the prim is: the center of the root prim
114 DetailLog("{0},BSPrimDisplaced.ForcePosition,val={1},disp={2},newPos={3}", LocalID, value, PositionDisplacement, displacedPos); 135 RawPosition = value;
115 base.ForcePosition = displacedPos; 136
137 // Move the passed root prim postion to the center-of-mass position and set in the physics engine.
138 OMV.Vector3 displacement = PositionDisplacement * RawOrientation;
139 OMV.Vector3 displacedPos = RawPosition + displacement;
140 DetailLog("{0},BSPrimDisplaced.ForcePosition,set,simPos={1},disp={2},physPos={3}",
141 LocalID, RawPosition, displacement, displacedPos);
142 if (PhysBody.HasPhysicalBody)
143 {
144 PhysScene.PE.SetTranslation(PhysBody, displacedPos, RawOrientation);
145 ActivateIfPhysical(false);
146 }
116 } 147 }
117 else 148 else
118 { 149 {
@@ -121,25 +152,12 @@ public class BSPrimDisplaced : BSPrim
121 } 152 }
122 } 153 }
123 154
124 public override Quaternion ForceOrientation 155 // These are also overridden by BSPrimLinkable if the prim can be part of a linkset
125 {
126 get { return base.ForceOrientation; }
127 set
128 {
129 // TODO:
130 base.ForceOrientation = value;
131 }
132 }
133
134 // TODO: decide if this is the right place for these variables.
135 // Somehow incorporate the optional settability by the user.
136 // Is this used?
137 public override OMV.Vector3 CenterOfMass 156 public override OMV.Vector3 CenterOfMass
138 { 157 {
139 get { return RawPosition; } 158 get { return RawPosition; }
140 } 159 }
141 160
142 // Is this used?
143 public override OMV.Vector3 GeometricCenter 161 public override OMV.Vector3 GeometricCenter
144 { 162 {
145 get { return RawPosition; } 163 get { return RawPosition; }
@@ -148,15 +166,18 @@ public class BSPrimDisplaced : BSPrim
148 public override void UpdateProperties(EntityProperties entprop) 166 public override void UpdateProperties(EntityProperties entprop)
149 { 167 {
150 // Undo any center-of-mass displacement that might have been done. 168 // Undo any center-of-mass displacement that might have been done.
151 if (PositionDisplacement != OMV.Vector3.Zero || OrientationDisplacement != OMV.Quaternion.Identity) 169 if (PositionDisplacement != OMV.Vector3.Zero)
152 { 170 {
153 // Correct for any rotation around the center-of-mass 171 // The origional shape was offset from 'zero' by PositionDisplacement.
154 // TODO!!! 172 // These physical location must be back converted to be centered around the displaced
155 173 // root shape.
156 OMV.Vector3 displacedPos = entprop.Position + (PositionDisplacement * entprop.Rotation); 174
157 DetailLog("{0},BSPrimDisplaced.ForcePosition,physPos={1},disp={2},newPos={3}", LocalID, entprop.Position, PositionDisplacement, displacedPos); 175 // Move the returned center-of-mass location to the root prim location.
176 OMV.Vector3 displacement = PositionDisplacement * entprop.Rotation;
177 OMV.Vector3 displacedPos = entprop.Position - displacement;
178 DetailLog("{0},BSPrimDisplaced.UpdateProperties,physPos={1},disp={2},simPos={3}",
179 LocalID, entprop.Position, displacement, displacedPos);
158 entprop.Position = displacedPos; 180 entprop.Position = displacedPos;
159 // entprop.Rotation = something;
160 } 181 }
161 182
162 base.UpdateProperties(entprop); 183 base.UpdateProperties(entprop);