diff options
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | 339 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSActors.cs | 254 |
2 files changed, 302 insertions, 291 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 | } | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs index b9b5ce1..3163440 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs | |||
@@ -1,123 +1,131 @@ | |||
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 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Text; | 29 | using System.Text; |
30 | 30 | ||
31 | namespace OpenSim.Region.Physics.BulletSPlugin | 31 | namespace OpenSim.Region.Physics.BulletSPlugin |
32 | { | 32 | { |
33 | public class BSActorCollection | 33 | public class BSActorCollection |
34 | { | 34 | { |
35 | private BSScene PhysicsScene { get; set; } | 35 | private BSScene PhysicsScene { get; set; } |
36 | private Dictionary<string, BSActor> m_actors; | 36 | private Dictionary<string, BSActor> m_actors; |
37 | 37 | ||
38 | public BSActorCollection(BSScene physicsScene) | 38 | public BSActorCollection(BSScene physicsScene) |
39 | { | 39 | { |
40 | PhysicsScene = physicsScene; | 40 | PhysicsScene = physicsScene; |
41 | m_actors = new Dictionary<string, BSActor>(); | 41 | m_actors = new Dictionary<string, BSActor>(); |
42 | } | 42 | } |
43 | public void Add(string name, BSActor actor) | 43 | public void Add(string name, BSActor actor) |
44 | { | 44 | { |
45 | m_actors[name] = actor; | 45 | m_actors[name] = actor; |
46 | } | 46 | } |
47 | public bool RemoveAndRelease(string name) | 47 | public bool RemoveAndRelease(string name) |
48 | { | 48 | { |
49 | bool ret = false; | 49 | bool ret = false; |
50 | if (m_actors.ContainsKey(name)) | 50 | if (m_actors.ContainsKey(name)) |
51 | { | 51 | { |
52 | BSActor beingRemoved = m_actors[name]; | 52 | BSActor beingRemoved = m_actors[name]; |
53 | beingRemoved.Release(); | 53 | beingRemoved.Dispose(); |
54 | m_actors.Remove(name); | 54 | m_actors.Remove(name); |
55 | ret = true; | 55 | ret = true; |
56 | } | 56 | } |
57 | return ret; | 57 | return ret; |
58 | } | 58 | } |
59 | public void Clear() | 59 | public void Clear() |
60 | { | 60 | { |
61 | Release(); | 61 | Release(); |
62 | m_actors.Clear(); | 62 | m_actors.Clear(); |
63 | } | 63 | } |
64 | public bool HasActor(string name) | 64 | public bool HasActor(string name) |
65 | { | 65 | { |
66 | return m_actors.ContainsKey(name); | 66 | return m_actors.ContainsKey(name); |
67 | } | 67 | } |
68 | public void ForEachActor(Action<BSActor> act) | 68 | public void ForEachActor(Action<BSActor> act) |
69 | { | 69 | { |
70 | foreach (KeyValuePair<string, BSActor> kvp in m_actors) | 70 | foreach (KeyValuePair<string, BSActor> kvp in m_actors) |
71 | act(kvp.Value); | 71 | act(kvp.Value); |
72 | } | 72 | } |
73 | 73 | ||
74 | public void Release() | 74 | public void Release() |
75 | { | 75 | { |
76 | ForEachActor(a => a.Release()); | 76 | ForEachActor(a => a.Dispose()); |
77 | } | 77 | } |
78 | public void Refresh() | 78 | public void Refresh() |
79 | { | 79 | { |
80 | ForEachActor(a => a.Refresh()); | 80 | ForEachActor(a => a.Refresh()); |
81 | } | 81 | } |
82 | public void RemoveBodyDependencies() | 82 | public void RemoveBodyDependencies() |
83 | { | 83 | { |
84 | ForEachActor(a => a.RemoveBodyDependencies()); | 84 | ForEachActor(a => a.RemoveBodyDependencies()); |
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | // ============================================================================= | 88 | // ============================================================================= |
89 | public abstract class BSActor | 89 | /// <summary> |
90 | { | 90 | /// Each physical object can have 'actors' who are pushing the object around. |
91 | protected BSScene PhysicsScene { get; private set; } | 91 | /// This can be used for hover, locking axis, making vehicles, etc. |
92 | protected BSPhysObject Prim { get; private set; } | 92 | /// Each physical object can have multiple actors acting on it. |
93 | protected bool Enabled { get; set; } | 93 | /// |
94 | public string ActorName { get; private set; } | 94 | /// An actor usually registers itself with physics scene events (pre-step action) |
95 | 95 | /// and modifies the parameters on the host physical object. | |
96 | public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName) | 96 | /// </summary> |
97 | { | 97 | public abstract class BSActor |
98 | PhysicsScene = physicsScene; | 98 | { |
99 | Prim = pObj; | 99 | protected BSScene PhysicsScene { get; private set; } |
100 | ActorName = actorName; | 100 | protected BSPhysObject Prim { get; private set; } |
101 | Enabled = true; | 101 | protected bool Enabled { get; set; } |
102 | } | 102 | public string ActorName { get; private set; } |
103 | 103 | ||
104 | // Return 'true' if activily updating the prim | 104 | public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName) |
105 | public virtual bool isActive | 105 | { |
106 | { | 106 | PhysicsScene = physicsScene; |
107 | get { return Enabled; } | 107 | Prim = pObj; |
108 | } | 108 | ActorName = actorName; |
109 | // Turn the actor on an off. | 109 | Enabled = true; |
110 | public virtual void Enable(bool setEnabled) | 110 | } |
111 | { | 111 | |
112 | Enabled = setEnabled; | 112 | // Return 'true' if activily updating the prim |
113 | } | 113 | public virtual bool isActive |
114 | // Release any connections and resources used by the actor. | 114 | { |
115 | public abstract void Release(); | 115 | get { return Enabled; } |
116 | // Called when physical parameters (properties set in Bullet) need to be re-applied. | 116 | } |
117 | public abstract void Refresh(); | 117 | // Turn the actor on an off. |
118 | // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). | 118 | public virtual void Enable(bool setEnabled) |
119 | // Register a prestep action to restore physical requirements before the next simulation step. | 119 | { |
120 | public abstract void RemoveBodyDependencies(); | 120 | Enabled = setEnabled; |
121 | 121 | } | |
122 | } | 122 | // Release any connections and resources used by the actor. |
123 | } | 123 | public abstract void Dispose(); |
124 | // Called when physical parameters (properties set in Bullet) need to be re-applied. | ||
125 | public abstract void Refresh(); | ||
126 | // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). | ||
127 | // Register a prestep action to restore physical requirements before the next simulation step. | ||
128 | public abstract void RemoveBodyDependencies(); | ||
129 | |||
130 | } | ||
131 | } | ||