aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
diff options
context:
space:
mode:
authorRobert Adams2013-06-10 06:40:07 -0700
committerRobert Adams2013-07-06 08:25:15 -0700
commit97698ae3119e01ecd2c98f7a17ad37204b9bfd9c (patch)
treee9fd36f0de282732d55e07ad7a139eb15a007abf /OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
parentBulletSim: comments and non-functional changes working toward the center-of-g... (diff)
downloadopensim-SC_OLD-97698ae3119e01ecd2c98f7a17ad37204b9bfd9c.zip
opensim-SC_OLD-97698ae3119e01ecd2c98f7a17ad37204b9bfd9c.tar.gz
opensim-SC_OLD-97698ae3119e01ecd2c98f7a17ad37204b9bfd9c.tar.bz2
opensim-SC_OLD-97698ae3119e01ecd2c98f7a17ad37204b9bfd9c.tar.xz
BulletSim: More tweaking on center-of-mass. Almost there. Changes have no effect if LinksetOffsetCenterOfMass=false (the default).
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs63
1 files changed, 24 insertions, 39 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
index 9a05349..a11bca0 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
@@ -51,7 +51,7 @@ public class BSPrimDisplaced : BSPrim
51 // the prim/linkset by the location of the root prim. So, if center-of-mass is anywhere 51 // the prim/linkset by the location of the root prim. So, if center-of-mass is anywhere
52 // but the origin 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 //
@@ -60,8 +60,6 @@ public class BSPrimDisplaced : BSPrim
60 // class. 60 // class.
61 61
62 public virtual OMV.Vector3 PositionDisplacement { get; set; } 62 public virtual OMV.Vector3 PositionDisplacement { get; set; }
63 public virtual OMV.Quaternion OrientationDisplacement { get; set; }
64 public virtual OMV.Quaternion OrientationDisplacementOrigInv { get; set; }
65 63
66 public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, 64 public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size,
67 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) 65 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
@@ -70,15 +68,17 @@ public class BSPrimDisplaced : BSPrim
70 ClearDisplacement(); 68 ClearDisplacement();
71 } 69 }
72 70
71 // Clears any center-of-mass displacement introduced by linksets, etc.
72 // Does not clear the displacement set by the user.
73 public void ClearDisplacement() 73 public void ClearDisplacement()
74 { 74 {
75 PositionDisplacement = OMV.Vector3.Zero; 75 SetEffectiveCenterOfMassDisplacement(OMV.Vector3.Zero);
76 OrientationDisplacement = OMV.Quaternion.Identity;
77 } 76 }
78 77
79 // Set this sets and computes the displacement from the passed prim to the center-of-mass. 78 // Set this sets and computes the displacement from the passed prim to the center-of-mass.
80 // A user set value for center-of-mass overrides whatever might be passed in here. 79 // A user set value for center-of-mass overrides whatever might be passed in here.
81 // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates). 80 // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates).
81 // Called at taint time.
82 public virtual void SetEffectiveCenterOfMassDisplacement(Vector3 centerOfMassDisplacement) 82 public virtual void SetEffectiveCenterOfMassDisplacement(Vector3 centerOfMassDisplacement)
83 { 83 {
84 Vector3 comDisp; 84 Vector3 comDisp;
@@ -87,21 +87,17 @@ public class BSPrimDisplaced : BSPrim
87 else 87 else
88 comDisp = centerOfMassDisplacement; 88 comDisp = centerOfMassDisplacement;
89 89
90 if (comDisp.ApproxEquals(Vector3.Zero, 0.01f) )
91 comDisp = Vector3.Zero;
92
90 DetailLog("{0},BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement,userSet={1},comDisp={2}", 93 DetailLog("{0},BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement,userSet={1},comDisp={2}",
91 LocalID, UserSetCenterOfMassDisplacement.HasValue, comDisp); 94 LocalID, UserSetCenterOfMassDisplacement.HasValue, comDisp);
92 if (comDisp == Vector3.Zero) 95 if ( comDisp != PositionDisplacement )
93 { 96 {
94 // If there is no diplacement. Things get reset. 97 // Displacement setting is changing.
95 PositionDisplacement = OMV.Vector3.Zero; 98 // The relationship between the physical object and simulated object must be aligned.
96 OrientationDisplacement = OMV.Quaternion.Identity;
97 }
98 else
99 {
100 // Remember the displacement from root as well as the origional rotation of the
101 // new center-of-mass.
102 PositionDisplacement = comDisp; 99 PositionDisplacement = comDisp;
103 OrientationDisplacement = Quaternion.Normalize(RawOrientation); 100 this.ForcePosition = RawPosition;
104 OrientationDisplacementOrigInv = Quaternion.Inverse(OrientationDisplacement);
105 } 101 }
106 } 102 }
107 103
@@ -112,7 +108,11 @@ public class BSPrimDisplaced : BSPrim
112 { 108 {
113 if (PositionDisplacement != OMV.Vector3.Zero) 109 if (PositionDisplacement != OMV.Vector3.Zero)
114 { 110 {
115 OMV.Vector3 displacedPos = value - (PositionDisplacement * (OrientationDisplacementOrigInv * RawOrientation)); 111 // The displacement is always relative to the vehicle so, when setting position,
112 // the caller means to set the position of the root prim.
113 // This offsets the setting value to the center-of-mass and sends that to the
114 // physics engine.
115 OMV.Vector3 displacedPos = value - (PositionDisplacement * RawOrientation);
116 DetailLog("{0},BSPrimDisplaced.ForcePosition,val={1},disp={2},newPos={3}", LocalID, value, PositionDisplacement, displacedPos); 116 DetailLog("{0},BSPrimDisplaced.ForcePosition,val={1},disp={2},newPos={3}", LocalID, value, PositionDisplacement, displacedPos);
117 base.ForcePosition = displacedPos; 117 base.ForcePosition = displacedPos;
118 } 118 }
@@ -123,26 +123,12 @@ public class BSPrimDisplaced : BSPrim
123 } 123 }
124 } 124 }
125 125
126 public override Quaternion ForceOrientation 126 // These are also overridden by BSPrimLinkable if the prim can be part of a linkset
127 {
128 get { return base.ForceOrientation; }
129 set
130 {
131 // Changing orientation also changes the position of the center-of-mass since
132 // the orientation passed is for a rotation around the root prim's center.
133 base.ForceOrientation = value;
134 }
135 }
136
137 // TODO: decide if this is the right place for these variables.
138 // Somehow incorporate the optional settability by the user.
139 // Is this used?
140 public override OMV.Vector3 CenterOfMass 127 public override OMV.Vector3 CenterOfMass
141 { 128 {
142 get { return RawPosition; } 129 get { return RawPosition; }
143 } 130 }
144 131
145 // Is this used?
146 public override OMV.Vector3 GeometricCenter 132 public override OMV.Vector3 GeometricCenter
147 { 133 {
148 get { return RawPosition; } 134 get { return RawPosition; }
@@ -151,18 +137,17 @@ public class BSPrimDisplaced : BSPrim
151 public override void UpdateProperties(EntityProperties entprop) 137 public override void UpdateProperties(EntityProperties entprop)
152 { 138 {
153 // Undo any center-of-mass displacement that might have been done. 139 // Undo any center-of-mass displacement that might have been done.
154 if (PositionDisplacement != OMV.Vector3.Zero || OrientationDisplacement != OMV.Quaternion.Identity) 140 if (PositionDisplacement != OMV.Vector3.Zero)
155 { 141 {
156 // The origional shape was offset from 'zero' by PositionDisplacement and rotated by OrientationDisplacement. 142 // The origional shape was offset from 'zero' by PositionDisplacement.
157 // These physical locations and rotation must be back converted to be centered around the displaced 143 // These physical location must be back converted to be centered around the displaced
158 // root shape. 144 // root shape.
159 145
160 // The root position is the reported position displaced by the rotated displacement. 146 // The root position is the reported position displaced by the rotated displacement.
161 OMV.Vector3 displacedPos = entprop.Position + (PositionDisplacement * (entprop.Rotation * OrientationDisplacementOrigInv)); 147 OMV.Vector3 displacedPos = entprop.Position + (PositionDisplacement * entprop.Rotation);
162 148 DetailLog("{0},BSPrimDisplaced.UpdateProperties,physPos={1},disp={2},newPos={3}",
163 DetailLog("{0},BSPrimDisplaced.ForcePosition,physPos={1},disp={2},newPos={3}", LocalID, entprop.Position, PositionDisplacement, displacedPos); 149 LocalID, entprop.Position, PositionDisplacement, displacedPos);
164 entprop.Position = displacedPos; 150 entprop.Position = displacedPos;
165 // entprop.Rotation = something;
166 } 151 }
167 152
168 base.UpdateProperties(entprop); 153 base.UpdateProperties(entprop);