aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs654
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs1278
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs2
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs37
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs27
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs86
6 files changed, 1806 insertions, 278 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index 3975776..2c0cb43 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -38,6 +38,91 @@ namespace OpenSim.Region.Physics.BulletSPlugin
38public sealed class BSAPIUnman : BSAPITemplate 38public sealed class BSAPIUnman : BSAPITemplate
39{ 39{
40 40
41private sealed class BulletWorldUnman : BulletWorld
42{
43 public IntPtr ptr;
44 public BulletWorldUnman(uint id, BSScene physScene, IntPtr xx)
45 : base(id, physScene)
46 {
47 ptr = xx;
48 }
49}
50
51private sealed class BulletBodyUnman : BulletBody
52{
53 public IntPtr ptr;
54 public BulletBodyUnman(uint id, IntPtr xx)
55 : base(id)
56 {
57 ptr = xx;
58 }
59 public override bool HasPhysicalBody
60 {
61 get { return ptr != IntPtr.Zero; }
62 }
63 public override void Clear()
64 {
65 ptr = IntPtr.Zero;
66 }
67 public override string AddrString
68 {
69 get { return ptr.ToString("X"); }
70 }
71}
72
73private sealed class BulletShapeUnman : BulletShape
74{
75 public IntPtr ptr;
76 public BulletShapeUnman(IntPtr xx, BSPhysicsShapeType typ)
77 : base()
78 {
79 ptr = xx;
80 type = typ;
81 }
82 public override bool HasPhysicalShape
83 {
84 get { return ptr != IntPtr.Zero; }
85 }
86 public override void Clear()
87 {
88 ptr = IntPtr.Zero;
89 }
90 public override BulletShape Clone()
91 {
92 return new BulletShapeUnman(ptr, type);
93 }
94 public override bool ReferenceSame(BulletShape other)
95 {
96 BulletShapeUnman otheru = other as BulletShapeUnman;
97 return (otheru != null) && (this.ptr == otheru.ptr);
98
99 }
100 public override string AddrString
101 {
102 get { return ptr.ToString("X"); }
103 }
104}
105private sealed class BulletConstraintUnman : BulletConstraint
106{
107 public BulletConstraintUnman(IntPtr xx) : base()
108 {
109 ptr = xx;
110 }
111 public IntPtr ptr;
112
113 public override void Clear()
114 {
115 ptr = IntPtr.Zero;
116 }
117 public override bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } }
118
119 // Used for log messages for a unique display of the memory/object allocated to this instance
120 public override string AddrString
121 {
122 get { return ptr.ToString("X"); }
123 }
124}
125
41// We pin the memory passed between the managed and unmanaged code. 126// We pin the memory passed between the managed and unmanaged code.
42GCHandle m_paramsHandle; 127GCHandle m_paramsHandle;
43private GCHandle m_collisionArrayPinnedHandle; 128private GCHandle m_collisionArrayPinnedHandle;
@@ -89,7 +174,7 @@ public override BulletWorld Initialize(Vector3 maxPosition, ConfigurationParamet
89 BulletEngineVersion = ""; 174 BulletEngineVersion = "";
90 175
91 // Call the unmanaged code with the buffers and other information 176 // Call the unmanaged code with the buffers and other information
92 return new BulletWorld(0, PhysicsScene, BSAPICPP.Initialize2(maxPosition, m_paramsHandle.AddrOfPinnedObject(), 177 return new BulletWorldUnman(0, PhysicsScene, BSAPICPP.Initialize2(maxPosition, m_paramsHandle.AddrOfPinnedObject(),
93 maxCollisions, m_collisionArrayPinnedHandle.AddrOfPinnedObject(), 178 maxCollisions, m_collisionArrayPinnedHandle.AddrOfPinnedObject(),
94 maxUpdates, m_updateArrayPinnedHandle.AddrOfPinnedObject(), 179 maxUpdates, m_updateArrayPinnedHandle.AddrOfPinnedObject(),
95 m_DebugLogCallbackHandle)); 180 m_DebugLogCallbackHandle));
@@ -111,22 +196,26 @@ private void BulletLoggerPhysLog(string msg)
111public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, 196public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
112 out int updatedEntityCount, out int collidersCount) 197 out int updatedEntityCount, out int collidersCount)
113{ 198{
114 return BSAPICPP.PhysicsStep2(world.ptr, timeStep, maxSubSteps, fixedTimeStep, out updatedEntityCount, out collidersCount); 199 BulletWorldUnman worldu = world as BulletWorldUnman;
200 return BSAPICPP.PhysicsStep2(worldu.ptr, timeStep, maxSubSteps, fixedTimeStep, out updatedEntityCount, out collidersCount);
115} 201}
116 202
117public override void Shutdown(BulletWorld sim) 203public override void Shutdown(BulletWorld world)
118{ 204{
119 BSAPICPP.Shutdown2(sim.ptr); 205 BulletWorldUnman worldu = world as BulletWorldUnman;
206 BSAPICPP.Shutdown2(worldu.ptr);
120} 207}
121 208
122public override bool PushUpdate(BulletBody obj) 209public override bool PushUpdate(BulletBody obj)
123{ 210{
124 return BSAPICPP.PushUpdate2(obj.ptr); 211 BulletBodyUnman bodyu = obj as BulletBodyUnman;
212 return BSAPICPP.PushUpdate2(bodyu.ptr);
125} 213}
126 214
127public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value) 215public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value)
128{ 216{
129 return BSAPICPP.UpdateParameter2(world.ptr, localID, parm, value); 217 BulletWorldUnman worldu = world as BulletWorldUnman;
218 return BSAPICPP.UpdateParameter2(worldu.ptr, localID, parm, value);
130} 219}
131 220
132// ===================================================================================== 221// =====================================================================================
@@ -135,138 +224,165 @@ public override BulletShape CreateMeshShape(BulletWorld world,
135 int indicesCount, int[] indices, 224 int indicesCount, int[] indices,
136 int verticesCount, float[] vertices) 225 int verticesCount, float[] vertices)
137{ 226{
138 return new BulletShape( 227 BulletWorldUnman worldu = world as BulletWorldUnman;
139 BSAPICPP.CreateMeshShape2(world.ptr, indicesCount, indices, verticesCount, vertices), 228 return new BulletShapeUnman(
229 BSAPICPP.CreateMeshShape2(worldu.ptr, indicesCount, indices, verticesCount, vertices),
140 BSPhysicsShapeType.SHAPE_MESH); 230 BSPhysicsShapeType.SHAPE_MESH);
141} 231}
142 232
143public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls) 233public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls)
144{ 234{
145 return new BulletShape( 235 BulletWorldUnman worldu = world as BulletWorldUnman;
146 BSAPICPP.CreateHullShape2(world.ptr, hullCount, hulls), 236 return new BulletShapeUnman(
237 BSAPICPP.CreateHullShape2(worldu.ptr, hullCount, hulls),
147 BSPhysicsShapeType.SHAPE_HULL); 238 BSPhysicsShapeType.SHAPE_HULL);
148} 239}
149 240
150public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) 241public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape)
151{ 242{
152 return new BulletShape( 243 BulletWorldUnman worldu = world as BulletWorldUnman;
153 BSAPICPP.BuildHullShapeFromMesh2(world.ptr, meshShape.ptr), 244 BulletShapeUnman shapeu = meshShape as BulletShapeUnman;
245 return new BulletShapeUnman(
246 BSAPICPP.BuildHullShapeFromMesh2(worldu.ptr, shapeu.ptr),
154 BSPhysicsShapeType.SHAPE_HULL); 247 BSPhysicsShapeType.SHAPE_HULL);
155} 248}
156 249
157public override BulletShape BuildNativeShape( BulletWorld world, ShapeData shapeData) 250public override BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData)
158{ 251{
159 return new BulletShape( 252 BulletWorldUnman worldu = world as BulletWorldUnman;
160 BSAPICPP.BuildNativeShape2(world.ptr, shapeData), 253 return new BulletShapeUnman(BSAPICPP.BuildNativeShape2(worldu.ptr, shapeData), shapeData.Type);
161 shapeData.Type);
162} 254}
163 255
164public override bool IsNativeShape(BulletShape shape) 256public override bool IsNativeShape(BulletShape shape)
165{ 257{
166 if (shape.HasPhysicalShape) 258 BulletShapeUnman shapeu = shape as BulletShapeUnman;
167 return BSAPICPP.IsNativeShape2(shape.ptr); 259 if (shapeu != null && shapeu.HasPhysicalShape)
260 return BSAPICPP.IsNativeShape2(shapeu.ptr);
168 return false; 261 return false;
169} 262}
170 263
171public override void SetShapeCollisionMargin(BulletShape shape, float margin) 264public override void SetShapeCollisionMargin(BulletShape shape, float margin)
172{ 265{
173 if (shape.HasPhysicalShape) 266 BulletShapeUnman shapeu = shape as BulletShapeUnman;
174 BSAPICPP.SetShapeCollisionMargin2(shape.ptr, margin); 267 if (shapeu != null && shapeu.HasPhysicalShape)
268 BSAPICPP.SetShapeCollisionMargin2(shapeu.ptr, margin);
175} 269}
176 270
177public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale) 271public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale)
178{ 272{
179 return new BulletShape( 273 BulletWorldUnman worldu = world as BulletWorldUnman;
180 BSAPICPP.BuildCapsuleShape2(world.ptr, radius, height, scale), 274 return new BulletShapeUnman(
275 BSAPICPP.BuildCapsuleShape2(worldu.ptr, radius, height, scale),
181 BSPhysicsShapeType.SHAPE_CAPSULE); 276 BSPhysicsShapeType.SHAPE_CAPSULE);
182} 277}
183 278
184public override BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree) 279public override BulletShape CreateCompoundShape(BulletWorld world, bool enableDynamicAabbTree)
185{ 280{
186 return new BulletShape( 281 BulletWorldUnman worldu = world as BulletWorldUnman;
187 BSAPICPP.CreateCompoundShape2(sim.ptr, enableDynamicAabbTree), 282 return new BulletShapeUnman(
283 BSAPICPP.CreateCompoundShape2(worldu.ptr, enableDynamicAabbTree),
188 BSPhysicsShapeType.SHAPE_COMPOUND); 284 BSPhysicsShapeType.SHAPE_COMPOUND);
189 285
190} 286}
191 287
192public override int GetNumberOfCompoundChildren(BulletShape shape) 288public override int GetNumberOfCompoundChildren(BulletShape shape)
193{ 289{
194 if (shape.HasPhysicalShape) 290 BulletShapeUnman shapeu = shape as BulletShapeUnman;
195 return BSAPICPP.GetNumberOfCompoundChildren2(shape.ptr); 291 if (shapeu != null && shapeu.HasPhysicalShape)
292 return BSAPICPP.GetNumberOfCompoundChildren2(shapeu.ptr);
196 return 0; 293 return 0;
197} 294}
198 295
199public override void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot) 296public override void AddChildShapeToCompoundShape(BulletShape shape, BulletShape addShape, Vector3 pos, Quaternion rot)
200{ 297{
201 BSAPICPP.AddChildShapeToCompoundShape2(cShape.ptr, addShape.ptr, pos, rot); 298 BulletShapeUnman shapeu = shape as BulletShapeUnman;
299 BulletShapeUnman addShapeu = addShape as BulletShapeUnman;
300 BSAPICPP.AddChildShapeToCompoundShape2(shapeu.ptr, addShapeu.ptr, pos, rot);
202} 301}
203 302
204public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) 303public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape shape, int indx)
205{ 304{
206 return new BulletShape(BSAPICPP.GetChildShapeFromCompoundShapeIndex2(cShape.ptr, indx)); 305 BulletShapeUnman shapeu = shape as BulletShapeUnman;
306 return new BulletShapeUnman(BSAPICPP.GetChildShapeFromCompoundShapeIndex2(shapeu.ptr, indx), BSPhysicsShapeType.SHAPE_UNKNOWN);
207} 307}
208 308
209public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) 309public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape shape, int indx)
210{ 310{
211 return new BulletShape(BSAPICPP.RemoveChildShapeFromCompoundShapeIndex2(cShape.ptr, indx)); 311 BulletShapeUnman shapeu = shape as BulletShapeUnman;
312 return new BulletShapeUnman(BSAPICPP.RemoveChildShapeFromCompoundShapeIndex2(shapeu.ptr, indx), BSPhysicsShapeType.SHAPE_UNKNOWN);
212} 313}
213 314
214public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape) 315public override void RemoveChildShapeFromCompoundShape(BulletShape shape, BulletShape removeShape)
215{ 316{
216 BSAPICPP.RemoveChildShapeFromCompoundShape2(cShape.ptr, removeShape.ptr); 317 BulletShapeUnman shapeu = shape as BulletShapeUnman;
318 BulletShapeUnman removeShapeu = removeShape as BulletShapeUnman;
319 BSAPICPP.RemoveChildShapeFromCompoundShape2(shapeu.ptr, removeShapeu.ptr);
217} 320}
218 321
219public override void RecalculateCompoundShapeLocalAabb(BulletShape cShape) 322public override void RecalculateCompoundShapeLocalAabb(BulletShape shape)
220{ 323{
221 BSAPICPP.RecalculateCompoundShapeLocalAabb2(cShape.ptr); 324 BulletShapeUnman shapeu = shape as BulletShapeUnman;
325 BSAPICPP.RecalculateCompoundShapeLocalAabb2(shapeu.ptr);
222} 326}
223 327
224public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id) 328public override BulletShape DuplicateCollisionShape(BulletWorld world, BulletShape srcShape, uint id)
225{ 329{
226 return new BulletShape(BSAPICPP.DuplicateCollisionShape2(sim.ptr, srcShape.ptr, id), srcShape.type); 330 BulletWorldUnman worldu = world as BulletWorldUnman;
331 BulletShapeUnman srcShapeu = srcShape as BulletShapeUnman;
332 return new BulletShapeUnman(BSAPICPP.DuplicateCollisionShape2(worldu.ptr, srcShapeu.ptr, id), srcShape.type);
227} 333}
228 334
229public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape) 335public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape)
230{ 336{
231 return BSAPICPP.DeleteCollisionShape2(world.ptr, shape.ptr); 337 BulletWorldUnman worldu = world as BulletWorldUnman;
338 BulletShapeUnman shapeu = shape as BulletShapeUnman;
339 return BSAPICPP.DeleteCollisionShape2(worldu.ptr, shapeu.ptr);
232} 340}
233 341
234public override int GetBodyType(BulletBody obj) 342public override int GetBodyType(BulletBody obj)
235{ 343{
236 return BSAPICPP.GetBodyType2(obj.ptr); 344 BulletBodyUnman bodyu = obj as BulletBodyUnman;
345 return BSAPICPP.GetBodyType2(bodyu.ptr);
237} 346}
238 347
239public override BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot) 348public override BulletBody CreateBodyFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
240{ 349{
241 return new BulletBody(id, BSAPICPP.CreateBodyFromShape2(sim.ptr, shape.ptr, id, pos, rot)); 350 BulletWorldUnman worldu = world as BulletWorldUnman;
351 BulletShapeUnman shapeu = shape as BulletShapeUnman;
352 return new BulletBodyUnman(id, BSAPICPP.CreateBodyFromShape2(worldu.ptr, shapeu.ptr, id, pos, rot));
242} 353}
243 354
244public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot) 355public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot)
245{ 356{
246 return new BulletBody(id, BSAPICPP.CreateBodyWithDefaultMotionState2(shape.ptr, id, pos, rot)); 357 BulletShapeUnman shapeu = shape as BulletShapeUnman;
358 return new BulletBodyUnman(id, BSAPICPP.CreateBodyWithDefaultMotionState2(shapeu.ptr, id, pos, rot));
247} 359}
248 360
249public override BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot) 361public override BulletBody CreateGhostFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
250{ 362{
251 return new BulletBody(id, BSAPICPP.CreateGhostFromShape2(sim.ptr, shape.ptr, id, pos, rot)); 363 BulletWorldUnman worldu = world as BulletWorldUnman;
364 BulletShapeUnman shapeu = shape as BulletShapeUnman;
365 return new BulletBodyUnman(id, BSAPICPP.CreateGhostFromShape2(worldu.ptr, shapeu.ptr, id, pos, rot));
252} 366}
253 367
254public override void DestroyObject(BulletWorld sim, BulletBody obj) 368public override void DestroyObject(BulletWorld world, BulletBody obj)
255{ 369{
256 BSAPICPP.DestroyObject2(sim.ptr, obj.ptr); 370 BulletWorldUnman worldu = world as BulletWorldUnman;
371 BulletBodyUnman bodyu = obj as BulletBodyUnman;
372 BSAPICPP.DestroyObject2(worldu.ptr, bodyu.ptr);
257} 373}
258 374
259// ===================================================================================== 375// =====================================================================================
260// Terrain creation and helper routines 376// Terrain creation and helper routines
261public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin) 377public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin)
262{ 378{
263 return new BulletShape(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE); 379 return new BulletShapeUnman(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE);
264} 380}
265 381
266public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, 382public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
267 float scaleFactor, float collisionMargin) 383 float scaleFactor, float collisionMargin)
268{ 384{
269 return new BulletShape(BSAPICPP.CreateTerrainShape2(id, size, minHeight, maxHeight, heightMap, scaleFactor, collisionMargin), 385 return new BulletShapeUnman(BSAPICPP.CreateTerrainShape2(id, size, minHeight, maxHeight, heightMap, scaleFactor, collisionMargin),
270 BSPhysicsShapeType.SHAPE_TERRAIN); 386 BSPhysicsShapeType.SHAPE_TERRAIN);
271} 387}
272 388
@@ -277,7 +393,10 @@ public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletB
277 Vector3 frame2loc, Quaternion frame2rot, 393 Vector3 frame2loc, Quaternion frame2rot,
278 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) 394 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
279{ 395{
280 return new BulletConstraint(BSAPICPP.Create6DofConstraint2(world.ptr, obj1.ptr, obj2.ptr, frame1loc, frame1rot, 396 BulletWorldUnman worldu = world as BulletWorldUnman;
397 BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
398 BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
399 return new BulletConstraintUnman(BSAPICPP.Create6DofConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot,
281 frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); 400 frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
282} 401}
283 402
@@ -285,7 +404,10 @@ public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world,
285 Vector3 joinPoint, 404 Vector3 joinPoint,
286 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) 405 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
287{ 406{
288 return new BulletConstraint(BSAPICPP.Create6DofConstraintToPoint2(world.ptr, obj1.ptr, obj2.ptr, 407 BulletWorldUnman worldu = world as BulletWorldUnman;
408 BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
409 BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
410 return new BulletConstraintUnman(BSAPICPP.Create6DofConstraintToPoint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr,
289 joinPoint, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); 411 joinPoint, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
290} 412}
291 413
@@ -294,560 +416,687 @@ public override BulletConstraint CreateHingeConstraint(BulletWorld world, Bullet
294 Vector3 axisInA, Vector3 axisInB, 416 Vector3 axisInA, Vector3 axisInB,
295 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) 417 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
296{ 418{
297 return new BulletConstraint(BSAPICPP.CreateHingeConstraint2(world.ptr, obj1.ptr, obj2.ptr, 419 BulletWorldUnman worldu = world as BulletWorldUnman;
420 BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
421 BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
422 return new BulletConstraintUnman(BSAPICPP.CreateHingeConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr,
298 pivotinA, pivotinB, axisInA, axisInB, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); 423 pivotinA, pivotinB, axisInA, axisInB, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
299} 424}
300 425
301public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse) 426public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse)
302{ 427{
303 BSAPICPP.SetConstraintEnable2(constrain.ptr, numericTrueFalse); 428 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
429 BSAPICPP.SetConstraintEnable2(constrainu.ptr, numericTrueFalse);
304} 430}
305 431
306public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations) 432public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations)
307{ 433{
308 BSAPICPP.SetConstraintNumSolverIterations2(constrain.ptr, iterations); 434 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
435 BSAPICPP.SetConstraintNumSolverIterations2(constrainu.ptr, iterations);
309} 436}
310 437
311public override bool SetFrames(BulletConstraint constrain, 438public override bool SetFrames(BulletConstraint constrain,
312 Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot) 439 Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot)
313{ 440{
314 return BSAPICPP.SetFrames2(constrain.ptr, frameA, frameArot, frameB, frameBrot); 441 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
442 return BSAPICPP.SetFrames2(constrainu.ptr, frameA, frameArot, frameB, frameBrot);
315} 443}
316 444
317public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi) 445public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi)
318{ 446{
319 return BSAPICPP.SetLinearLimits2(constrain.ptr, low, hi); 447 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
448 return BSAPICPP.SetLinearLimits2(constrainu.ptr, low, hi);
320} 449}
321 450
322public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi) 451public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi)
323{ 452{
324 return BSAPICPP.SetAngularLimits2(constrain.ptr, low, hi); 453 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
454 return BSAPICPP.SetAngularLimits2(constrainu.ptr, low, hi);
325} 455}
326 456
327public override bool UseFrameOffset(BulletConstraint constrain, float enable) 457public override bool UseFrameOffset(BulletConstraint constrain, float enable)
328{ 458{
329 return BSAPICPP.UseFrameOffset2(constrain.ptr, enable); 459 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
460 return BSAPICPP.UseFrameOffset2(constrainu.ptr, enable);
330} 461}
331 462
332public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce) 463public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce)
333{ 464{
334 return BSAPICPP.TranslationalLimitMotor2(constrain.ptr, enable, targetVel, maxMotorForce); 465 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
466 return BSAPICPP.TranslationalLimitMotor2(constrainu.ptr, enable, targetVel, maxMotorForce);
335} 467}
336 468
337public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold) 469public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold)
338{ 470{
339 return BSAPICPP.SetBreakingImpulseThreshold2(constrain.ptr, threshold); 471 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
472 return BSAPICPP.SetBreakingImpulseThreshold2(constrainu.ptr, threshold);
340} 473}
341 474
342public override bool CalculateTransforms(BulletConstraint constrain) 475public override bool CalculateTransforms(BulletConstraint constrain)
343{ 476{
344 return BSAPICPP.CalculateTransforms2(constrain.ptr); 477 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
478 return BSAPICPP.CalculateTransforms2(constrainu.ptr);
345} 479}
346 480
347public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis) 481public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis)
348{ 482{
349 return BSAPICPP.SetConstraintParam2(constrain.ptr, paramIndex, value, axis); 483 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
484 return BSAPICPP.SetConstraintParam2(constrainu.ptr, paramIndex, value, axis);
350} 485}
351 486
352public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain) 487public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain)
353{ 488{
354 return BSAPICPP.DestroyConstraint2(world.ptr, constrain.ptr); 489 BulletWorldUnman worldu = world as BulletWorldUnman;
490 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
491 return BSAPICPP.DestroyConstraint2(worldu.ptr, constrainu.ptr);
355} 492}
356 493
357// ===================================================================================== 494// =====================================================================================
358// btCollisionWorld entries 495// btCollisionWorld entries
359public override void UpdateSingleAabb(BulletWorld world, BulletBody obj) 496public override void UpdateSingleAabb(BulletWorld world, BulletBody obj)
360{ 497{
361 BSAPICPP.UpdateSingleAabb2(world.ptr, obj.ptr); 498 BulletWorldUnman worldu = world as BulletWorldUnman;
499 BulletBodyUnman bodyu = obj as BulletBodyUnman;
500 BSAPICPP.UpdateSingleAabb2(worldu.ptr, bodyu.ptr);
362} 501}
363 502
364public override void UpdateAabbs(BulletWorld world) 503public override void UpdateAabbs(BulletWorld world)
365{ 504{
366 BSAPICPP.UpdateAabbs2(world.ptr); 505 BulletWorldUnman worldu = world as BulletWorldUnman;
506 BSAPICPP.UpdateAabbs2(worldu.ptr);
367} 507}
368 508
369public override bool GetForceUpdateAllAabbs(BulletWorld world) 509public override bool GetForceUpdateAllAabbs(BulletWorld world)
370{ 510{
371 return BSAPICPP.GetForceUpdateAllAabbs2(world.ptr); 511 BulletWorldUnman worldu = world as BulletWorldUnman;
512 return BSAPICPP.GetForceUpdateAllAabbs2(worldu.ptr);
372} 513}
373 514
374public override void SetForceUpdateAllAabbs(BulletWorld world, bool force) 515public override void SetForceUpdateAllAabbs(BulletWorld world, bool force)
375{ 516{
376 BSAPICPP.SetForceUpdateAllAabbs2(world.ptr, force); 517 BulletWorldUnman worldu = world as BulletWorldUnman;
518 BSAPICPP.SetForceUpdateAllAabbs2(worldu.ptr, force);
377} 519}
378 520
379// ===================================================================================== 521// =====================================================================================
380// btDynamicsWorld entries 522// btDynamicsWorld entries
381public override bool AddObjectToWorld(BulletWorld world, BulletBody obj) 523public override bool AddObjectToWorld(BulletWorld world, BulletBody obj)
382{ 524{
383 return BSAPICPP.AddObjectToWorld2(world.ptr, obj.ptr); 525 BulletWorldUnman worldu = world as BulletWorldUnman;
526 BulletBodyUnman bodyu = obj as BulletBodyUnman;
527 return BSAPICPP.AddObjectToWorld2(worldu.ptr, bodyu.ptr);
384} 528}
385 529
386public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj) 530public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj)
387{ 531{
388 return BSAPICPP.RemoveObjectFromWorld2(world.ptr, obj.ptr); 532 BulletWorldUnman worldu = world as BulletWorldUnman;
533 BulletBodyUnman bodyu = obj as BulletBodyUnman;
534 return BSAPICPP.RemoveObjectFromWorld2(worldu.ptr, bodyu.ptr);
389} 535}
390 536
391public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects) 537public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects)
392{ 538{
393 return BSAPICPP.AddConstraintToWorld2(world.ptr, constrain.ptr, disableCollisionsBetweenLinkedObjects); 539 BulletWorldUnman worldu = world as BulletWorldUnman;
540 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
541 return BSAPICPP.AddConstraintToWorld2(worldu.ptr, constrainu.ptr, disableCollisionsBetweenLinkedObjects);
394} 542}
395 543
396public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain) 544public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain)
397{ 545{
398 return BSAPICPP.RemoveConstraintFromWorld2(world.ptr, constrain.ptr); 546 BulletWorldUnman worldu = world as BulletWorldUnman;
547 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
548 return BSAPICPP.RemoveConstraintFromWorld2(worldu.ptr, constrainu.ptr);
399} 549}
400// ===================================================================================== 550// =====================================================================================
401// btCollisionObject entries 551// btCollisionObject entries
402public override Vector3 GetAnisotripicFriction(BulletConstraint constrain) 552public override Vector3 GetAnisotripicFriction(BulletConstraint constrain)
403{ 553{
404 return BSAPICPP.GetAnisotripicFriction2(constrain.ptr); 554 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
555 return BSAPICPP.GetAnisotripicFriction2(constrainu.ptr);
405} 556}
406 557
407public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict) 558public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict)
408{ 559{
409 return BSAPICPP.SetAnisotripicFriction2(constrain.ptr, frict); 560 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
561 return BSAPICPP.SetAnisotripicFriction2(constrainu.ptr, frict);
410} 562}
411 563
412public override bool HasAnisotripicFriction(BulletConstraint constrain) 564public override bool HasAnisotripicFriction(BulletConstraint constrain)
413{ 565{
414 return BSAPICPP.HasAnisotripicFriction2(constrain.ptr); 566 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
567 return BSAPICPP.HasAnisotripicFriction2(constrainu.ptr);
415} 568}
416 569
417public override void SetContactProcessingThreshold(BulletBody obj, float val) 570public override void SetContactProcessingThreshold(BulletBody obj, float val)
418{ 571{
419 BSAPICPP.SetContactProcessingThreshold2(obj.ptr, val); 572 BulletBodyUnman bodyu = obj as BulletBodyUnman;
573 BSAPICPP.SetContactProcessingThreshold2(bodyu.ptr, val);
420} 574}
421 575
422public override float GetContactProcessingThreshold(BulletBody obj) 576public override float GetContactProcessingThreshold(BulletBody obj)
423{ 577{
424 return BSAPICPP.GetContactProcessingThreshold2(obj.ptr); 578 BulletBodyUnman bodyu = obj as BulletBodyUnman;
579 return BSAPICPP.GetContactProcessingThreshold2(bodyu.ptr);
425} 580}
426 581
427public override bool IsStaticObject(BulletBody obj) 582public override bool IsStaticObject(BulletBody obj)
428{ 583{
429 return BSAPICPP.IsStaticObject2(obj.ptr); 584 BulletBodyUnman bodyu = obj as BulletBodyUnman;
585 return BSAPICPP.IsStaticObject2(bodyu.ptr);
430} 586}
431 587
432public override bool IsKinematicObject(BulletBody obj) 588public override bool IsKinematicObject(BulletBody obj)
433{ 589{
434 return BSAPICPP.IsKinematicObject2(obj.ptr); 590 BulletBodyUnman bodyu = obj as BulletBodyUnman;
591 return BSAPICPP.IsKinematicObject2(bodyu.ptr);
435} 592}
436 593
437public override bool IsStaticOrKinematicObject(BulletBody obj) 594public override bool IsStaticOrKinematicObject(BulletBody obj)
438{ 595{
439 return BSAPICPP.IsStaticOrKinematicObject2(obj.ptr); 596 BulletBodyUnman bodyu = obj as BulletBodyUnman;
597 return BSAPICPP.IsStaticOrKinematicObject2(bodyu.ptr);
440} 598}
441 599
442public override bool HasContactResponse(BulletBody obj) 600public override bool HasContactResponse(BulletBody obj)
443{ 601{
444 return BSAPICPP.HasContactResponse2(obj.ptr); 602 BulletBodyUnman bodyu = obj as BulletBodyUnman;
603 return BSAPICPP.HasContactResponse2(bodyu.ptr);
445} 604}
446 605
447public override void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape) 606public override void SetCollisionShape(BulletWorld world, BulletBody obj, BulletShape shape)
448{ 607{
449 BSAPICPP.SetCollisionShape2(sim.ptr, obj.ptr, shape.ptr); 608 BulletWorldUnman worldu = world as BulletWorldUnman;
609 BulletBodyUnman bodyu = obj as BulletBodyUnman;
610 BulletShapeUnman shapeu = shape as BulletShapeUnman;
611 if (worldu != null && bodyu != null)
612 {
613 // Special case to allow the caller to zero out the reference to any physical shape
614 if (shapeu != null)
615 BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, shapeu.ptr);
616 else
617 BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, IntPtr.Zero);
618 }
450} 619}
451 620
452public override BulletShape GetCollisionShape(BulletBody obj) 621public override BulletShape GetCollisionShape(BulletBody obj)
453{ 622{
454 return new BulletShape(BSAPICPP.GetCollisionShape2(obj.ptr)); 623 BulletBodyUnman bodyu = obj as BulletBodyUnman;
624 return new BulletShapeUnman(BSAPICPP.GetCollisionShape2(bodyu.ptr), BSPhysicsShapeType.SHAPE_UNKNOWN);
455} 625}
456 626
457public override int GetActivationState(BulletBody obj) 627public override int GetActivationState(BulletBody obj)
458{ 628{
459 return BSAPICPP.GetActivationState2(obj.ptr); 629 BulletBodyUnman bodyu = obj as BulletBodyUnman;
630 return BSAPICPP.GetActivationState2(bodyu.ptr);
460} 631}
461 632
462public override void SetActivationState(BulletBody obj, int state) 633public override void SetActivationState(BulletBody obj, int state)
463{ 634{
464 BSAPICPP.SetActivationState2(obj.ptr, state); 635 BulletBodyUnman bodyu = obj as BulletBodyUnman;
636 BSAPICPP.SetActivationState2(bodyu.ptr, state);
465} 637}
466 638
467public override void SetDeactivationTime(BulletBody obj, float dtime) 639public override void SetDeactivationTime(BulletBody obj, float dtime)
468{ 640{
469 BSAPICPP.SetDeactivationTime2(obj.ptr, dtime); 641 BulletBodyUnman bodyu = obj as BulletBodyUnman;
642 BSAPICPP.SetDeactivationTime2(bodyu.ptr, dtime);
470} 643}
471 644
472public override float GetDeactivationTime(BulletBody obj) 645public override float GetDeactivationTime(BulletBody obj)
473{ 646{
474 return BSAPICPP.GetDeactivationTime2(obj.ptr); 647 BulletBodyUnman bodyu = obj as BulletBodyUnman;
648 return BSAPICPP.GetDeactivationTime2(bodyu.ptr);
475} 649}
476 650
477public override void ForceActivationState(BulletBody obj, ActivationState state) 651public override void ForceActivationState(BulletBody obj, ActivationState state)
478{ 652{
479 BSAPICPP.ForceActivationState2(obj.ptr, state); 653 BulletBodyUnman bodyu = obj as BulletBodyUnman;
654 BSAPICPP.ForceActivationState2(bodyu.ptr, state);
480} 655}
481 656
482public override void Activate(BulletBody obj, bool forceActivation) 657public override void Activate(BulletBody obj, bool forceActivation)
483{ 658{
484 BSAPICPP.Activate2(obj.ptr, forceActivation); 659 BulletBodyUnman bodyu = obj as BulletBodyUnman;
660 BSAPICPP.Activate2(bodyu.ptr, forceActivation);
485} 661}
486 662
487public override bool IsActive(BulletBody obj) 663public override bool IsActive(BulletBody obj)
488{ 664{
489 return BSAPICPP.IsActive2(obj.ptr); 665 BulletBodyUnman bodyu = obj as BulletBodyUnman;
666 return BSAPICPP.IsActive2(bodyu.ptr);
490} 667}
491 668
492public override void SetRestitution(BulletBody obj, float val) 669public override void SetRestitution(BulletBody obj, float val)
493{ 670{
494 BSAPICPP.SetRestitution2(obj.ptr, val); 671 BulletBodyUnman bodyu = obj as BulletBodyUnman;
672 BSAPICPP.SetRestitution2(bodyu.ptr, val);
495} 673}
496 674
497public override float GetRestitution(BulletBody obj) 675public override float GetRestitution(BulletBody obj)
498{ 676{
499 return BSAPICPP.GetRestitution2(obj.ptr); 677 BulletBodyUnman bodyu = obj as BulletBodyUnman;
678 return BSAPICPP.GetRestitution2(bodyu.ptr);
500} 679}
501 680
502public override void SetFriction(BulletBody obj, float val) 681public override void SetFriction(BulletBody obj, float val)
503{ 682{
504 BSAPICPP.SetFriction2(obj.ptr, val); 683 BulletBodyUnman bodyu = obj as BulletBodyUnman;
684 BSAPICPP.SetFriction2(bodyu.ptr, val);
505} 685}
506 686
507public override float GetFriction(BulletBody obj) 687public override float GetFriction(BulletBody obj)
508{ 688{
509 return BSAPICPP.GetFriction2(obj.ptr); 689 BulletBodyUnman bodyu = obj as BulletBodyUnman;
690 return BSAPICPP.GetFriction2(bodyu.ptr);
510} 691}
511 692
512public override Vector3 GetPosition(BulletBody obj) 693public override Vector3 GetPosition(BulletBody obj)
513{ 694{
514 return BSAPICPP.GetPosition2(obj.ptr); 695 BulletBodyUnman bodyu = obj as BulletBodyUnman;
696 return BSAPICPP.GetPosition2(bodyu.ptr);
515} 697}
516 698
517public override Quaternion GetOrientation(BulletBody obj) 699public override Quaternion GetOrientation(BulletBody obj)
518{ 700{
519 return BSAPICPP.GetOrientation2(obj.ptr); 701 BulletBodyUnman bodyu = obj as BulletBodyUnman;
702 return BSAPICPP.GetOrientation2(bodyu.ptr);
520} 703}
521 704
522public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation) 705public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation)
523{ 706{
524 BSAPICPP.SetTranslation2(obj.ptr, position, rotation); 707 BulletBodyUnman bodyu = obj as BulletBodyUnman;
708 BSAPICPP.SetTranslation2(bodyu.ptr, position, rotation);
525} 709}
526 710
527 /* 711 /*
528public override IntPtr GetBroadphaseHandle(BulletBody obj) 712public override IntPtr GetBroadphaseHandle(BulletBody obj)
529{ 713{
530 return BSAPICPP.GetBroadphaseHandle2(obj.ptr); 714 BulletBodyUnman bodyu = obj as BulletBodyUnman;
715 return BSAPICPP.GetBroadphaseHandle2(bodyu.ptr);
531} 716}
532 717
533public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle) 718public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle)
534{ 719{
535 BSAPICPP.SetUserPointer2(obj.ptr, handle); 720 BulletBodyUnman bodyu = obj as BulletBodyUnman;
721 BSAPICPP.SetUserPointer2(bodyu.ptr, handle);
536} 722}
537 */ 723 */
538 724
539public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel) 725public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel)
540{ 726{
541 BSAPICPP.SetInterpolationLinearVelocity2(obj.ptr, vel); 727 BulletBodyUnman bodyu = obj as BulletBodyUnman;
728 BSAPICPP.SetInterpolationLinearVelocity2(bodyu.ptr, vel);
542} 729}
543 730
544public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel) 731public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel)
545{ 732{
546 BSAPICPP.SetInterpolationAngularVelocity2(obj.ptr, vel); 733 BulletBodyUnman bodyu = obj as BulletBodyUnman;
734 BSAPICPP.SetInterpolationAngularVelocity2(bodyu.ptr, vel);
547} 735}
548 736
549public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel) 737public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel)
550{ 738{
551 BSAPICPP.SetInterpolationVelocity2(obj.ptr, linearVel, angularVel); 739 BulletBodyUnman bodyu = obj as BulletBodyUnman;
740 BSAPICPP.SetInterpolationVelocity2(bodyu.ptr, linearVel, angularVel);
552} 741}
553 742
554public override float GetHitFraction(BulletBody obj) 743public override float GetHitFraction(BulletBody obj)
555{ 744{
556 return BSAPICPP.GetHitFraction2(obj.ptr); 745 BulletBodyUnman bodyu = obj as BulletBodyUnman;
746 return BSAPICPP.GetHitFraction2(bodyu.ptr);
557} 747}
558 748
559public override void SetHitFraction(BulletBody obj, float val) 749public override void SetHitFraction(BulletBody obj, float val)
560{ 750{
561 BSAPICPP.SetHitFraction2(obj.ptr, val); 751 BulletBodyUnman bodyu = obj as BulletBodyUnman;
752 BSAPICPP.SetHitFraction2(bodyu.ptr, val);
562} 753}
563 754
564public override CollisionFlags GetCollisionFlags(BulletBody obj) 755public override CollisionFlags GetCollisionFlags(BulletBody obj)
565{ 756{
566 return BSAPICPP.GetCollisionFlags2(obj.ptr); 757 BulletBodyUnman bodyu = obj as BulletBodyUnman;
758 return BSAPICPP.GetCollisionFlags2(bodyu.ptr);
567} 759}
568 760
569public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags) 761public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags)
570{ 762{
571 return BSAPICPP.SetCollisionFlags2(obj.ptr, flags); 763 BulletBodyUnman bodyu = obj as BulletBodyUnman;
764 return BSAPICPP.SetCollisionFlags2(bodyu.ptr, flags);
572} 765}
573 766
574public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags) 767public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags)
575{ 768{
576 return BSAPICPP.AddToCollisionFlags2(obj.ptr, flags); 769 BulletBodyUnman bodyu = obj as BulletBodyUnman;
770 return BSAPICPP.AddToCollisionFlags2(bodyu.ptr, flags);
577} 771}
578 772
579public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags) 773public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags)
580{ 774{
581 return BSAPICPP.RemoveFromCollisionFlags2(obj.ptr, flags); 775 BulletBodyUnman bodyu = obj as BulletBodyUnman;
776 return BSAPICPP.RemoveFromCollisionFlags2(bodyu.ptr, flags);
582} 777}
583 778
584public override float GetCcdMotionThreshold(BulletBody obj) 779public override float GetCcdMotionThreshold(BulletBody obj)
585{ 780{
586 return BSAPICPP.GetCcdMotionThreshold2(obj.ptr); 781 BulletBodyUnman bodyu = obj as BulletBodyUnman;
782 return BSAPICPP.GetCcdMotionThreshold2(bodyu.ptr);
587} 783}
588 784
589 785
590public override void SetCcdMotionThreshold(BulletBody obj, float val) 786public override void SetCcdMotionThreshold(BulletBody obj, float val)
591{ 787{
592 BSAPICPP.SetCcdMotionThreshold2(obj.ptr, val); 788 BulletBodyUnman bodyu = obj as BulletBodyUnman;
789 BSAPICPP.SetCcdMotionThreshold2(bodyu.ptr, val);
593} 790}
594 791
595public override float GetCcdSweptSphereRadius(BulletBody obj) 792public override float GetCcdSweptSphereRadius(BulletBody obj)
596{ 793{
597 return BSAPICPP.GetCcdSweptSphereRadius2(obj.ptr); 794 BulletBodyUnman bodyu = obj as BulletBodyUnman;
795 return BSAPICPP.GetCcdSweptSphereRadius2(bodyu.ptr);
598} 796}
599 797
600public override void SetCcdSweptSphereRadius(BulletBody obj, float val) 798public override void SetCcdSweptSphereRadius(BulletBody obj, float val)
601{ 799{
602 BSAPICPP.SetCcdSweptSphereRadius2(obj.ptr, val); 800 BulletBodyUnman bodyu = obj as BulletBodyUnman;
801 BSAPICPP.SetCcdSweptSphereRadius2(bodyu.ptr, val);
603} 802}
604 803
605public override IntPtr GetUserPointer(BulletBody obj) 804public override IntPtr GetUserPointer(BulletBody obj)
606{ 805{
607 return BSAPICPP.GetUserPointer2(obj.ptr); 806 BulletBodyUnman bodyu = obj as BulletBodyUnman;
807 return BSAPICPP.GetUserPointer2(bodyu.ptr);
608} 808}
609 809
610public override void SetUserPointer(BulletBody obj, IntPtr val) 810public override void SetUserPointer(BulletBody obj, IntPtr val)
611{ 811{
612 BSAPICPP.SetUserPointer2(obj.ptr, val); 812 BulletBodyUnman bodyu = obj as BulletBodyUnman;
813 BSAPICPP.SetUserPointer2(bodyu.ptr, val);
613} 814}
614 815
615// ===================================================================================== 816// =====================================================================================
616// btRigidBody entries 817// btRigidBody entries
617public override void ApplyGravity(BulletBody obj) 818public override void ApplyGravity(BulletBody obj)
618{ 819{
619 BSAPICPP.ApplyGravity2(obj.ptr); 820 BulletBodyUnman bodyu = obj as BulletBodyUnman;
821 BSAPICPP.ApplyGravity2(bodyu.ptr);
620} 822}
621 823
622public override void SetGravity(BulletBody obj, Vector3 val) 824public override void SetGravity(BulletBody obj, Vector3 val)
623{ 825{
624 BSAPICPP.SetGravity2(obj.ptr, val); 826 BulletBodyUnman bodyu = obj as BulletBodyUnman;
827 BSAPICPP.SetGravity2(bodyu.ptr, val);
625} 828}
626 829
627public override Vector3 GetGravity(BulletBody obj) 830public override Vector3 GetGravity(BulletBody obj)
628{ 831{
629 return BSAPICPP.GetGravity2(obj.ptr); 832 BulletBodyUnman bodyu = obj as BulletBodyUnman;
833 return BSAPICPP.GetGravity2(bodyu.ptr);
630} 834}
631 835
632public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping) 836public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping)
633{ 837{
634 BSAPICPP.SetDamping2(obj.ptr, lin_damping, ang_damping); 838 BulletBodyUnman bodyu = obj as BulletBodyUnman;
839 BSAPICPP.SetDamping2(bodyu.ptr, lin_damping, ang_damping);
635} 840}
636 841
637public override void SetLinearDamping(BulletBody obj, float lin_damping) 842public override void SetLinearDamping(BulletBody obj, float lin_damping)
638{ 843{
639 BSAPICPP.SetLinearDamping2(obj.ptr, lin_damping); 844 BulletBodyUnman bodyu = obj as BulletBodyUnman;
845 BSAPICPP.SetLinearDamping2(bodyu.ptr, lin_damping);
640} 846}
641 847
642public override void SetAngularDamping(BulletBody obj, float ang_damping) 848public override void SetAngularDamping(BulletBody obj, float ang_damping)
643{ 849{
644 BSAPICPP.SetAngularDamping2(obj.ptr, ang_damping); 850 BulletBodyUnman bodyu = obj as BulletBodyUnman;
851 BSAPICPP.SetAngularDamping2(bodyu.ptr, ang_damping);
645} 852}
646 853
647public override float GetLinearDamping(BulletBody obj) 854public override float GetLinearDamping(BulletBody obj)
648{ 855{
649 return BSAPICPP.GetLinearDamping2(obj.ptr); 856 BulletBodyUnman bodyu = obj as BulletBodyUnman;
857 return BSAPICPP.GetLinearDamping2(bodyu.ptr);
650} 858}
651 859
652public override float GetAngularDamping(BulletBody obj) 860public override float GetAngularDamping(BulletBody obj)
653{ 861{
654 return BSAPICPP.GetAngularDamping2(obj.ptr); 862 BulletBodyUnman bodyu = obj as BulletBodyUnman;
863 return BSAPICPP.GetAngularDamping2(bodyu.ptr);
655} 864}
656 865
657public override float GetLinearSleepingThreshold(BulletBody obj) 866public override float GetLinearSleepingThreshold(BulletBody obj)
658{ 867{
659 return BSAPICPP.GetLinearSleepingThreshold2(obj.ptr); 868 BulletBodyUnman bodyu = obj as BulletBodyUnman;
869 return BSAPICPP.GetLinearSleepingThreshold2(bodyu.ptr);
660} 870}
661 871
662public override void ApplyDamping(BulletBody obj, float timeStep) 872public override void ApplyDamping(BulletBody obj, float timeStep)
663{ 873{
664 BSAPICPP.ApplyDamping2(obj.ptr, timeStep); 874 BulletBodyUnman bodyu = obj as BulletBodyUnman;
875 BSAPICPP.ApplyDamping2(bodyu.ptr, timeStep);
665} 876}
666 877
667public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia) 878public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia)
668{ 879{
669 BSAPICPP.SetMassProps2(obj.ptr, mass, inertia); 880 BulletBodyUnman bodyu = obj as BulletBodyUnman;
881 BSAPICPP.SetMassProps2(bodyu.ptr, mass, inertia);
670} 882}
671 883
672public override Vector3 GetLinearFactor(BulletBody obj) 884public override Vector3 GetLinearFactor(BulletBody obj)
673{ 885{
674 return BSAPICPP.GetLinearFactor2(obj.ptr); 886 BulletBodyUnman bodyu = obj as BulletBodyUnman;
887 return BSAPICPP.GetLinearFactor2(bodyu.ptr);
675} 888}
676 889
677public override void SetLinearFactor(BulletBody obj, Vector3 factor) 890public override void SetLinearFactor(BulletBody obj, Vector3 factor)
678{ 891{
679 BSAPICPP.SetLinearFactor2(obj.ptr, factor); 892 BulletBodyUnman bodyu = obj as BulletBodyUnman;
893 BSAPICPP.SetLinearFactor2(bodyu.ptr, factor);
680} 894}
681 895
682public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot) 896public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot)
683{ 897{
684 BSAPICPP.SetCenterOfMassByPosRot2(obj.ptr, pos, rot); 898 BulletBodyUnman bodyu = obj as BulletBodyUnman;
899 BSAPICPP.SetCenterOfMassByPosRot2(bodyu.ptr, pos, rot);
685} 900}
686 901
687// Add a force to the object as if its mass is one. 902// Add a force to the object as if its mass is one.
688public override void ApplyCentralForce(BulletBody obj, Vector3 force) 903public override void ApplyCentralForce(BulletBody obj, Vector3 force)
689{ 904{
690 BSAPICPP.ApplyCentralForce2(obj.ptr, force); 905 BulletBodyUnman bodyu = obj as BulletBodyUnman;
906 BSAPICPP.ApplyCentralForce2(bodyu.ptr, force);
691} 907}
692 908
693// Set the force being applied to the object as if its mass is one. 909// Set the force being applied to the object as if its mass is one.
694public override void SetObjectForce(BulletBody obj, Vector3 force) 910public override void SetObjectForce(BulletBody obj, Vector3 force)
695{ 911{
696 BSAPICPP.SetObjectForce2(obj.ptr, force); 912 BulletBodyUnman bodyu = obj as BulletBodyUnman;
913 BSAPICPP.SetObjectForce2(bodyu.ptr, force);
697} 914}
698 915
699public override Vector3 GetTotalForce(BulletBody obj) 916public override Vector3 GetTotalForce(BulletBody obj)
700{ 917{
701 return BSAPICPP.GetTotalForce2(obj.ptr); 918 BulletBodyUnman bodyu = obj as BulletBodyUnman;
919 return BSAPICPP.GetTotalForce2(bodyu.ptr);
702} 920}
703 921
704public override Vector3 GetTotalTorque(BulletBody obj) 922public override Vector3 GetTotalTorque(BulletBody obj)
705{ 923{
706 return BSAPICPP.GetTotalTorque2(obj.ptr); 924 BulletBodyUnman bodyu = obj as BulletBodyUnman;
925 return BSAPICPP.GetTotalTorque2(bodyu.ptr);
707} 926}
708 927
709public override Vector3 GetInvInertiaDiagLocal(BulletBody obj) 928public override Vector3 GetInvInertiaDiagLocal(BulletBody obj)
710{ 929{
711 return BSAPICPP.GetInvInertiaDiagLocal2(obj.ptr); 930 BulletBodyUnman bodyu = obj as BulletBodyUnman;
931 return BSAPICPP.GetInvInertiaDiagLocal2(bodyu.ptr);
712} 932}
713 933
714public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert) 934public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert)
715{ 935{
716 BSAPICPP.SetInvInertiaDiagLocal2(obj.ptr, inert); 936 BulletBodyUnman bodyu = obj as BulletBodyUnman;
937 BSAPICPP.SetInvInertiaDiagLocal2(bodyu.ptr, inert);
717} 938}
718 939
719public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold) 940public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold)
720{ 941{
721 BSAPICPP.SetSleepingThresholds2(obj.ptr, lin_threshold, ang_threshold); 942 BulletBodyUnman bodyu = obj as BulletBodyUnman;
943 BSAPICPP.SetSleepingThresholds2(bodyu.ptr, lin_threshold, ang_threshold);
722} 944}
723 945
724public override void ApplyTorque(BulletBody obj, Vector3 torque) 946public override void ApplyTorque(BulletBody obj, Vector3 torque)
725{ 947{
726 BSAPICPP.ApplyTorque2(obj.ptr, torque); 948 BulletBodyUnman bodyu = obj as BulletBodyUnman;
949 BSAPICPP.ApplyTorque2(bodyu.ptr, torque);
727} 950}
728 951
729// Apply force at the given point. Will add torque to the object. 952// Apply force at the given point. Will add torque to the object.
730public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos) 953public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos)
731{ 954{
732 BSAPICPP.ApplyForce2(obj.ptr, force, pos); 955 BulletBodyUnman bodyu = obj as BulletBodyUnman;
956 BSAPICPP.ApplyForce2(bodyu.ptr, force, pos);
733} 957}
734 958
735// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. 959// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
736public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp) 960public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp)
737{ 961{
738 BSAPICPP.ApplyCentralImpulse2(obj.ptr, imp); 962 BulletBodyUnman bodyu = obj as BulletBodyUnman;
963 BSAPICPP.ApplyCentralImpulse2(bodyu.ptr, imp);
739} 964}
740 965
741// Apply impulse to the object's torque. Force is scaled by object's mass. 966// Apply impulse to the object's torque. Force is scaled by object's mass.
742public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp) 967public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp)
743{ 968{
744 BSAPICPP.ApplyTorqueImpulse2(obj.ptr, imp); 969 BulletBodyUnman bodyu = obj as BulletBodyUnman;
970 BSAPICPP.ApplyTorqueImpulse2(bodyu.ptr, imp);
745} 971}
746 972
747// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. 973// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
748public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos) 974public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos)
749{ 975{
750 BSAPICPP.ApplyImpulse2(obj.ptr, imp, pos); 976 BulletBodyUnman bodyu = obj as BulletBodyUnman;
977 BSAPICPP.ApplyImpulse2(bodyu.ptr, imp, pos);
751} 978}
752 979
753public override void ClearForces(BulletBody obj) 980public override void ClearForces(BulletBody obj)
754{ 981{
755 BSAPICPP.ClearForces2(obj.ptr); 982 BulletBodyUnman bodyu = obj as BulletBodyUnman;
983 BSAPICPP.ClearForces2(bodyu.ptr);
756} 984}
757 985
758public override void ClearAllForces(BulletBody obj) 986public override void ClearAllForces(BulletBody obj)
759{ 987{
760 BSAPICPP.ClearAllForces2(obj.ptr); 988 BulletBodyUnman bodyu = obj as BulletBodyUnman;
989 BSAPICPP.ClearAllForces2(bodyu.ptr);
761} 990}
762 991
763public override void UpdateInertiaTensor(BulletBody obj) 992public override void UpdateInertiaTensor(BulletBody obj)
764{ 993{
765 BSAPICPP.UpdateInertiaTensor2(obj.ptr); 994 BulletBodyUnman bodyu = obj as BulletBodyUnman;
995 BSAPICPP.UpdateInertiaTensor2(bodyu.ptr);
766} 996}
767 997
768public override Vector3 GetLinearVelocity(BulletBody obj) 998public override Vector3 GetLinearVelocity(BulletBody obj)
769{ 999{
770 return BSAPICPP.GetLinearVelocity2(obj.ptr); 1000 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1001 return BSAPICPP.GetLinearVelocity2(bodyu.ptr);
771} 1002}
772 1003
773public override Vector3 GetAngularVelocity(BulletBody obj) 1004public override Vector3 GetAngularVelocity(BulletBody obj)
774{ 1005{
775 return BSAPICPP.GetAngularVelocity2(obj.ptr); 1006 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1007 return BSAPICPP.GetAngularVelocity2(bodyu.ptr);
776} 1008}
777 1009
778public override void SetLinearVelocity(BulletBody obj, Vector3 vel) 1010public override void SetLinearVelocity(BulletBody obj, Vector3 vel)
779{ 1011{
780 BSAPICPP.SetLinearVelocity2(obj.ptr, vel); 1012 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1013 BSAPICPP.SetLinearVelocity2(bodyu.ptr, vel);
781} 1014}
782 1015
783public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity) 1016public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity)
784{ 1017{
785 BSAPICPP.SetAngularVelocity2(obj.ptr, angularVelocity); 1018 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1019 BSAPICPP.SetAngularVelocity2(bodyu.ptr, angularVelocity);
786} 1020}
787 1021
788public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos) 1022public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos)
789{ 1023{
790 return BSAPICPP.GetVelocityInLocalPoint2(obj.ptr, pos); 1024 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1025 return BSAPICPP.GetVelocityInLocalPoint2(bodyu.ptr, pos);
791} 1026}
792 1027
793public override void Translate(BulletBody obj, Vector3 trans) 1028public override void Translate(BulletBody obj, Vector3 trans)
794{ 1029{
795 BSAPICPP.Translate2(obj.ptr, trans); 1030 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1031 BSAPICPP.Translate2(bodyu.ptr, trans);
796} 1032}
797 1033
798public override void UpdateDeactivation(BulletBody obj, float timeStep) 1034public override void UpdateDeactivation(BulletBody obj, float timeStep)
799{ 1035{
800 BSAPICPP.UpdateDeactivation2(obj.ptr, timeStep); 1036 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1037 BSAPICPP.UpdateDeactivation2(bodyu.ptr, timeStep);
801} 1038}
802 1039
803public override bool WantsSleeping(BulletBody obj) 1040public override bool WantsSleeping(BulletBody obj)
804{ 1041{
805 return BSAPICPP.WantsSleeping2(obj.ptr); 1042 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1043 return BSAPICPP.WantsSleeping2(bodyu.ptr);
806} 1044}
807 1045
808public override void SetAngularFactor(BulletBody obj, float factor) 1046public override void SetAngularFactor(BulletBody obj, float factor)
809{ 1047{
810 BSAPICPP.SetAngularFactor2(obj.ptr, factor); 1048 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1049 BSAPICPP.SetAngularFactor2(bodyu.ptr, factor);
811} 1050}
812 1051
813public override void SetAngularFactorV(BulletBody obj, Vector3 factor) 1052public override void SetAngularFactorV(BulletBody obj, Vector3 factor)
814{ 1053{
815 BSAPICPP.SetAngularFactorV2(obj.ptr, factor); 1054 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1055 BSAPICPP.SetAngularFactorV2(bodyu.ptr, factor);
816} 1056}
817 1057
818public override Vector3 GetAngularFactor(BulletBody obj) 1058public override Vector3 GetAngularFactor(BulletBody obj)
819{ 1059{
820 return BSAPICPP.GetAngularFactor2(obj.ptr); 1060 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1061 return BSAPICPP.GetAngularFactor2(bodyu.ptr);
821} 1062}
822 1063
823public override bool IsInWorld(BulletBody obj) 1064public override bool IsInWorld(BulletBody obj)
824{ 1065{
825 return BSAPICPP.IsInWorld2(obj.ptr); 1066 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1067 return BSAPICPP.IsInWorld2(bodyu.ptr);
826} 1068}
827 1069
828public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain) 1070public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain)
829{ 1071{
830 BSAPICPP.AddConstraintRef2(obj.ptr, constrain.ptr); 1072 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1073 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
1074 BSAPICPP.AddConstraintRef2(bodyu.ptr, constrainu.ptr);
831} 1075}
832 1076
833public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain) 1077public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain)
834{ 1078{
835 BSAPICPP.RemoveConstraintRef2(obj.ptr, constrain.ptr); 1079 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1080 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
1081 BSAPICPP.RemoveConstraintRef2(bodyu.ptr, constrainu.ptr);
836} 1082}
837 1083
838public override BulletConstraint GetConstraintRef(BulletBody obj, int index) 1084public override BulletConstraint GetConstraintRef(BulletBody obj, int index)
839{ 1085{
840 return new BulletConstraint(BSAPICPP.GetConstraintRef2(obj.ptr, index)); 1086 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1087 return new BulletConstraintUnman(BSAPICPP.GetConstraintRef2(bodyu.ptr, index));
841} 1088}
842 1089
843public override int GetNumConstraintRefs(BulletBody obj) 1090public override int GetNumConstraintRefs(BulletBody obj)
844{ 1091{
845 return BSAPICPP.GetNumConstraintRefs2(obj.ptr); 1092 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1093 return BSAPICPP.GetNumConstraintRefs2(bodyu.ptr);
846} 1094}
847 1095
848public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask) 1096public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask)
849{ 1097{
850 return BSAPICPP.SetCollisionGroupMask2(body.ptr, filter, mask); 1098 BulletBodyUnman bodyu = body as BulletBodyUnman;
1099 return BSAPICPP.SetCollisionGroupMask2(bodyu.ptr, filter, mask);
851} 1100}
852 1101
853// ===================================================================================== 1102// =====================================================================================
@@ -855,114 +1104,139 @@ public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint ma
855 1104
856public override float GetAngularMotionDisc(BulletShape shape) 1105public override float GetAngularMotionDisc(BulletShape shape)
857{ 1106{
858 return BSAPICPP.GetAngularMotionDisc2(shape.ptr); 1107 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1108 return BSAPICPP.GetAngularMotionDisc2(shapeu.ptr);
859} 1109}
860 1110
861public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor) 1111public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor)
862{ 1112{
863 return BSAPICPP.GetContactBreakingThreshold2(shape.ptr, defaultFactor); 1113 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1114 return BSAPICPP.GetContactBreakingThreshold2(shapeu.ptr, defaultFactor);
864} 1115}
865 1116
866public override bool IsPolyhedral(BulletShape shape) 1117public override bool IsPolyhedral(BulletShape shape)
867{ 1118{
868 return BSAPICPP.IsPolyhedral2(shape.ptr); 1119 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1120 return BSAPICPP.IsPolyhedral2(shapeu.ptr);
869} 1121}
870 1122
871public override bool IsConvex2d(BulletShape shape) 1123public override bool IsConvex2d(BulletShape shape)
872{ 1124{
873 return BSAPICPP.IsConvex2d2(shape.ptr); 1125 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1126 return BSAPICPP.IsConvex2d2(shapeu.ptr);
874} 1127}
875 1128
876public override bool IsConvex(BulletShape shape) 1129public override bool IsConvex(BulletShape shape)
877{ 1130{
878 return BSAPICPP.IsConvex2(shape.ptr); 1131 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1132 return BSAPICPP.IsConvex2(shapeu.ptr);
879} 1133}
880 1134
881public override bool IsNonMoving(BulletShape shape) 1135public override bool IsNonMoving(BulletShape shape)
882{ 1136{
883 return BSAPICPP.IsNonMoving2(shape.ptr); 1137 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1138 return BSAPICPP.IsNonMoving2(shapeu.ptr);
884} 1139}
885 1140
886public override bool IsConcave(BulletShape shape) 1141public override bool IsConcave(BulletShape shape)
887{ 1142{
888 return BSAPICPP.IsConcave2(shape.ptr); 1143 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1144 return BSAPICPP.IsConcave2(shapeu.ptr);
889} 1145}
890 1146
891public override bool IsCompound(BulletShape shape) 1147public override bool IsCompound(BulletShape shape)
892{ 1148{
893 return BSAPICPP.IsCompound2(shape.ptr); 1149 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1150 return BSAPICPP.IsCompound2(shapeu.ptr);
894} 1151}
895 1152
896public override bool IsSoftBody(BulletShape shape) 1153public override bool IsSoftBody(BulletShape shape)
897{ 1154{
898 return BSAPICPP.IsSoftBody2(shape.ptr); 1155 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1156 return BSAPICPP.IsSoftBody2(shapeu.ptr);
899} 1157}
900 1158
901public override bool IsInfinite(BulletShape shape) 1159public override bool IsInfinite(BulletShape shape)
902{ 1160{
903 return BSAPICPP.IsInfinite2(shape.ptr); 1161 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1162 return BSAPICPP.IsInfinite2(shapeu.ptr);
904} 1163}
905 1164
906public override void SetLocalScaling(BulletShape shape, Vector3 scale) 1165public override void SetLocalScaling(BulletShape shape, Vector3 scale)
907{ 1166{
908 BSAPICPP.SetLocalScaling2(shape.ptr, scale); 1167 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1168 BSAPICPP.SetLocalScaling2(shapeu.ptr, scale);
909} 1169}
910 1170
911public override Vector3 GetLocalScaling(BulletShape shape) 1171public override Vector3 GetLocalScaling(BulletShape shape)
912{ 1172{
913 return BSAPICPP.GetLocalScaling2(shape.ptr); 1173 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1174 return BSAPICPP.GetLocalScaling2(shapeu.ptr);
914} 1175}
915 1176
916public override Vector3 CalculateLocalInertia(BulletShape shape, float mass) 1177public override Vector3 CalculateLocalInertia(BulletShape shape, float mass)
917{ 1178{
918 return BSAPICPP.CalculateLocalInertia2(shape.ptr, mass); 1179 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1180 return BSAPICPP.CalculateLocalInertia2(shapeu.ptr, mass);
919} 1181}
920 1182
921public override int GetShapeType(BulletShape shape) 1183public override int GetShapeType(BulletShape shape)
922{ 1184{
923 return BSAPICPP.GetShapeType2(shape.ptr); 1185 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1186 return BSAPICPP.GetShapeType2(shapeu.ptr);
924} 1187}
925 1188
926public override void SetMargin(BulletShape shape, float val) 1189public override void SetMargin(BulletShape shape, float val)
927{ 1190{
928 BSAPICPP.SetMargin2(shape.ptr, val); 1191 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1192 BSAPICPP.SetMargin2(shapeu.ptr, val);
929} 1193}
930 1194
931public override float GetMargin(BulletShape shape) 1195public override float GetMargin(BulletShape shape)
932{ 1196{
933 return BSAPICPP.GetMargin2(shape.ptr); 1197 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1198 return BSAPICPP.GetMargin2(shapeu.ptr);
934} 1199}
935 1200
936// ===================================================================================== 1201// =====================================================================================
937// Debugging 1202// Debugging
938public override void DumpRigidBody(BulletWorld sim, BulletBody collisionObject) 1203public override void DumpRigidBody(BulletWorld world, BulletBody collisionObject)
939{ 1204{
940 BSAPICPP.DumpRigidBody2(sim.ptr, collisionObject.ptr); 1205 BulletWorldUnman worldu = world as BulletWorldUnman;
1206 BulletBodyUnman bodyu = collisionObject as BulletBodyUnman;
1207 BSAPICPP.DumpRigidBody2(worldu.ptr, bodyu.ptr);
941} 1208}
942 1209
943public override void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape) 1210public override void DumpCollisionShape(BulletWorld world, BulletShape collisionShape)
944{ 1211{
945 BSAPICPP.DumpCollisionShape2(sim.ptr, collisionShape.ptr); 1212 BulletWorldUnman worldu = world as BulletWorldUnman;
1213 BulletShapeUnman shapeu = collisionShape as BulletShapeUnman;
1214 BSAPICPP.DumpCollisionShape2(worldu.ptr, shapeu.ptr);
946} 1215}
947 1216
948public override void DumpConstraint(BulletWorld sim, BulletConstraint constrain) 1217public override void DumpConstraint(BulletWorld world, BulletConstraint constrain)
949{ 1218{
950 BSAPICPP.DumpConstraint2(sim.ptr, constrain.ptr); 1219 BulletWorldUnman worldu = world as BulletWorldUnman;
1220 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
1221 BSAPICPP.DumpConstraint2(worldu.ptr, constrainu.ptr);
951} 1222}
952 1223
953public override void DumpActivationInfo(BulletWorld sim) 1224public override void DumpActivationInfo(BulletWorld world)
954{ 1225{
955 BSAPICPP.DumpActivationInfo2(sim.ptr); 1226 BulletWorldUnman worldu = world as BulletWorldUnman;
1227 BSAPICPP.DumpActivationInfo2(worldu.ptr);
956} 1228}
957 1229
958public override void DumpAllInfo(BulletWorld sim) 1230public override void DumpAllInfo(BulletWorld world)
959{ 1231{
960 BSAPICPP.DumpAllInfo2(sim.ptr); 1232 BulletWorldUnman worldu = world as BulletWorldUnman;
1233 BSAPICPP.DumpAllInfo2(worldu.ptr);
961} 1234}
962 1235
963public override void DumpPhysicsStatistics(BulletWorld sim) 1236public override void DumpPhysicsStatistics(BulletWorld world)
964{ 1237{
965 BSAPICPP.DumpPhysicsStatistics2(sim.ptr); 1238 BulletWorldUnman worldu = world as BulletWorldUnman;
1239 BSAPICPP.DumpPhysicsStatistics2(worldu.ptr);
966} 1240}
967 1241
968 1242
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
index 8ed791e..f70ad30 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
@@ -29,11 +29,1287 @@ using System.Collections.Generic;
29using System.Linq; 29using System.Linq;
30using System.Text; 30using System.Text;
31 31
32using BulletXNA;
33using BulletXNA.LinearMath;
34using BulletXNA.BulletCollision;
35using BulletXNA.BulletDynamics;
36using BulletXNA.BulletCollision.CollisionDispatch;
37
38using OpenMetaverse;
39
32namespace OpenSim.Region.Physics.BulletSPlugin 40namespace OpenSim.Region.Physics.BulletSPlugin
33{ 41{
34 /* 42 /*
35public sealed class BSAPIXNA : BSAPITemplate 43public sealed class BSAPIXNA : BSAPITemplate
36{ 44{
45 private static int m_collisionsThisFrame;
46 private BSScene PhysicsScene { get; set; }
47
48 public override string BulletEngineName { get { return "BulletXNA"; } }
49 public override string BulletEngineVersion { get; protected set; }
50
51 public BSAPIXNA(string paramName, BSScene physScene)
52 {
53 PhysicsScene = physScene;
54 }
55
56 /// <summary>
57 ///
58 /// </summary>
59 /// <param name="p"></param>
60 /// <param name="p_2"></param>
61 public override bool RemoveObjectFromWorld2(object pWorld, object pBody)
62 {
63 DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
64 RigidBody body = pBody as RigidBody;
65 world.RemoveRigidBody(body);
66 return true;
67 }
68
69 public override void SetRestitution2(object pBody, float pRestitution)
70 {
71 RigidBody body = pBody as RigidBody;
72 body.SetRestitution(pRestitution);
73 }
74
75 public override void SetMargin2(object pShape, float pMargin)
76 {
77 CollisionShape shape = pShape as CollisionShape;
78 shape.SetMargin(pMargin);
79 }
80
81 public override void SetLocalScaling2(object pShape, Vector3 pScale)
82 {
83 CollisionShape shape = pShape as CollisionShape;
84 IndexedVector3 vec = new IndexedVector3(pScale.X, pScale.Y, pScale.Z);
85 shape.SetLocalScaling(ref vec);
86
87 }
88
89 public override void SetContactProcessingThreshold2(object pBody, float contactprocessingthreshold)
90 {
91 RigidBody body = pBody as RigidBody;
92 body.SetContactProcessingThreshold(contactprocessingthreshold);
93 }
94
95 public override void SetCcdMotionThreshold2(object pBody, float pccdMotionThreashold)
96 {
97 RigidBody body = pBody as RigidBody;
98 body.SetCcdMotionThreshold(pccdMotionThreashold);
99 }
100
101 public override void SetCcdSweptSphereRadius2(object pBody, float pCcdSweptSphereRadius)
102 {
103 RigidBody body = pBody as RigidBody;
104 body.SetCcdSweptSphereRadius(pCcdSweptSphereRadius);
105 }
106
107 public override void SetAngularFactorV2(object pBody, Vector3 pAngularFactor)
108 {
109 RigidBody body = pBody as RigidBody;
110 body.SetAngularFactor(new IndexedVector3(pAngularFactor.X, pAngularFactor.Y, pAngularFactor.Z));
111 }
112
113 public override CollisionFlags AddToCollisionFlags2(object pBody, CollisionFlags pcollisionFlags)
114 {
115 CollisionObject body = pBody as CollisionObject;
116 CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags();
117 existingcollisionFlags |= pcollisionFlags;
118 body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags);
119 return (CollisionFlags) (uint) existingcollisionFlags;
120 }
121
122 public override void AddObjectToWorld2(object pWorld, object pBody)
123 {
124 RigidBody body = pBody as RigidBody;
125 DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
126 //if (!(body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE && body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE))
127
128 world.AddRigidBody(body);
129
130 //if (body.GetBroadphaseHandle() != null)
131 // world.UpdateSingleAabb(body);
132 }
133
134 public override void AddObjectToWorld2(object pWorld, object pBody, Vector3 _position, Quaternion _orientation)
135 {
136 RigidBody body = pBody as RigidBody;
137 DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
138 //if (!(body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE && body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE))
139
140 world.AddRigidBody(body);
141 IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z);
142 IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z,
143 _orientation.W);
144 IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion);
145 mat._origin = vposition;
146 body.SetWorldTransform(mat);
147 //if (body.GetBroadphaseHandle() != null)
148 // world.UpdateSingleAabb(body);
149 }
150
151 public override void ForceActivationState2(object pBody, ActivationState pActivationState)
152 {
153 CollisionObject body = pBody as CollisionObject;
154 body.ForceActivationState((BulletXNA.BulletCollision.ActivationState)(uint)pActivationState);
155 }
156
157 public override void UpdateSingleAabb2(object pWorld, object pBody)
158 {
159 CollisionObject body = pBody as CollisionObject;
160 DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
161 world.UpdateSingleAabb(body);
162 }
163
164 public override bool SetCollisionGroupMask2(object pBody, uint pGroup, uint pMask)
165 {
166 RigidBody body = pBody as RigidBody;
167 body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup;
168 body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup;
169 if ((uint) body.GetBroadphaseHandle().m_collisionFilterGroup == 0)
170 return false;
171 return true;
172 }
173
174 public override void ClearAllForces2(object pBody)
175 {
176 CollisionObject body = pBody as CollisionObject;
177 IndexedVector3 zeroVector = new IndexedVector3(0, 0, 0);
178 body.SetInterpolationLinearVelocity(ref zeroVector);
179 body.SetInterpolationAngularVelocity(ref zeroVector);
180 IndexedMatrix bodytransform = body.GetWorldTransform();
181
182 body.SetInterpolationWorldTransform(ref bodytransform);
183
184 if (body is RigidBody)
185 {
186 RigidBody rigidbody = body as RigidBody;
187 rigidbody.SetLinearVelocity(zeroVector);
188 rigidbody.SetAngularVelocity(zeroVector);
189 rigidbody.ClearForces();
190 }
191 }
192
193 public override void SetInterpolationAngularVelocity2(object pBody, Vector3 pVector3)
194 {
195 RigidBody body = pBody as RigidBody;
196 IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z);
197 body.SetInterpolationAngularVelocity(ref vec);
198 }
199
200 public override void SetAngularVelocity2(object pBody, Vector3 pVector3)
201 {
202 RigidBody body = pBody as RigidBody;
203 IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z);
204 body.SetAngularVelocity(ref vec);
205 }
206
207 public override void ClearForces2(object pBody)
208 {
209 RigidBody body = pBody as RigidBody;
210 body.ClearForces();
211 }
212
213 public override void SetTranslation2(object pBody, Vector3 _position, Quaternion _orientation)
214 {
215 RigidBody body = pBody as RigidBody;
216 IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z);
217 IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z,
218 _orientation.W);
219 IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion);
220 mat._origin = vposition;
221 body.SetWorldTransform(mat);
222
223 }
224
225 public override Vector3 GetPosition2(object pBody)
226 {
227 RigidBody body = pBody as RigidBody;
228 IndexedVector3 pos = body.GetInterpolationWorldTransform()._origin;
229 return new Vector3(pos.X, pos.Y, pos.Z);
230 }
231
232 public override Vector3 CalculateLocalInertia2(object pShape, float pphysMass)
233 {
234 CollisionShape shape = pShape as CollisionShape;
235 IndexedVector3 inertia = IndexedVector3.Zero;
236 shape.CalculateLocalInertia(pphysMass, out inertia);
237 return new Vector3(inertia.X, inertia.Y, inertia.Z);
238 }
239
240 public override void SetMassProps2(object pBody, float pphysMass, Vector3 plocalInertia)
241 {
242 RigidBody body = pBody as RigidBody;
243 IndexedVector3 inertia = new IndexedVector3(plocalInertia.X, plocalInertia.Y, plocalInertia.Z);
244 body.SetMassProps(pphysMass, inertia);
245 }
246
247
248 public override void SetObjectForce2(object pBody, Vector3 _force)
249 {
250 RigidBody body = pBody as RigidBody;
251 IndexedVector3 force = new IndexedVector3(_force.X, _force.Y, _force.Z);
252 body.SetTotalForce(ref force);
253 }
254
255 public override void SetFriction2(object pBody, float _currentFriction)
256 {
257 RigidBody body = pBody as RigidBody;
258 body.SetFriction(_currentFriction);
259 }
260
261 public override void SetLinearVelocity2(object pBody, Vector3 _velocity)
262 {
263 RigidBody body = pBody as RigidBody;
264 IndexedVector3 velocity = new IndexedVector3(_velocity.X, _velocity.Y, _velocity.Z);
265 body.SetLinearVelocity(velocity);
266 }
267
268 public override void Activate2(object pBody, bool pforceactivation)
269 {
270 RigidBody body = pBody as RigidBody;
271 body.Activate(pforceactivation);
272
273 }
274
275 public override Quaternion GetOrientation2(object pBody)
276 {
277 RigidBody body = pBody as RigidBody;
278 IndexedQuaternion mat = body.GetInterpolationWorldTransform().GetRotation();
279 return new Quaternion(mat.X, mat.Y, mat.Z, mat.W);
280 }
281
282 public override CollisionFlags RemoveFromCollisionFlags2(object pBody, CollisionFlags pcollisionFlags)
283 {
284 RigidBody body = pBody as RigidBody;
285 CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags();
286 existingcollisionFlags &= ~pcollisionFlags;
287 body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags);
288 return (CollisionFlags)(uint)existingcollisionFlags;
289 }
290
291 public override void SetGravity2(object pBody, Vector3 pGravity)
292 {
293 RigidBody body = pBody as RigidBody;
294 IndexedVector3 gravity = new IndexedVector3(pGravity.X, pGravity.Y, pGravity.Z);
295 body.SetGravity(gravity);
296 }
297
298 public override bool DestroyConstraint2(object pBody, object pConstraint)
299 {
300 RigidBody body = pBody as RigidBody;
301 TypedConstraint constraint = pConstraint as TypedConstraint;
302 body.RemoveConstraintRef(constraint);
303 return true;
304 }
305
306 public override bool SetLinearLimits2(object pConstraint, Vector3 low, Vector3 high)
307 {
308 Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
309 IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z);
310 IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z);
311 constraint.SetLinearLowerLimit(lowlimit);
312 constraint.SetLinearUpperLimit(highlimit);
313 return true;
314 }
315
316 public override bool SetAngularLimits2(object pConstraint, Vector3 low, Vector3 high)
317 {
318 Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
319 IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z);
320 IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z);
321 constraint.SetAngularLowerLimit(lowlimit);
322 constraint.SetAngularUpperLimit(highlimit);
323 return true;
324 }
325
326 public override void SetConstraintNumSolverIterations2(object pConstraint, float cnt)
327 {
328 Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
329 constraint.SetOverrideNumSolverIterations((int)cnt);
330 }
331
332 public override void CalculateTransforms2(object pConstraint)
333 {
334 Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
335 constraint.CalculateTransforms();
336 }
337
338 public override void SetConstraintEnable2(object pConstraint, float p_2)
339 {
340 Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
341 constraint.SetEnabled((p_2 == 0) ? false : true);
342 }
343
344
345 //BulletSimAPI.Create6DofConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr,frame1, frame1rot,frame2, frame2rot,useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
346 public override object Create6DofConstraint2(object pWorld, object pBody1, object pBody2, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
347
348 {
349 DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
350 RigidBody body1 = pBody1 as RigidBody;
351 RigidBody body2 = pBody2 as RigidBody;
352 IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
353 IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
354 IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
355 frame1._origin = frame1v;
356
357 IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z);
358 IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W);
359 IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot);
360 frame2._origin = frame1v;
361
362 Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2,
363 puseLinearReferenceFrameA);
364 consttr.CalculateTransforms();
365 world.AddConstraint(consttr,pdisableCollisionsBetweenLinkedBodies);
366
367 return consttr;
368 }
369
370
371 /// <summary>
372 ///
373 /// </summary>
374 /// <param name="pWorld"></param>
375 /// <param name="pBody1"></param>
376 /// <param name="pBody2"></param>
377 /// <param name="pjoinPoint"></param>
378 /// <param name="puseLinearReferenceFrameA"></param>
379 /// <param name="pdisableCollisionsBetweenLinkedBodies"></param>
380 /// <returns></returns>
381 public override object Create6DofConstraintToPoint2(object pWorld, object pBody1, object pBody2, Vector3 pjoinPoint, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
382 {
383 DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
384 RigidBody body1 = pBody1 as RigidBody;
385 RigidBody body2 = pBody2 as RigidBody;
386 IndexedMatrix frame1 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));
387 IndexedMatrix frame2 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));
388
389 IndexedVector3 joinPoint = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
390 IndexedMatrix mat = IndexedMatrix.Identity;
391 mat._origin = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
392 frame1._origin = body1.GetWorldTransform().Inverse()*joinPoint;
393 frame2._origin = body2.GetWorldTransform().Inverse()*joinPoint;
394
395 Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2, puseLinearReferenceFrameA);
396 consttr.CalculateTransforms();
397 world.AddConstraint(consttr, pdisableCollisionsBetweenLinkedBodies);
398
399 return consttr;
400 }
401 //SetFrames2(m_constraint.ptr, frameA, frameArot, frameB, frameBrot);
402 public override void SetFrames2(object pConstraint, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot)
403 {
404 Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
405 IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
406 IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
407 IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
408 frame1._origin = frame1v;
409
410 IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z);
411 IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W);
412 IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot);
413 frame2._origin = frame1v;
414 constraint.SetFrames(ref frame1, ref frame2);
415 }
416
417
418
419
420 public override bool IsInWorld2(object pWorld, object pShapeObj)
421 {
422 DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
423 CollisionObject shape = pShapeObj as CollisionObject;
424 return world.IsInWorld(shape);
425 }
426
427 public override void SetInterpolationLinearVelocity2(object pBody, Vector3 VehicleVelocity)
428 {
429 RigidBody body = pBody as RigidBody;
430 IndexedVector3 velocity = new IndexedVector3(VehicleVelocity.X, VehicleVelocity.Y, VehicleVelocity.Z);
431 body.SetInterpolationLinearVelocity(ref velocity);
432 }
433
434 public override bool UseFrameOffset2(object pConstraint, float onOff)
435 {
436 Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
437 constraint.SetUseFrameOffset((onOff == 0) ? false : true);
438 return true;
439 }
440 //SetBreakingImpulseThreshold2(m_constraint.ptr, threshold);
441 public override bool SetBreakingImpulseThreshold2(object pConstraint, float threshold)
442 {
443 Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
444 constraint.SetBreakingImpulseThreshold(threshold);
445 return true;
446 }
447 //BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping);
448 public override void SetAngularDamping2(object pBody, float angularDamping)
449 {
450 RigidBody body = pBody as RigidBody;
451 float lineardamping = body.GetLinearDamping();
452 body.SetDamping(lineardamping, angularDamping);
453
454 }
455
456 public override void UpdateInertiaTensor2(object pBody)
457 {
458 RigidBody body = pBody as RigidBody;
459 body.UpdateInertiaTensor();
460 }
461
462 public override void RecalculateCompoundShapeLocalAabb2( object pCompoundShape)
463 {
464
465 CompoundShape shape = pCompoundShape as CompoundShape;
466 shape.RecalculateLocalAabb();
467 }
468
469 //BulletSimAPI.GetCollisionFlags2(PhysBody.ptr)
470 public override CollisionFlags GetCollisionFlags2(object pBody)
471 {
472 RigidBody body = pBody as RigidBody;
473 uint flags = (uint)body.GetCollisionFlags();
474 return (CollisionFlags) flags;
475 }
476
477 public override void SetDamping2(object pBody, float pLinear, float pAngular)
478 {
479 RigidBody body = pBody as RigidBody;
480 body.SetDamping(pLinear, pAngular);
481 }
482 //PhysBody.ptr, PhysicsScene.Params.deactivationTime);
483 public override void SetDeactivationTime2(object pBody, float pDeactivationTime)
484 {
485 RigidBody body = pBody as RigidBody;
486 body.SetDeactivationTime(pDeactivationTime);
487 }
488 //SetSleepingThresholds2(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold);
489 public override void SetSleepingThresholds2(object pBody, float plinearSleepingThreshold, float pangularSleepingThreshold)
490 {
491 RigidBody body = pBody as RigidBody;
492 body.SetSleepingThresholds(plinearSleepingThreshold, pangularSleepingThreshold);
493 }
494
495 public override CollisionObjectTypes GetBodyType2(object pBody)
496 {
497 RigidBody body = pBody as RigidBody;
498 return (CollisionObjectTypes)(int) body.GetInternalType();
499 }
500
501 //BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum);
502 public override void ApplyCentralForce2(object pBody, Vector3 pfSum)
503 {
504 RigidBody body = pBody as RigidBody;
505 IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
506 body.ApplyCentralForce(ref fSum);
507 }
508 public override void ApplyCentralImpulse2(object pBody, Vector3 pfSum)
509 {
510 RigidBody body = pBody as RigidBody;
511 IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
512 body.ApplyCentralImpulse(ref fSum);
513 }
514 public override void ApplyTorque2(object pBody, Vector3 pfSum)
515 {
516 RigidBody body = pBody as RigidBody;
517 IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
518 body.ApplyTorque(ref fSum);
519 }
520 public override void ApplyTorqueImpulse2(object pBody, Vector3 pfSum)
521 {
522 RigidBody body = pBody as RigidBody;
523 IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
524 body.ApplyTorqueImpulse(ref fSum);
525 }
526
527 public override void DumpRigidBody2(object p, object p_2)
528 {
529 //TODO:
530 }
531
532 public override void DumpCollisionShape2(object p, object p_2)
533 {
534 //TODO:
535 }
536
537 public override void DestroyObject2(object p, object p_2)
538 {
539 //TODO:
540 }
541
542 public override void Shutdown2(object pWorld)
543 {
544 DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
545 world.Cleanup();
546 }
547
548 public override void DeleteCollisionShape2(object p, object p_2)
549 {
550 //TODO:
551 }
552 //(sim.ptr, shape.ptr, prim.LocalID, prim.RawPosition, prim.RawOrientation);
553
554 public override object CreateBodyFromShape2(object pWorld, object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
555 {
556 CollisionWorld world = pWorld as CollisionWorld;
557 IndexedMatrix mat =
558 IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
559 pRawOrientation.Z, pRawOrientation.W));
560 mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
561 CollisionShape shape = pShape as CollisionShape;
562 //UpdateSingleAabb2(world, shape);
563 // TODO: Feed Update array into null
564 RigidBody body = new RigidBody(0,new SimMotionState(world,pLocalID,mat,null),shape,IndexedVector3.Zero);
565
566 body.SetUserPointer(pLocalID);
567 return body;
568 }
569
570
571 public override object CreateBodyWithDefaultMotionState2( object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
572 {
573
574 IndexedMatrix mat =
575 IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
576 pRawOrientation.Z, pRawOrientation.W));
577 mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
578
579 CollisionShape shape = pShape as CollisionShape;
580
581 // TODO: Feed Update array into null
582 RigidBody body = new RigidBody(0, new DefaultMotionState( mat, IndexedMatrix.Identity), shape, IndexedVector3.Zero);
583 body.SetWorldTransform(mat);
584 body.SetUserPointer(pLocalID);
585 return body;
586 }
587 //(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
588 public override void SetCollisionFlags2(object pBody, CollisionFlags collisionFlags)
589 {
590 RigidBody body = pBody as RigidBody;
591 body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags) (uint) collisionFlags);
592 }
593 //(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainHitFraction);
594 public override void SetHitFraction2(object pBody, float pHitFraction)
595 {
596 RigidBody body = pBody as RigidBody;
597 body.SetHitFraction(pHitFraction);
598 }
599 //BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale);
600 public override object BuildCapsuleShape2(object pWorld, float pRadius, float pHeight, Vector3 pScale)
601 {
602 DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
603 IndexedVector3 scale = new IndexedVector3(pScale.X, pScale.Y, pScale.Z);
604 CapsuleShapeZ capsuleShapeZ = new CapsuleShapeZ(pRadius, pHeight);
605 capsuleShapeZ.SetMargin(world.WorldSettings.Params.collisionMargin);
606 capsuleShapeZ.SetLocalScaling(ref scale);
607
608 return capsuleShapeZ;
609 }
610
611 public static object Initialize2(Vector3 worldExtent, ConfigurationParameters[] o, int mMaxCollisionsPerFrame, ref List<BulletXNA.CollisionDesc> collisionArray, int mMaxUpdatesPerFrame, ref List<BulletXNA.EntityProperties> updateArray, object mDebugLogCallbackHandle)
612 {
613 CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData();
614
615 p.angularDamping = o[0].XangularDamping;
616 p.defaultFriction = o[0].defaultFriction;
617 p.defaultFriction = o[0].defaultFriction;
618 p.defaultDensity = o[0].defaultDensity;
619 p.defaultRestitution = o[0].defaultRestitution;
620 p.collisionMargin = o[0].collisionMargin;
621 p.gravity = o[0].gravity;
622
623 p.linearDamping = o[0].XlinearDamping;
624 p.angularDamping = o[0].XangularDamping;
625 p.deactivationTime = o[0].XdeactivationTime;
626 p.linearSleepingThreshold = o[0].XlinearSleepingThreshold;
627 p.angularSleepingThreshold = o[0].XangularSleepingThreshold;
628 p.ccdMotionThreshold = o[0].XccdMotionThreshold;
629 p.ccdSweptSphereRadius = o[0].XccdSweptSphereRadius;
630 p.contactProcessingThreshold = o[0].XcontactProcessingThreshold;
631
632 p.terrainImplementation = o[0].XterrainImplementation;
633 p.terrainFriction = o[0].XterrainFriction;
634
635 p.terrainHitFraction = o[0].XterrainHitFraction;
636 p.terrainRestitution = o[0].XterrainRestitution;
637 p.terrainCollisionMargin = o[0].XterrainCollisionMargin;
638
639 p.avatarFriction = o[0].XavatarFriction;
640 p.avatarStandingFriction = o[0].XavatarStandingFriction;
641 p.avatarDensity = o[0].XavatarDensity;
642 p.avatarRestitution = o[0].XavatarRestitution;
643 p.avatarCapsuleWidth = o[0].XavatarCapsuleWidth;
644 p.avatarCapsuleDepth = o[0].XavatarCapsuleDepth;
645 p.avatarCapsuleHeight = o[0].XavatarCapsuleHeight;
646 p.avatarContactProcessingThreshold = o[0].XavatarContactProcessingThreshold;
647
648 p.vehicleAngularDamping = o[0].XvehicleAngularDamping;
649
650 p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize;
651 p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize;
652 p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation;
653 p.shouldForceUpdateAllAabbs = o[0].shouldForceUpdateAllAabbs;
654 p.shouldRandomizeSolverOrder = o[0].shouldRandomizeSolverOrder;
655 p.shouldSplitSimulationIslands = o[0].shouldSplitSimulationIslands;
656 p.shouldEnableFrictionCaching = o[0].shouldEnableFrictionCaching;
657 p.numberOfSolverIterations = o[0].numberOfSolverIterations;
658
659 p.linksetImplementation = o[0].XlinksetImplementation;
660 p.linkConstraintUseFrameOffset = o[0].XlinkConstraintUseFrameOffset;
661 p.linkConstraintEnableTransMotor = o[0].XlinkConstraintEnableTransMotor;
662 p.linkConstraintTransMotorMaxVel = o[0].XlinkConstraintTransMotorMaxVel;
663 p.linkConstraintTransMotorMaxForce = o[0].XlinkConstraintTransMotorMaxForce;
664 p.linkConstraintERP = o[0].XlinkConstraintERP;
665 p.linkConstraintCFM = o[0].XlinkConstraintCFM;
666 p.linkConstraintSolverIterations = o[0].XlinkConstraintSolverIterations;
667 p.physicsLoggingFrames = o[0].physicsLoggingFrames;
668 DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo();
669
670 DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration();
671 CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci);
672
673
674 if (p.maxPersistantManifoldPoolSize > 0)
675 cci.m_persistentManifoldPoolSize = (int)p.maxPersistantManifoldPoolSize;
676 if (p.shouldDisableContactPoolDynamicAllocation !=0)
677 m_dispatcher.SetDispatcherFlags(DispatcherFlags.CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION);
678 //if (p.maxCollisionAlgorithmPoolSize >0 )
679
680 DbvtBroadphase m_broadphase = new DbvtBroadphase();
681 //IndexedVector3 aabbMin = new IndexedVector3(0, 0, 0);
682 //IndexedVector3 aabbMax = new IndexedVector3(256, 256, 256);
683
684 //AxisSweep3Internal m_broadphase2 = new AxisSweep3Internal(ref aabbMin, ref aabbMax, Convert.ToInt32(0xfffe), 0xffff, ushort.MaxValue/2, null, true);
685 m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback());
686
687 SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver();
688
689 DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci);
690 world.UpdatedObjects = updateArray;
691 world.UpdatedCollisions = collisionArray;
692 world.WorldSettings.Params = p;
693 world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0);
694 world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD;
695 if (p.shouldRandomizeSolverOrder != 0)
696 world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_RANDMIZE_ORDER;
697
698 world.GetSimulationIslandManager().SetSplitIslands(p.shouldSplitSimulationIslands != 0);
699 //world.GetDispatchInfo().m_enableSatConvex Not implemented in C# port
700
701 if (p.shouldEnableFrictionCaching != 0)
702 world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_ENABLE_FRICTION_DIRECTION_CACHING;
703
704 if (p.numberOfSolverIterations > 0)
705 world.GetSolverInfo().m_numIterations = (int) p.numberOfSolverIterations;
706
707
708 world.GetSolverInfo().m_damping = world.WorldSettings.Params.linearDamping;
709 world.GetSolverInfo().m_restitution = world.WorldSettings.Params.defaultRestitution;
710 world.GetSolverInfo().m_globalCfm = 0.0f;
711 world.GetSolverInfo().m_tau = 0.6f;
712 world.GetSolverInfo().m_friction = 0.3f;
713 world.GetSolverInfo().m_maxErrorReduction = 20f;
714 world.GetSolverInfo().m_numIterations = 10;
715 world.GetSolverInfo().m_erp = 0.2f;
716 world.GetSolverInfo().m_erp2 = 0.1f;
717 world.GetSolverInfo().m_sor = 1.0f;
718 world.GetSolverInfo().m_splitImpulse = false;
719 world.GetSolverInfo().m_splitImpulsePenetrationThreshold = -0.02f;
720 world.GetSolverInfo().m_linearSlop = 0.0f;
721 world.GetSolverInfo().m_warmstartingFactor = 0.85f;
722 world.GetSolverInfo().m_restingContactRestitutionThreshold = 2;
723 world.SetForceUpdateAllAabbs(true);
724
725
726 world.SetGravity(new IndexedVector3(0,0,p.gravity));
727
728 return world;
729 }
730 //m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL
731 public override bool SetConstraintParam2(object pConstraint, ConstraintParams paramIndex, float paramvalue, ConstraintParamAxis axis)
732 {
733 Generic6DofConstraint constrain = pConstraint as Generic6DofConstraint;
734 if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL || axis == ConstraintParamAxis.AXIS_ALL)
735 {
736 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 0);
737 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 1);
738 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 2);
739 }
740 if (axis == ConstraintParamAxis.AXIS_ANGULAR_ALL || axis == ConstraintParamAxis.AXIS_ALL)
741 {
742 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 3);
743 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 4);
744 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 5);
745 }
746 if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL)
747 {
748 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, (int)axis);
749 }
750 return true;
751 }
752
753 public override bool PushUpdate2(object pCollisionObject)
754 {
755 bool ret = false;
756 RigidBody rb = pCollisionObject as RigidBody;
757 if (rb != null)
758 {
759 SimMotionState sms = rb.GetMotionState() as SimMotionState;
760 if (sms != null)
761 {
762 IndexedMatrix wt = IndexedMatrix.Identity;
763 sms.GetWorldTransform(out wt);
764 sms.SetWorldTransform(ref wt, true);
765 ret = true;
766 }
767 }
768 return ret;
769
770 }
771
772 public override bool IsCompound2(object pShape)
773 {
774 CollisionShape shape = pShape as CollisionShape;
775 return shape.IsCompound();
776 }
777 public override bool IsPloyhedral2(object pShape)
778 {
779 CollisionShape shape = pShape as CollisionShape;
780 return shape.IsPolyhedral();
781 }
782 public override bool IsConvex2d2(object pShape)
783 {
784 CollisionShape shape = pShape as CollisionShape;
785 return shape.IsConvex2d();
786 }
787 public override bool IsConvex2(object pShape)
788 {
789 CollisionShape shape = pShape as CollisionShape;
790 return shape.IsConvex();
791 }
792 public override bool IsNonMoving2(object pShape)
793 {
794 CollisionShape shape = pShape as CollisionShape;
795 return shape.IsNonMoving();
796 }
797 public override bool IsConcave2(object pShape)
798 {
799 CollisionShape shape = pShape as CollisionShape;
800 return shape.IsConcave();
801 }
802 public override bool IsInfinite2(object pShape)
803 {
804 CollisionShape shape = pShape as CollisionShape;
805 return shape.IsInfinite();
806 }
807 public override bool IsNativeShape2(object pShape)
808 {
809 CollisionShape shape = pShape as CollisionShape;
810 bool ret;
811 switch (shape.GetShapeType())
812 {
813 case BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE:
814 case BroadphaseNativeTypes.CONE_SHAPE_PROXYTYPE:
815 case BroadphaseNativeTypes.SPHERE_SHAPE_PROXYTYPE:
816 case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE:
817 ret = true;
818 break;
819 default:
820 ret = false;
821 break;
822 }
823 return ret;
824 }
825 //sim.ptr, shape.ptr,prim.LocalID, prim.RawPosition, prim.RawOrientation
826 public override object CreateGhostFromShape2(object pWorld, object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
827 {
828 IndexedMatrix bodyTransform = new IndexedMatrix();
829 bodyTransform._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
830 bodyTransform.SetRotation(new IndexedQuaternion(pRawOrientation.X,pRawOrientation.Y,pRawOrientation.Z,pRawOrientation.W));
831 GhostObject gObj = new PairCachingGhostObject();
832 gObj.SetWorldTransform(bodyTransform);
833 CollisionShape shape = pShape as CollisionShape;
834 gObj.SetCollisionShape(shape);
835 gObj.SetUserPointer(pLocalID);
836 // TODO: Add to Special CollisionObjects!
837 return gObj;
838 }
839
840 public static void SetCollisionShape2(object pWorld, object pObj, object pShape)
841 {
842 var world = pWorld as DiscreteDynamicsWorld;
843 var obj = pObj as CollisionObject;
844 var shape = pShape as CollisionShape;
845 obj.SetCollisionShape(shape);
846
847 }
848 //(PhysicsScene.World.ptr, nativeShapeData)
849 public override object BuildNativeShape2(object pWorld, ShapeData pShapeData)
850 {
851 var world = pWorld as DiscreteDynamicsWorld;
852 CollisionShape shape = null;
853 switch (pShapeData.Type)
854 {
855 case BSPhysicsShapeType.SHAPE_BOX:
856 shape = new BoxShape(new IndexedVector3(0.5f,0.5f,0.5f));
857 break;
858 case BSPhysicsShapeType.SHAPE_CONE:
859 shape = new ConeShapeZ(0.5f, 1.0f);
860 break;
861 case BSPhysicsShapeType.SHAPE_CYLINDER:
862 shape = new CylinderShapeZ(new IndexedVector3(0.5f, 0.5f, 0.5f));
863 break;
864 case BSPhysicsShapeType.SHAPE_SPHERE:
865 shape = new SphereShape(0.5f);
866 break;
867
868 }
869 if (shape != null)
870 {
871 IndexedVector3 scaling = new IndexedVector3(pShapeData.Scale.X, pShapeData.Scale.Y, pShapeData.Scale.Z);
872 shape.SetMargin(world.WorldSettings.Params.collisionMargin);
873 shape.SetLocalScaling(ref scaling);
874
875 }
876 return shape;
877 }
878 //PhysicsScene.World.ptr, false
879 public override object CreateCompoundShape2(object pWorld, bool enableDynamicAabbTree)
880 {
881 return new CompoundShape(enableDynamicAabbTree);
882 }
883
884 public override int GetNumberOfCompoundChildren2(object pCompoundShape)
885 {
886 var compoundshape = pCompoundShape as CompoundShape;
887 return compoundshape.GetNumChildShapes();
888 }
889 //LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot
890 public override void AddChildShapeToCompoundShape2(object pCShape, object paddShape, Vector3 displacementPos, Quaternion displacementRot)
891 {
892 IndexedMatrix relativeTransform = new IndexedMatrix();
893 var compoundshape = pCShape as CompoundShape;
894 var addshape = paddShape as CollisionShape;
895
896 relativeTransform._origin = new IndexedVector3(displacementPos.X, displacementPos.Y, displacementPos.Z);
897 relativeTransform.SetRotation(new IndexedQuaternion(displacementRot.X,displacementRot.Y,displacementRot.Z,displacementRot.W));
898 compoundshape.AddChildShape(ref relativeTransform, addshape);
899
900 }
901
902 public override object RemoveChildShapeFromCompoundShapeIndex2(object pCShape, int pii)
903 {
904 var compoundshape = pCShape as CompoundShape;
905 CollisionShape ret = null;
906 ret = compoundshape.GetChildShape(pii);
907 compoundshape.RemoveChildShapeByIndex(pii);
908 return ret;
909 }
910
911 public override object CreateGroundPlaneShape2(uint pLocalId, float pheight, float pcollisionMargin)
912 {
913 StaticPlaneShape m_planeshape = new StaticPlaneShape(new IndexedVector3(0,0,1),(int)pheight );
914 m_planeshape.SetMargin(pcollisionMargin);
915 m_planeshape.SetUserPointer(pLocalId);
916 return m_planeshape;
917 }
918
919 public override object CreateHingeConstraint2(object pWorld, object pBody1, object ppBody2, Vector3 ppivotInA, Vector3 ppivotInB, Vector3 paxisInA, Vector3 paxisInB, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
920 {
921 HingeConstraint constrain = null;
922 var rb1 = pBody1 as RigidBody;
923 var rb2 = ppBody2 as RigidBody;
924 if (rb1 != null && rb2 != null)
925 {
926 IndexedVector3 pivotInA = new IndexedVector3(ppivotInA.X, ppivotInA.Y, ppivotInA.Z);
927 IndexedVector3 pivotInB = new IndexedVector3(ppivotInB.X, ppivotInB.Y, ppivotInB.Z);
928 IndexedVector3 axisInA = new IndexedVector3(paxisInA.X, paxisInA.Y, paxisInA.Z);
929 IndexedVector3 axisInB = new IndexedVector3(paxisInB.X, paxisInB.Y, paxisInB.Z);
930 var world = pWorld as DiscreteDynamicsWorld;
931 world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies);
932 }
933 return constrain;
934 }
935
936 public override bool ReleaseHeightMapInfo2(object pMapInfo)
937 {
938 if (pMapInfo != null)
939 {
940 BulletHeightMapInfo mapinfo = pMapInfo as BulletHeightMapInfo;
941 if (mapinfo.heightMap != null)
942 mapinfo.heightMap = null;
943
944
945 }
946 return true;
947 }
948
949 public override object CreateHullShape2(object pWorld, int pHullCount, float[] pConvHulls)
950 {
951 CompoundShape compoundshape = new CompoundShape(false);
952 var world = pWorld as DiscreteDynamicsWorld;
953
954
955 compoundshape.SetMargin(world.WorldSettings.Params.collisionMargin);
956 int ii = 1;
957
958 for (int i = 0; i < pHullCount; i++)
959 {
960 int vertexCount = (int) pConvHulls[ii];
961
962 IndexedVector3 centroid = new IndexedVector3(pConvHulls[ii + 1], pConvHulls[ii + 2], pConvHulls[ii + 3]);
963 IndexedMatrix childTrans = IndexedMatrix.Identity;
964 childTrans._origin = centroid;
965
966 List<IndexedVector3> virts = new List<IndexedVector3>();
967 int ender = ((ii + 4) + (vertexCount*3));
968 for (int iii = ii + 4; iii < ender; iii+=3)
969 {
970
971 virts.Add(new IndexedVector3(pConvHulls[iii], pConvHulls[iii + 1], pConvHulls[iii +2]));
972 }
973 ConvexHullShape convexShape = new ConvexHullShape(virts, vertexCount);
974 convexShape.SetMargin(world.WorldSettings.Params.collisionMargin);
975 compoundshape.AddChildShape(ref childTrans, convexShape);
976 ii += (vertexCount*3 + 4);
977 }
978
979
980 return compoundshape;
981 }
982
983 public override object CreateMeshShape2(object pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats)
984 {
985 //DumpRaw(indices,verticesAsFloats,pIndicesCount,pVerticesCount);
986
987 for (int iter = 0; iter < pVerticesCount; iter++)
988 {
989 if (verticesAsFloats[iter] > 0 && verticesAsFloats[iter] < 0.0001) verticesAsFloats[iter] = 0;
990 if (verticesAsFloats[iter] < 0 && verticesAsFloats[iter] > -0.0001) verticesAsFloats[iter] = 0;
991 }
992
993 ObjectArray<int> indicesarr = new ObjectArray<int>(indices);
994 ObjectArray<float> vertices = new ObjectArray<float>(verticesAsFloats);
995 DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount);
996 var world = pWorld as DiscreteDynamicsWorld;
997 IndexedMesh mesh = new IndexedMesh();
998 mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
999 mesh.m_numTriangles = pIndicesCount/3;
1000 mesh.m_numVertices = pVerticesCount;
1001 mesh.m_triangleIndexBase = indicesarr;
1002 mesh.m_vertexBase = vertices;
1003 mesh.m_vertexStride = 3;
1004 mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
1005 mesh.m_triangleIndexStride = 3;
1006
1007 TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
1008 tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
1009 BvhTriangleMeshShape meshShape = new BvhTriangleMeshShape(tribuilder, true,true);
1010 meshShape.SetMargin(world.WorldSettings.Params.collisionMargin);
1011 // world.UpdateSingleAabb(meshShape);
1012 return meshShape;
1013
1014 }
1015 public static void DumpRaw(ObjectArray<int>indices, ObjectArray<float> vertices, int pIndicesCount,int pVerticesCount )
1016 {
1017
1018 String fileName = "objTest3.raw";
1019 String completePath = System.IO.Path.Combine(Util.configDir(), fileName);
1020 StreamWriter sw = new StreamWriter(completePath);
1021 IndexedMesh mesh = new IndexedMesh();
1022
1023 mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
1024 mesh.m_numTriangles = pIndicesCount / 3;
1025 mesh.m_numVertices = pVerticesCount;
1026 mesh.m_triangleIndexBase = indices;
1027 mesh.m_vertexBase = vertices;
1028 mesh.m_vertexStride = 3;
1029 mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
1030 mesh.m_triangleIndexStride = 3;
1031
1032 TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
1033 tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
1034
1035
1036
1037 for (int i = 0; i < pVerticesCount; i++)
1038 {
1039
1040 string s = vertices[indices[i * 3]].ToString("0.0000");
1041 s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000");
1042 s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000");
1043
1044 sw.Write(s + "\n");
1045 }
1046
1047 sw.Close();
1048 }
1049 public static void DumpRaw(int[] indices, float[] vertices, int pIndicesCount, int pVerticesCount)
1050 {
1051
1052 String fileName = "objTest6.raw";
1053 String completePath = System.IO.Path.Combine(Util.configDir(), fileName);
1054 StreamWriter sw = new StreamWriter(completePath);
1055 IndexedMesh mesh = new IndexedMesh();
1056
1057 mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
1058 mesh.m_numTriangles = pIndicesCount / 3;
1059 mesh.m_numVertices = pVerticesCount;
1060 mesh.m_triangleIndexBase = indices;
1061 mesh.m_vertexBase = vertices;
1062 mesh.m_vertexStride = 3;
1063 mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
1064 mesh.m_triangleIndexStride = 3;
1065
1066 TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
1067 tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
1068
1069
1070 sw.WriteLine("Indices");
1071 sw.WriteLine(string.Format("int[] indices = new int[{0}];",pIndicesCount));
1072 for (int iter = 0; iter < indices.Length; iter++)
1073 {
1074 sw.WriteLine(string.Format("indices[{0}]={1};",iter,indices[iter]));
1075 }
1076 sw.WriteLine("VerticesFloats");
1077 sw.WriteLine(string.Format("float[] vertices = new float[{0}];", pVerticesCount));
1078 for (int iter = 0; iter < vertices.Length; iter++)
1079 {
1080 sw.WriteLine(string.Format("Vertices[{0}]={1};", iter, vertices[iter].ToString("0.0000")));
1081 }
1082
1083 // for (int i = 0; i < pVerticesCount; i++)
1084 // {
1085 //
1086 // string s = vertices[indices[i * 3]].ToString("0.0000");
1087 // s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000");
1088 // s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000");
1089 //
1090 // sw.Write(s + "\n");
1091 //}
1092
1093 sw.Close();
1094 }
1095 //PhysicsScene.World.ptr, m_mapInfo.ID, m_mapInfo.minCoords, m_mapInfo.maxCoords, m_mapInfo.heightMap, PhysicsScene.Params.terrainCollisionMargin
1096 public override object CreateHeightMapInfo2(object pWorld, uint pId, Vector3 pminCoords, Vector3 pmaxCoords, float[] pheightMap, float pCollisionMargin)
1097 {
1098 BulletHeightMapInfo mapInfo = new BulletHeightMapInfo(pId, pheightMap, null);
1099 mapInfo.heightMap = null;
1100 mapInfo.minCoords = pminCoords;
1101 mapInfo.maxCoords = pmaxCoords;
1102 mapInfo.sizeX = (int) (pmaxCoords.X - pminCoords.X);
1103 mapInfo.sizeY = (int) (pmaxCoords.Y - pminCoords.Y);
1104 mapInfo.ID = pId;
1105 mapInfo.minZ = pminCoords.Z;
1106 mapInfo.maxZ = pmaxCoords.Z;
1107 mapInfo.collisionMargin = pCollisionMargin;
1108 if (mapInfo.minZ == mapInfo.maxZ)
1109 mapInfo.minZ -= 0.2f;
1110 mapInfo.heightMap = pheightMap;
1111
1112 return mapInfo;
1113
1114 }
1115
1116 public override object CreateTerrainShape2(object pMapInfo)
1117 {
1118 BulletHeightMapInfo mapinfo = pMapInfo as BulletHeightMapInfo;
1119 const int upAxis = 2;
1120 const float scaleFactor = 1.0f;
1121 HeightfieldTerrainShape terrainShape = new HeightfieldTerrainShape((int)mapinfo.sizeX, (int)mapinfo.sizeY,
1122 mapinfo.heightMap, scaleFactor,
1123 mapinfo.minZ, mapinfo.maxZ, upAxis,
1124 false);
1125 terrainShape.SetMargin(mapinfo.collisionMargin + 0.5f);
1126 terrainShape.SetUseDiamondSubdivision(true);
1127 terrainShape.SetUserPointer(mapinfo.ID);
1128 return terrainShape;
1129 }
1130
1131 public override bool TranslationalLimitMotor2(object pConstraint, float ponOff, float targetVelocity, float maxMotorForce)
1132 {
1133 TypedConstraint tconstrain = pConstraint as TypedConstraint;
1134 bool onOff = ponOff != 0;
1135 bool ret = false;
1136
1137 switch (tconstrain.GetConstraintType())
1138 {
1139 case TypedConstraintType.D6_CONSTRAINT_TYPE:
1140 Generic6DofConstraint constrain = pConstraint as Generic6DofConstraint;
1141 constrain.GetTranslationalLimitMotor().m_enableMotor[0] = onOff;
1142 constrain.GetTranslationalLimitMotor().m_targetVelocity[0] = targetVelocity;
1143 constrain.GetTranslationalLimitMotor().m_maxMotorForce[0] = maxMotorForce;
1144 ret = true;
1145 break;
1146 }
1147
1148
1149 return ret;
1150
1151 }
1152
1153 public override int PhysicsStep2(object pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, out List<BulletXNA.EntityProperties> updatedEntities, out int collidersCount, out List<BulletXNA.CollisionDesc>colliders)
1154 {
1155 int epic = PhysicsStepint2(pWorld, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out updatedEntities,
1156 out collidersCount, out colliders);
1157 return epic;
1158 }
1159
1160 private static int PhysicsStepint2(object pWorld,float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, out List<BulletXNA.EntityProperties> updatedEntities, out int collidersCount, out List<BulletXNA.CollisionDesc> colliders)
1161 {
1162 int numSimSteps = 0;
1163
1164
1165 //if (updatedEntities is null)
1166 // updatedEntities = new List<BulletXNA.EntityProperties>();
1167
1168 //if (colliders is null)
1169 // colliders = new List<BulletXNA.CollisionDesc>();
1170
1171
1172 if (pWorld is DiscreteDynamicsWorld)
1173 {
1174 DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
1175
1176 numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep);
1177 int updates = 0;
1178
1179 updatedEntityCount = world.UpdatedObjects.Count;
1180 updatedEntities = new List<BulletXNA.EntityProperties>(world.UpdatedObjects);
1181 updatedEntityCount = updatedEntities.Count;
1182 world.UpdatedObjects.Clear();
1183
1184
1185 collidersCount = world.UpdatedCollisions.Count;
1186 colliders = new List<BulletXNA.CollisionDesc>(world.UpdatedCollisions);
1187
1188 world.UpdatedCollisions.Clear();
1189 m_collisionsThisFrame = 0;
1190 int numManifolds = world.GetDispatcher().GetNumManifolds();
1191 for (int j = 0; j < numManifolds; j++)
1192 {
1193 PersistentManifold contactManifold = world.GetDispatcher().GetManifoldByIndexInternal(j);
1194 int numContacts = contactManifold.GetNumContacts();
1195 if (numContacts == 0)
1196 continue;
1197
1198 CollisionObject objA = contactManifold.GetBody0() as CollisionObject;
1199 CollisionObject objB = contactManifold.GetBody1() as CollisionObject;
1200
1201 ManifoldPoint manifoldPoint = contactManifold.GetContactPoint(0);
1202 IndexedVector3 contactPoint = manifoldPoint.GetPositionWorldOnB();
1203 IndexedVector3 contactNormal = -manifoldPoint.m_normalWorldOnB; // make relative to A
1204
1205 RecordCollision(world, objA, objB, contactPoint, contactNormal);
1206 m_collisionsThisFrame ++;
1207 if (m_collisionsThisFrame >= 9999999)
1208 break;
1209
1210
1211 }
1212
1213
1214 }
1215 else
1216 {
1217 //if (updatedEntities is null)
1218 updatedEntities = new List<BulletXNA.EntityProperties>();
1219 updatedEntityCount = 0;
1220 //if (colliders is null)
1221 colliders = new List<BulletXNA.CollisionDesc>();
1222 collidersCount = 0;
1223 }
1224 return numSimSteps;
1225 }
1226
1227 private static void RecordCollision(CollisionWorld world,CollisionObject objA, CollisionObject objB, IndexedVector3 contact, IndexedVector3 norm)
1228 {
1229
1230 IndexedVector3 contactNormal = norm;
1231 if ((objA.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0 &&
1232 (objB.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0)
1233 {
1234 return;
1235 }
1236 uint idA = (uint)objA.GetUserPointer();
1237 uint idB = (uint)objB.GetUserPointer();
1238 if (idA > idB)
1239 {
1240 uint temp = idA;
1241 idA = idB;
1242 idB = temp;
1243 contactNormal = -contactNormal;
1244 }
1245
1246 ulong collisionID = ((ulong) idA << 32) | idB;
1247
1248 BulletXNA.CollisionDesc cDesc = new BulletXNA.CollisionDesc()
1249 {
1250 aID = idA,
1251 bID = idB,
1252 point = contact,
1253 normal = contactNormal
1254 };
1255 world.UpdatedCollisions.Add(cDesc);
1256 m_collisionsThisFrame++;
1257
1258
1259 }
1260 private static EntityProperties GetDebugProperties(object pWorld, object pBody)
1261 {
1262 EntityProperties ent = new EntityProperties();
1263 DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
1264 RigidBody body = pBody as RigidBody;
1265 IndexedMatrix transform = body.GetWorldTransform();
1266 IndexedVector3 LinearVelocity = body.GetInterpolationLinearVelocity();
1267 IndexedVector3 AngularVelocity = body.GetInterpolationAngularVelocity();
1268 IndexedQuaternion rotation = transform.GetRotation();
1269 ent.Acceleration = Vector3.Zero;
1270 ent.ID = (uint)body.GetUserPointer();
1271 ent.Position = new Vector3(transform._origin.X,transform._origin.Y,transform._origin.Z);
1272 ent.Rotation = new Quaternion(rotation.X,rotation.Y,rotation.Z,rotation.W);
1273 ent.Velocity = new Vector3(LinearVelocity.X, LinearVelocity.Y, LinearVelocity.Z);
1274 ent.RotationalVelocity = new Vector3(AngularVelocity.X, AngularVelocity.Y, AngularVelocity.Z);
1275 return ent;
1276 }
1277
1278 public override Vector3 GetLocalScaling2(object pBody)
1279 {
1280 CollisionShape shape = pBody as CollisionShape;
1281 IndexedVector3 scale = shape.GetLocalScaling();
1282 return new Vector3(scale.X,scale.Y,scale.Z);
1283 }
1284
1285 public override bool RayCastGround(object pWorld, Vector3 _RayOrigin, float pRayHeight, object NotMe)
1286 {
1287 DynamicsWorld world = pWorld as DynamicsWorld;
1288 if (world != null)
1289 {
1290 if (NotMe is CollisionObject || NotMe is RigidBody)
1291 {
1292 CollisionObject AvoidBody = NotMe as CollisionObject;
1293
1294 IndexedVector3 rOrigin = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z);
1295 IndexedVector3 rEnd = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z - pRayHeight);
1296 using (
1297 ClosestNotMeRayResultCallback rayCallback = new ClosestNotMeRayResultCallback(rOrigin,
1298 rEnd, AvoidBody)
1299 )
1300 {
1301 world.RayTest(ref rOrigin, ref rEnd, rayCallback);
1302 if (rayCallback.HasHit())
1303 {
1304 IndexedVector3 hitLocation = rayCallback.m_hitPointWorld;
1305
1306 }
1307 return rayCallback.HasHit();
1308 }
1309 }
1310 }
1311 return false;
1312 }
37} 1313}
38 */ 1314*/
39} 1315}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
index 699f055..2350f59 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
@@ -362,7 +362,7 @@ public abstract void DestroyObject(BulletWorld sim, BulletBody obj);
362// ===================================================================================== 362// =====================================================================================
363public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin); 363public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin);
364 364
365public abstract BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, 365public abstract BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
366 float scaleFactor, float collisionMargin); 366 float scaleFactor, float collisionMargin);
367 367
368// ===================================================================================== 368// =====================================================================================
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 064ce3c..cb8108d 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -300,7 +300,7 @@ public sealed class BSPrim : BSPhysObject
300 // All positions are given in world positions. 300 // All positions are given in world positions.
301 if (_position == value) 301 if (_position == value)
302 { 302 {
303 DetailLog("{0},BSPrim.setPosition,taint,positionNotChanging,pos={1},orient={2}", LocalID, _position, _orientation); 303 DetailLog("{0},BSPrim.setPosition,call,positionNotChanging,pos={1},orient={2}", LocalID, _position, _orientation);
304 return; 304 return;
305 } 305 }
306 _position = value; 306 _position = value;
@@ -894,21 +894,26 @@ public sealed class BSPrim : BSPhysObject
894 // Object MUST NOT already be in the world. 894 // Object MUST NOT already be in the world.
895 // This routine exists because some assorted properties get mangled by adding to the world. 895 // This routine exists because some assorted properties get mangled by adding to the world.
896 internal void AddObjectToPhysicalWorld() 896 internal void AddObjectToPhysicalWorld()
897 { 897 {
898 if (PhysBody.HasPhysicalBody) 898 if (PhysBody.HasPhysicalBody)
899 { 899 {
900 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); 900 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
901 901
902 // TODO: Fix this. Total kludge because adding object to world resets its gravity to default. 902 // TODO: Fix this. Total kludge because adding object to world resets its gravity to default.
903 // Replace this when the new AddObjectToWorld function is complete. 903 // Replace this when the new AddObjectToWorld function is complete.
904 PhysicsScene.PE.SetGravity(PhysBody, ComputeGravity()); 904 PhysicsScene.PE.SetGravity(PhysBody, ComputeGravity());
905 905
906 // Collision filter can be set only when the object is in the world 906 // Collision filter can be set only when the object is in the world
907 if (!PhysBody.ApplyCollisionMask(PhysicsScene)) 907 if (!PhysBody.ApplyCollisionMask(PhysicsScene))
908 { 908 {
909 m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID); 909 m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID);
910 DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType); 910 DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType);
911 } 911 }
912 }
913 else
914 {
915 m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID);
916 DetailLog("{0},BSPrim.UpdatePhysicalParameters,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType);
912 } 917 }
913 } 918 }
914 919
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index cd77581..2b652f5 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -45,7 +45,7 @@ public sealed class BSShapeCollection : IDisposable
45 // Description of a Mesh 45 // Description of a Mesh
46 private struct MeshDesc 46 private struct MeshDesc
47 { 47 {
48 public IntPtr ptr; 48 public BulletShape shape;
49 public int referenceCount; 49 public int referenceCount;
50 public DateTime lastReferenced; 50 public DateTime lastReferenced;
51 public UInt64 shapeKey; 51 public UInt64 shapeKey;
@@ -55,7 +55,7 @@ public sealed class BSShapeCollection : IDisposable
55 // Meshes and hulls have the same shape hash key but we only need hulls for efficient collision calculations. 55 // Meshes and hulls have the same shape hash key but we only need hulls for efficient collision calculations.
56 private struct HullDesc 56 private struct HullDesc
57 { 57 {
58 public IntPtr ptr; 58 public BulletShape shape;
59 public int referenceCount; 59 public int referenceCount;
60 public DateTime lastReferenced; 60 public DateTime lastReferenced;
61 public UInt64 shapeKey; 61 public UInt64 shapeKey;
@@ -173,7 +173,7 @@ public sealed class BSShapeCollection : IDisposable
173 } 173 }
174 174
175 // Zero any reference to the shape so it is not freed when the body is deleted. 175 // Zero any reference to the shape so it is not freed when the body is deleted.
176 PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, new BulletShape()); 176 PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, null);
177 PhysicsScene.PE.DestroyObject(PhysicsScene.World, body); 177 PhysicsScene.PE.DestroyObject(PhysicsScene.World, body);
178 }); 178 });
179 } 179 }
@@ -202,7 +202,7 @@ public sealed class BSShapeCollection : IDisposable
202 else 202 else
203 { 203 {
204 // This is a new reference to a mesh 204 // This is a new reference to a mesh
205 meshDesc.ptr = shape.ptr; 205 meshDesc.shape = shape.Clone();
206 meshDesc.shapeKey = shape.shapeKey; 206 meshDesc.shapeKey = shape.shapeKey;
207 // We keep a reference to the underlying IMesh data so a hull can be built 207 // We keep a reference to the underlying IMesh data so a hull can be built
208 meshDesc.referenceCount = 1; 208 meshDesc.referenceCount = 1;
@@ -225,7 +225,7 @@ public sealed class BSShapeCollection : IDisposable
225 else 225 else
226 { 226 {
227 // This is a new reference to a hull 227 // This is a new reference to a hull
228 hullDesc.ptr = shape.ptr; 228 hullDesc.shape = shape.Clone();
229 hullDesc.shapeKey = shape.shapeKey; 229 hullDesc.shapeKey = shape.shapeKey;
230 hullDesc.referenceCount = 1; 230 hullDesc.referenceCount = 1;
231 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", 231 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}",
@@ -361,15 +361,14 @@ public sealed class BSShapeCollection : IDisposable
361 MeshDesc meshDesc; 361 MeshDesc meshDesc;
362 HullDesc hullDesc; 362 HullDesc hullDesc;
363 363
364 IntPtr cShape = shapeInfo.ptr; 364 if (TryGetMeshByPtr(shapeInfo, out meshDesc))
365 if (TryGetMeshByPtr(cShape, out meshDesc))
366 { 365 {
367 shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH; 366 shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH;
368 shapeInfo.shapeKey = meshDesc.shapeKey; 367 shapeInfo.shapeKey = meshDesc.shapeKey;
369 } 368 }
370 else 369 else
371 { 370 {
372 if (TryGetHullByPtr(cShape, out hullDesc)) 371 if (TryGetHullByPtr(shapeInfo, out hullDesc))
373 { 372 {
374 shapeInfo.type = BSPhysicsShapeType.SHAPE_HULL; 373 shapeInfo.type = BSPhysicsShapeType.SHAPE_HULL;
375 shapeInfo.shapeKey = hullDesc.shapeKey; 374 shapeInfo.shapeKey = hullDesc.shapeKey;
@@ -632,7 +631,7 @@ public sealed class BSShapeCollection : IDisposable
632 if (Meshes.TryGetValue(newMeshKey, out meshDesc)) 631 if (Meshes.TryGetValue(newMeshKey, out meshDesc))
633 { 632 {
634 // If the mesh has already been built just use it. 633 // If the mesh has already been built just use it.
635 newShape = new BulletShape(meshDesc.ptr, BSPhysicsShapeType.SHAPE_MESH); 634 newShape = meshDesc.shape.Clone();
636 } 635 }
637 else 636 else
638 { 637 {
@@ -703,7 +702,7 @@ public sealed class BSShapeCollection : IDisposable
703 if (Hulls.TryGetValue(newHullKey, out hullDesc)) 702 if (Hulls.TryGetValue(newHullKey, out hullDesc))
704 { 703 {
705 // If the hull shape already is created, just use it. 704 // If the hull shape already is created, just use it.
706 newShape = new BulletShape(hullDesc.ptr, BSPhysicsShapeType.SHAPE_HULL); 705 newShape = hullDesc.shape.Clone();
707 } 706 }
708 else 707 else
709 { 708 {
@@ -965,13 +964,13 @@ public sealed class BSShapeCollection : IDisposable
965 return ret; 964 return ret;
966 } 965 }
967 966
968 private bool TryGetMeshByPtr(IntPtr addr, out MeshDesc outDesc) 967 private bool TryGetMeshByPtr(BulletShape shape, out MeshDesc outDesc)
969 { 968 {
970 bool ret = false; 969 bool ret = false;
971 MeshDesc foundDesc = new MeshDesc(); 970 MeshDesc foundDesc = new MeshDesc();
972 foreach (MeshDesc md in Meshes.Values) 971 foreach (MeshDesc md in Meshes.Values)
973 { 972 {
974 if (md.ptr == addr) 973 if (md.shape.ReferenceSame(shape))
975 { 974 {
976 foundDesc = md; 975 foundDesc = md;
977 ret = true; 976 ret = true;
@@ -983,13 +982,13 @@ public sealed class BSShapeCollection : IDisposable
983 return ret; 982 return ret;
984 } 983 }
985 984
986 private bool TryGetHullByPtr(IntPtr addr, out HullDesc outDesc) 985 private bool TryGetHullByPtr(BulletShape shape, out HullDesc outDesc)
987 { 986 {
988 bool ret = false; 987 bool ret = false;
989 HullDesc foundDesc = new HullDesc(); 988 HullDesc foundDesc = new HullDesc();
990 foreach (HullDesc hd in Hulls.Values) 989 foreach (HullDesc hd in Hulls.Values)
991 { 990 {
992 if (hd.ptr == addr) 991 if (hd.shape.ReferenceSame(shape))
993 { 992 {
994 foundDesc = hd; 993 foundDesc = hd;
995 ret = true; 994 ret = true;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
index 681d21e..662dd68 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
@@ -33,17 +33,23 @@ namespace OpenSim.Region.Physics.BulletSPlugin
33{ 33{
34// Classes to allow some type checking for the API 34// Classes to allow some type checking for the API
35// These hold pointers to allocated objects in the unmanaged space. 35// These hold pointers to allocated objects in the unmanaged space.
36// These classes are subclassed by the various physical implementations of
37// objects. In particular, there is a version for physical instances in
38// unmanaged memory ("unman") and one for in managed memory ("XNA").
39
40// Currently, the instances of these classes are a reference to a
41// physical representation and this has no releationship to other
42// instances. Someday, refarb the usage of these classes so each instance
43// refers to a particular physical instance and this class controls reference
44// counts and such. This should be done along with adding BSShapes.
36 45
37// The physics engine controller class created at initialization
38public class BulletWorld 46public class BulletWorld
39{ 47{
40 public BulletWorld(uint worldId, BSScene bss, IntPtr xx) 48 public BulletWorld(uint worldId, BSScene bss)
41 { 49 {
42 ptr = xx;
43 worldID = worldId; 50 worldID = worldId;
44 physicsScene = bss; 51 physicsScene = bss;
45 } 52 }
46 public IntPtr ptr;
47 public uint worldID; 53 public uint worldID;
48 // The scene is only in here so very low level routines have a handle to print debug/error messages 54 // The scene is only in here so very low level routines have a handle to print debug/error messages
49 public BSScene physicsScene; 55 public BSScene physicsScene;
@@ -52,27 +58,19 @@ public class BulletWorld
52// An allocated Bullet btRigidBody 58// An allocated Bullet btRigidBody
53public class BulletBody 59public class BulletBody
54{ 60{
55 public BulletBody(uint id) : this(id, IntPtr.Zero) 61 public BulletBody(uint id)
56 {
57 }
58 public BulletBody(uint id, IntPtr xx)
59 { 62 {
60 ID = id; 63 ID = id;
61 ptr = xx;
62 collisionType = CollisionType.Static; 64 collisionType = CollisionType.Static;
63 } 65 }
64 public IntPtr ptr;
65 public uint ID; 66 public uint ID;
66 public CollisionType collisionType; 67 public CollisionType collisionType;
67 68
68 public void Clear() 69 public virtual void Clear() { }
69 { 70 public virtual bool HasPhysicalBody { get { return false; } }
70 ptr = IntPtr.Zero;
71 }
72 public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } }
73 71
74 // Apply the specificed collision mask into the physical world 72 // Apply the specificed collision mask into the physical world
75 public bool ApplyCollisionMask(BSScene physicsScene) 73 public virtual bool ApplyCollisionMask(BSScene physicsScene)
76 { 74 {
77 // Should assert the body has been added to the physical world. 75 // Should assert the body has been added to the physical world.
78 // (The collision masks are stored in the collision proxy cache which only exists for 76 // (The collision masks are stored in the collision proxy cache which only exists for
@@ -83,12 +81,9 @@ public class BulletBody
83 } 81 }
84 82
85 // Used for log messages for a unique display of the memory/object allocated to this instance 83 // Used for log messages for a unique display of the memory/object allocated to this instance
86 public string AddrString 84 public virtual string AddrString
87 { 85 {
88 get 86 get { return "unknown"; }
89 {
90 return ptr.ToString("X");
91 }
92 } 87 }
93 88
94 public override string ToString() 89 public override string ToString()
@@ -108,38 +103,26 @@ public class BulletBody
108public class BulletShape 103public class BulletShape
109{ 104{
110 public BulletShape() 105 public BulletShape()
111 : this(IntPtr.Zero, BSPhysicsShapeType.SHAPE_UNKNOWN)
112 {
113 }
114 public BulletShape(IntPtr xx)
115 : this(xx, BSPhysicsShapeType.SHAPE_UNKNOWN)
116 { 106 {
117 } 107 type = BSPhysicsShapeType.SHAPE_UNKNOWN;
118 public BulletShape(IntPtr xx, BSPhysicsShapeType typ)
119 {
120 ptr = xx;
121 type = typ;
122 shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; 108 shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE;
123 isNativeShape = false; 109 isNativeShape = false;
124 } 110 }
125 public IntPtr ptr;
126 public BSPhysicsShapeType type; 111 public BSPhysicsShapeType type;
127 public System.UInt64 shapeKey; 112 public System.UInt64 shapeKey;
128 public bool isNativeShape; 113 public bool isNativeShape;
129 114
130 public void Clear() 115 public virtual void Clear() { }
131 { 116 public virtual bool HasPhysicalShape { get { return false; } }
132 ptr = IntPtr.Zero; 117 // Make another reference to this physical object.
133 } 118 public virtual BulletShape Clone() { return new BulletShape(); }
134 public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } } 119 // Return 'true' if this and other refer to the same physical object
120 public virtual bool ReferenceSame(BulletShape xx) { return false; }
135 121
136 // Used for log messages for a unique display of the memory/object allocated to this instance 122 // Used for log messages for a unique display of the memory/object allocated to this instance
137 public string AddrString 123 public virtual string AddrString
138 { 124 {
139 get 125 get { return "unknown"; }
140 {
141 return ptr.ToString("X");
142 }
143 } 126 }
144 127
145 public override string ToString() 128 public override string ToString()
@@ -161,25 +144,16 @@ public class BulletShape
161// An allocated Bullet btConstraint 144// An allocated Bullet btConstraint
162public class BulletConstraint 145public class BulletConstraint
163{ 146{
164 public BulletConstraint(IntPtr xx) 147 public BulletConstraint()
165 {
166 ptr = xx;
167 }
168 public IntPtr ptr;
169
170 public void Clear()
171 { 148 {
172 ptr = IntPtr.Zero;
173 } 149 }
174 public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } } 150 public virtual void Clear() { }
151 public virtual bool HasPhysicalConstraint { get { return false; } }
175 152
176 // Used for log messages for a unique display of the memory/object allocated to this instance 153 // Used for log messages for a unique display of the memory/object allocated to this instance
177 public string AddrString 154 public virtual string AddrString
178 { 155 {
179 get 156 get { return "unknown"; }
180 {
181 return ptr.ToString("X");
182 }
183 } 157 }
184} 158}
185 159