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.cs85
1 files changed, 60 insertions, 25 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
index 6401308..f1c3b5c 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
@@ -44,72 +44,107 @@ namespace OpenSim.Region.Physics.BulletSPlugin
44{ 44{
45public class BSPrimDisplaced : BSPrim 45public class BSPrimDisplaced : BSPrim
46{ 46{
47 // 'Position' and 'Orientation' is what the simulator thinks the positions of the prim is. 47 // The purpose of this module is to do any mapping between what the simulator thinks
48 // Because Bullet needs the zero coordinate to be the center of mass of the linkset, 48 // the prim position and orientation is and what the physical position/orientation.
49 // sometimes it is necessary to displace the position the physics engine thinks 49 // This difference happens because Bullet assumes the center-of-mass is the <0,0,0>
50 // the position is. PositionDisplacement must be added and removed from the 50 // of the prim/linkset. The simulator tracks the location of the prim/linkset by
51 // position as the simulator position is stored and fetched from the physics 51 // the location of the root prim. So, if center-of-mass is anywhere but the origin
52 // engine. Similar to OrientationDisplacement. 52 // of the root prim, the physical origin is displaced from the simulator origin.
53 //
54 // This routine works by capturing the Force* setting of position/orientation/... and
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).
57 //
58 // The updateParameter call is also captured and the values from the physics engine
59 // are converted into simulator origin values before being passed to the base
60 // class.
61
53 public virtual OMV.Vector3 PositionDisplacement { get; set; } 62 public virtual OMV.Vector3 PositionDisplacement { get; set; }
54 public virtual OMV.Quaternion OrientationDisplacement { get; set; } 63 public virtual OMV.Quaternion OrientationDisplacement { get; set; }
55 public virtual OMV.Vector3 CenterOfMassLocation { get; set; }
56 public virtual OMV.Vector3 GeometricCenterLocation { get; set; }
57 64
58 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,
59 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) 66 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
60 : base(localID, primName, parent_scene, pos, size, rotation, pbs, pisPhysical) 67 : base(localID, primName, parent_scene, pos, size, rotation, pbs, pisPhysical)
61 { 68 {
62 CenterOfMassLocation = RawPosition; 69 ClearDisplacement();
63 GeometricCenterLocation = RawPosition;
64 } 70 }
65 71
66 public override Vector3 ForcePosition 72 public void ClearDisplacement()
73 {
74 PositionDisplacement = OMV.Vector3.Zero;
75 OrientationDisplacement = OMV.Quaternion.Identity;
76 }
77
78 // 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.
80 // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates).
81 public virtual void SetEffectiveCenterOfMassW(Vector3 centerOfMassDisplacement)
67 { 82 {
68 get 83 Vector3 comDisp;
84 if (UserSetCenterOfMass.HasValue)
85 comDisp = (OMV.Vector3)UserSetCenterOfMass;
86 else
87 comDisp = centerOfMassDisplacement;
88
89 if (comDisp == Vector3.Zero)
69 { 90 {
70 return base.ForcePosition; 91 // If there is no diplacement. Things get reset.
92 PositionDisplacement = OMV.Vector3.Zero;
93 OrientationDisplacement = OMV.Quaternion.Identity;
71 } 94 }
72 set 95 else
73 { 96 {
74 base.ForcePosition = value; 97 // Remember the displacement from root as well as the origional rotation of the
75 CenterOfMassLocation = RawPosition; 98 // new center-of-mass.
76 GeometricCenterLocation = RawPosition; 99 PositionDisplacement = comDisp;
100 OrientationDisplacement = OMV.Quaternion.Identity;
77 } 101 }
78 } 102 }
79 103
80 public override Quaternion ForceOrientation 104 public override Vector3 ForcePosition
81 { 105 {
82 get 106 get { return base.ForcePosition; }
107 set
83 { 108 {
84 return base.ForceOrientation; 109 if (PositionDisplacement != OMV.Vector3.Zero)
110 base.ForcePosition = value - (PositionDisplacement * RawOrientation);
111 else
112 base.ForcePosition = value;
85 } 113 }
114 }
115
116 public override Quaternion ForceOrientation
117 {
118 get { return base.ForceOrientation; }
86 set 119 set
87 { 120 {
88 base.ForceOrientation = value; 121 base.ForceOrientation = value;
89 } 122 }
90 } 123 }
91 124
125 // TODO: decide if this is the right place for these variables.
126 // Somehow incorporate the optional settability by the user.
92 // Is this used? 127 // Is this used?
93 public override OMV.Vector3 CenterOfMass 128 public override OMV.Vector3 CenterOfMass
94 { 129 {
95 get { return CenterOfMassLocation; } 130 get { return RawPosition; }
96 } 131 }
97 132
98 // Is this used? 133 // Is this used?
99 public override OMV.Vector3 GeometricCenter 134 public override OMV.Vector3 GeometricCenter
100 { 135 {
101 get { return GeometricCenterLocation; } 136 get { return RawPosition; }
102 } 137 }
103 138
104
105 public override void UpdateProperties(EntityProperties entprop) 139 public override void UpdateProperties(EntityProperties entprop)
106 { 140 {
107 // Undo any center-of-mass displacement that might have been done. 141 // Undo any center-of-mass displacement that might have been done.
108 if (PositionDisplacement != OMV.Vector3.Zero) 142 if (PositionDisplacement != OMV.Vector3.Zero || OrientationDisplacement != OMV.Quaternion.Identity)
109 { 143 {
110 // Correct for any rotation around the center-of-mass 144 // Correct for any rotation around the center-of-mass
111 // TODO!!! 145 // TODO!!!
112 entprop.Position -= PositionDisplacement; 146 entprop.Position = entprop.Position + (PositionDisplacement * entprop.Rotation);
147 // entprop.Rotation = something;
113 } 148 }
114 149
115 base.UpdateProperties(entprop); 150 base.UpdateProperties(entprop);