diff options
author | Robert Adams | 2013-03-31 17:38:13 -0700 |
---|---|---|
committer | Robert Adams | 2013-03-31 22:19:42 -0700 |
commit | 75b8cf428e352b8939bb5e49f583d45dd226cf66 (patch) | |
tree | fd0091addd643abe1690645a879cddeb90bdd0d6 /OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | |
parent | BulletSim: convert BSDynamic to a BSActor and change BSPrim to set (diff) | |
download | opensim-SC-75b8cf428e352b8939bb5e49f583d45dd226cf66.zip opensim-SC-75b8cf428e352b8939bb5e49f583d45dd226cf66.tar.gz opensim-SC-75b8cf428e352b8939bb5e49f583d45dd226cf66.tar.bz2 opensim-SC-75b8cf428e352b8939bb5e49f583d45dd226cf66.tar.xz |
BulletSim: fix line endings in BSActor*
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | 339 |
1 files changed, 171 insertions, 168 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index b4af126..5f74a14 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | |||
@@ -1,168 +1,171 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyrightD | 9 | * * Redistributions in binary form must reproduce the above copyrightD |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSimulator Project nor the | 12 | * * Neither the name of the OpenSimulator Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Linq; | 30 | using System.Linq; |
31 | using System.Text; | 31 | using System.Text; |
32 | 32 | ||
33 | using OMV = OpenMetaverse; | 33 | using OMV = OpenMetaverse; |
34 | 34 | ||
35 | namespace OpenSim.Region.Physics.BulletSPlugin | 35 | namespace OpenSim.Region.Physics.BulletSPlugin |
36 | { | 36 | { |
37 | public class BSActorLockAxis : BSActor | 37 | public class BSActorLockAxis : BSActor |
38 | { | 38 | { |
39 | bool TryExperimentalLockAxisCode = false; | 39 | bool TryExperimentalLockAxisCode = false; |
40 | BSConstraint LockAxisConstraint = null; | 40 | BSConstraint LockAxisConstraint = null; |
41 | 41 | ||
42 | public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) | 42 | public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) |
43 | : base(physicsScene, pObj,actorName) | 43 | : base(physicsScene, pObj,actorName) |
44 | { | 44 | { |
45 | LockAxisConstraint = null; | 45 | PhysicsScene.DetailLog("{0},BSActorLockAxis,constructor", Prim.LocalID); |
46 | } | 46 | LockAxisConstraint = null; |
47 | 47 | } | |
48 | // BSActor.isActive | 48 | |
49 | public override bool isActive | 49 | // BSActor.isActive |
50 | { | 50 | public override bool isActive |
51 | get { return Enabled && Prim.IsPhysicallyActive; } | 51 | { |
52 | } | 52 | get { return Enabled && Prim.IsPhysicallyActive; } |
53 | 53 | } | |
54 | // Release any connections and resources used by the actor. | 54 | |
55 | // BSActor.Release() | 55 | // Release any connections and resources used by the actor. |
56 | public override void Release() | 56 | // BSActor.Dispose() |
57 | { | 57 | public override void Dispose() |
58 | RemoveAxisLockConstraint(); | 58 | { |
59 | } | 59 | RemoveAxisLockConstraint(); |
60 | 60 | } | |
61 | // Called when physical parameters (properties set in Bullet) need to be re-applied. | 61 | |
62 | // Called at taint-time. | 62 | // Called when physical parameters (properties set in Bullet) need to be re-applied. |
63 | // BSActor.Refresh() | 63 | // Called at taint-time. |
64 | public override void Refresh() | 64 | // BSActor.Refresh() |
65 | { | 65 | public override void Refresh() |
66 | // If all the axis are free, we don't need to exist | 66 | { |
67 | if (Prim.LockedAxis == Prim.LockedAxisFree) | 67 | PhysicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", |
68 | { | 68 | Prim.LocalID, Prim.LockedAxis, Enabled, Prim.IsPhysicallyActive); |
69 | Prim.PhysicalActors.RemoveAndRelease(ActorName); | 69 | // If all the axis are free, we don't need to exist |
70 | return; | 70 | if (Prim.LockedAxis == Prim.LockedAxisFree) |
71 | } | 71 | { |
72 | // If the object is physically active, add the axis locking constraint | 72 | Prim.PhysicalActors.RemoveAndRelease(ActorName); |
73 | if (Enabled | 73 | return; |
74 | && Prim.IsPhysicallyActive | 74 | } |
75 | && TryExperimentalLockAxisCode | 75 | // If the object is physically active, add the axis locking constraint |
76 | && Prim.LockedAxis != Prim.LockedAxisFree) | 76 | if (Enabled |
77 | { | 77 | && Prim.IsPhysicallyActive |
78 | if (LockAxisConstraint != null) | 78 | && TryExperimentalLockAxisCode |
79 | AddAxisLockConstraint(); | 79 | && Prim.LockedAxis != Prim.LockedAxisFree) |
80 | } | 80 | { |
81 | else | 81 | if (LockAxisConstraint != null) |
82 | { | 82 | AddAxisLockConstraint(); |
83 | RemoveAxisLockConstraint(); | 83 | } |
84 | } | 84 | else |
85 | } | 85 | { |
86 | 86 | RemoveAxisLockConstraint(); | |
87 | // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). | 87 | } |
88 | // Register a prestep action to restore physical requirements before the next simulation step. | 88 | } |
89 | // Called at taint-time. | 89 | |
90 | // BSActor.RemoveBodyDependencies() | 90 | // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). |
91 | public override void RemoveBodyDependencies() | 91 | // Register a prestep action to restore physical requirements before the next simulation step. |
92 | { | 92 | // Called at taint-time. |
93 | if (LockAxisConstraint != null) | 93 | // BSActor.RemoveBodyDependencies() |
94 | { | 94 | public override void RemoveBodyDependencies() |
95 | // If a constraint is set up, remove it from the physical scene | 95 | { |
96 | RemoveAxisLockConstraint(); | 96 | if (LockAxisConstraint != null) |
97 | // Schedule a call before the next simulation step to restore the constraint. | 97 | { |
98 | PhysicsScene.PostTaintObject(Prim.LockedAxisActorName, Prim.LocalID, delegate() | 98 | // If a constraint is set up, remove it from the physical scene |
99 | { | 99 | RemoveAxisLockConstraint(); |
100 | Refresh(); | 100 | // Schedule a call before the next simulation step to restore the constraint. |
101 | }); | 101 | PhysicsScene.PostTaintObject(Prim.LockedAxisActorName, Prim.LocalID, delegate() |
102 | } | 102 | { |
103 | } | 103 | Refresh(); |
104 | 104 | }); | |
105 | private void AddAxisLockConstraint() | 105 | } |
106 | { | 106 | } |
107 | // Lock that axis by creating a 6DOF constraint that has one end in the world and | 107 | |
108 | // the other in the object. | 108 | private void AddAxisLockConstraint() |
109 | // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 | 109 | { |
110 | // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 | 110 | // Lock that axis by creating a 6DOF constraint that has one end in the world and |
111 | 111 | // the other in the object. | |
112 | // Remove any existing axis constraint (just to be sure) | 112 | // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 |
113 | RemoveAxisLockConstraint(); | 113 | // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 |
114 | 114 | ||
115 | BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, Prim.PhysBody, | 115 | // Remove any existing axis constraint (just to be sure) |
116 | OMV.Vector3.Zero, OMV.Quaternion.Inverse(Prim.RawOrientation), | 116 | RemoveAxisLockConstraint(); |
117 | true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); | 117 | |
118 | LockAxisConstraint = axisConstrainer; | 118 | BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, Prim.PhysBody, |
119 | PhysicsScene.Constraints.AddConstraint(LockAxisConstraint); | 119 | OMV.Vector3.Zero, OMV.Quaternion.Inverse(Prim.RawOrientation), |
120 | 120 | true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); | |
121 | // The constraint is tied to the world and oriented to the prim. | 121 | LockAxisConstraint = axisConstrainer; |
122 | 122 | PhysicsScene.Constraints.AddConstraint(LockAxisConstraint); | |
123 | // Free to move linearly | 123 | |
124 | OMV.Vector3 linearLow = OMV.Vector3.Zero; | 124 | // The constraint is tied to the world and oriented to the prim. |
125 | OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize; | 125 | |
126 | axisConstrainer.SetLinearLimits(linearLow, linearHigh); | 126 | // Free to move linearly |
127 | 127 | OMV.Vector3 linearLow = OMV.Vector3.Zero; | |
128 | // Angular with some axis locked | 128 | OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize; |
129 | float f2PI = (float)Math.PI * 2f; | 129 | axisConstrainer.SetLinearLimits(linearLow, linearHigh); |
130 | OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI); | 130 | |
131 | OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI); | 131 | // Angular with some axis locked |
132 | if (Prim.LockedAxis.X != 1f) | 132 | float f2PI = (float)Math.PI * 2f; |
133 | { | 133 | OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI); |
134 | angularLow.X = 0f; | 134 | OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI); |
135 | angularHigh.X = 0f; | 135 | if (Prim.LockedAxis.X != 1f) |
136 | } | 136 | { |
137 | if (Prim.LockedAxis.Y != 1f) | 137 | angularLow.X = 0f; |
138 | { | 138 | angularHigh.X = 0f; |
139 | angularLow.Y = 0f; | 139 | } |
140 | angularHigh.Y = 0f; | 140 | if (Prim.LockedAxis.Y != 1f) |
141 | } | 141 | { |
142 | if (Prim.LockedAxis.Z != 1f) | 142 | angularLow.Y = 0f; |
143 | { | 143 | angularHigh.Y = 0f; |
144 | angularLow.Z = 0f; | 144 | } |
145 | angularHigh.Z = 0f; | 145 | if (Prim.LockedAxis.Z != 1f) |
146 | } | 146 | { |
147 | axisConstrainer.SetAngularLimits(angularLow, angularHigh); | 147 | angularLow.Z = 0f; |
148 | 148 | angularHigh.Z = 0f; | |
149 | PhysicsScene.DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}", | 149 | } |
150 | Prim.LocalID, linearLow, linearHigh, angularLow, angularHigh); | 150 | axisConstrainer.SetAngularLimits(angularLow, angularHigh); |
151 | 151 | ||
152 | // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. | 152 | PhysicsScene.DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}", |
153 | axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); | 153 | Prim.LocalID, linearLow, linearHigh, angularLow, angularHigh); |
154 | 154 | ||
155 | axisConstrainer.RecomputeConstraintVariables(Prim.RawMass); | 155 | // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. |
156 | } | 156 | axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); |
157 | 157 | ||
158 | private void RemoveAxisLockConstraint() | 158 | axisConstrainer.RecomputeConstraintVariables(Prim.RawMass); |
159 | { | 159 | } |
160 | if (LockAxisConstraint != null) | 160 | |
161 | { | 161 | private void RemoveAxisLockConstraint() |
162 | PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); | 162 | { |
163 | LockAxisConstraint = null; | 163 | if (LockAxisConstraint != null) |
164 | PhysicsScene.DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", Prim.LocalID); | 164 | { |
165 | } | 165 | PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); |
166 | } | 166 | LockAxisConstraint = null; |
167 | } | 167 | PhysicsScene.DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", Prim.LocalID); |
168 | } | 168 | } |
169 | } | ||
170 | } | ||
171 | } | ||