diff options
author | Robert Adams | 2013-06-02 10:04:15 -0700 |
---|---|---|
committer | Robert Adams | 2013-07-06 08:25:14 -0700 |
commit | 03268d85c41c94e7b35802b9dea1ce08299e5426 (patch) | |
tree | 67f18d3f8003f34f5d42004005e21723b7e5d689 /OpenSim/Region/Physics | |
parent | BulletSim: non-functional updates. Comments and formatting. (diff) | |
download | opensim-SC_OLD-03268d85c41c94e7b35802b9dea1ce08299e5426.zip opensim-SC_OLD-03268d85c41c94e7b35802b9dea1ce08299e5426.tar.gz opensim-SC_OLD-03268d85c41c94e7b35802b9dea1ce08299e5426.tar.bz2 opensim-SC_OLD-03268d85c41c94e7b35802b9dea1ce08299e5426.tar.xz |
BulletSim: comments and non-functional changes working toward the center-of-gravity implementation.
Diffstat (limited to 'OpenSim/Region/Physics')
4 files changed, 39 insertions, 20 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 308cf13..30f6c8c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | |||
@@ -315,7 +315,6 @@ public sealed class BSLinksetCompound : BSLinkset | |||
315 | // Note that this works for rebuilding just the root after a linkset is taken apart. | 315 | // Note that this works for rebuilding just the root after a linkset is taken apart. |
316 | // Called at taint time!! | 316 | // Called at taint time!! |
317 | private bool UseBulletSimRootOffsetHack = false; // Attempt to have Bullet track the coords of root compound shape | 317 | private bool UseBulletSimRootOffsetHack = false; // Attempt to have Bullet track the coords of root compound shape |
318 | private bool disableCOM = true; // For basic linkset debugging, turn off the center-of-mass setting | ||
319 | private void RecomputeLinksetCompound() | 318 | private void RecomputeLinksetCompound() |
320 | { | 319 | { |
321 | try | 320 | try |
@@ -331,9 +330,7 @@ public sealed class BSLinksetCompound : BSLinkset | |||
331 | // There is no reason to build all this physical stuff for a non-physical linkset. | 330 | // There is no reason to build all this physical stuff for a non-physical linkset. |
332 | if (!LinksetRoot.IsPhysicallyActive) | 331 | if (!LinksetRoot.IsPhysicallyActive) |
333 | { | 332 | { |
334 | // Clean up any old linkset shape and make sure the root shape is set to the root object. | ||
335 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,notPhysical", LinksetRoot.LocalID); | 333 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,notPhysical", LinksetRoot.LocalID); |
336 | |||
337 | return; // Note the 'finally' clause at the botton which will get executed. | 334 | return; // Note the 'finally' clause at the botton which will get executed. |
338 | } | 335 | } |
339 | 336 | ||
@@ -347,9 +344,9 @@ public sealed class BSLinksetCompound : BSLinkset | |||
347 | 344 | ||
348 | OMV.Quaternion invRootOrientation = OMV.Quaternion.Normalize(OMV.Quaternion.Inverse(LinksetRoot.RawOrientation)); | 345 | OMV.Quaternion invRootOrientation = OMV.Quaternion.Normalize(OMV.Quaternion.Inverse(LinksetRoot.RawOrientation)); |
349 | 346 | ||
350 | // 'centerDisplacement' is the value to subtract from children to give physical offset position | 347 | // 'centerDisplacementV' is the value to subtract from children to give physical offset position |
351 | OMV.Vector3 centerDisplacementV = (centerOfMassW - LinksetRoot.RawPosition) * invRootOrientation; | 348 | OMV.Vector3 centerDisplacementV = (centerOfMassW - LinksetRoot.RawPosition) * invRootOrientation; |
352 | if (UseBulletSimRootOffsetHack || disableCOM) | 349 | if (UseBulletSimRootOffsetHack || !BSParam.LinksetOffsetCenterOfMass) |
353 | { | 350 | { |
354 | centerDisplacementV = OMV.Vector3.Zero; | 351 | centerDisplacementV = OMV.Vector3.Zero; |
355 | LinksetRoot.ClearDisplacement(); | 352 | LinksetRoot.ClearDisplacement(); |
@@ -357,6 +354,8 @@ public sealed class BSLinksetCompound : BSLinkset | |||
357 | else | 354 | else |
358 | { | 355 | { |
359 | LinksetRoot.SetEffectiveCenterOfMassDisplacement(centerDisplacementV); | 356 | LinksetRoot.SetEffectiveCenterOfMassDisplacement(centerDisplacementV); |
357 | // The actual center-of-mass could have been set by the user. | ||
358 | centerDisplacementV = LinksetRoot.PositionDisplacement; | ||
360 | } | 359 | } |
361 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,COM,rootPos={1},com={2},comDisp={3}", | 360 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,COM,rootPos={1},com={2},comDisp={3}", |
362 | LinksetRoot.LocalID, LinksetRoot.RawPosition, centerOfMassW, centerDisplacementV); | 361 | LinksetRoot.LocalID, LinksetRoot.RawPosition, centerOfMassW, centerDisplacementV); |
@@ -409,7 +408,7 @@ public sealed class BSLinksetCompound : BSLinkset | |||
409 | { | 408 | { |
410 | // Enable the physical position updator to return the position and rotation of the root shape. | 409 | // Enable the physical position updator to return the position and rotation of the root shape. |
411 | // This enables a feature in the C++ code to return the world coordinates of the first shape in the | 410 | // This enables a feature in the C++ code to return the world coordinates of the first shape in the |
412 | // compound shape. This eleviates the need to offset the returned physical position by the | 411 | // compound shape. This aleviates the need to offset the returned physical position by the |
413 | // center-of-mass offset. | 412 | // center-of-mass offset. |
414 | m_physicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, CollisionFlags.BS_RETURN_ROOT_COMPOUND_SHAPE); | 413 | m_physicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, CollisionFlags.BS_RETURN_ROOT_COMPOUND_SHAPE); |
415 | } | 414 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index d17c8e7..0f84bf7 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | |||
@@ -176,6 +176,7 @@ public static class BSParam | |||
176 | 176 | ||
177 | // Linkset implementation parameters | 177 | // Linkset implementation parameters |
178 | public static float LinksetImplementation { get; private set; } | 178 | public static float LinksetImplementation { get; private set; } |
179 | public static bool LinksetOffsetCenterOfMass { get; private set; } | ||
179 | public static bool LinkConstraintUseFrameOffset { get; private set; } | 180 | public static bool LinkConstraintUseFrameOffset { get; private set; } |
180 | public static bool LinkConstraintEnableTransMotor { get; private set; } | 181 | public static bool LinkConstraintEnableTransMotor { get; private set; } |
181 | public static float LinkConstraintTransMotorMaxVel { get; private set; } | 182 | public static float LinkConstraintTransMotorMaxVel { get; private set; } |
@@ -684,6 +685,8 @@ public static class BSParam | |||
684 | 685 | ||
685 | new ParameterDefn<float>("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)", | 686 | new ParameterDefn<float>("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)", |
686 | (float)BSLinkset.LinksetImplementation.Compound ), | 687 | (float)BSLinkset.LinksetImplementation.Compound ), |
688 | new ParameterDefn<bool>("LinksetOffsetCenterOfMass", "If 'true', compute linkset center-of-mass and offset linkset position to account for same", | ||
689 | false ), | ||
687 | new ParameterDefn<bool>("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.", | 690 | new ParameterDefn<bool>("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.", |
688 | false ), | 691 | false ), |
689 | new ParameterDefn<bool>("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints", | 692 | new ParameterDefn<bool>("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints", |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs index f5ee671..9a05349 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs | |||
@@ -44,12 +44,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
44 | { | 44 | { |
45 | public class BSPrimDisplaced : BSPrim | 45 | public 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 the Force* setting of position/orientation/... and |
55 | // adjusting the simulator values (being set) into the physical values. | 55 | // adjusting the simulator values (being set) into the physical values. |
@@ -61,6 +61,7 @@ public class BSPrimDisplaced : BSPrim | |||
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; } | 63 | public virtual OMV.Quaternion OrientationDisplacement { get; set; } |
64 | public virtual OMV.Quaternion OrientationDisplacementOrigInv { get; set; } | ||
64 | 65 | ||
65 | public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, | 66 | public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, |
66 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) | 67 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) |
@@ -99,7 +100,8 @@ public class BSPrimDisplaced : BSPrim | |||
99 | // Remember the displacement from root as well as the origional rotation of the | 100 | // Remember the displacement from root as well as the origional rotation of the |
100 | // new center-of-mass. | 101 | // new center-of-mass. |
101 | PositionDisplacement = comDisp; | 102 | PositionDisplacement = comDisp; |
102 | OrientationDisplacement = OMV.Quaternion.Identity; | 103 | OrientationDisplacement = Quaternion.Normalize(RawOrientation); |
104 | OrientationDisplacementOrigInv = Quaternion.Inverse(OrientationDisplacement); | ||
103 | } | 105 | } |
104 | } | 106 | } |
105 | 107 | ||
@@ -110,7 +112,7 @@ public class BSPrimDisplaced : BSPrim | |||
110 | { | 112 | { |
111 | if (PositionDisplacement != OMV.Vector3.Zero) | 113 | if (PositionDisplacement != OMV.Vector3.Zero) |
112 | { | 114 | { |
113 | OMV.Vector3 displacedPos = value - (PositionDisplacement * RawOrientation); | 115 | OMV.Vector3 displacedPos = value - (PositionDisplacement * (OrientationDisplacementOrigInv * RawOrientation)); |
114 | 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); |
115 | base.ForcePosition = displacedPos; | 117 | base.ForcePosition = displacedPos; |
116 | } | 118 | } |
@@ -126,7 +128,8 @@ public class BSPrimDisplaced : BSPrim | |||
126 | get { return base.ForceOrientation; } | 128 | get { return base.ForceOrientation; } |
127 | set | 129 | set |
128 | { | 130 | { |
129 | // TODO: | 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. | ||
130 | base.ForceOrientation = value; | 133 | base.ForceOrientation = value; |
131 | } | 134 | } |
132 | } | 135 | } |
@@ -150,10 +153,13 @@ public class BSPrimDisplaced : BSPrim | |||
150 | // Undo any center-of-mass displacement that might have been done. | 153 | // Undo any center-of-mass displacement that might have been done. |
151 | if (PositionDisplacement != OMV.Vector3.Zero || OrientationDisplacement != OMV.Quaternion.Identity) | 154 | if (PositionDisplacement != OMV.Vector3.Zero || OrientationDisplacement != OMV.Quaternion.Identity) |
152 | { | 155 | { |
153 | // Correct for any rotation around the center-of-mass | 156 | // The origional shape was offset from 'zero' by PositionDisplacement and rotated by OrientationDisplacement. |
154 | // TODO!!! | 157 | // These physical locations and rotation must be back converted to be centered around the displaced |
158 | // root shape. | ||
159 | |||
160 | // The root position is the reported position displaced by the rotated displacement. | ||
161 | OMV.Vector3 displacedPos = entprop.Position + (PositionDisplacement * (entprop.Rotation * OrientationDisplacementOrigInv)); | ||
155 | 162 | ||
156 | OMV.Vector3 displacedPos = entprop.Position + (PositionDisplacement * entprop.Rotation); | ||
157 | DetailLog("{0},BSPrimDisplaced.ForcePosition,physPos={1},disp={2},newPos={3}", LocalID, entprop.Position, PositionDisplacement, displacedPos); | 163 | DetailLog("{0},BSPrimDisplaced.ForcePosition,physPos={1},disp={2},newPos={3}", LocalID, entprop.Position, PositionDisplacement, displacedPos); |
158 | entprop.Position = displacedPos; | 164 | entprop.Position = displacedPos; |
159 | // entprop.Rotation = something; | 165 | // entprop.Rotation = something; |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs index 87eed98..6d7de35 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs | |||
@@ -37,6 +37,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
37 | { | 37 | { |
38 | public class BSPrimLinkable : BSPrimDisplaced | 38 | public class BSPrimLinkable : BSPrimDisplaced |
39 | { | 39 | { |
40 | // The purpose of this subclass is to add linkset functionality to the prim. This overrides | ||
41 | // operations necessary for keeping the linkset created and, additionally, this | ||
42 | // calls the linkset implementation for its creation and management. | ||
43 | |||
44 | // This adds the overrides for link() and delink() so the prim is linkable. | ||
45 | |||
40 | public BSLinkset Linkset { get; set; } | 46 | public BSLinkset Linkset { get; set; } |
41 | // The index of this child prim. | 47 | // The index of this child prim. |
42 | public int LinksetChildIndex { get; set; } | 48 | public int LinksetChildIndex { get; set; } |
@@ -69,8 +75,8 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
69 | BSPrimLinkable parent = obj as BSPrimLinkable; | 75 | BSPrimLinkable parent = obj as BSPrimLinkable; |
70 | if (parent != null) | 76 | if (parent != null) |
71 | { | 77 | { |
72 | BSPhysObject parentBefore = Linkset.LinksetRoot; | 78 | BSPhysObject parentBefore = Linkset.LinksetRoot; // DEBUG |
73 | int childrenBefore = Linkset.NumberOfChildren; | 79 | int childrenBefore = Linkset.NumberOfChildren; // DEBUG |
74 | 80 | ||
75 | Linkset = parent.Linkset.AddMeToLinkset(this); | 81 | Linkset = parent.Linkset.AddMeToLinkset(this); |
76 | 82 | ||
@@ -85,8 +91,8 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
85 | // TODO: decide if this parent checking needs to happen at taint time | 91 | // TODO: decide if this parent checking needs to happen at taint time |
86 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen | 92 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen |
87 | 93 | ||
88 | BSPhysObject parentBefore = Linkset.LinksetRoot; | 94 | BSPhysObject parentBefore = Linkset.LinksetRoot; // DEBUG |
89 | int childrenBefore = Linkset.NumberOfChildren; | 95 | int childrenBefore = Linkset.NumberOfChildren; // DEBUG |
90 | 96 | ||
91 | Linkset = Linkset.RemoveMeFromLinkset(this); | 97 | Linkset = Linkset.RemoveMeFromLinkset(this); |
92 | 98 | ||
@@ -128,6 +134,7 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
128 | get { return Linkset.LinksetMass; } | 134 | get { return Linkset.LinksetMass; } |
129 | } | 135 | } |
130 | 136 | ||
137 | // Refresh the linkset structure and parameters when the prim's physical parameters are changed. | ||
131 | public override void UpdatePhysicalParameters() | 138 | public override void UpdatePhysicalParameters() |
132 | { | 139 | { |
133 | base.UpdatePhysicalParameters(); | 140 | base.UpdatePhysicalParameters(); |
@@ -139,6 +146,7 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
139 | Linkset.Refresh(this); | 146 | Linkset.Refresh(this); |
140 | } | 147 | } |
141 | 148 | ||
149 | // When the prim is made dynamic or static, the linkset needs to change. | ||
142 | protected override void MakeDynamic(bool makeStatic) | 150 | protected override void MakeDynamic(bool makeStatic) |
143 | { | 151 | { |
144 | base.MakeDynamic(makeStatic); | 152 | base.MakeDynamic(makeStatic); |
@@ -155,6 +163,8 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
155 | base.RemoveDependencies(); | 163 | base.RemoveDependencies(); |
156 | } | 164 | } |
157 | 165 | ||
166 | // Called after a simulation step for the changes in physical object properties. | ||
167 | // Do any filtering/modification needed for linksets. | ||
158 | public override void UpdateProperties(EntityProperties entprop) | 168 | public override void UpdateProperties(EntityProperties entprop) |
159 | { | 169 | { |
160 | if (Linkset.IsRoot(this)) | 170 | if (Linkset.IsRoot(this)) |
@@ -176,6 +186,7 @@ public class BSPrimLinkable : BSPrimDisplaced | |||
176 | Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); | 186 | Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); |
177 | } | 187 | } |
178 | 188 | ||
189 | // Called after a simulation step to post a collision with this object. | ||
179 | public override bool Collide(uint collidingWith, BSPhysObject collidee, | 190 | public override bool Collide(uint collidingWith, BSPhysObject collidee, |
180 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) | 191 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) |
181 | { | 192 | { |