diff options
author | lbsa71 | 2007-10-30 09:05:31 +0000 |
---|---|---|
committer | lbsa71 | 2007-10-30 09:05:31 +0000 |
commit | 67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch) | |
tree | 20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Region/Physics/BulletXPlugin | |
parent | * Deleted .user file (diff) | |
download | opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2 opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz |
* Optimized usings
* Shortened type references
* Removed redundant 'this' qualifier
Diffstat (limited to 'OpenSim/Region/Physics/BulletXPlugin')
-rw-r--r-- | OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs | 24 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs | 589 |
2 files changed, 345 insertions, 268 deletions
diff --git a/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs index 0180917..c8596f7 100644 --- a/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs +++ b/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs | |||
@@ -1,4 +1,4 @@ | |||
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 | * |
@@ -27,24 +27,26 @@ | |||
27 | */ | 27 | */ |
28 | using System.Reflection; | 28 | using System.Reflection; |
29 | using System.Runtime.InteropServices; | 29 | using System.Runtime.InteropServices; |
30 | |||
30 | // Information about this assembly is defined by the following | 31 | // Information about this assembly is defined by the following |
31 | // attributes. | 32 | // attributes. |
32 | // | 33 | // |
33 | // change them to the information which is associated with the assembly | 34 | // change them to the information which is associated with the assembly |
34 | // you compile. | 35 | // you compile. |
35 | 36 | ||
36 | [assembly: AssemblyTitle("BulletXPlugin")] | 37 | [assembly : AssemblyTitle("BulletXPlugin")] |
37 | [assembly: AssemblyDescription("")] | 38 | [assembly : AssemblyDescription("")] |
38 | [assembly: AssemblyConfiguration("")] | 39 | [assembly : AssemblyConfiguration("")] |
39 | [assembly: AssemblyCompany("")] | 40 | [assembly : AssemblyCompany("")] |
40 | [assembly: AssemblyProduct("BulletXPlugin")] | 41 | [assembly : AssemblyProduct("BulletXPlugin")] |
41 | [assembly: AssemblyCopyright("")] | 42 | [assembly : AssemblyCopyright("")] |
42 | [assembly: AssemblyTrademark("")] | 43 | [assembly : AssemblyTrademark("")] |
43 | [assembly: AssemblyCulture("")] | 44 | [assembly : AssemblyCulture("")] |
44 | 45 | ||
45 | // This sets the default COM visibility of types in the assembly to invisible. | 46 | // This sets the default COM visibility of types in the assembly to invisible. |
46 | // If you need to expose a type to COM, use [ComVisible(true)] on that type. | 47 | // If you need to expose a type to COM, use [ComVisible(true)] on that type. |
47 | [assembly: ComVisible(false)] | 48 | |
49 | [assembly : ComVisible(false)] | ||
48 | 50 | ||
49 | // The assembly version has following format : | 51 | // The assembly version has following format : |
50 | // | 52 | // |
@@ -53,4 +55,4 @@ using System.Runtime.InteropServices; | |||
53 | // You can specify all values by your own or you can build default build and revision | 55 | // You can specify all values by your own or you can build default build and revision |
54 | // numbers with the '*' character (the default): | 56 | // numbers with the '*' character (the default): |
55 | 57 | ||
56 | [assembly: AssemblyVersion("1.0.0.0")] | 58 | [assembly : AssemblyVersion("1.0.0.0")] \ No newline at end of file |
diff --git a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs index 9fdc017..1658e2d 100644 --- a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs +++ b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #region Copyright | 29 | #region Copyright |
30 | |||
30 | /* | 31 | /* |
31 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | 32 | * Copyright (c) Contributors, http://www.openmetaverse.org/ |
32 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 33 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
@@ -54,18 +55,21 @@ | |||
54 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 55 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
55 | * | 56 | * |
56 | */ | 57 | */ |
58 | |||
57 | #endregion | 59 | #endregion |
60 | |||
58 | #region References | 61 | #region References |
62 | |||
59 | using System; | 63 | using System; |
60 | using System.Collections.Generic; | 64 | using System.Collections.Generic; |
61 | using OpenSim.Region.Physics.Manager; | ||
62 | using OpenSim.Framework; | ||
63 | using Axiom.Math; | ||
64 | using AxiomQuaternion = Axiom.Math.Quaternion; | ||
65 | //Specific References for BulletXPlugin | ||
66 | using MonoXnaCompactMaths; | 65 | using MonoXnaCompactMaths; |
66 | using OpenSim.Framework; | ||
67 | using OpenSim.Region.Physics.Manager; | ||
67 | using XnaDevRu.BulletX; | 68 | using XnaDevRu.BulletX; |
68 | using XnaDevRu.BulletX.Dynamics; | 69 | using XnaDevRu.BulletX.Dynamics; |
70 | using AxiomQuaternion = Axiom.Math.Quaternion; | ||
71 | using BoxShape=XnaDevRu.BulletX.BoxShape; | ||
72 | //Specific References for BulletXPlugin | ||
69 | 73 | ||
70 | #endregion | 74 | #endregion |
71 | 75 | ||
@@ -80,27 +84,31 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
80 | { | 84 | { |
81 | } | 85 | } |
82 | } | 86 | } |
87 | |||
83 | /// <summary> | 88 | /// <summary> |
84 | /// BulletXConversions are called now BulletXMaths | 89 | /// BulletXConversions are called now BulletXMaths |
85 | /// This Class converts objects and types for BulletX and give some operations | 90 | /// This Class converts objects and types for BulletX and give some operations |
86 | /// </summary> | 91 | /// </summary> |
87 | public class BulletXMaths | 92 | public class BulletXMaths |
88 | { | 93 | { |
89 | //Vector3 | 94 | //Vector3 |
90 | public static MonoXnaCompactMaths.Vector3 PhysicsVectorToXnaVector3(PhysicsVector physicsVector) | 95 | public static Vector3 PhysicsVectorToXnaVector3(PhysicsVector physicsVector) |
91 | { | 96 | { |
92 | return new MonoXnaCompactMaths.Vector3(physicsVector.X, physicsVector.Y, physicsVector.Z); | 97 | return new Vector3(physicsVector.X, physicsVector.Y, physicsVector.Z); |
93 | } | 98 | } |
94 | public static PhysicsVector XnaVector3ToPhysicsVector(MonoXnaCompactMaths.Vector3 xnaVector3) | 99 | |
100 | public static PhysicsVector XnaVector3ToPhysicsVector(Vector3 xnaVector3) | ||
95 | { | 101 | { |
96 | return new PhysicsVector(xnaVector3.X, xnaVector3.Y, xnaVector3.Z); | 102 | return new PhysicsVector(xnaVector3.X, xnaVector3.Y, xnaVector3.Z); |
97 | } | 103 | } |
104 | |||
98 | //Quaternion | 105 | //Quaternion |
99 | public static MonoXnaCompactMaths.Quaternion AxiomQuaternionToXnaQuaternion(AxiomQuaternion axiomQuaternion) | 106 | public static Quaternion AxiomQuaternionToXnaQuaternion(AxiomQuaternion axiomQuaternion) |
100 | { | 107 | { |
101 | return new MonoXnaCompactMaths.Quaternion(axiomQuaternion.x, axiomQuaternion.y, axiomQuaternion.z, axiomQuaternion.w); | 108 | return new Quaternion(axiomQuaternion.x, axiomQuaternion.y, axiomQuaternion.z, axiomQuaternion.w); |
102 | } | 109 | } |
103 | public static AxiomQuaternion XnaQuaternionToAxiomQuaternion(MonoXnaCompactMaths.Quaternion xnaQuaternion) | 110 | |
111 | public static AxiomQuaternion XnaQuaternionToAxiomQuaternion(Quaternion xnaQuaternion) | ||
104 | { | 112 | { |
105 | return new AxiomQuaternion(xnaQuaternion.W, xnaQuaternion.X, xnaQuaternion.Y, xnaQuaternion.Z); | 113 | return new AxiomQuaternion(xnaQuaternion.W, xnaQuaternion.X, xnaQuaternion.Y, xnaQuaternion.Z); |
106 | } | 114 | } |
@@ -110,70 +118,79 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
110 | //- GetRotation (class MatrixOperations) | 118 | //- GetRotation (class MatrixOperations) |
111 | //- GetElement (class MathHelper) | 119 | //- GetElement (class MathHelper) |
112 | //- SetElement (class MathHelper) | 120 | //- SetElement (class MathHelper) |
113 | internal static void SetRotation(ref Matrix m, MonoXnaCompactMaths.Quaternion q) | 121 | internal static void SetRotation(ref Matrix m, Quaternion q) |
114 | { | 122 | { |
115 | float d = q.LengthSquared(); | 123 | float d = q.LengthSquared(); |
116 | float s = 2f / d; | 124 | float s = 2f/d; |
117 | float xs = q.X * s, ys = q.Y * s, zs = q.Z * s; | 125 | float xs = q.X*s, ys = q.Y*s, zs = q.Z*s; |
118 | float wx = q.W * xs, wy = q.W * ys, wz = q.W * zs; | 126 | float wx = q.W*xs, wy = q.W*ys, wz = q.W*zs; |
119 | float xx = q.X * xs, xy = q.X * ys, xz = q.X * zs; | 127 | float xx = q.X*xs, xy = q.X*ys, xz = q.X*zs; |
120 | float yy = q.Y * ys, yz = q.Y * zs, zz = q.Z * zs; | 128 | float yy = q.Y*ys, yz = q.Y*zs, zz = q.Z*zs; |
121 | m = new Matrix(1 - (yy + zz), xy - wz, xz + wy, 0, | 129 | m = new Matrix(1 - (yy + zz), xy - wz, xz + wy, 0, |
122 | xy + wz, 1 - (xx + zz), yz - wx, 0, | 130 | xy + wz, 1 - (xx + zz), yz - wx, 0, |
123 | xz - wy, yz + wx, 1 - (xx + yy), 0, | 131 | xz - wy, yz + wx, 1 - (xx + yy), 0, |
124 | m.M41, m.M42, m.M43, 1); | 132 | m.M41, m.M42, m.M43, 1); |
125 | } | 133 | } |
126 | internal static MonoXnaCompactMaths.Quaternion GetRotation(Matrix m) | 134 | |
135 | internal static Quaternion GetRotation(Matrix m) | ||
127 | { | 136 | { |
128 | MonoXnaCompactMaths.Quaternion q = new MonoXnaCompactMaths.Quaternion(); | 137 | Quaternion q = new Quaternion(); |
129 | 138 | ||
130 | float trace = m.M11 + m.M22 + m.M33; | 139 | float trace = m.M11 + m.M22 + m.M33; |
131 | 140 | ||
132 | if (trace > 0) | 141 | if (trace > 0) |
133 | { | 142 | { |
134 | float s = (float)Math.Sqrt(trace + 1); | 143 | float s = (float) Math.Sqrt(trace + 1); |
135 | q.W = s * 0.5f; | 144 | q.W = s*0.5f; |
136 | s = 0.5f / s; | 145 | s = 0.5f/s; |
137 | 146 | ||
138 | q.X = (m.M32 - m.M23) * s; | 147 | q.X = (m.M32 - m.M23)*s; |
139 | q.Y = (m.M13 - m.M31) * s; | 148 | q.Y = (m.M13 - m.M31)*s; |
140 | q.Z = (m.M21 - m.M12) * s; | 149 | q.Z = (m.M21 - m.M12)*s; |
141 | } | 150 | } |
142 | else | 151 | else |
143 | { | 152 | { |
144 | int i = m.M11 < m.M22 ? | 153 | int i = m.M11 < m.M22 |
145 | (m.M22 < m.M33 ? 2 : 1) : | 154 | ? |
146 | (m.M11 < m.M33 ? 2 : 0); | 155 | (m.M22 < m.M33 ? 2 : 1) |
147 | int j = (i + 1) % 3; | 156 | : |
148 | int k = (i + 2) % 3; | 157 | (m.M11 < m.M33 ? 2 : 0); |
149 | 158 | int j = (i + 1)%3; | |
150 | float s = (float)Math.Sqrt(GetElement(m, i, i) - GetElement(m, j, j) - GetElement(m, k, k) + 1); | 159 | int k = (i + 2)%3; |
151 | SetElement(ref q, i, s * 0.5f); | 160 | |
152 | s = 0.5f / s; | 161 | float s = (float) Math.Sqrt(GetElement(m, i, i) - GetElement(m, j, j) - GetElement(m, k, k) + 1); |
153 | 162 | SetElement(ref q, i, s*0.5f); | |
154 | q.W = (GetElement(m, k, j) - GetElement(m, j, k)) * s; | 163 | s = 0.5f/s; |
155 | SetElement(ref q, j, (GetElement(m, j, i) + GetElement(m, i, j)) * s); | 164 | |
156 | SetElement(ref q, k, (GetElement(m, k, i) + GetElement(m, i, k)) * s); | 165 | q.W = (GetElement(m, k, j) - GetElement(m, j, k))*s; |
166 | SetElement(ref q, j, (GetElement(m, j, i) + GetElement(m, i, j))*s); | ||
167 | SetElement(ref q, k, (GetElement(m, k, i) + GetElement(m, i, k))*s); | ||
157 | } | 168 | } |
158 | 169 | ||
159 | return q; | 170 | return q; |
160 | } | 171 | } |
161 | internal static float SetElement(ref MonoXnaCompactMaths.Quaternion q, int index, float value) | 172 | |
173 | internal static float SetElement(ref Quaternion q, int index, float value) | ||
162 | { | 174 | { |
163 | switch (index) | 175 | switch (index) |
164 | { | 176 | { |
165 | case 0: | 177 | case 0: |
166 | q.X = value; break; | 178 | q.X = value; |
179 | break; | ||
167 | case 1: | 180 | case 1: |
168 | q.Y = value; break; | 181 | q.Y = value; |
182 | break; | ||
169 | case 2: | 183 | case 2: |
170 | q.Z = value; break; | 184 | q.Z = value; |
185 | break; | ||
171 | case 3: | 186 | case 3: |
172 | q.W = value; break; | 187 | q.W = value; |
188 | break; | ||
173 | } | 189 | } |
174 | 190 | ||
175 | return 0; | 191 | return 0; |
176 | } | 192 | } |
193 | |||
177 | internal static float GetElement(Matrix mat, int row, int col) | 194 | internal static float GetElement(Matrix mat, int row, int col) |
178 | { | 195 | { |
179 | switch (row) | 196 | switch (row) |
@@ -187,7 +204,8 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
187 | return mat.M12; | 204 | return mat.M12; |
188 | case 2: | 205 | case 2: |
189 | return mat.M13; | 206 | return mat.M13; |
190 | } break; | 207 | } |
208 | break; | ||
191 | case 1: | 209 | case 1: |
192 | switch (col) | 210 | switch (col) |
193 | { | 211 | { |
@@ -197,7 +215,8 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
197 | return mat.M22; | 215 | return mat.M22; |
198 | case 2: | 216 | case 2: |
199 | return mat.M23; | 217 | return mat.M23; |
200 | } break; | 218 | } |
219 | break; | ||
201 | case 2: | 220 | case 2: |
202 | switch (col) | 221 | switch (col) |
203 | { | 222 | { |
@@ -207,12 +226,14 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
207 | return mat.M32; | 226 | return mat.M32; |
208 | case 2: | 227 | case 2: |
209 | return mat.M33; | 228 | return mat.M33; |
210 | } break; | 229 | } |
230 | break; | ||
211 | } | 231 | } |
212 | 232 | ||
213 | return 0; | 233 | return 0; |
214 | } | 234 | } |
215 | } | 235 | } |
236 | |||
216 | /// <summary> | 237 | /// <summary> |
217 | /// PhysicsPlugin Class for BulletX | 238 | /// PhysicsPlugin Class for BulletX |
218 | /// </summary> | 239 | /// </summary> |
@@ -223,10 +244,12 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
223 | public BulletXPlugin() | 244 | public BulletXPlugin() |
224 | { | 245 | { |
225 | } | 246 | } |
247 | |||
226 | public bool Init() | 248 | public bool Init() |
227 | { | 249 | { |
228 | return true; | 250 | return true; |
229 | } | 251 | } |
252 | |||
230 | public PhysicsScene GetScene() | 253 | public PhysicsScene GetScene() |
231 | { | 254 | { |
232 | if (_mScene == null) | 255 | if (_mScene == null) |
@@ -235,20 +258,24 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
235 | } | 258 | } |
236 | return (_mScene); | 259 | return (_mScene); |
237 | } | 260 | } |
261 | |||
238 | public string GetName() | 262 | public string GetName() |
239 | { | 263 | { |
240 | return ("modified_BulletX");//Changed!! "BulletXEngine" To "modified_BulletX" | 264 | return ("modified_BulletX"); //Changed!! "BulletXEngine" To "modified_BulletX" |
241 | } | 265 | } |
266 | |||
242 | public void Dispose() | 267 | public void Dispose() |
243 | { | 268 | { |
244 | } | 269 | } |
245 | } | 270 | } |
271 | |||
246 | /// <summary> | 272 | /// <summary> |
247 | /// PhysicsScene Class for BulletX | 273 | /// PhysicsScene Class for BulletX |
248 | /// </summary> | 274 | /// </summary> |
249 | public class BulletXScene : PhysicsScene | 275 | public class BulletXScene : PhysicsScene |
250 | { | 276 | { |
251 | #region BulletXScene Fields | 277 | #region BulletXScene Fields |
278 | |||
252 | public DiscreteDynamicsWorld ddWorld; | 279 | public DiscreteDynamicsWorld ddWorld; |
253 | private CollisionDispatcher cDispatcher; | 280 | private CollisionDispatcher cDispatcher; |
254 | private OverlappingPairCache opCache; | 281 | private OverlappingPairCache opCache; |
@@ -271,33 +298,58 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
271 | private List<BulletXCharacter> _characters = new List<BulletXCharacter>(); | 298 | private List<BulletXCharacter> _characters = new List<BulletXCharacter>(); |
272 | private List<BulletXPrim> _prims = new List<BulletXPrim>(); | 299 | private List<BulletXPrim> _prims = new List<BulletXPrim>(); |
273 | 300 | ||
274 | public static float Gravity { get { return gravity; } } | 301 | public static float Gravity |
275 | public static float HeightLevel0 { get { return heightLevel0; } } | 302 | { |
276 | public static float HeightLevel1 { get { return heightLevel1; } } | 303 | get { return gravity; } |
277 | public static float LowGravityFactor { get { return lowGravityFactor; } } | 304 | } |
278 | public static int MaxXY { get { return maxXY; } } | 305 | |
279 | public static int MaxZ { get { return maxZ; } } | 306 | public static float HeightLevel0 |
307 | { | ||
308 | get { return heightLevel0; } | ||
309 | } | ||
310 | |||
311 | public static float HeightLevel1 | ||
312 | { | ||
313 | get { return heightLevel1; } | ||
314 | } | ||
315 | |||
316 | public static float LowGravityFactor | ||
317 | { | ||
318 | get { return lowGravityFactor; } | ||
319 | } | ||
320 | |||
321 | public static int MaxXY | ||
322 | { | ||
323 | get { return maxXY; } | ||
324 | } | ||
325 | |||
326 | public static int MaxZ | ||
327 | { | ||
328 | get { return maxZ; } | ||
329 | } | ||
280 | 330 | ||
281 | private List<RigidBody> _forgottenRigidBodies = new List<RigidBody>(); | 331 | private List<RigidBody> _forgottenRigidBodies = new List<RigidBody>(); |
282 | internal string is_ex_message = "Can't remove rigidBody!: "; | 332 | internal string is_ex_message = "Can't remove rigidBody!: "; |
333 | |||
283 | #endregion | 334 | #endregion |
284 | 335 | ||
285 | public BulletXScene() | 336 | public BulletXScene() |
286 | { | 337 | { |
287 | cDispatcher = new CollisionDispatcher(); | 338 | cDispatcher = new CollisionDispatcher(); |
288 | MonoXnaCompactMaths.Vector3 worldMinDim = new MonoXnaCompactMaths.Vector3((float)minXY, (float)minXY, (float)minZ); | 339 | Vector3 worldMinDim = new Vector3((float) minXY, (float) minXY, (float) minZ); |
289 | MonoXnaCompactMaths.Vector3 worldMaxDim = new MonoXnaCompactMaths.Vector3((float)maxXY, (float)maxXY, (float)maxZ); | 340 | Vector3 worldMaxDim = new Vector3((float) maxXY, (float) maxXY, (float) maxZ); |
290 | opCache = new AxisSweep3(worldMinDim, worldMaxDim, maxHandles); | 341 | opCache = new AxisSweep3(worldMinDim, worldMaxDim, maxHandles); |
291 | sicSolver = new SequentialImpulseConstraintSolver(); | 342 | sicSolver = new SequentialImpulseConstraintSolver(); |
292 | 343 | ||
293 | lock (BulletXLock) | 344 | lock (BulletXLock) |
294 | { | 345 | { |
295 | ddWorld = new DiscreteDynamicsWorld(cDispatcher, opCache, sicSolver); | 346 | ddWorld = new DiscreteDynamicsWorld(cDispatcher, opCache, sicSolver); |
296 | ddWorld.Gravity = new MonoXnaCompactMaths.Vector3(0, 0, -gravity); | 347 | ddWorld.Gravity = new Vector3(0, 0, -gravity); |
297 | } | 348 | } |
298 | //this._heightmap = new float[65536]; | 349 | //this._heightmap = new float[65536]; |
299 | } | 350 | } |
300 | public override PhysicsActor AddAvatar(string avName, PhysicsVector position) | 351 | |
352 | public override PhysicsActor AddAvatar(string avName, PhysicsVector position) | ||
301 | { | 353 | { |
302 | PhysicsVector pos = new PhysicsVector(); | 354 | PhysicsVector pos = new PhysicsVector(); |
303 | pos.X = position.X; | 355 | pos.X = position.X; |
@@ -311,6 +363,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
311 | } | 363 | } |
312 | return newAv; | 364 | return newAv; |
313 | } | 365 | } |
366 | |||
314 | public override void RemoveAvatar(PhysicsActor actor) | 367 | public override void RemoveAvatar(PhysicsActor actor) |
315 | { | 368 | { |
316 | if (actor is BulletXCharacter) | 369 | if (actor is BulletXCharacter) |
@@ -319,20 +372,22 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
319 | { | 372 | { |
320 | try | 373 | try |
321 | { | 374 | { |
322 | ddWorld.RemoveRigidBody(((BulletXCharacter)actor).RigidBody); | 375 | ddWorld.RemoveRigidBody(((BulletXCharacter) actor).RigidBody); |
323 | } | 376 | } |
324 | catch (Exception ex) | 377 | catch (Exception ex) |
325 | { | 378 | { |
326 | BulletXMessage(is_ex_message + ex.Message, true); | 379 | BulletXMessage(is_ex_message + ex.Message, true); |
327 | ((BulletXCharacter)actor).RigidBody.ActivationState = ActivationState.DisableSimulation; | 380 | ((BulletXCharacter) actor).RigidBody.ActivationState = ActivationState.DisableSimulation; |
328 | AddForgottenRigidBody(((BulletXCharacter)actor).RigidBody); | 381 | AddForgottenRigidBody(((BulletXCharacter) actor).RigidBody); |
329 | } | 382 | } |
330 | _characters.Remove((BulletXCharacter)actor); | 383 | _characters.Remove((BulletXCharacter) actor); |
331 | } | 384 | } |
332 | GC.Collect(); | 385 | GC.Collect(); |
333 | } | 386 | } |
334 | } | 387 | } |
335 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation) | 388 | |
389 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | ||
390 | PhysicsVector size, AxiomQuaternion rotation) | ||
336 | { | 391 | { |
337 | PhysicsActor result; | 392 | PhysicsActor result; |
338 | 393 | ||
@@ -358,11 +413,14 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
358 | 413 | ||
359 | return result; | 414 | return result; |
360 | } | 415 | } |
361 | public PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Axiom.Math.Quaternion rotation) | 416 | |
417 | public PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation) | ||
362 | { | 418 | { |
363 | return AddPrim("", position, size, rotation, null, null); | 419 | return AddPrim("", position, size, rotation, null, null); |
364 | } | 420 | } |
365 | public PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) | 421 | |
422 | public PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation, | ||
423 | Mesh mesh, PrimitiveBaseShape pbs) | ||
366 | { | 424 | { |
367 | BulletXPrim newPrim = null; | 425 | BulletXPrim newPrim = null; |
368 | lock (BulletXLock) | 426 | lock (BulletXLock) |
@@ -372,6 +430,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
372 | } | 430 | } |
373 | return newPrim; | 431 | return newPrim; |
374 | } | 432 | } |
433 | |||
375 | public override void RemovePrim(PhysicsActor prim) | 434 | public override void RemovePrim(PhysicsActor prim) |
376 | { | 435 | { |
377 | if (prim is BulletXPrim) | 436 | if (prim is BulletXPrim) |
@@ -380,19 +439,20 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
380 | { | 439 | { |
381 | try | 440 | try |
382 | { | 441 | { |
383 | ddWorld.RemoveRigidBody(((BulletXPrim)prim).RigidBody); | 442 | ddWorld.RemoveRigidBody(((BulletXPrim) prim).RigidBody); |
384 | } | 443 | } |
385 | catch (Exception ex) | 444 | catch (Exception ex) |
386 | { | 445 | { |
387 | BulletXMessage(is_ex_message + ex.Message, true); | 446 | BulletXMessage(is_ex_message + ex.Message, true); |
388 | ((BulletXPrim)prim).RigidBody.ActivationState = ActivationState.DisableSimulation; | 447 | ((BulletXPrim) prim).RigidBody.ActivationState = ActivationState.DisableSimulation; |
389 | AddForgottenRigidBody(((BulletXPrim)prim).RigidBody); | 448 | AddForgottenRigidBody(((BulletXPrim) prim).RigidBody); |
390 | } | 449 | } |
391 | _prims.Remove((BulletXPrim)prim); | 450 | _prims.Remove((BulletXPrim) prim); |
392 | } | 451 | } |
393 | GC.Collect(); | 452 | GC.Collect(); |
394 | } | 453 | } |
395 | } | 454 | } |
455 | |||
396 | public override void Simulate(float timeStep) | 456 | public override void Simulate(float timeStep) |
397 | { | 457 | { |
398 | lock (BulletXLock) | 458 | lock (BulletXLock) |
@@ -408,6 +468,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
408 | UpdateKineticsForAll(); | 468 | UpdateKineticsForAll(); |
409 | } | 469 | } |
410 | } | 470 | } |
471 | |||
411 | private void MoveAllObjects(float timeStep) | 472 | private void MoveAllObjects(float timeStep) |
412 | { | 473 | { |
413 | foreach (BulletXCharacter actor in _characters) | 474 | foreach (BulletXCharacter actor in _characters) |
@@ -418,6 +479,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
418 | { | 479 | { |
419 | } | 480 | } |
420 | } | 481 | } |
482 | |||
421 | private void ValidateHeightForAll() | 483 | private void ValidateHeightForAll() |
422 | { | 484 | { |
423 | float _height; | 485 | float _height; |
@@ -431,7 +493,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
431 | foreach (BulletXPrim prim in _prims) | 493 | foreach (BulletXPrim prim in _prims) |
432 | { | 494 | { |
433 | //_height = HeightValue(prim.RigidBodyPosition); | 495 | //_height = HeightValue(prim.RigidBodyPosition); |
434 | _height = _simFlatPlanet.HeightValue(prim.RigidBodyPosition); | 496 | _height = _simFlatPlanet.HeightValue(prim.RigidBodyPosition); |
435 | prim.ValidateHeight(_height); | 497 | prim.ValidateHeight(_height); |
436 | //if (_simFlatPlanet.heightIsNotValid(prim.RigidBodyPosition, out _height)) prim.ValidateHeight(_height); | 498 | //if (_simFlatPlanet.heightIsNotValid(prim.RigidBodyPosition, out _height)) prim.ValidateHeight(_height); |
437 | } | 499 | } |
@@ -444,6 +506,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
444 | // prim.ValidateHeight(0); | 506 | // prim.ValidateHeight(0); |
445 | //} | 507 | //} |
446 | } | 508 | } |
509 | |||
447 | private void UpdateKineticsForAll() | 510 | private void UpdateKineticsForAll() |
448 | { | 511 | { |
449 | //UpdatePosition > UpdateKinetics. | 512 | //UpdatePosition > UpdateKinetics. |
@@ -458,17 +521,17 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
458 | } | 521 | } |
459 | //if(this._simFlatPlanet!=null) this._simFlatPlanet.Restore(); | 522 | //if(this._simFlatPlanet!=null) this._simFlatPlanet.Restore(); |
460 | } | 523 | } |
524 | |||
461 | public override void GetResults() | 525 | public override void GetResults() |
462 | { | 526 | { |
463 | |||
464 | } | 527 | } |
528 | |||
465 | public override bool IsThreaded | 529 | public override bool IsThreaded |
466 | { | 530 | { |
467 | get | 531 | get { return (false); // for now we won't be multithreaded |
468 | { | ||
469 | return (false); // for now we won't be multithreaded | ||
470 | } | 532 | } |
471 | } | 533 | } |
534 | |||
472 | public override void SetTerrain(float[] heightMap) | 535 | public override void SetTerrain(float[] heightMap) |
473 | { | 536 | { |
474 | ////As the same as ODE, heightmap (x,y) must be swapped for BulletX | 537 | ////As the same as ODE, heightmap (x,y) must be swapped for BulletX |
@@ -494,41 +557,44 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
494 | DeleteTerrain(); | 557 | DeleteTerrain(); |
495 | //There is a BulletXLock inside the constructor of BulletXPlanet | 558 | //There is a BulletXLock inside the constructor of BulletXPlanet |
496 | //this._simFlatPlanet = new BulletXPlanet(this, swappedHeightMap); | 559 | //this._simFlatPlanet = new BulletXPlanet(this, swappedHeightMap); |
497 | this._simFlatPlanet = new BulletXPlanet(this, heightMap); | 560 | _simFlatPlanet = new BulletXPlanet(this, heightMap); |
498 | //this._heightmap = heightMap; | 561 | //this._heightmap = heightMap; |
499 | } | 562 | } |
563 | |||
500 | public override void DeleteTerrain() | 564 | public override void DeleteTerrain() |
501 | { | 565 | { |
502 | if (this._simFlatPlanet != null) | 566 | if (_simFlatPlanet != null) |
503 | { | 567 | { |
504 | lock (BulletXLock) | 568 | lock (BulletXLock) |
505 | { | 569 | { |
506 | try | 570 | try |
507 | { | 571 | { |
508 | ddWorld.RemoveRigidBody(this._simFlatPlanet.RigidBody); | 572 | ddWorld.RemoveRigidBody(_simFlatPlanet.RigidBody); |
509 | } | 573 | } |
510 | catch (Exception ex) | 574 | catch (Exception ex) |
511 | { | 575 | { |
512 | BulletXMessage(is_ex_message + ex.Message, true); | 576 | BulletXMessage(is_ex_message + ex.Message, true); |
513 | this._simFlatPlanet.RigidBody.ActivationState = ActivationState.DisableSimulation; | 577 | _simFlatPlanet.RigidBody.ActivationState = ActivationState.DisableSimulation; |
514 | AddForgottenRigidBody(this._simFlatPlanet.RigidBody); | 578 | AddForgottenRigidBody(_simFlatPlanet.RigidBody); |
515 | } | 579 | } |
516 | } | 580 | } |
517 | this._simFlatPlanet = null; | 581 | _simFlatPlanet = null; |
518 | GC.Collect(); | 582 | GC.Collect(); |
519 | BulletXMessage("Terrain erased!", false); | 583 | BulletXMessage("Terrain erased!", false); |
520 | } | 584 | } |
521 | //this._heightmap = null; | 585 | //this._heightmap = null; |
522 | } | 586 | } |
587 | |||
523 | internal void AddForgottenRigidBody(RigidBody forgottenRigidBody) | 588 | internal void AddForgottenRigidBody(RigidBody forgottenRigidBody) |
524 | { | 589 | { |
525 | _forgottenRigidBodies.Add(forgottenRigidBody); | 590 | _forgottenRigidBodies.Add(forgottenRigidBody); |
526 | } | 591 | } |
592 | |||
527 | private void RemoveForgottenRigidBodies() | 593 | private void RemoveForgottenRigidBodies() |
528 | { | 594 | { |
529 | RigidBody forgottenRigidBody; | 595 | RigidBody forgottenRigidBody; |
530 | int nRigidBodies = _forgottenRigidBodies.Count; | 596 | int nRigidBodies = _forgottenRigidBodies.Count; |
531 | for(int i = nRigidBodies - 1; i >= 0; i--) | 597 | for (int i = nRigidBodies - 1; i >= 0; i--) |
532 | { | 598 | { |
533 | forgottenRigidBody = _forgottenRigidBodies[i]; | 599 | forgottenRigidBody = _forgottenRigidBodies[i]; |
534 | try | 600 | try |
@@ -544,10 +610,12 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
544 | } | 610 | } |
545 | GC.Collect(); | 611 | GC.Collect(); |
546 | } | 612 | } |
613 | |||
547 | internal void BulletXMessage(string message, bool isWarning) | 614 | internal void BulletXMessage(string message, bool isWarning) |
548 | { | 615 | { |
549 | PhysicsPluginManager.PhysicsPluginMessage("[Modified BulletX]:\t" + message, isWarning); | 616 | PhysicsPluginManager.PhysicsPluginMessage("[Modified BulletX]:\t" + message, isWarning); |
550 | } | 617 | } |
618 | |||
551 | //temp | 619 | //temp |
552 | //private float HeightValue(MonoXnaCompactMaths.Vector3 position) | 620 | //private float HeightValue(MonoXnaCompactMaths.Vector3 position) |
553 | //{ | 621 | //{ |
@@ -559,10 +627,11 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
559 | // height = this._heightmap[li_y * 256 + li_x]; | 627 | // height = this._heightmap[li_y * 256 + li_x]; |
560 | // if (height < 0) height = 0; | 628 | // if (height < 0) height = 0; |
561 | // else if (height > maxZ) height = maxZ; | 629 | // else if (height > maxZ) height = maxZ; |
562 | 630 | ||
563 | // return height; | 631 | // return height; |
564 | //} | 632 | //} |
565 | } | 633 | } |
634 | |||
566 | /// <summary> | 635 | /// <summary> |
567 | /// PhysicsActor Character Class for BulletX | 636 | /// PhysicsActor Character Class for BulletX |
568 | /// </summary> | 637 | /// </summary> |
@@ -576,21 +645,24 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
576 | private bool flying; | 645 | private bool flying; |
577 | private RigidBody rigidBody; | 646 | private RigidBody rigidBody; |
578 | 647 | ||
579 | public MonoXnaCompactMaths.Vector3 RigidBodyPosition | 648 | public Vector3 RigidBodyPosition |
580 | { | 649 | { |
581 | get { return this.rigidBody.CenterOfMassPosition; } | 650 | get { return rigidBody.CenterOfMassPosition; } |
582 | } | 651 | } |
652 | |||
583 | public BulletXCharacter(BulletXScene parent_scene, PhysicsVector pos) | 653 | public BulletXCharacter(BulletXScene parent_scene, PhysicsVector pos) |
584 | : this("", parent_scene, pos) | 654 | : this("", parent_scene, pos) |
585 | { | 655 | { |
586 | } | 656 | } |
657 | |||
587 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos) | 658 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos) |
588 | : this(avName, parent_scene, pos, new PhysicsVector(), new PhysicsVector(), new PhysicsVector(), | 659 | : this(avName, parent_scene, pos, new PhysicsVector(), new PhysicsVector(), new PhysicsVector(), |
589 | AxiomQuaternion.Identity) | 660 | AxiomQuaternion.Identity) |
590 | { | 661 | { |
591 | } | 662 | } |
663 | |||
592 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, | 664 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, |
593 | PhysicsVector size, PhysicsVector acceleration, AxiomQuaternion orientation) | 665 | PhysicsVector size, PhysicsVector acceleration, AxiomQuaternion orientation) |
594 | { | 666 | { |
595 | //This fields will be removed. They're temporal | 667 | //This fields will be removed. They're temporal |
596 | float _sizeX = 0.5f; | 668 | float _sizeX = 0.5f; |
@@ -622,23 +694,23 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
622 | //For now, like ODE, collisionShape = sphere of radious = 1.0 | 694 | //For now, like ODE, collisionShape = sphere of radious = 1.0 |
623 | CollisionShape _collisionShape = new SphereShape(1.0f); | 695 | CollisionShape _collisionShape = new SphereShape(1.0f); |
624 | DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); | 696 | DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); |
625 | MonoXnaCompactMaths.Vector3 _localInertia = new MonoXnaCompactMaths.Vector3(); | 697 | Vector3 _localInertia = new Vector3(); |
626 | _collisionShape.CalculateLocalInertia(_mass, out _localInertia); //Always when mass > 0 | 698 | _collisionShape.CalculateLocalInertia(_mass, out _localInertia); //Always when mass > 0 |
627 | rigidBody = new RigidBody(_mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, _friction, _restitution); | 699 | rigidBody = |
700 | new RigidBody(_mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, | ||
701 | _friction, _restitution); | ||
628 | //rigidBody.ActivationState = ActivationState.DisableDeactivation; | 702 | //rigidBody.ActivationState = ActivationState.DisableDeactivation; |
629 | //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition | 703 | //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition |
630 | MonoXnaCompactMaths.Vector3 _vDebugTranslation; | 704 | Vector3 _vDebugTranslation; |
631 | _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition; | 705 | _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition; |
632 | rigidBody.Translate(_vDebugTranslation); | 706 | rigidBody.Translate(_vDebugTranslation); |
633 | parent_scene.ddWorld.AddRigidBody(rigidBody); | 707 | parent_scene.ddWorld.AddRigidBody(rigidBody); |
634 | } | 708 | } |
635 | } | 709 | } |
710 | |||
636 | public override PhysicsVector Position | 711 | public override PhysicsVector Position |
637 | { | 712 | { |
638 | get | 713 | get { return _position; } |
639 | { | ||
640 | return _position; | ||
641 | } | ||
642 | set | 714 | set |
643 | { | 715 | { |
644 | lock (BulletXScene.BulletXLock) | 716 | lock (BulletXScene.BulletXLock) |
@@ -648,12 +720,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
648 | } | 720 | } |
649 | } | 721 | } |
650 | } | 722 | } |
723 | |||
651 | public override PhysicsVector Velocity | 724 | public override PhysicsVector Velocity |
652 | { | 725 | { |
653 | get | 726 | get { return _velocity; } |
654 | { | ||
655 | return _velocity; | ||
656 | } | ||
657 | set | 727 | set |
658 | { | 728 | { |
659 | lock (BulletXScene.BulletXLock) | 729 | lock (BulletXScene.BulletXLock) |
@@ -663,12 +733,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
663 | } | 733 | } |
664 | } | 734 | } |
665 | } | 735 | } |
736 | |||
666 | public override PhysicsVector Size | 737 | public override PhysicsVector Size |
667 | { | 738 | { |
668 | get | 739 | get { return _size; } |
669 | { | ||
670 | return _size; | ||
671 | } | ||
672 | set | 740 | set |
673 | { | 741 | { |
674 | lock (BulletXScene.BulletXLock) | 742 | lock (BulletXScene.BulletXLock) |
@@ -677,19 +745,15 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
677 | } | 745 | } |
678 | } | 746 | } |
679 | } | 747 | } |
748 | |||
680 | public override PhysicsVector Acceleration | 749 | public override PhysicsVector Acceleration |
681 | { | 750 | { |
682 | get | 751 | get { return _acceleration; } |
683 | { | ||
684 | return _acceleration; | ||
685 | } | ||
686 | } | 752 | } |
753 | |||
687 | public override AxiomQuaternion Orientation | 754 | public override AxiomQuaternion Orientation |
688 | { | 755 | { |
689 | get | 756 | get { return _orientation; } |
690 | { | ||
691 | return _orientation; | ||
692 | } | ||
693 | set | 757 | set |
694 | { | 758 | { |
695 | lock (BulletXScene.BulletXLock) | 759 | lock (BulletXScene.BulletXLock) |
@@ -698,24 +762,18 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
698 | } | 762 | } |
699 | } | 763 | } |
700 | } | 764 | } |
765 | |||
701 | public RigidBody RigidBody | 766 | public RigidBody RigidBody |
702 | { | 767 | { |
703 | get | 768 | get { return rigidBody; } |
704 | { | ||
705 | return rigidBody; | ||
706 | } | ||
707 | } | 769 | } |
770 | |||
708 | public override bool Flying | 771 | public override bool Flying |
709 | { | 772 | { |
710 | get | 773 | get { return flying; } |
711 | { | 774 | set { flying = value; } |
712 | return flying; | ||
713 | } | ||
714 | set | ||
715 | { | ||
716 | flying = value; | ||
717 | } | ||
718 | } | 775 | } |
776 | |||
719 | public void SetAcceleration(PhysicsVector accel) | 777 | public void SetAcceleration(PhysicsVector accel) |
720 | { | 778 | { |
721 | lock (BulletXScene.BulletXLock) | 779 | lock (BulletXScene.BulletXLock) |
@@ -723,116 +781,121 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
723 | _acceleration = accel; | 781 | _acceleration = accel; |
724 | } | 782 | } |
725 | } | 783 | } |
784 | |||
726 | public override bool Kinematic | 785 | public override bool Kinematic |
727 | { | 786 | { |
728 | get | 787 | get { return false; } |
729 | { | 788 | set { } |
730 | return false; | ||
731 | } | ||
732 | set | ||
733 | { | ||
734 | |||
735 | } | ||
736 | } | 789 | } |
790 | |||
737 | public override void AddForce(PhysicsVector force) | 791 | public override void AddForce(PhysicsVector force) |
738 | { | 792 | { |
739 | |||
740 | } | 793 | } |
794 | |||
741 | public override void SetMomentum(PhysicsVector momentum) | 795 | public override void SetMomentum(PhysicsVector momentum) |
742 | { | 796 | { |
743 | |||
744 | } | 797 | } |
798 | |||
745 | internal void Move(float timeStep) | 799 | internal void Move(float timeStep) |
746 | { | 800 | { |
747 | MonoXnaCompactMaths.Vector3 vec = new MonoXnaCompactMaths.Vector3(); | 801 | Vector3 vec = new Vector3(); |
748 | //At this point it's supossed that: | 802 | //At this point it's supossed that: |
749 | //_velocity == rigidBody.LinearVelocity | 803 | //_velocity == rigidBody.LinearVelocity |
750 | vec.X = this._velocity.X; | 804 | vec.X = _velocity.X; |
751 | vec.Y = this._velocity.Y; | 805 | vec.Y = _velocity.Y; |
752 | vec.Z = this._velocity.Z; | 806 | vec.Z = _velocity.Z; |
753 | if ((vec.X != 0.0f) || (vec.Y != 0.0f) || (vec.Z != 0.0f)) rigidBody.Activate(); | 807 | if ((vec.X != 0.0f) || (vec.Y != 0.0f) || (vec.Z != 0.0f)) rigidBody.Activate(); |
754 | if (flying) | 808 | if (flying) |
755 | { | 809 | { |
756 | //Antigravity with movement | 810 | //Antigravity with movement |
757 | if (this._position.Z <= BulletXScene.HeightLevel0) | 811 | if (_position.Z <= BulletXScene.HeightLevel0) |
758 | { | 812 | { |
759 | vec.Z += BulletXScene.Gravity * timeStep; | 813 | vec.Z += BulletXScene.Gravity*timeStep; |
760 | } | 814 | } |
761 | //Lowgravity with movement | 815 | //Lowgravity with movement |
762 | else if ((this._position.Z > BulletXScene.HeightLevel0) | 816 | else if ((_position.Z > BulletXScene.HeightLevel0) |
763 | && (this._position.Z <= BulletXScene.HeightLevel1)) | 817 | && (_position.Z <= BulletXScene.HeightLevel1)) |
764 | { | 818 | { |
765 | vec.Z += BulletXScene.Gravity * timeStep * (1.0f - BulletXScene.LowGravityFactor); | 819 | vec.Z += BulletXScene.Gravity*timeStep*(1.0f - BulletXScene.LowGravityFactor); |
766 | } | 820 | } |
767 | //Lowgravity with... | 821 | //Lowgravity with... |
768 | else if (this._position.Z > BulletXScene.HeightLevel1) | 822 | else if (_position.Z > BulletXScene.HeightLevel1) |
769 | { | 823 | { |
770 | if (vec.Z > 0) //no movement | 824 | if (vec.Z > 0) //no movement |
771 | vec.Z = BulletXScene.Gravity * timeStep * (1.0f - BulletXScene.LowGravityFactor); | 825 | vec.Z = BulletXScene.Gravity*timeStep*(1.0f - BulletXScene.LowGravityFactor); |
772 | else | 826 | else |
773 | vec.Z += BulletXScene.Gravity * timeStep * (1.0f - BulletXScene.LowGravityFactor); | 827 | vec.Z += BulletXScene.Gravity*timeStep*(1.0f - BulletXScene.LowGravityFactor); |
774 | |||
775 | } | 828 | } |
776 | } | 829 | } |
777 | rigidBody.LinearVelocity = vec; | 830 | rigidBody.LinearVelocity = vec; |
778 | } | 831 | } |
832 | |||
779 | //This validation is very basic | 833 | //This validation is very basic |
780 | internal void ValidateHeight(float heighmapPositionValue) | 834 | internal void ValidateHeight(float heighmapPositionValue) |
781 | { | 835 | { |
782 | if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z / 2.0f) | 836 | if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z/2.0f) |
783 | { | 837 | { |
784 | Matrix m = rigidBody.WorldTransform; | 838 | Matrix m = rigidBody.WorldTransform; |
785 | MonoXnaCompactMaths.Vector3 v3 = m.Translation; | 839 | Vector3 v3 = m.Translation; |
786 | v3.Z = heighmapPositionValue + _size.Z / 2.0f; | 840 | v3.Z = heighmapPositionValue + _size.Z/2.0f; |
787 | m.Translation = v3; | 841 | m.Translation = v3; |
788 | rigidBody.WorldTransform = m; | 842 | rigidBody.WorldTransform = m; |
789 | //When an Avie touch the ground it's vertical velocity it's reduced to ZERO | 843 | //When an Avie touch the ground it's vertical velocity it's reduced to ZERO |
790 | Speed(new PhysicsVector(this.rigidBody.LinearVelocity.X, this.rigidBody.LinearVelocity.Y, 0.0f)); | 844 | Speed(new PhysicsVector(rigidBody.LinearVelocity.X, rigidBody.LinearVelocity.Y, 0.0f)); |
791 | } | 845 | } |
792 | } | 846 | } |
847 | |||
793 | internal void UpdateKinetics() | 848 | internal void UpdateKinetics() |
794 | { | 849 | { |
795 | this._position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); | 850 | _position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); |
796 | this._velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity); | 851 | _velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity); |
797 | //Orientation it seems that it will be the default. | 852 | //Orientation it seems that it will be the default. |
798 | ReOrient(); | 853 | ReOrient(); |
799 | } | 854 | } |
800 | 855 | ||
801 | #region Methods for updating values of RigidBody | 856 | #region Methods for updating values of RigidBody |
857 | |||
802 | private void Translate() | 858 | private void Translate() |
803 | { | 859 | { |
804 | Translate(this._position); | 860 | Translate(_position); |
805 | } | 861 | } |
862 | |||
806 | private void Translate(PhysicsVector _newPos) | 863 | private void Translate(PhysicsVector _newPos) |
807 | { | 864 | { |
808 | MonoXnaCompactMaths.Vector3 _translation; | 865 | Vector3 _translation; |
809 | _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition; | 866 | _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition; |
810 | rigidBody.Translate(_translation); | 867 | rigidBody.Translate(_translation); |
811 | } | 868 | } |
869 | |||
812 | private void Speed() | 870 | private void Speed() |
813 | { | 871 | { |
814 | Speed(this._velocity); | 872 | Speed(_velocity); |
815 | } | 873 | } |
874 | |||
816 | private void Speed(PhysicsVector _newSpeed) | 875 | private void Speed(PhysicsVector _newSpeed) |
817 | { | 876 | { |
818 | MonoXnaCompactMaths.Vector3 _speed; | 877 | Vector3 _speed; |
819 | _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed); | 878 | _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed); |
820 | rigidBody.LinearVelocity = _speed; | 879 | rigidBody.LinearVelocity = _speed; |
821 | } | 880 | } |
881 | |||
822 | private void ReOrient() | 882 | private void ReOrient() |
823 | { | 883 | { |
824 | ReOrient(this._orientation); | 884 | ReOrient(_orientation); |
825 | } | 885 | } |
886 | |||
826 | private void ReOrient(AxiomQuaternion _newOrient) | 887 | private void ReOrient(AxiomQuaternion _newOrient) |
827 | { | 888 | { |
828 | MonoXnaCompactMaths.Quaternion _newOrientation; | 889 | Quaternion _newOrientation; |
829 | _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient); | 890 | _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient); |
830 | Matrix _comTransform = rigidBody.CenterOfMassTransform; | 891 | Matrix _comTransform = rigidBody.CenterOfMassTransform; |
831 | BulletXMaths.SetRotation(ref _comTransform, _newOrientation); | 892 | BulletXMaths.SetRotation(ref _comTransform, _newOrientation); |
832 | rigidBody.CenterOfMassTransform = _comTransform; | 893 | rigidBody.CenterOfMassTransform = _comTransform; |
833 | } | 894 | } |
895 | |||
834 | #endregion | 896 | #endregion |
835 | } | 897 | } |
898 | |||
836 | /// <summary> | 899 | /// <summary> |
837 | /// PhysicsActor Prim Class for BulletX | 900 | /// PhysicsActor Prim Class for BulletX |
838 | /// </summary> | 901 | /// </summary> |
@@ -851,27 +914,32 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
851 | //_physical value will be linked with the prim object value | 914 | //_physical value will be linked with the prim object value |
852 | private Boolean _physical = false; | 915 | private Boolean _physical = false; |
853 | 916 | ||
854 | public MonoXnaCompactMaths.Vector3 RigidBodyPosition | 917 | public Vector3 RigidBodyPosition |
855 | { | 918 | { |
856 | get { return this.rigidBody.CenterOfMassPosition; } | 919 | get { return rigidBody.CenterOfMassPosition; } |
857 | } | 920 | } |
921 | |||
858 | public BulletXPrim(BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, AxiomQuaternion rotation) | 922 | public BulletXPrim(BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, AxiomQuaternion rotation) |
859 | : this("", parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, null, null) | 923 | : this("", parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, null, null) |
860 | { | 924 | { |
861 | } | 925 | } |
862 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, | 926 | |
863 | AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) | 927 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, |
928 | AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) | ||
864 | : this(primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs) | 929 | : this(primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs) |
865 | { | 930 | { |
866 | } | 931 | } |
867 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, PhysicsVector size, | 932 | |
868 | PhysicsVector aceleration, AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) | 933 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, |
934 | PhysicsVector size, | ||
935 | PhysicsVector aceleration, AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) | ||
869 | { | 936 | { |
870 | if ((size.X == 0) || (size.Y == 0) || (size.Z == 0)) throw new Exception("Size 0"); | 937 | if ((size.X == 0) || (size.Y == 0) || (size.Z == 0)) throw new Exception("Size 0"); |
871 | if (rotation.Norm == 0f) rotation = AxiomQuaternion.Identity; | 938 | if (rotation.Norm == 0f) rotation = AxiomQuaternion.Identity; |
872 | 939 | ||
873 | _position = pos; | 940 | _position = pos; |
874 | if (_physical) _velocity = velocity; else _velocity = new PhysicsVector(); | 941 | if (_physical) _velocity = velocity; |
942 | else _velocity = new PhysicsVector(); | ||
875 | _size = size; | 943 | _size = size; |
876 | _acceleration = aceleration; | 944 | _acceleration = aceleration; |
877 | _orientation = rotation; | 945 | _orientation = rotation; |
@@ -889,26 +957,26 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
889 | { | 957 | { |
890 | _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(pos); | 958 | _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(pos); |
891 | //For now all prims are boxes | 959 | //For now all prims are boxes |
892 | CollisionShape _collisionShape = new XnaDevRu.BulletX.BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_size) / 2.0f); | 960 | CollisionShape _collisionShape = new BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_size)/2.0f); |
893 | DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); | 961 | DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); |
894 | MonoXnaCompactMaths.Vector3 _localInertia = new MonoXnaCompactMaths.Vector3(); | 962 | Vector3 _localInertia = new Vector3(); |
895 | if(_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0 | 963 | if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0 |
896 | rigidBody = new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, _friction, _restitution); | 964 | rigidBody = |
965 | new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, | ||
966 | _friction, _restitution); | ||
897 | //rigidBody.ActivationState = ActivationState.DisableDeactivation; | 967 | //rigidBody.ActivationState = ActivationState.DisableDeactivation; |
898 | //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition | 968 | //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition |
899 | MonoXnaCompactMaths.Vector3 _vDebugTranslation; | 969 | Vector3 _vDebugTranslation; |
900 | _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition; | 970 | _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition; |
901 | rigidBody.Translate(_vDebugTranslation); | 971 | rigidBody.Translate(_vDebugTranslation); |
902 | //--- | 972 | //--- |
903 | parent_scene.ddWorld.AddRigidBody(rigidBody); | 973 | parent_scene.ddWorld.AddRigidBody(rigidBody); |
904 | } | 974 | } |
905 | } | 975 | } |
976 | |||
906 | public override PhysicsVector Position | 977 | public override PhysicsVector Position |
907 | { | 978 | { |
908 | get | 979 | get { return _position; } |
909 | { | ||
910 | return _position; | ||
911 | } | ||
912 | set | 980 | set |
913 | { | 981 | { |
914 | lock (BulletXScene.BulletXLock) | 982 | lock (BulletXScene.BulletXLock) |
@@ -918,12 +986,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
918 | } | 986 | } |
919 | } | 987 | } |
920 | } | 988 | } |
989 | |||
921 | public override PhysicsVector Velocity | 990 | public override PhysicsVector Velocity |
922 | { | 991 | { |
923 | get | 992 | get { return _velocity; } |
924 | { | ||
925 | return _velocity; | ||
926 | } | ||
927 | set | 993 | set |
928 | { | 994 | { |
929 | lock (BulletXScene.BulletXLock) | 995 | lock (BulletXScene.BulletXLock) |
@@ -941,12 +1007,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
941 | } | 1007 | } |
942 | } | 1008 | } |
943 | } | 1009 | } |
1010 | |||
944 | public override PhysicsVector Size | 1011 | public override PhysicsVector Size |
945 | { | 1012 | { |
946 | get | 1013 | get { return _size; } |
947 | { | ||
948 | return _size; | ||
949 | } | ||
950 | set | 1014 | set |
951 | { | 1015 | { |
952 | lock (BulletXScene.BulletXLock) | 1016 | lock (BulletXScene.BulletXLock) |
@@ -956,19 +1020,15 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
956 | } | 1020 | } |
957 | } | 1021 | } |
958 | } | 1022 | } |
1023 | |||
959 | public override PhysicsVector Acceleration | 1024 | public override PhysicsVector Acceleration |
960 | { | 1025 | { |
961 | get | 1026 | get { return _acceleration; } |
962 | { | ||
963 | return _acceleration; | ||
964 | } | ||
965 | } | 1027 | } |
1028 | |||
966 | public override AxiomQuaternion Orientation | 1029 | public override AxiomQuaternion Orientation |
967 | { | 1030 | { |
968 | get | 1031 | get { return _orientation; } |
969 | { | ||
970 | return _orientation; | ||
971 | } | ||
972 | set | 1032 | set |
973 | { | 1033 | { |
974 | lock (BulletXScene.BulletXLock) | 1034 | lock (BulletXScene.BulletXLock) |
@@ -978,43 +1038,34 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
978 | } | 1038 | } |
979 | } | 1039 | } |
980 | } | 1040 | } |
1041 | |||
981 | public float Mass | 1042 | public float Mass |
982 | { | 1043 | { |
983 | get | 1044 | get |
984 | { | 1045 | { |
985 | //For now all prims are boxes | 1046 | //For now all prims are boxes |
986 | return (_physical ? 1 : 0) * _density * _size.X * _size.Y * _size.Z; | 1047 | return (_physical ? 1 : 0)*_density*_size.X*_size.Y*_size.Z; |
987 | } | 1048 | } |
988 | } | 1049 | } |
1050 | |||
989 | public RigidBody RigidBody | 1051 | public RigidBody RigidBody |
990 | { | 1052 | { |
991 | get | 1053 | get { return rigidBody; } |
992 | { | ||
993 | return rigidBody; | ||
994 | } | ||
995 | } | 1054 | } |
1055 | |||
996 | public override bool Flying | 1056 | public override bool Flying |
997 | { | 1057 | { |
998 | get | 1058 | get { return false; //no flying prims for you |
999 | { | ||
1000 | return false; //no flying prims for you | ||
1001 | } | ||
1002 | set | ||
1003 | { | ||
1004 | |||
1005 | } | 1059 | } |
1060 | set { } | ||
1006 | } | 1061 | } |
1062 | |||
1007 | public Boolean Physical | 1063 | public Boolean Physical |
1008 | { | 1064 | { |
1009 | get | 1065 | get { return _physical; } |
1010 | { | 1066 | set { _physical = value; } |
1011 | return _physical; | ||
1012 | } | ||
1013 | set | ||
1014 | { | ||
1015 | _physical = value; | ||
1016 | } | ||
1017 | } | 1067 | } |
1068 | |||
1018 | public void SetAcceleration(PhysicsVector accel) | 1069 | public void SetAcceleration(PhysicsVector accel) |
1019 | { | 1070 | { |
1020 | lock (BulletXScene.BulletXLock) | 1071 | lock (BulletXScene.BulletXLock) |
@@ -1022,6 +1073,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1022 | _acceleration = accel; | 1073 | _acceleration = accel; |
1023 | } | 1074 | } |
1024 | } | 1075 | } |
1076 | |||
1025 | public override bool Kinematic | 1077 | public override bool Kinematic |
1026 | { | 1078 | { |
1027 | get | 1079 | get |
@@ -1034,36 +1086,38 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1034 | //this._prim.Kinematic = value; | 1086 | //this._prim.Kinematic = value; |
1035 | } | 1087 | } |
1036 | } | 1088 | } |
1089 | |||
1037 | public override void AddForce(PhysicsVector force) | 1090 | public override void AddForce(PhysicsVector force) |
1038 | { | 1091 | { |
1039 | |||
1040 | } | 1092 | } |
1093 | |||
1041 | public override void SetMomentum(PhysicsVector momentum) | 1094 | public override void SetMomentum(PhysicsVector momentum) |
1042 | { | 1095 | { |
1043 | |||
1044 | } | 1096 | } |
1097 | |||
1045 | internal void ValidateHeight(float heighmapPositionValue) | 1098 | internal void ValidateHeight(float heighmapPositionValue) |
1046 | { | 1099 | { |
1047 | if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z / 2.0f) | 1100 | if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z/2.0f) |
1048 | { | 1101 | { |
1049 | Matrix m = rigidBody.WorldTransform; | 1102 | Matrix m = rigidBody.WorldTransform; |
1050 | MonoXnaCompactMaths.Vector3 v3 = m.Translation; | 1103 | Vector3 v3 = m.Translation; |
1051 | v3.Z = heighmapPositionValue + _size.Z / 2.0f; | 1104 | v3.Z = heighmapPositionValue + _size.Z/2.0f; |
1052 | m.Translation = v3; | 1105 | m.Translation = v3; |
1053 | rigidBody.WorldTransform = m; | 1106 | rigidBody.WorldTransform = m; |
1054 | //When a Prim touch the ground it's vertical velocity it's reduced to ZERO | 1107 | //When a Prim touch the ground it's vertical velocity it's reduced to ZERO |
1055 | //Static objects don't have linear velocity | 1108 | //Static objects don't have linear velocity |
1056 | if(_physical) | 1109 | if (_physical) |
1057 | Speed(new PhysicsVector(this.rigidBody.LinearVelocity.X, this.rigidBody.LinearVelocity.Y, 0.0f)); | 1110 | Speed(new PhysicsVector(rigidBody.LinearVelocity.X, rigidBody.LinearVelocity.Y, 0.0f)); |
1058 | } | 1111 | } |
1059 | } | 1112 | } |
1113 | |||
1060 | internal void UpdateKinetics() | 1114 | internal void UpdateKinetics() |
1061 | { | 1115 | { |
1062 | if (_physical) //Updates properties. Prim updates its properties physically | 1116 | if (_physical) //Updates properties. Prim updates its properties physically |
1063 | { | 1117 | { |
1064 | this._position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); | 1118 | _position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); |
1065 | this._velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity); | 1119 | _velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity); |
1066 | this._orientation = BulletXMaths.XnaQuaternionToAxiomQuaternion(rigidBody.Orientation); | 1120 | _orientation = BulletXMaths.XnaQuaternionToAxiomQuaternion(rigidBody.Orientation); |
1067 | } | 1121 | } |
1068 | else //Doesn't updates properties. That's a cancel | 1122 | else //Doesn't updates properties. That's a cancel |
1069 | { | 1123 | { |
@@ -1074,35 +1128,41 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1074 | } | 1128 | } |
1075 | 1129 | ||
1076 | #region Methods for updating values of RigidBody | 1130 | #region Methods for updating values of RigidBody |
1131 | |||
1077 | private void Translate() | 1132 | private void Translate() |
1078 | { | 1133 | { |
1079 | Translate(this._position); | 1134 | Translate(_position); |
1080 | } | 1135 | } |
1136 | |||
1081 | private void Translate(PhysicsVector _newPos) | 1137 | private void Translate(PhysicsVector _newPos) |
1082 | { | 1138 | { |
1083 | MonoXnaCompactMaths.Vector3 _translation; | 1139 | Vector3 _translation; |
1084 | _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition; | 1140 | _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition; |
1085 | rigidBody.Translate(_translation); | 1141 | rigidBody.Translate(_translation); |
1086 | } | 1142 | } |
1143 | |||
1087 | private void Speed() | 1144 | private void Speed() |
1088 | { | 1145 | { |
1089 | Speed(this._velocity); | 1146 | Speed(_velocity); |
1090 | } | 1147 | } |
1148 | |||
1091 | private void Speed(PhysicsVector _newSpeed) | 1149 | private void Speed(PhysicsVector _newSpeed) |
1092 | { | 1150 | { |
1093 | MonoXnaCompactMaths.Vector3 _speed; | 1151 | Vector3 _speed; |
1094 | _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed); | 1152 | _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed); |
1095 | rigidBody.LinearVelocity = _speed; | 1153 | rigidBody.LinearVelocity = _speed; |
1096 | } | 1154 | } |
1155 | |||
1097 | private void ReSize() | 1156 | private void ReSize() |
1098 | { | 1157 | { |
1099 | ReSize(this._size); | 1158 | ReSize(_size); |
1100 | } | 1159 | } |
1160 | |||
1101 | private void ReSize(PhysicsVector _newSize) | 1161 | private void ReSize(PhysicsVector _newSize) |
1102 | { | 1162 | { |
1103 | //I wonder to know how to resize with a simple instruction in BulletX. It seems that for now there isn't | 1163 | //I wonder to know how to resize with a simple instruction in BulletX. It seems that for now there isn't |
1104 | //so i have to do it manually. That's recreating rigidbody | 1164 | //so i have to do it manually. That's recreating rigidbody |
1105 | MonoXnaCompactMaths.Vector3 _newsize; | 1165 | Vector3 _newsize; |
1106 | _newsize = BulletXMaths.PhysicsVectorToXnaVector3(_newSize); | 1166 | _newsize = BulletXMaths.PhysicsVectorToXnaVector3(_newSize); |
1107 | if ((_newsize.X == 0) || (_newsize.Y == 0) || (_newsize.Z == 0)) throw new Exception("Size 0"); | 1167 | if ((_newsize.X == 0) || (_newsize.Y == 0) || (_newsize.Z == 0)) throw new Exception("Size 0"); |
1108 | 1168 | ||
@@ -1114,67 +1174,77 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1114 | Matrix _startTransform = Matrix.Identity; | 1174 | Matrix _startTransform = Matrix.Identity; |
1115 | Matrix _centerOfMassOffset = Matrix.Identity; | 1175 | Matrix _centerOfMassOffset = Matrix.Identity; |
1116 | RigidBody _tmpRigidBody; | 1176 | RigidBody _tmpRigidBody; |
1117 | _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(this._position); | 1177 | _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(_position); |
1118 | //For now all prims are boxes | 1178 | //For now all prims are boxes |
1119 | CollisionShape _collisionShape = new XnaDevRu.BulletX.BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_newSize) / 2.0f); | 1179 | CollisionShape _collisionShape = new BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_newSize)/2.0f); |
1120 | DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); | 1180 | DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); |
1121 | MonoXnaCompactMaths.Vector3 _localInertia = new MonoXnaCompactMaths.Vector3(); | 1181 | Vector3 _localInertia = new Vector3(); |
1122 | if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0 | 1182 | if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0 |
1123 | _tmpRigidBody = new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, _friction, _restitution); | 1183 | _tmpRigidBody = |
1184 | new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, | ||
1185 | _friction, _restitution); | ||
1124 | //rigidBody.ActivationState = ActivationState.DisableDeactivation; | 1186 | //rigidBody.ActivationState = ActivationState.DisableDeactivation; |
1125 | //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition | 1187 | //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition |
1126 | MonoXnaCompactMaths.Vector3 _vDebugTranslation; | 1188 | Vector3 _vDebugTranslation; |
1127 | _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition; | 1189 | _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition; |
1128 | _tmpRigidBody.Translate(_vDebugTranslation); | 1190 | _tmpRigidBody.Translate(_vDebugTranslation); |
1129 | //--- | 1191 | //--- |
1130 | //There is a bug when trying to remove a rigidBody that is colliding with something.. | 1192 | //There is a bug when trying to remove a rigidBody that is colliding with something.. |
1131 | try | 1193 | try |
1132 | { | 1194 | { |
1133 | this._parent_scene.ddWorld.RemoveRigidBody(rigidBody); | 1195 | _parent_scene.ddWorld.RemoveRigidBody(rigidBody); |
1134 | } | 1196 | } |
1135 | catch(Exception ex) | 1197 | catch (Exception ex) |
1136 | { | 1198 | { |
1137 | this._parent_scene.BulletXMessage(this._parent_scene.is_ex_message + ex.Message, true); | 1199 | _parent_scene.BulletXMessage(_parent_scene.is_ex_message + ex.Message, true); |
1138 | rigidBody.ActivationState = ActivationState.DisableSimulation; | 1200 | rigidBody.ActivationState = ActivationState.DisableSimulation; |
1139 | this._parent_scene.AddForgottenRigidBody(rigidBody); | 1201 | _parent_scene.AddForgottenRigidBody(rigidBody); |
1140 | } | 1202 | } |
1141 | rigidBody = _tmpRigidBody; | 1203 | rigidBody = _tmpRigidBody; |
1142 | this._parent_scene.ddWorld.AddRigidBody(rigidBody); | 1204 | _parent_scene.ddWorld.AddRigidBody(rigidBody); |
1143 | if (_physical) Speed();//Static objects don't have linear velocity | 1205 | if (_physical) Speed(); //Static objects don't have linear velocity |
1144 | ReOrient(); | 1206 | ReOrient(); |
1145 | GC.Collect(); | 1207 | GC.Collect(); |
1146 | } | 1208 | } |
1209 | |||
1147 | private void ReOrient() | 1210 | private void ReOrient() |
1148 | { | 1211 | { |
1149 | ReOrient(this._orientation); | 1212 | ReOrient(_orientation); |
1150 | } | 1213 | } |
1214 | |||
1151 | private void ReOrient(AxiomQuaternion _newOrient) | 1215 | private void ReOrient(AxiomQuaternion _newOrient) |
1152 | { | 1216 | { |
1153 | MonoXnaCompactMaths.Quaternion _newOrientation; | 1217 | Quaternion _newOrientation; |
1154 | _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient); | 1218 | _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient); |
1155 | Matrix _comTransform = rigidBody.CenterOfMassTransform; | 1219 | Matrix _comTransform = rigidBody.CenterOfMassTransform; |
1156 | BulletXMaths.SetRotation(ref _comTransform, _newOrientation); | 1220 | BulletXMaths.SetRotation(ref _comTransform, _newOrientation); |
1157 | rigidBody.CenterOfMassTransform = _comTransform; | 1221 | rigidBody.CenterOfMassTransform = _comTransform; |
1158 | } | 1222 | } |
1159 | #endregion | ||
1160 | 1223 | ||
1224 | #endregion | ||
1161 | } | 1225 | } |
1226 | |||
1162 | /// <summary> | 1227 | /// <summary> |
1163 | /// This Class manage a HeighField as a RigidBody. This is for to be added in the BulletXScene | 1228 | /// This Class manage a HeighField as a RigidBody. This is for to be added in the BulletXScene |
1164 | /// </summary> | 1229 | /// </summary> |
1165 | internal class BulletXPlanet | 1230 | internal class BulletXPlanet |
1166 | { | 1231 | { |
1167 | private PhysicsVector _staticPosition; | 1232 | private PhysicsVector _staticPosition; |
1168 | private PhysicsVector _staticVelocity; | 1233 | private PhysicsVector _staticVelocity; |
1169 | private AxiomQuaternion _staticOrientation; | 1234 | private AxiomQuaternion _staticOrientation; |
1170 | private float _mass; | 1235 | private float _mass; |
1171 | private BulletXScene _parentscene; | 1236 | private BulletXScene _parentscene; |
1172 | internal float[] _heightField; | 1237 | internal float[] _heightField; |
1173 | private RigidBody _flatPlanet; | 1238 | private RigidBody _flatPlanet; |
1174 | internal RigidBody RigidBody { get { return _flatPlanet; } } | 1239 | |
1240 | internal RigidBody RigidBody | ||
1241 | { | ||
1242 | get { return _flatPlanet; } | ||
1243 | } | ||
1244 | |||
1175 | internal BulletXPlanet(BulletXScene parent_scene, float[] heightField) | 1245 | internal BulletXPlanet(BulletXScene parent_scene, float[] heightField) |
1176 | { | 1246 | { |
1177 | _staticPosition = new PhysicsVector(BulletXScene.MaxXY / 2, BulletXScene.MaxXY/2, 0); | 1247 | _staticPosition = new PhysicsVector(BulletXScene.MaxXY/2, BulletXScene.MaxXY/2, 0); |
1178 | _staticVelocity = new PhysicsVector(); | 1248 | _staticVelocity = new PhysicsVector(); |
1179 | _staticOrientation = AxiomQuaternion.Identity; | 1249 | _staticOrientation = AxiomQuaternion.Identity; |
1180 | _mass = 0; //No active | 1250 | _mass = 0; //No active |
@@ -1193,40 +1263,45 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1193 | try | 1263 | try |
1194 | { | 1264 | { |
1195 | _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(_staticPosition); | 1265 | _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(_staticPosition); |
1196 | CollisionShape _collisionShape = new HeightfieldTerrainShape(BulletXScene.MaxXY, BulletXScene.MaxXY, _heightField, (float)BulletXScene.MaxZ, 2, true, false); | 1266 | CollisionShape _collisionShape = |
1267 | new HeightfieldTerrainShape(BulletXScene.MaxXY, BulletXScene.MaxXY, _heightField, | ||
1268 | (float) BulletXScene.MaxZ, 2, true, false); | ||
1197 | DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); | 1269 | DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); |
1198 | MonoXnaCompactMaths.Vector3 _localInertia = new MonoXnaCompactMaths.Vector3(); | 1270 | Vector3 _localInertia = new Vector3(); |
1199 | //_collisionShape.CalculateLocalInertia(_mass, out _localInertia); //Always when mass > 0 | 1271 | //_collisionShape.CalculateLocalInertia(_mass, out _localInertia); //Always when mass > 0 |
1200 | _flatPlanet = new RigidBody(_mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, _friction, _restitution); | 1272 | _flatPlanet = |
1273 | new RigidBody(_mass, _motionState, _collisionShape, _localInertia, _linearDamping, | ||
1274 | _angularDamping, _friction, _restitution); | ||
1201 | //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition | 1275 | //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition |
1202 | MonoXnaCompactMaths.Vector3 _vDebugTranslation; | 1276 | Vector3 _vDebugTranslation; |
1203 | _vDebugTranslation = _startTransform.Translation - _flatPlanet.CenterOfMassPosition; | 1277 | _vDebugTranslation = _startTransform.Translation - _flatPlanet.CenterOfMassPosition; |
1204 | _flatPlanet.Translate(_vDebugTranslation); | 1278 | _flatPlanet.Translate(_vDebugTranslation); |
1205 | parent_scene.ddWorld.AddRigidBody(_flatPlanet); | 1279 | parent_scene.ddWorld.AddRigidBody(_flatPlanet); |
1206 | } | 1280 | } |
1207 | catch (Exception ex) | 1281 | catch (Exception ex) |
1208 | { | 1282 | { |
1209 | this._parentscene.BulletXMessage(ex.Message, true); | 1283 | _parentscene.BulletXMessage(ex.Message, true); |
1210 | } | 1284 | } |
1211 | } | 1285 | } |
1212 | this._parentscene.BulletXMessage("BulletXPlanet created.", false); | 1286 | _parentscene.BulletXMessage("BulletXPlanet created.", false); |
1213 | } | 1287 | } |
1214 | internal float HeightValue(MonoXnaCompactMaths.Vector3 position) | 1288 | |
1289 | internal float HeightValue(Vector3 position) | ||
1215 | { | 1290 | { |
1216 | int li_x, li_y; | 1291 | int li_x, li_y; |
1217 | float height; | 1292 | float height; |
1218 | li_x = (int)Math.Round(position.X); | 1293 | li_x = (int) Math.Round(position.X); |
1219 | if (li_x < 0) li_x = 0; | 1294 | if (li_x < 0) li_x = 0; |
1220 | if (li_x >= BulletXScene.MaxXY) li_x = BulletXScene.MaxXY - 1; | 1295 | if (li_x >= BulletXScene.MaxXY) li_x = BulletXScene.MaxXY - 1; |
1221 | li_y = (int)Math.Round(position.Y); | 1296 | li_y = (int) Math.Round(position.Y); |
1222 | if (li_y < 0) li_y = 0; | 1297 | if (li_y < 0) li_y = 0; |
1223 | if (li_y >= BulletXScene.MaxXY) li_y = BulletXScene.MaxXY - 1; | 1298 | if (li_y >= BulletXScene.MaxXY) li_y = BulletXScene.MaxXY - 1; |
1224 | 1299 | ||
1225 | height = ((HeightfieldTerrainShape)this._flatPlanet.CollisionShape).getHeightFieldValue(li_x, li_y); | 1300 | height = ((HeightfieldTerrainShape) _flatPlanet.CollisionShape).getHeightFieldValue(li_x, li_y); |
1226 | if (height < 0) height = 0; | 1301 | if (height < 0) height = 0; |
1227 | else if (height > BulletXScene.MaxZ) height = BulletXScene.MaxZ; | 1302 | else if (height > BulletXScene.MaxZ) height = BulletXScene.MaxZ; |
1228 | 1303 | ||
1229 | return height; | 1304 | return height; |
1230 | } | 1305 | } |
1231 | } | 1306 | } |
1232 | } | 1307 | } \ No newline at end of file |