aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs4
-rw-r--r--OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs4
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs1839
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs1622
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs662
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs86
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs21
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs40
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs10
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs26
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs27
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs42
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSParam.cs26
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs9
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs6
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs139
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSScene.cs129
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs106
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapes.cs21
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs42
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs23
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs28
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs1276
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs90
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt21
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs13
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs1
28 files changed, 4584 insertions, 1731 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs
index 9d373ef..32549d6 100644
--- a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs
@@ -110,12 +110,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcRouterModule
110 110
111 public void ScriptRemoved(UUID itemID) 111 public void ScriptRemoved(UUID itemID)
112 { 112 {
113 System.Console.WriteLine("TEST Script Removed!"); 113 // System.Console.WriteLine("TEST Script Removed!");
114 } 114 }
115 115
116 public void ObjectRemoved(UUID objectID) 116 public void ObjectRemoved(UUID objectID)
117 { 117 {
118 System.Console.WriteLine("TEST Obj Removed!"); 118 // System.Console.WriteLine("TEST Obj Removed!");
119 } 119 }
120 } 120 }
121} 121}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
index 9c4ba30..aadb5b2 100644
--- a/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
@@ -111,10 +111,6 @@ public sealed class BSPrim : BSPhysObject
111 111
112 _mass = CalculateMass(); 112 _mass = CalculateMass();
113 113
114 // No body or shape yet
115 PhysBody = new BulletBody(LocalID);
116 PhysShape = new BulletShape();
117
118 Linkset.Refresh(this); 114 Linkset.Refresh(this);
119 115
120 DetailLog("{0},BSPrim.constructor,call", LocalID); 116 DetailLog("{0},BSPrim.constructor,call", LocalID);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
new file mode 100755
index 0000000..8c6e7d6
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -0,0 +1,1839 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyrightD
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30using System.Runtime.InteropServices;
31using System.Security;
32using System.Text;
33
34using OpenSim.Framework;
35
36using OpenMetaverse;
37
38namespace OpenSim.Region.Physics.BulletSPlugin
39{
40public sealed class BSAPIUnman : BSAPITemplate
41{
42
43private sealed class BulletWorldUnman : BulletWorld
44{
45 public IntPtr ptr;
46 public BulletWorldUnman(uint id, BSScene physScene, IntPtr xx)
47 : base(id, physScene)
48 {
49 ptr = xx;
50 }
51}
52
53private sealed class BulletBodyUnman : BulletBody
54{
55 public IntPtr ptr;
56 public BulletBodyUnman(uint id, IntPtr xx)
57 : base(id)
58 {
59 ptr = xx;
60 }
61 public override bool HasPhysicalBody
62 {
63 get { return ptr != IntPtr.Zero; }
64 }
65 public override void Clear()
66 {
67 ptr = IntPtr.Zero;
68 }
69 public override string AddrString
70 {
71 get { return ptr.ToString("X"); }
72 }
73}
74
75private sealed class BulletShapeUnman : BulletShape
76{
77 public IntPtr ptr;
78 public BulletShapeUnman(IntPtr xx, BSPhysicsShapeType typ)
79 : base()
80 {
81 ptr = xx;
82 type = typ;
83 }
84 public override bool HasPhysicalShape
85 {
86 get { return ptr != IntPtr.Zero; }
87 }
88 public override void Clear()
89 {
90 ptr = IntPtr.Zero;
91 }
92 public override BulletShape Clone()
93 {
94 return new BulletShapeUnman(ptr, type);
95 }
96 public override bool ReferenceSame(BulletShape other)
97 {
98 BulletShapeUnman otheru = other as BulletShapeUnman;
99 return (otheru != null) && (this.ptr == otheru.ptr);
100
101 }
102 public override string AddrString
103 {
104 get { return ptr.ToString("X"); }
105 }
106}
107private sealed class BulletConstraintUnman : BulletConstraint
108{
109 public BulletConstraintUnman(IntPtr xx) : base()
110 {
111 ptr = xx;
112 }
113 public IntPtr ptr;
114
115 public override void Clear()
116 {
117 ptr = IntPtr.Zero;
118 }
119 public override bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } }
120
121 // Used for log messages for a unique display of the memory/object allocated to this instance
122 public override string AddrString
123 {
124 get { return ptr.ToString("X"); }
125 }
126}
127
128// We pin the memory passed between the managed and unmanaged code.
129GCHandle m_paramsHandle;
130private GCHandle m_collisionArrayPinnedHandle;
131private GCHandle m_updateArrayPinnedHandle;
132
133// Handle to the callback used by the unmanaged code to call into the managed code.
134// Used for debug logging.
135// Need to store the handle in a persistant variable so it won't be freed.
136private BSAPICPP.DebugLogCallback m_DebugLogCallbackHandle;
137
138private BSScene PhysicsScene { get; set; }
139
140public override string BulletEngineName { get { return "BulletUnmanaged"; } }
141public override string BulletEngineVersion { get; protected set; }
142
143public BSAPIUnman(string paramName, BSScene physScene)
144{
145 PhysicsScene = physScene;
146
147 // Do something fancy with the paramName to get the right DLL implementation
148 // like "Bullet-2.80-OpenCL-Intel" loading the version for Intel based OpenCL implementation, etc.
149 if (Util.IsWindows())
150 Util.LoadArchSpecificWindowsDll("BulletSim.dll");
151 // If not Windows, loading is performed by the
152 // Mono loader as specified in
153 // "bin/Physics/OpenSim.Region.Physics.BulletSPlugin.dll.config".
154}
155
156// Initialization and simulation
157public override BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms,
158 int maxCollisions, ref CollisionDesc[] collisionArray,
159 int maxUpdates, ref EntityProperties[] updateArray
160 )
161{
162 // Pin down the memory that will be used to pass object collisions and updates back from unmanaged code
163 m_paramsHandle = GCHandle.Alloc(parms, GCHandleType.Pinned);
164 m_collisionArrayPinnedHandle = GCHandle.Alloc(collisionArray, GCHandleType.Pinned);
165 m_updateArrayPinnedHandle = GCHandle.Alloc(updateArray, GCHandleType.Pinned);
166
167 // If Debug logging level, enable logging from the unmanaged code
168 m_DebugLogCallbackHandle = null;
169 if (BSScene.m_log.IsDebugEnabled || PhysicsScene.PhysicsLogging.Enabled)
170 {
171 BSScene.m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", BSScene.LogHeader);
172 if (PhysicsScene.PhysicsLogging.Enabled)
173 // The handle is saved in a variable to make sure it doesn't get freed after this call
174 m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLoggerPhysLog);
175 else
176 m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLogger);
177 }
178
179 // Get the version of the DLL
180 // TODO: this doesn't work yet. Something wrong with marshaling the returned string.
181 // BulletEngineVersion = BulletSimAPI.GetVersion2();
182 BulletEngineVersion = "";
183
184 // Call the unmanaged code with the buffers and other information
185 return new BulletWorldUnman(0, PhysicsScene, BSAPICPP.Initialize2(maxPosition, m_paramsHandle.AddrOfPinnedObject(),
186 maxCollisions, m_collisionArrayPinnedHandle.AddrOfPinnedObject(),
187 maxUpdates, m_updateArrayPinnedHandle.AddrOfPinnedObject(),
188 m_DebugLogCallbackHandle));
189
190}
191
192// Called directly from unmanaged code so don't do much
193private void BulletLogger(string msg)
194{
195 BSScene.m_log.Debug("[BULLETS UNMANAGED]:" + msg);
196}
197
198// Called directly from unmanaged code so don't do much
199private void BulletLoggerPhysLog(string msg)
200{
201 PhysicsScene.DetailLog("[BULLETS UNMANAGED]:" + msg);
202}
203
204public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
205 out int updatedEntityCount, out int collidersCount)
206{
207 BulletWorldUnman worldu = world as BulletWorldUnman;
208 return BSAPICPP.PhysicsStep2(worldu.ptr, timeStep, maxSubSteps, fixedTimeStep, out updatedEntityCount, out collidersCount);
209}
210
211public override void Shutdown(BulletWorld world)
212{
213 BulletWorldUnman worldu = world as BulletWorldUnman;
214 BSAPICPP.Shutdown2(worldu.ptr);
215}
216
217public override bool PushUpdate(BulletBody obj)
218{
219 BulletBodyUnman bodyu = obj as BulletBodyUnman;
220 return BSAPICPP.PushUpdate2(bodyu.ptr);
221}
222
223public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value)
224{
225 BulletWorldUnman worldu = world as BulletWorldUnman;
226 return BSAPICPP.UpdateParameter2(worldu.ptr, localID, parm, value);
227}
228
229// =====================================================================================
230// Mesh, hull, shape and body creation helper routines
231public override BulletShape CreateMeshShape(BulletWorld world,
232 int indicesCount, int[] indices,
233 int verticesCount, float[] vertices)
234{
235 BulletWorldUnman worldu = world as BulletWorldUnman;
236 return new BulletShapeUnman(
237 BSAPICPP.CreateMeshShape2(worldu.ptr, indicesCount, indices, verticesCount, vertices),
238 BSPhysicsShapeType.SHAPE_MESH);
239}
240
241public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls)
242{
243 BulletWorldUnman worldu = world as BulletWorldUnman;
244 return new BulletShapeUnman(
245 BSAPICPP.CreateHullShape2(worldu.ptr, hullCount, hulls),
246 BSPhysicsShapeType.SHAPE_HULL);
247}
248
249public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape)
250{
251 BulletWorldUnman worldu = world as BulletWorldUnman;
252 BulletShapeUnman shapeu = meshShape as BulletShapeUnman;
253 return new BulletShapeUnman(
254 BSAPICPP.BuildHullShapeFromMesh2(worldu.ptr, shapeu.ptr),
255 BSPhysicsShapeType.SHAPE_HULL);
256}
257
258public override BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData)
259{
260 BulletWorldUnman worldu = world as BulletWorldUnman;
261 return new BulletShapeUnman(BSAPICPP.BuildNativeShape2(worldu.ptr, shapeData), shapeData.Type);
262}
263
264public override bool IsNativeShape(BulletShape shape)
265{
266 BulletShapeUnman shapeu = shape as BulletShapeUnman;
267 if (shapeu != null && shapeu.HasPhysicalShape)
268 return BSAPICPP.IsNativeShape2(shapeu.ptr);
269 return false;
270}
271
272public override void SetShapeCollisionMargin(BulletShape shape, float margin)
273{
274 BulletShapeUnman shapeu = shape as BulletShapeUnman;
275 if (shapeu != null && shapeu.HasPhysicalShape)
276 BSAPICPP.SetShapeCollisionMargin2(shapeu.ptr, margin);
277}
278
279public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale)
280{
281 BulletWorldUnman worldu = world as BulletWorldUnman;
282 return new BulletShapeUnman(
283 BSAPICPP.BuildCapsuleShape2(worldu.ptr, radius, height, scale),
284 BSPhysicsShapeType.SHAPE_CAPSULE);
285}
286
287public override BulletShape CreateCompoundShape(BulletWorld world, bool enableDynamicAabbTree)
288{
289 BulletWorldUnman worldu = world as BulletWorldUnman;
290 return new BulletShapeUnman(
291 BSAPICPP.CreateCompoundShape2(worldu.ptr, enableDynamicAabbTree),
292 BSPhysicsShapeType.SHAPE_COMPOUND);
293
294}
295
296public override int GetNumberOfCompoundChildren(BulletShape shape)
297{
298 BulletShapeUnman shapeu = shape as BulletShapeUnman;
299 if (shapeu != null && shapeu.HasPhysicalShape)
300 return BSAPICPP.GetNumberOfCompoundChildren2(shapeu.ptr);
301 return 0;
302}
303
304public override void AddChildShapeToCompoundShape(BulletShape shape, BulletShape addShape, Vector3 pos, Quaternion rot)
305{
306 BulletShapeUnman shapeu = shape as BulletShapeUnman;
307 BulletShapeUnman addShapeu = addShape as BulletShapeUnman;
308 BSAPICPP.AddChildShapeToCompoundShape2(shapeu.ptr, addShapeu.ptr, pos, rot);
309}
310
311public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape shape, int indx)
312{
313 BulletShapeUnman shapeu = shape as BulletShapeUnman;
314 return new BulletShapeUnman(BSAPICPP.GetChildShapeFromCompoundShapeIndex2(shapeu.ptr, indx), BSPhysicsShapeType.SHAPE_UNKNOWN);
315}
316
317public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape shape, int indx)
318{
319 BulletShapeUnman shapeu = shape as BulletShapeUnman;
320 return new BulletShapeUnman(BSAPICPP.RemoveChildShapeFromCompoundShapeIndex2(shapeu.ptr, indx), BSPhysicsShapeType.SHAPE_UNKNOWN);
321}
322
323public override void RemoveChildShapeFromCompoundShape(BulletShape shape, BulletShape removeShape)
324{
325 BulletShapeUnman shapeu = shape as BulletShapeUnman;
326 BulletShapeUnman removeShapeu = removeShape as BulletShapeUnman;
327 BSAPICPP.RemoveChildShapeFromCompoundShape2(shapeu.ptr, removeShapeu.ptr);
328}
329
330public override void RecalculateCompoundShapeLocalAabb(BulletShape shape)
331{
332 BulletShapeUnman shapeu = shape as BulletShapeUnman;
333 BSAPICPP.RecalculateCompoundShapeLocalAabb2(shapeu.ptr);
334}
335
336public override BulletShape DuplicateCollisionShape(BulletWorld world, BulletShape srcShape, uint id)
337{
338 BulletWorldUnman worldu = world as BulletWorldUnman;
339 BulletShapeUnman srcShapeu = srcShape as BulletShapeUnman;
340 return new BulletShapeUnman(BSAPICPP.DuplicateCollisionShape2(worldu.ptr, srcShapeu.ptr, id), srcShape.type);
341}
342
343public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape)
344{
345 BulletWorldUnman worldu = world as BulletWorldUnman;
346 BulletShapeUnman shapeu = shape as BulletShapeUnman;
347 return BSAPICPP.DeleteCollisionShape2(worldu.ptr, shapeu.ptr);
348}
349
350public override CollisionObjectTypes GetBodyType(BulletBody obj)
351{
352 BulletBodyUnman bodyu = obj as BulletBodyUnman;
353 return (CollisionObjectTypes)BSAPICPP.GetBodyType2(bodyu.ptr);
354}
355
356public override BulletBody CreateBodyFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
357{
358 BulletWorldUnman worldu = world as BulletWorldUnman;
359 BulletShapeUnman shapeu = shape as BulletShapeUnman;
360 return new BulletBodyUnman(id, BSAPICPP.CreateBodyFromShape2(worldu.ptr, shapeu.ptr, id, pos, rot));
361}
362
363public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot)
364{
365 BulletShapeUnman shapeu = shape as BulletShapeUnman;
366 return new BulletBodyUnman(id, BSAPICPP.CreateBodyWithDefaultMotionState2(shapeu.ptr, id, pos, rot));
367}
368
369public override BulletBody CreateGhostFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
370{
371 BulletWorldUnman worldu = world as BulletWorldUnman;
372 BulletShapeUnman shapeu = shape as BulletShapeUnman;
373 return new BulletBodyUnman(id, BSAPICPP.CreateGhostFromShape2(worldu.ptr, shapeu.ptr, id, pos, rot));
374}
375
376public override void DestroyObject(BulletWorld world, BulletBody obj)
377{
378 BulletWorldUnman worldu = world as BulletWorldUnman;
379 BulletBodyUnman bodyu = obj as BulletBodyUnman;
380 BSAPICPP.DestroyObject2(worldu.ptr, bodyu.ptr);
381}
382
383// =====================================================================================
384// Terrain creation and helper routines
385public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin)
386{
387 return new BulletShapeUnman(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE);
388}
389
390public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
391 float scaleFactor, float collisionMargin)
392{
393 return new BulletShapeUnman(BSAPICPP.CreateTerrainShape2(id, size, minHeight, maxHeight, heightMap, scaleFactor, collisionMargin),
394 BSPhysicsShapeType.SHAPE_TERRAIN);
395}
396
397// =====================================================================================
398// Constraint creation and helper routines
399public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
400 Vector3 frame1loc, Quaternion frame1rot,
401 Vector3 frame2loc, Quaternion frame2rot,
402 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
403{
404 BulletWorldUnman worldu = world as BulletWorldUnman;
405 BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
406 BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
407 return new BulletConstraintUnman(BSAPICPP.Create6DofConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot,
408 frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
409}
410
411public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2,
412 Vector3 joinPoint,
413 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
414{
415 BulletWorldUnman worldu = world as BulletWorldUnman;
416 BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
417 BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
418 return new BulletConstraintUnman(BSAPICPP.Create6DofConstraintToPoint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr,
419 joinPoint, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
420}
421
422public override BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
423 Vector3 pivotinA, Vector3 pivotinB,
424 Vector3 axisInA, Vector3 axisInB,
425 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
426{
427 BulletWorldUnman worldu = world as BulletWorldUnman;
428 BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
429 BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
430 return new BulletConstraintUnman(BSAPICPP.CreateHingeConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr,
431 pivotinA, pivotinB, axisInA, axisInB, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
432}
433
434public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse)
435{
436 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
437 BSAPICPP.SetConstraintEnable2(constrainu.ptr, numericTrueFalse);
438}
439
440public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations)
441{
442 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
443 BSAPICPP.SetConstraintNumSolverIterations2(constrainu.ptr, iterations);
444}
445
446public override bool SetFrames(BulletConstraint constrain,
447 Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot)
448{
449 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
450 return BSAPICPP.SetFrames2(constrainu.ptr, frameA, frameArot, frameB, frameBrot);
451}
452
453public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi)
454{
455 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
456 return BSAPICPP.SetLinearLimits2(constrainu.ptr, low, hi);
457}
458
459public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi)
460{
461 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
462 return BSAPICPP.SetAngularLimits2(constrainu.ptr, low, hi);
463}
464
465public override bool UseFrameOffset(BulletConstraint constrain, float enable)
466{
467 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
468 return BSAPICPP.UseFrameOffset2(constrainu.ptr, enable);
469}
470
471public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce)
472{
473 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
474 return BSAPICPP.TranslationalLimitMotor2(constrainu.ptr, enable, targetVel, maxMotorForce);
475}
476
477public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold)
478{
479 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
480 return BSAPICPP.SetBreakingImpulseThreshold2(constrainu.ptr, threshold);
481}
482
483public override bool CalculateTransforms(BulletConstraint constrain)
484{
485 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
486 return BSAPICPP.CalculateTransforms2(constrainu.ptr);
487}
488
489public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis)
490{
491 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
492 return BSAPICPP.SetConstraintParam2(constrainu.ptr, paramIndex, value, axis);
493}
494
495public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain)
496{
497 BulletWorldUnman worldu = world as BulletWorldUnman;
498 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
499 return BSAPICPP.DestroyConstraint2(worldu.ptr, constrainu.ptr);
500}
501
502// =====================================================================================
503// btCollisionWorld entries
504public override void UpdateSingleAabb(BulletWorld world, BulletBody obj)
505{
506 BulletWorldUnman worldu = world as BulletWorldUnman;
507 BulletBodyUnman bodyu = obj as BulletBodyUnman;
508 BSAPICPP.UpdateSingleAabb2(worldu.ptr, bodyu.ptr);
509}
510
511public override void UpdateAabbs(BulletWorld world)
512{
513 BulletWorldUnman worldu = world as BulletWorldUnman;
514 BSAPICPP.UpdateAabbs2(worldu.ptr);
515}
516
517public override bool GetForceUpdateAllAabbs(BulletWorld world)
518{
519 BulletWorldUnman worldu = world as BulletWorldUnman;
520 return BSAPICPP.GetForceUpdateAllAabbs2(worldu.ptr);
521}
522
523public override void SetForceUpdateAllAabbs(BulletWorld world, bool force)
524{
525 BulletWorldUnman worldu = world as BulletWorldUnman;
526 BSAPICPP.SetForceUpdateAllAabbs2(worldu.ptr, force);
527}
528
529// =====================================================================================
530// btDynamicsWorld entries
531public override bool AddObjectToWorld(BulletWorld world, BulletBody obj)
532{
533 // Bullet resets several variables when an object is added to the world.
534 // Gravity is reset to world default depending on the static/dynamic
535 // type. Of course, the collision flags in the broadphase proxy are initialized to default.
536 BulletWorldUnman worldu = world as BulletWorldUnman;
537 BulletBodyUnman bodyu = obj as BulletBodyUnman;
538
539 Vector3 origGrav = BSAPICPP.GetGravity2(bodyu.ptr);
540
541 bool ret = BSAPICPP.AddObjectToWorld2(worldu.ptr, bodyu.ptr);
542
543 if (ret)
544 {
545 BSAPICPP.SetGravity2(bodyu.ptr, origGrav);
546 obj.ApplyCollisionMask(world.physicsScene);
547 }
548 return ret;
549}
550
551public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj)
552{
553 BulletWorldUnman worldu = world as BulletWorldUnman;
554 BulletBodyUnman bodyu = obj as BulletBodyUnman;
555 return BSAPICPP.RemoveObjectFromWorld2(worldu.ptr, bodyu.ptr);
556}
557
558public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects)
559{
560 BulletWorldUnman worldu = world as BulletWorldUnman;
561 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
562 return BSAPICPP.AddConstraintToWorld2(worldu.ptr, constrainu.ptr, disableCollisionsBetweenLinkedObjects);
563}
564
565public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain)
566{
567 BulletWorldUnman worldu = world as BulletWorldUnman;
568 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
569 return BSAPICPP.RemoveConstraintFromWorld2(worldu.ptr, constrainu.ptr);
570}
571// =====================================================================================
572// btCollisionObject entries
573public override Vector3 GetAnisotripicFriction(BulletConstraint constrain)
574{
575 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
576 return BSAPICPP.GetAnisotripicFriction2(constrainu.ptr);
577}
578
579public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict)
580{
581 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
582 return BSAPICPP.SetAnisotripicFriction2(constrainu.ptr, frict);
583}
584
585public override bool HasAnisotripicFriction(BulletConstraint constrain)
586{
587 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
588 return BSAPICPP.HasAnisotripicFriction2(constrainu.ptr);
589}
590
591public override void SetContactProcessingThreshold(BulletBody obj, float val)
592{
593 BulletBodyUnman bodyu = obj as BulletBodyUnman;
594 BSAPICPP.SetContactProcessingThreshold2(bodyu.ptr, val);
595}
596
597public override float GetContactProcessingThreshold(BulletBody obj)
598{
599 BulletBodyUnman bodyu = obj as BulletBodyUnman;
600 return BSAPICPP.GetContactProcessingThreshold2(bodyu.ptr);
601}
602
603public override bool IsStaticObject(BulletBody obj)
604{
605 BulletBodyUnman bodyu = obj as BulletBodyUnman;
606 return BSAPICPP.IsStaticObject2(bodyu.ptr);
607}
608
609public override bool IsKinematicObject(BulletBody obj)
610{
611 BulletBodyUnman bodyu = obj as BulletBodyUnman;
612 return BSAPICPP.IsKinematicObject2(bodyu.ptr);
613}
614
615public override bool IsStaticOrKinematicObject(BulletBody obj)
616{
617 BulletBodyUnman bodyu = obj as BulletBodyUnman;
618 return BSAPICPP.IsStaticOrKinematicObject2(bodyu.ptr);
619}
620
621public override bool HasContactResponse(BulletBody obj)
622{
623 BulletBodyUnman bodyu = obj as BulletBodyUnman;
624 return BSAPICPP.HasContactResponse2(bodyu.ptr);
625}
626
627public override void SetCollisionShape(BulletWorld world, BulletBody obj, BulletShape shape)
628{
629 BulletWorldUnman worldu = world as BulletWorldUnman;
630 BulletBodyUnman bodyu = obj as BulletBodyUnman;
631 BulletShapeUnman shapeu = shape as BulletShapeUnman;
632 if (worldu != null && bodyu != null)
633 {
634 // Special case to allow the caller to zero out the reference to any physical shape
635 if (shapeu != null)
636 BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, shapeu.ptr);
637 else
638 BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, IntPtr.Zero);
639 }
640}
641
642public override BulletShape GetCollisionShape(BulletBody obj)
643{
644 BulletBodyUnman bodyu = obj as BulletBodyUnman;
645 return new BulletShapeUnman(BSAPICPP.GetCollisionShape2(bodyu.ptr), BSPhysicsShapeType.SHAPE_UNKNOWN);
646}
647
648public override int GetActivationState(BulletBody obj)
649{
650 BulletBodyUnman bodyu = obj as BulletBodyUnman;
651 return BSAPICPP.GetActivationState2(bodyu.ptr);
652}
653
654public override void SetActivationState(BulletBody obj, int state)
655{
656 BulletBodyUnman bodyu = obj as BulletBodyUnman;
657 BSAPICPP.SetActivationState2(bodyu.ptr, state);
658}
659
660public override void SetDeactivationTime(BulletBody obj, float dtime)
661{
662 BulletBodyUnman bodyu = obj as BulletBodyUnman;
663 BSAPICPP.SetDeactivationTime2(bodyu.ptr, dtime);
664}
665
666public override float GetDeactivationTime(BulletBody obj)
667{
668 BulletBodyUnman bodyu = obj as BulletBodyUnman;
669 return BSAPICPP.GetDeactivationTime2(bodyu.ptr);
670}
671
672public override void ForceActivationState(BulletBody obj, ActivationState state)
673{
674 BulletBodyUnman bodyu = obj as BulletBodyUnman;
675 BSAPICPP.ForceActivationState2(bodyu.ptr, state);
676}
677
678public override void Activate(BulletBody obj, bool forceActivation)
679{
680 BulletBodyUnman bodyu = obj as BulletBodyUnman;
681 BSAPICPP.Activate2(bodyu.ptr, forceActivation);
682}
683
684public override bool IsActive(BulletBody obj)
685{
686 BulletBodyUnman bodyu = obj as BulletBodyUnman;
687 return BSAPICPP.IsActive2(bodyu.ptr);
688}
689
690public override void SetRestitution(BulletBody obj, float val)
691{
692 BulletBodyUnman bodyu = obj as BulletBodyUnman;
693 BSAPICPP.SetRestitution2(bodyu.ptr, val);
694}
695
696public override float GetRestitution(BulletBody obj)
697{
698 BulletBodyUnman bodyu = obj as BulletBodyUnman;
699 return BSAPICPP.GetRestitution2(bodyu.ptr);
700}
701
702public override void SetFriction(BulletBody obj, float val)
703{
704 BulletBodyUnman bodyu = obj as BulletBodyUnman;
705 BSAPICPP.SetFriction2(bodyu.ptr, val);
706}
707
708public override float GetFriction(BulletBody obj)
709{
710 BulletBodyUnman bodyu = obj as BulletBodyUnman;
711 return BSAPICPP.GetFriction2(bodyu.ptr);
712}
713
714public override Vector3 GetPosition(BulletBody obj)
715{
716 BulletBodyUnman bodyu = obj as BulletBodyUnman;
717 return BSAPICPP.GetPosition2(bodyu.ptr);
718}
719
720public override Quaternion GetOrientation(BulletBody obj)
721{
722 BulletBodyUnman bodyu = obj as BulletBodyUnman;
723 return BSAPICPP.GetOrientation2(bodyu.ptr);
724}
725
726public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation)
727{
728 BulletBodyUnman bodyu = obj as BulletBodyUnman;
729 BSAPICPP.SetTranslation2(bodyu.ptr, position, rotation);
730}
731
732 /*
733public override IntPtr GetBroadphaseHandle(BulletBody obj)
734{
735 BulletBodyUnman bodyu = obj as BulletBodyUnman;
736 return BSAPICPP.GetBroadphaseHandle2(bodyu.ptr);
737}
738
739public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle)
740{
741 BulletBodyUnman bodyu = obj as BulletBodyUnman;
742 BSAPICPP.SetUserPointer2(bodyu.ptr, handle);
743}
744 */
745
746public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel)
747{
748 BulletBodyUnman bodyu = obj as BulletBodyUnman;
749 BSAPICPP.SetInterpolationLinearVelocity2(bodyu.ptr, vel);
750}
751
752public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel)
753{
754 BulletBodyUnman bodyu = obj as BulletBodyUnman;
755 BSAPICPP.SetInterpolationAngularVelocity2(bodyu.ptr, vel);
756}
757
758public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel)
759{
760 BulletBodyUnman bodyu = obj as BulletBodyUnman;
761 BSAPICPP.SetInterpolationVelocity2(bodyu.ptr, linearVel, angularVel);
762}
763
764public override float GetHitFraction(BulletBody obj)
765{
766 BulletBodyUnman bodyu = obj as BulletBodyUnman;
767 return BSAPICPP.GetHitFraction2(bodyu.ptr);
768}
769
770public override void SetHitFraction(BulletBody obj, float val)
771{
772 BulletBodyUnman bodyu = obj as BulletBodyUnman;
773 BSAPICPP.SetHitFraction2(bodyu.ptr, val);
774}
775
776public override CollisionFlags GetCollisionFlags(BulletBody obj)
777{
778 BulletBodyUnman bodyu = obj as BulletBodyUnman;
779 return BSAPICPP.GetCollisionFlags2(bodyu.ptr);
780}
781
782public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags)
783{
784 BulletBodyUnman bodyu = obj as BulletBodyUnman;
785 return BSAPICPP.SetCollisionFlags2(bodyu.ptr, flags);
786}
787
788public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags)
789{
790 BulletBodyUnman bodyu = obj as BulletBodyUnman;
791 return BSAPICPP.AddToCollisionFlags2(bodyu.ptr, flags);
792}
793
794public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags)
795{
796 BulletBodyUnman bodyu = obj as BulletBodyUnman;
797 return BSAPICPP.RemoveFromCollisionFlags2(bodyu.ptr, flags);
798}
799
800public override float GetCcdMotionThreshold(BulletBody obj)
801{
802 BulletBodyUnman bodyu = obj as BulletBodyUnman;
803 return BSAPICPP.GetCcdMotionThreshold2(bodyu.ptr);
804}
805
806
807public override void SetCcdMotionThreshold(BulletBody obj, float val)
808{
809 BulletBodyUnman bodyu = obj as BulletBodyUnman;
810 BSAPICPP.SetCcdMotionThreshold2(bodyu.ptr, val);
811}
812
813public override float GetCcdSweptSphereRadius(BulletBody obj)
814{
815 BulletBodyUnman bodyu = obj as BulletBodyUnman;
816 return BSAPICPP.GetCcdSweptSphereRadius2(bodyu.ptr);
817}
818
819public override void SetCcdSweptSphereRadius(BulletBody obj, float val)
820{
821 BulletBodyUnman bodyu = obj as BulletBodyUnman;
822 BSAPICPP.SetCcdSweptSphereRadius2(bodyu.ptr, val);
823}
824
825public override IntPtr GetUserPointer(BulletBody obj)
826{
827 BulletBodyUnman bodyu = obj as BulletBodyUnman;
828 return BSAPICPP.GetUserPointer2(bodyu.ptr);
829}
830
831public override void SetUserPointer(BulletBody obj, IntPtr val)
832{
833 BulletBodyUnman bodyu = obj as BulletBodyUnman;
834 BSAPICPP.SetUserPointer2(bodyu.ptr, val);
835}
836
837// =====================================================================================
838// btRigidBody entries
839public override void ApplyGravity(BulletBody obj)
840{
841 BulletBodyUnman bodyu = obj as BulletBodyUnman;
842 BSAPICPP.ApplyGravity2(bodyu.ptr);
843}
844
845public override void SetGravity(BulletBody obj, Vector3 val)
846{
847 BulletBodyUnman bodyu = obj as BulletBodyUnman;
848 BSAPICPP.SetGravity2(bodyu.ptr, val);
849}
850
851public override Vector3 GetGravity(BulletBody obj)
852{
853 BulletBodyUnman bodyu = obj as BulletBodyUnman;
854 return BSAPICPP.GetGravity2(bodyu.ptr);
855}
856
857public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping)
858{
859 BulletBodyUnman bodyu = obj as BulletBodyUnman;
860 BSAPICPP.SetDamping2(bodyu.ptr, lin_damping, ang_damping);
861}
862
863public override void SetLinearDamping(BulletBody obj, float lin_damping)
864{
865 BulletBodyUnman bodyu = obj as BulletBodyUnman;
866 BSAPICPP.SetLinearDamping2(bodyu.ptr, lin_damping);
867}
868
869public override void SetAngularDamping(BulletBody obj, float ang_damping)
870{
871 BulletBodyUnman bodyu = obj as BulletBodyUnman;
872 BSAPICPP.SetAngularDamping2(bodyu.ptr, ang_damping);
873}
874
875public override float GetLinearDamping(BulletBody obj)
876{
877 BulletBodyUnman bodyu = obj as BulletBodyUnman;
878 return BSAPICPP.GetLinearDamping2(bodyu.ptr);
879}
880
881public override float GetAngularDamping(BulletBody obj)
882{
883 BulletBodyUnman bodyu = obj as BulletBodyUnman;
884 return BSAPICPP.GetAngularDamping2(bodyu.ptr);
885}
886
887public override float GetLinearSleepingThreshold(BulletBody obj)
888{
889 BulletBodyUnman bodyu = obj as BulletBodyUnman;
890 return BSAPICPP.GetLinearSleepingThreshold2(bodyu.ptr);
891}
892
893public override void ApplyDamping(BulletBody obj, float timeStep)
894{
895 BulletBodyUnman bodyu = obj as BulletBodyUnman;
896 BSAPICPP.ApplyDamping2(bodyu.ptr, timeStep);
897}
898
899public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia)
900{
901 BulletBodyUnman bodyu = obj as BulletBodyUnman;
902 BSAPICPP.SetMassProps2(bodyu.ptr, mass, inertia);
903}
904
905public override Vector3 GetLinearFactor(BulletBody obj)
906{
907 BulletBodyUnman bodyu = obj as BulletBodyUnman;
908 return BSAPICPP.GetLinearFactor2(bodyu.ptr);
909}
910
911public override void SetLinearFactor(BulletBody obj, Vector3 factor)
912{
913 BulletBodyUnman bodyu = obj as BulletBodyUnman;
914 BSAPICPP.SetLinearFactor2(bodyu.ptr, factor);
915}
916
917public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot)
918{
919 BulletBodyUnman bodyu = obj as BulletBodyUnman;
920 BSAPICPP.SetCenterOfMassByPosRot2(bodyu.ptr, pos, rot);
921}
922
923// Add a force to the object as if its mass is one.
924public override void ApplyCentralForce(BulletBody obj, Vector3 force)
925{
926 BulletBodyUnman bodyu = obj as BulletBodyUnman;
927 BSAPICPP.ApplyCentralForce2(bodyu.ptr, force);
928}
929
930// Set the force being applied to the object as if its mass is one.
931public override void SetObjectForce(BulletBody obj, Vector3 force)
932{
933 BulletBodyUnman bodyu = obj as BulletBodyUnman;
934 BSAPICPP.SetObjectForce2(bodyu.ptr, force);
935}
936
937public override Vector3 GetTotalForce(BulletBody obj)
938{
939 BulletBodyUnman bodyu = obj as BulletBodyUnman;
940 return BSAPICPP.GetTotalForce2(bodyu.ptr);
941}
942
943public override Vector3 GetTotalTorque(BulletBody obj)
944{
945 BulletBodyUnman bodyu = obj as BulletBodyUnman;
946 return BSAPICPP.GetTotalTorque2(bodyu.ptr);
947}
948
949public override Vector3 GetInvInertiaDiagLocal(BulletBody obj)
950{
951 BulletBodyUnman bodyu = obj as BulletBodyUnman;
952 return BSAPICPP.GetInvInertiaDiagLocal2(bodyu.ptr);
953}
954
955public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert)
956{
957 BulletBodyUnman bodyu = obj as BulletBodyUnman;
958 BSAPICPP.SetInvInertiaDiagLocal2(bodyu.ptr, inert);
959}
960
961public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold)
962{
963 BulletBodyUnman bodyu = obj as BulletBodyUnman;
964 BSAPICPP.SetSleepingThresholds2(bodyu.ptr, lin_threshold, ang_threshold);
965}
966
967public override void ApplyTorque(BulletBody obj, Vector3 torque)
968{
969 BulletBodyUnman bodyu = obj as BulletBodyUnman;
970 BSAPICPP.ApplyTorque2(bodyu.ptr, torque);
971}
972
973// Apply force at the given point. Will add torque to the object.
974public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos)
975{
976 BulletBodyUnman bodyu = obj as BulletBodyUnman;
977 BSAPICPP.ApplyForce2(bodyu.ptr, force, pos);
978}
979
980// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
981public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp)
982{
983 BulletBodyUnman bodyu = obj as BulletBodyUnman;
984 BSAPICPP.ApplyCentralImpulse2(bodyu.ptr, imp);
985}
986
987// Apply impulse to the object's torque. Force is scaled by object's mass.
988public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp)
989{
990 BulletBodyUnman bodyu = obj as BulletBodyUnman;
991 BSAPICPP.ApplyTorqueImpulse2(bodyu.ptr, imp);
992}
993
994// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
995public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos)
996{
997 BulletBodyUnman bodyu = obj as BulletBodyUnman;
998 BSAPICPP.ApplyImpulse2(bodyu.ptr, imp, pos);
999}
1000
1001public override void ClearForces(BulletBody obj)
1002{
1003 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1004 BSAPICPP.ClearForces2(bodyu.ptr);
1005}
1006
1007public override void ClearAllForces(BulletBody obj)
1008{
1009 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1010 BSAPICPP.ClearAllForces2(bodyu.ptr);
1011}
1012
1013public override void UpdateInertiaTensor(BulletBody obj)
1014{
1015 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1016 BSAPICPP.UpdateInertiaTensor2(bodyu.ptr);
1017}
1018
1019public override Vector3 GetLinearVelocity(BulletBody obj)
1020{
1021 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1022 return BSAPICPP.GetLinearVelocity2(bodyu.ptr);
1023}
1024
1025public override Vector3 GetAngularVelocity(BulletBody obj)
1026{
1027 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1028 return BSAPICPP.GetAngularVelocity2(bodyu.ptr);
1029}
1030
1031public override void SetLinearVelocity(BulletBody obj, Vector3 vel)
1032{
1033 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1034 BSAPICPP.SetLinearVelocity2(bodyu.ptr, vel);
1035}
1036
1037public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity)
1038{
1039 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1040 BSAPICPP.SetAngularVelocity2(bodyu.ptr, angularVelocity);
1041}
1042
1043public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos)
1044{
1045 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1046 return BSAPICPP.GetVelocityInLocalPoint2(bodyu.ptr, pos);
1047}
1048
1049public override void Translate(BulletBody obj, Vector3 trans)
1050{
1051 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1052 BSAPICPP.Translate2(bodyu.ptr, trans);
1053}
1054
1055public override void UpdateDeactivation(BulletBody obj, float timeStep)
1056{
1057 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1058 BSAPICPP.UpdateDeactivation2(bodyu.ptr, timeStep);
1059}
1060
1061public override bool WantsSleeping(BulletBody obj)
1062{
1063 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1064 return BSAPICPP.WantsSleeping2(bodyu.ptr);
1065}
1066
1067public override void SetAngularFactor(BulletBody obj, float factor)
1068{
1069 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1070 BSAPICPP.SetAngularFactor2(bodyu.ptr, factor);
1071}
1072
1073public override void SetAngularFactorV(BulletBody obj, Vector3 factor)
1074{
1075 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1076 BSAPICPP.SetAngularFactorV2(bodyu.ptr, factor);
1077}
1078
1079public override Vector3 GetAngularFactor(BulletBody obj)
1080{
1081 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1082 return BSAPICPP.GetAngularFactor2(bodyu.ptr);
1083}
1084
1085public override bool IsInWorld(BulletWorld world, BulletBody obj)
1086{
1087 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1088 return BSAPICPP.IsInWorld2(bodyu.ptr);
1089}
1090
1091public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain)
1092{
1093 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1094 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
1095 BSAPICPP.AddConstraintRef2(bodyu.ptr, constrainu.ptr);
1096}
1097
1098public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain)
1099{
1100 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1101 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
1102 BSAPICPP.RemoveConstraintRef2(bodyu.ptr, constrainu.ptr);
1103}
1104
1105public override BulletConstraint GetConstraintRef(BulletBody obj, int index)
1106{
1107 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1108 return new BulletConstraintUnman(BSAPICPP.GetConstraintRef2(bodyu.ptr, index));
1109}
1110
1111public override int GetNumConstraintRefs(BulletBody obj)
1112{
1113 BulletBodyUnman bodyu = obj as BulletBodyUnman;
1114 return BSAPICPP.GetNumConstraintRefs2(bodyu.ptr);
1115}
1116
1117public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask)
1118{
1119 BulletBodyUnman bodyu = body as BulletBodyUnman;
1120 return BSAPICPP.SetCollisionGroupMask2(bodyu.ptr, filter, mask);
1121}
1122
1123// =====================================================================================
1124// btCollisionShape entries
1125
1126public override float GetAngularMotionDisc(BulletShape shape)
1127{
1128 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1129 return BSAPICPP.GetAngularMotionDisc2(shapeu.ptr);
1130}
1131
1132public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor)
1133{
1134 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1135 return BSAPICPP.GetContactBreakingThreshold2(shapeu.ptr, defaultFactor);
1136}
1137
1138public override bool IsPolyhedral(BulletShape shape)
1139{
1140 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1141 return BSAPICPP.IsPolyhedral2(shapeu.ptr);
1142}
1143
1144public override bool IsConvex2d(BulletShape shape)
1145{
1146 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1147 return BSAPICPP.IsConvex2d2(shapeu.ptr);
1148}
1149
1150public override bool IsConvex(BulletShape shape)
1151{
1152 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1153 return BSAPICPP.IsConvex2(shapeu.ptr);
1154}
1155
1156public override bool IsNonMoving(BulletShape shape)
1157{
1158 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1159 return BSAPICPP.IsNonMoving2(shapeu.ptr);
1160}
1161
1162public override bool IsConcave(BulletShape shape)
1163{
1164 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1165 return BSAPICPP.IsConcave2(shapeu.ptr);
1166}
1167
1168public override bool IsCompound(BulletShape shape)
1169{
1170 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1171 return BSAPICPP.IsCompound2(shapeu.ptr);
1172}
1173
1174public override bool IsSoftBody(BulletShape shape)
1175{
1176 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1177 return BSAPICPP.IsSoftBody2(shapeu.ptr);
1178}
1179
1180public override bool IsInfinite(BulletShape shape)
1181{
1182 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1183 return BSAPICPP.IsInfinite2(shapeu.ptr);
1184}
1185
1186public override void SetLocalScaling(BulletShape shape, Vector3 scale)
1187{
1188 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1189 BSAPICPP.SetLocalScaling2(shapeu.ptr, scale);
1190}
1191
1192public override Vector3 GetLocalScaling(BulletShape shape)
1193{
1194 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1195 return BSAPICPP.GetLocalScaling2(shapeu.ptr);
1196}
1197
1198public override Vector3 CalculateLocalInertia(BulletShape shape, float mass)
1199{
1200 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1201 return BSAPICPP.CalculateLocalInertia2(shapeu.ptr, mass);
1202}
1203
1204public override int GetShapeType(BulletShape shape)
1205{
1206 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1207 return BSAPICPP.GetShapeType2(shapeu.ptr);
1208}
1209
1210public override void SetMargin(BulletShape shape, float val)
1211{
1212 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1213 BSAPICPP.SetMargin2(shapeu.ptr, val);
1214}
1215
1216public override float GetMargin(BulletShape shape)
1217{
1218 BulletShapeUnman shapeu = shape as BulletShapeUnman;
1219 return BSAPICPP.GetMargin2(shapeu.ptr);
1220}
1221
1222// =====================================================================================
1223// Debugging
1224public override void DumpRigidBody(BulletWorld world, BulletBody collisionObject)
1225{
1226 BulletWorldUnman worldu = world as BulletWorldUnman;
1227 BulletBodyUnman bodyu = collisionObject as BulletBodyUnman;
1228 BSAPICPP.DumpRigidBody2(worldu.ptr, bodyu.ptr);
1229}
1230
1231public override void DumpCollisionShape(BulletWorld world, BulletShape collisionShape)
1232{
1233 BulletWorldUnman worldu = world as BulletWorldUnman;
1234 BulletShapeUnman shapeu = collisionShape as BulletShapeUnman;
1235 BSAPICPP.DumpCollisionShape2(worldu.ptr, shapeu.ptr);
1236}
1237
1238public override void DumpConstraint(BulletWorld world, BulletConstraint constrain)
1239{
1240 BulletWorldUnman worldu = world as BulletWorldUnman;
1241 BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
1242 BSAPICPP.DumpConstraint2(worldu.ptr, constrainu.ptr);
1243}
1244
1245public override void DumpActivationInfo(BulletWorld world)
1246{
1247 BulletWorldUnman worldu = world as BulletWorldUnman;
1248 BSAPICPP.DumpActivationInfo2(worldu.ptr);
1249}
1250
1251public override void DumpAllInfo(BulletWorld world)
1252{
1253 BulletWorldUnman worldu = world as BulletWorldUnman;
1254 BSAPICPP.DumpAllInfo2(worldu.ptr);
1255}
1256
1257public override void DumpPhysicsStatistics(BulletWorld world)
1258{
1259 BulletWorldUnman worldu = world as BulletWorldUnman;
1260 BSAPICPP.DumpPhysicsStatistics2(worldu.ptr);
1261}
1262
1263// =====================================================================================
1264// =====================================================================================
1265// =====================================================================================
1266// =====================================================================================
1267// =====================================================================================
1268// The actual interface to the unmanaged code
1269static class BSAPICPP
1270{
1271// ===============================================================================
1272// Link back to the managed code for outputting log messages
1273[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
1274public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
1275
1276// ===============================================================================
1277// Initialization and simulation
1278[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1279public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
1280 int maxCollisions, IntPtr collisionArray,
1281 int maxUpdates, IntPtr updateArray,
1282 DebugLogCallback logRoutine);
1283
1284[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1285public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
1286 out int updatedEntityCount, out int collidersCount);
1287
1288[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1289public static extern void Shutdown2(IntPtr sim);
1290
1291[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1292public static extern bool PushUpdate2(IntPtr obj);
1293
1294[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1295public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
1296
1297// =====================================================================================
1298// Mesh, hull, shape and body creation helper routines
1299[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1300public static extern IntPtr CreateMeshShape2(IntPtr world,
1301 int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
1302 int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
1303
1304[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1305public static extern IntPtr CreateHullShape2(IntPtr world,
1306 int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls);
1307
1308[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1309public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape);
1310
1311[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1312public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData);
1313
1314[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1315public static extern bool IsNativeShape2(IntPtr shape);
1316
1317[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1318public static extern void SetShapeCollisionMargin2(IntPtr shape, float margin);
1319
1320[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1321public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale);
1322
1323[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1324public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree);
1325
1326[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1327public static extern int GetNumberOfCompoundChildren2(IntPtr cShape);
1328
1329[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1330public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot);
1331
1332[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1333public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
1334
1335[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1336public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
1337
1338[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1339public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape);
1340
1341[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1342public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape);
1343
1344[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1345public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id);
1346
1347[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1348public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape);
1349
1350[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1351public static extern int GetBodyType2(IntPtr obj);
1352
1353[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1354public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
1355
1356[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1357public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot);
1358
1359[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1360public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
1361
1362[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1363public static extern void DestroyObject2(IntPtr sim, IntPtr obj);
1364
1365// =====================================================================================
1366// Terrain creation and helper routines
1367[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1368public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
1369
1370[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1371public static extern IntPtr CreateTerrainShape2(uint id, Vector3 size, float minHeight, float maxHeight,
1372 [MarshalAs(UnmanagedType.LPArray)] float[] heightMap,
1373 float scaleFactor, float collisionMargin);
1374
1375// =====================================================================================
1376// Constraint creation and helper routines
1377[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1378public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
1379 Vector3 frame1loc, Quaternion frame1rot,
1380 Vector3 frame2loc, Quaternion frame2rot,
1381 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
1382
1383[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1384public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2,
1385 Vector3 joinPoint,
1386 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
1387
1388[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1389public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
1390 Vector3 pivotinA, Vector3 pivotinB,
1391 Vector3 axisInA, Vector3 axisInB,
1392 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
1393
1394[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1395public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse);
1396
1397[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1398public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations);
1399
1400[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1401public static extern bool SetFrames2(IntPtr constrain,
1402 Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
1403
1404[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1405public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
1406
1407[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1408public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
1409
1410[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1411public static extern bool UseFrameOffset2(IntPtr constrain, float enable);
1412
1413[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1414public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce);
1415
1416[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1417public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold);
1418
1419[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1420public static extern bool CalculateTransforms2(IntPtr constrain);
1421
1422[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1423public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
1424
1425[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1426public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain);
1427
1428// =====================================================================================
1429// btCollisionWorld entries
1430[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1431public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj);
1432
1433[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1434public static extern void UpdateAabbs2(IntPtr world);
1435
1436[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1437public static extern bool GetForceUpdateAllAabbs2(IntPtr world);
1438
1439[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1440public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force);
1441
1442// =====================================================================================
1443// btDynamicsWorld entries
1444[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1445public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj);
1446
1447[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1448public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj);
1449
1450[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1451public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects);
1452
1453[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1454public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain);
1455// =====================================================================================
1456// btCollisionObject entries
1457[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1458public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain);
1459
1460[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1461public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict);
1462
1463[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1464public static extern bool HasAnisotripicFriction2(IntPtr constrain);
1465
1466[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1467public static extern void SetContactProcessingThreshold2(IntPtr obj, float val);
1468
1469[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1470public static extern float GetContactProcessingThreshold2(IntPtr obj);
1471
1472[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1473public static extern bool IsStaticObject2(IntPtr obj);
1474
1475[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1476public static extern bool IsKinematicObject2(IntPtr obj);
1477
1478[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1479public static extern bool IsStaticOrKinematicObject2(IntPtr obj);
1480
1481[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1482public static extern bool HasContactResponse2(IntPtr obj);
1483
1484[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1485public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape);
1486
1487[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1488public static extern IntPtr GetCollisionShape2(IntPtr obj);
1489
1490[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1491public static extern int GetActivationState2(IntPtr obj);
1492
1493[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1494public static extern void SetActivationState2(IntPtr obj, int state);
1495
1496[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1497public static extern void SetDeactivationTime2(IntPtr obj, float dtime);
1498
1499[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1500public static extern float GetDeactivationTime2(IntPtr obj);
1501
1502[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1503public static extern void ForceActivationState2(IntPtr obj, ActivationState state);
1504
1505[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1506public static extern void Activate2(IntPtr obj, bool forceActivation);
1507
1508[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1509public static extern bool IsActive2(IntPtr obj);
1510
1511[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1512public static extern void SetRestitution2(IntPtr obj, float val);
1513
1514[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1515public static extern float GetRestitution2(IntPtr obj);
1516
1517[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1518public static extern void SetFriction2(IntPtr obj, float val);
1519
1520[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1521public static extern float GetFriction2(IntPtr obj);
1522
1523 /* Haven't defined the type 'Transform'
1524[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1525public static extern Transform GetWorldTransform2(IntPtr obj);
1526
1527[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1528public static extern void setWorldTransform2(IntPtr obj, Transform trans);
1529 */
1530
1531[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1532public static extern Vector3 GetPosition2(IntPtr obj);
1533
1534[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1535public static extern Quaternion GetOrientation2(IntPtr obj);
1536
1537[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1538public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation);
1539
1540[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1541public static extern IntPtr GetBroadphaseHandle2(IntPtr obj);
1542
1543[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1544public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle);
1545
1546 /*
1547[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1548public static extern Transform GetInterpolationWorldTransform2(IntPtr obj);
1549
1550[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1551public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans);
1552 */
1553
1554[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1555public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel);
1556
1557[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1558public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel);
1559
1560[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1561public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel);
1562
1563[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1564public static extern float GetHitFraction2(IntPtr obj);
1565
1566[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1567public static extern void SetHitFraction2(IntPtr obj, float val);
1568
1569[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1570public static extern CollisionFlags GetCollisionFlags2(IntPtr obj);
1571
1572[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1573public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags);
1574
1575[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1576public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags);
1577
1578[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1579public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags);
1580
1581[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1582public static extern float GetCcdMotionThreshold2(IntPtr obj);
1583
1584[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1585public static extern void SetCcdMotionThreshold2(IntPtr obj, float val);
1586
1587[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1588public static extern float GetCcdSweptSphereRadius2(IntPtr obj);
1589
1590[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1591public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val);
1592
1593[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1594public static extern IntPtr GetUserPointer2(IntPtr obj);
1595
1596[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1597public static extern void SetUserPointer2(IntPtr obj, IntPtr val);
1598
1599// =====================================================================================
1600// btRigidBody entries
1601[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1602public static extern void ApplyGravity2(IntPtr obj);
1603
1604[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1605public static extern void SetGravity2(IntPtr obj, Vector3 val);
1606
1607[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1608public static extern Vector3 GetGravity2(IntPtr obj);
1609
1610[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1611public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping);
1612
1613[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1614public static extern void SetLinearDamping2(IntPtr obj, float lin_damping);
1615
1616[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1617public static extern void SetAngularDamping2(IntPtr obj, float ang_damping);
1618
1619[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1620public static extern float GetLinearDamping2(IntPtr obj);
1621
1622[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1623public static extern float GetAngularDamping2(IntPtr obj);
1624
1625[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1626public static extern float GetLinearSleepingThreshold2(IntPtr obj);
1627
1628[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1629public static extern float GetAngularSleepingThreshold2(IntPtr obj);
1630
1631[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1632public static extern void ApplyDamping2(IntPtr obj, float timeStep);
1633
1634[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1635public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia);
1636
1637[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1638public static extern Vector3 GetLinearFactor2(IntPtr obj);
1639
1640[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1641public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor);
1642
1643 /*
1644[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1645public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans);
1646 */
1647
1648[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1649public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot);
1650
1651// Add a force to the object as if its mass is one.
1652[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1653public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force);
1654
1655// Set the force being applied to the object as if its mass is one.
1656[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1657public static extern void SetObjectForce2(IntPtr obj, Vector3 force);
1658
1659[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1660public static extern Vector3 GetTotalForce2(IntPtr obj);
1661
1662[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1663public static extern Vector3 GetTotalTorque2(IntPtr obj);
1664
1665[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1666public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj);
1667
1668[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1669public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert);
1670
1671[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1672public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold);
1673
1674[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1675public static extern void ApplyTorque2(IntPtr obj, Vector3 torque);
1676
1677// Apply force at the given point. Will add torque to the object.
1678[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1679public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos);
1680
1681// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
1682[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1683public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp);
1684
1685// Apply impulse to the object's torque. Force is scaled by object's mass.
1686[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1687public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp);
1688
1689// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
1690[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1691public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos);
1692
1693[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1694public static extern void ClearForces2(IntPtr obj);
1695
1696[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1697public static extern void ClearAllForces2(IntPtr obj);
1698
1699[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1700public static extern void UpdateInertiaTensor2(IntPtr obj);
1701
1702[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1703public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj);
1704
1705 /*
1706[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1707public static extern Transform GetCenterOfMassTransform2(IntPtr obj);
1708 */
1709
1710[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1711public static extern Vector3 GetLinearVelocity2(IntPtr obj);
1712
1713[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1714public static extern Vector3 GetAngularVelocity2(IntPtr obj);
1715
1716[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1717public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val);
1718
1719[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1720public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity);
1721
1722[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1723public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos);
1724
1725[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1726public static extern void Translate2(IntPtr obj, Vector3 trans);
1727
1728[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1729public static extern void UpdateDeactivation2(IntPtr obj, float timeStep);
1730
1731[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1732public static extern bool WantsSleeping2(IntPtr obj);
1733
1734[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1735public static extern void SetAngularFactor2(IntPtr obj, float factor);
1736
1737[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1738public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor);
1739
1740[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1741public static extern Vector3 GetAngularFactor2(IntPtr obj);
1742
1743[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1744public static extern bool IsInWorld2(IntPtr obj);
1745
1746[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1747public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain);
1748
1749[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1750public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain);
1751
1752[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1753public static extern IntPtr GetConstraintRef2(IntPtr obj, int index);
1754
1755[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1756public static extern int GetNumConstraintRefs2(IntPtr obj);
1757
1758[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1759public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask);
1760
1761// =====================================================================================
1762// btCollisionShape entries
1763
1764[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1765public static extern float GetAngularMotionDisc2(IntPtr shape);
1766
1767[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1768public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor);
1769
1770[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1771public static extern bool IsPolyhedral2(IntPtr shape);
1772
1773[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1774public static extern bool IsConvex2d2(IntPtr shape);
1775
1776[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1777public static extern bool IsConvex2(IntPtr shape);
1778
1779[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1780public static extern bool IsNonMoving2(IntPtr shape);
1781
1782[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1783public static extern bool IsConcave2(IntPtr shape);
1784
1785[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1786public static extern bool IsCompound2(IntPtr shape);
1787
1788[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1789public static extern bool IsSoftBody2(IntPtr shape);
1790
1791[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1792public static extern bool IsInfinite2(IntPtr shape);
1793
1794[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1795public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale);
1796
1797[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1798public static extern Vector3 GetLocalScaling2(IntPtr shape);
1799
1800[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1801public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass);
1802
1803[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1804public static extern int GetShapeType2(IntPtr shape);
1805
1806[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1807public static extern void SetMargin2(IntPtr shape, float val);
1808
1809[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1810public static extern float GetMargin2(IntPtr shape);
1811
1812// =====================================================================================
1813// Debugging
1814[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1815public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject);
1816
1817[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1818public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape);
1819
1820[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1821public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo);
1822
1823[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1824public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain);
1825
1826[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1827public static extern void DumpActivationInfo2(IntPtr sim);
1828
1829[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1830public static extern void DumpAllInfo2(IntPtr sim);
1831
1832[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1833public static extern void DumpPhysicsStatistics2(IntPtr sim);
1834
1835}
1836
1837}
1838
1839}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
new file mode 100755
index 0000000..30a7bee
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
@@ -0,0 +1,1622 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyrightD
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.IO;
30using System.Text;
31
32using OpenSim.Framework;
33
34using OpenMetaverse;
35
36using BulletXNA;
37using BulletXNA.LinearMath;
38using BulletXNA.BulletCollision;
39using BulletXNA.BulletDynamics;
40using BulletXNA.BulletCollision.CollisionDispatch;
41
42namespace OpenSim.Region.Physics.BulletSPlugin
43{
44public sealed class BSAPIXNA : BSAPITemplate
45{
46private sealed class BulletWorldXNA : BulletWorld
47{
48 public DiscreteDynamicsWorld world;
49 public BulletWorldXNA(uint id, BSScene physScene, DiscreteDynamicsWorld xx)
50 : base(id, physScene)
51 {
52 world = xx;
53 }
54}
55
56private sealed class BulletBodyXNA : BulletBody
57{
58 public CollisionObject body;
59 public RigidBody rigidBody { get { return RigidBody.Upcast(body); } }
60
61 public BulletBodyXNA(uint id, CollisionObject xx)
62 : base(id)
63 {
64 body = xx;
65 }
66 public override bool HasPhysicalBody
67 {
68 get { return body != null; }
69 }
70 public override void Clear()
71 {
72 body = null;
73 }
74 public override string AddrString
75 {
76 get { return "XNARigidBody"; }
77 }
78}
79
80private sealed class BulletShapeXNA : BulletShape
81{
82 public CollisionShape shape;
83 public BulletShapeXNA(CollisionShape xx, BSPhysicsShapeType typ)
84 : base()
85 {
86 shape = xx;
87 type = typ;
88 }
89 public override bool HasPhysicalShape
90 {
91 get { return shape != null; }
92 }
93 public override void Clear()
94 {
95 shape = null;
96 }
97 public override BulletShape Clone()
98 {
99 return new BulletShapeXNA(shape, type);
100 }
101 public override bool ReferenceSame(BulletShape other)
102 {
103 BulletShapeXNA otheru = other as BulletShapeXNA;
104 return (otheru != null) && (this.shape == otheru.shape);
105
106 }
107 public override string AddrString
108 {
109 get { return "XNACollisionShape"; }
110 }
111}
112private sealed class BulletConstraintXNA : BulletConstraint
113{
114 public TypedConstraint constrain;
115 public BulletConstraintXNA(TypedConstraint xx) : base()
116 {
117 constrain = xx;
118 }
119
120 public override void Clear()
121 {
122 constrain = null;
123 }
124 public override bool HasPhysicalConstraint { get { return constrain != null; } }
125
126 // Used for log messages for a unique display of the memory/object allocated to this instance
127 public override string AddrString
128 {
129 get { return "XNAConstraint"; }
130 }
131}
132
133 private static int m_collisionsThisFrame;
134 private BSScene PhysicsScene { get; set; }
135
136 public override string BulletEngineName { get { return "BulletXNA"; } }
137 public override string BulletEngineVersion { get; protected set; }
138
139 public BSAPIXNA(string paramName, BSScene physScene)
140 {
141 PhysicsScene = physScene;
142 }
143
144 /// <summary>
145 ///
146 /// </summary>
147 /// <param name="p"></param>
148 /// <param name="p_2"></param>
149 public override bool RemoveObjectFromWorld(BulletWorld pWorld, BulletBody pBody)
150 {
151 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
152 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
153 world.RemoveRigidBody(body);
154 return true;
155 }
156
157 public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects)
158 {
159 /* TODO */
160 return false;
161 }
162
163 public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain)
164 {
165 /* TODO */
166 return false;
167 }
168
169 public override void SetRestitution(BulletBody pBody, float pRestitution)
170 {
171 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
172 body.SetRestitution(pRestitution);
173 }
174
175 public override int GetShapeType(BulletShape pShape)
176 {
177 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
178 return (int)shape.GetShapeType();
179 }
180 public override void SetMargin(BulletShape pShape, float pMargin)
181 {
182 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
183 shape.SetMargin(pMargin);
184 }
185
186 public override float GetMargin(BulletShape pShape)
187 {
188 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
189 return shape.GetMargin();
190 }
191
192 public override void SetLocalScaling(BulletShape pShape, Vector3 pScale)
193 {
194 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
195 IndexedVector3 vec = new IndexedVector3(pScale.X, pScale.Y, pScale.Z);
196 shape.SetLocalScaling(ref vec);
197
198 }
199
200 public override void SetContactProcessingThreshold(BulletBody pBody, float contactprocessingthreshold)
201 {
202 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
203 body.SetContactProcessingThreshold(contactprocessingthreshold);
204 }
205
206 public override void SetCcdMotionThreshold(BulletBody pBody, float pccdMotionThreashold)
207 {
208 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
209 body.SetCcdMotionThreshold(pccdMotionThreashold);
210 }
211
212 public override void SetCcdSweptSphereRadius(BulletBody pBody, float pCcdSweptSphereRadius)
213 {
214 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
215 body.SetCcdSweptSphereRadius(pCcdSweptSphereRadius);
216 }
217
218 public override void SetAngularFactorV(BulletBody pBody, Vector3 pAngularFactor)
219 {
220 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
221 body.SetAngularFactor(new IndexedVector3(pAngularFactor.X, pAngularFactor.Y, pAngularFactor.Z));
222 }
223
224 public override CollisionFlags AddToCollisionFlags(BulletBody pBody, CollisionFlags pcollisionFlags)
225 {
226 CollisionObject body = ((BulletBodyXNA)pBody).body;
227 CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags();
228 existingcollisionFlags |= pcollisionFlags;
229 body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags);
230 return (CollisionFlags) (uint) existingcollisionFlags;
231 }
232
233 public override bool AddObjectToWorld(BulletWorld pWorld, BulletBody pBody)
234 {
235 // Bullet resets several variables when an object is added to the world. In particular,
236 // BulletXNA resets position and rotation. Gravity is also reset depending on the static/dynamic
237 // type. Of course, the collision flags in the broadphase proxy are initialized to default.
238 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
239 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
240
241 IndexedMatrix origPos = body.GetWorldTransform();
242 IndexedVector3 origGrav = body.GetGravity();
243
244 //if (!(body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE && body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE))
245
246 world.AddRigidBody(body);
247
248 body.SetWorldTransform(origPos);
249 body.SetGravity(origGrav);
250
251 pBody.ApplyCollisionMask(pWorld.physicsScene);
252
253 //if (body.GetBroadphaseHandle() != null)
254 // world.UpdateSingleAabb(body);
255 return true;
256 }
257
258 public override void ForceActivationState(BulletBody pBody, ActivationState pActivationState)
259 {
260 CollisionObject body = ((BulletBodyXNA)pBody).body;
261 body.ForceActivationState((BulletXNA.BulletCollision.ActivationState)(uint)pActivationState);
262 }
263
264 public override void UpdateSingleAabb(BulletWorld pWorld, BulletBody pBody)
265 {
266 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
267 CollisionObject body = ((BulletBodyXNA)pBody).body;
268 world.UpdateSingleAabb(body);
269 }
270
271 public override void UpdateAabbs(BulletWorld world) { /* TODO */ }
272 public override bool GetForceUpdateAllAabbs(BulletWorld world) { /* TODO */ return false; }
273 public override void SetForceUpdateAllAabbs(BulletWorld world, bool force) { /* TODO */ }
274
275 public override bool SetCollisionGroupMask(BulletBody pBody, uint pGroup, uint pMask)
276 {
277 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
278 body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup;
279 body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup;
280 if ((uint) body.GetBroadphaseHandle().m_collisionFilterGroup == 0)
281 return false;
282 return true;
283 }
284
285 public override void ClearAllForces(BulletBody pBody)
286 {
287 CollisionObject body = ((BulletBodyXNA)pBody).body;
288 IndexedVector3 zeroVector = new IndexedVector3(0, 0, 0);
289 body.SetInterpolationLinearVelocity(ref zeroVector);
290 body.SetInterpolationAngularVelocity(ref zeroVector);
291 IndexedMatrix bodytransform = body.GetWorldTransform();
292
293 body.SetInterpolationWorldTransform(ref bodytransform);
294
295 if (body is RigidBody)
296 {
297 RigidBody rigidbody = body as RigidBody;
298 rigidbody.SetLinearVelocity(zeroVector);
299 rigidbody.SetAngularVelocity(zeroVector);
300 rigidbody.ClearForces();
301 }
302 }
303
304 public override void SetInterpolationAngularVelocity(BulletBody pBody, Vector3 pVector3)
305 {
306 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
307 IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z);
308 body.SetInterpolationAngularVelocity(ref vec);
309 }
310
311 public override void SetAngularVelocity(BulletBody pBody, Vector3 pVector3)
312 {
313 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
314 IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z);
315 body.SetAngularVelocity(ref vec);
316 }
317 public override Vector3 GetTotalForce(BulletBody pBody)
318 {
319 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
320 IndexedVector3 iv3 = body.GetTotalForce();
321 return new Vector3(iv3.X, iv3.Y, iv3.Z);
322 }
323 public override Vector3 GetTotalTorque(BulletBody pBody)
324 {
325 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
326 IndexedVector3 iv3 = body.GetTotalTorque();
327 return new Vector3(iv3.X, iv3.Y, iv3.Z);
328 }
329 public override Vector3 GetInvInertiaDiagLocal(BulletBody pBody)
330 {
331 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
332 IndexedVector3 iv3 = body.GetInvInertiaDiagLocal();
333 return new Vector3(iv3.X, iv3.Y, iv3.Z);
334 }
335 public override void SetInvInertiaDiagLocal(BulletBody pBody, Vector3 inert)
336 {
337 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
338 IndexedVector3 iv3 = new IndexedVector3(inert.X, inert.Y, inert.Z);
339 body.SetInvInertiaDiagLocal(ref iv3);
340 }
341 public override void ApplyForce(BulletBody pBody, Vector3 force, Vector3 pos)
342 {
343 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
344 IndexedVector3 forceiv3 = new IndexedVector3(force.X, force.Y, force.Z);
345 IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z);
346 body.ApplyForce(ref forceiv3, ref posiv3);
347 }
348 public override void ApplyImpulse(BulletBody pBody, Vector3 imp, Vector3 pos)
349 {
350 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
351 IndexedVector3 impiv3 = new IndexedVector3(imp.X, imp.Y, imp.Z);
352 IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z);
353 body.ApplyImpulse(ref impiv3, ref posiv3);
354 }
355
356 public override void ClearForces(BulletBody pBody)
357 {
358 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
359 body.ClearForces();
360 }
361
362 public override void SetTranslation(BulletBody pBody, Vector3 _position, Quaternion _orientation)
363 {
364 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
365 IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z);
366 IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z,
367 _orientation.W);
368 IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion);
369 mat._origin = vposition;
370 body.SetWorldTransform(mat);
371
372 }
373
374 public override Vector3 GetPosition(BulletBody pBody)
375 {
376 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
377 IndexedVector3 pos = body.GetInterpolationWorldTransform()._origin;
378 return new Vector3(pos.X, pos.Y, pos.Z);
379 }
380
381 public override Vector3 CalculateLocalInertia(BulletShape pShape, float pphysMass)
382 {
383 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
384 IndexedVector3 inertia = IndexedVector3.Zero;
385 shape.CalculateLocalInertia(pphysMass, out inertia);
386 return new Vector3(inertia.X, inertia.Y, inertia.Z);
387 }
388
389 public override void SetMassProps(BulletBody pBody, float pphysMass, Vector3 plocalInertia)
390 {
391 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
392 IndexedVector3 inertia = new IndexedVector3(plocalInertia.X, plocalInertia.Y, plocalInertia.Z);
393 body.SetMassProps(pphysMass, inertia);
394 }
395
396
397 public override void SetObjectForce(BulletBody pBody, Vector3 _force)
398 {
399 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
400 IndexedVector3 force = new IndexedVector3(_force.X, _force.Y, _force.Z);
401 body.SetTotalForce(ref force);
402 }
403
404 public override void SetFriction(BulletBody pBody, float _currentFriction)
405 {
406 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
407 body.SetFriction(_currentFriction);
408 }
409
410 public override void SetLinearVelocity(BulletBody pBody, Vector3 _velocity)
411 {
412 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
413 IndexedVector3 velocity = new IndexedVector3(_velocity.X, _velocity.Y, _velocity.Z);
414 body.SetLinearVelocity(velocity);
415 }
416
417 public override void Activate(BulletBody pBody, bool pforceactivation)
418 {
419 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
420 body.Activate(pforceactivation);
421
422 }
423
424 public override Quaternion GetOrientation(BulletBody pBody)
425 {
426 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
427 IndexedQuaternion mat = body.GetInterpolationWorldTransform().GetRotation();
428 return new Quaternion(mat.X, mat.Y, mat.Z, mat.W);
429 }
430
431 public override CollisionFlags RemoveFromCollisionFlags(BulletBody pBody, CollisionFlags pcollisionFlags)
432 {
433 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
434 CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags();
435 existingcollisionFlags &= ~pcollisionFlags;
436 body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags);
437 return (CollisionFlags)(uint)existingcollisionFlags;
438 }
439
440 public override float GetCcdMotionThreshold(BulletBody obj) { /* TODO */ return 0f; }
441
442 public override float GetCcdSweptSphereRadius(BulletBody obj) { /* TODO */ return 0f; }
443
444 public override IntPtr GetUserPointer(BulletBody obj) { /* TODO */ return IntPtr.Zero; }
445
446 public override void SetUserPointer(BulletBody obj, IntPtr val) { /* TODO */ }
447
448 public override void SetGravity(BulletBody pBody, Vector3 pGravity)
449 {
450 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
451 IndexedVector3 gravity = new IndexedVector3(pGravity.X, pGravity.Y, pGravity.Z);
452 body.SetGravity(gravity);
453 }
454
455 public override bool DestroyConstraint(BulletWorld pWorld, BulletConstraint pConstraint)
456 {
457 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
458 TypedConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain;
459 world.RemoveConstraint(constraint);
460 return true;
461 }
462
463 public override bool SetLinearLimits(BulletConstraint pConstraint, Vector3 low, Vector3 high)
464 {
465 Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint;
466 IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z);
467 IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z);
468 constraint.SetLinearLowerLimit(lowlimit);
469 constraint.SetLinearUpperLimit(highlimit);
470 return true;
471 }
472
473 public override bool SetAngularLimits(BulletConstraint pConstraint, Vector3 low, Vector3 high)
474 {
475 Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint;
476 IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z);
477 IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z);
478 constraint.SetAngularLowerLimit(lowlimit);
479 constraint.SetAngularUpperLimit(highlimit);
480 return true;
481 }
482
483 public override void SetConstraintNumSolverIterations(BulletConstraint pConstraint, float cnt)
484 {
485 Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint;
486 constraint.SetOverrideNumSolverIterations((int)cnt);
487 }
488
489 public override bool CalculateTransforms(BulletConstraint pConstraint)
490 {
491 Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint;
492 constraint.CalculateTransforms();
493 return true;
494 }
495
496 public override void SetConstraintEnable(BulletConstraint pConstraint, float p_2)
497 {
498 Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint;
499 constraint.SetEnabled((p_2 == 0) ? false : true);
500 }
501
502
503 //BulletSimAPI.Create6DofConstraint(m_world.ptr, m_body1.ptr, m_body2.ptr,frame1, frame1rot,frame2, frame2rot,useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
504 public override BulletConstraint Create6DofConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
505
506 {
507 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
508 RigidBody body1 = ((BulletBodyXNA)pBody1).rigidBody;
509 RigidBody body2 = ((BulletBodyXNA)pBody2).rigidBody;
510 IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
511 IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
512 IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
513 frame1._origin = frame1v;
514
515 IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z);
516 IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W);
517 IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot);
518 frame2._origin = frame1v;
519
520 Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2,
521 puseLinearReferenceFrameA);
522 consttr.CalculateTransforms();
523 world.AddConstraint(consttr,pdisableCollisionsBetweenLinkedBodies);
524
525 return new BulletConstraintXNA(consttr);
526 }
527
528
529 /// <summary>
530 ///
531 /// </summary>
532 /// <param name="pWorld"></param>
533 /// <param name="pBody1"></param>
534 /// <param name="pBody2"></param>
535 /// <param name="pjoinPoint"></param>
536 /// <param name="puseLinearReferenceFrameA"></param>
537 /// <param name="pdisableCollisionsBetweenLinkedBodies"></param>
538 /// <returns></returns>
539 public override BulletConstraint Create6DofConstraintToPoint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 pjoinPoint, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
540 {
541 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
542 RigidBody body1 = ((BulletBodyXNA)pBody1).rigidBody;
543 RigidBody body2 = ((BulletBodyXNA)pBody2).rigidBody;
544 IndexedMatrix frame1 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));
545 IndexedMatrix frame2 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));
546
547 IndexedVector3 joinPoint = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
548 IndexedMatrix mat = IndexedMatrix.Identity;
549 mat._origin = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
550 frame1._origin = body1.GetWorldTransform().Inverse()*joinPoint;
551 frame2._origin = body2.GetWorldTransform().Inverse()*joinPoint;
552
553 Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2, puseLinearReferenceFrameA);
554 consttr.CalculateTransforms();
555 world.AddConstraint(consttr, pdisableCollisionsBetweenLinkedBodies);
556
557 return new BulletConstraintXNA(consttr);
558 }
559 //SetFrames(m_constraint.ptr, frameA, frameArot, frameB, frameBrot);
560 public override bool SetFrames(BulletConstraint pConstraint, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot)
561 {
562 Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint;
563 IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
564 IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
565 IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
566 frame1._origin = frame1v;
567
568 IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z);
569 IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W);
570 IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot);
571 frame2._origin = frame1v;
572 constraint.SetFrames(ref frame1, ref frame2);
573 return true;
574 }
575
576 public override Vector3 GetLinearVelocity(BulletBody pBody)
577 {
578 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
579 IndexedVector3 iv3 = body.GetLinearVelocity();
580 return new Vector3(iv3.X, iv3.Y, iv3.Z);
581 }
582 public override Vector3 GetAngularVelocity(BulletBody pBody)
583 {
584 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
585 IndexedVector3 iv3 = body.GetAngularVelocity();
586 return new Vector3(iv3.X, iv3.Y, iv3.Z);
587 }
588 public override Vector3 GetVelocityInLocalPoint(BulletBody pBody, Vector3 pos)
589 {
590 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
591 IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z);
592 IndexedVector3 iv3 = body.GetVelocityInLocalPoint(ref posiv3);
593 return new Vector3(iv3.X, iv3.Y, iv3.Z);
594 }
595 public override void Translate(BulletBody pBody, Vector3 trans)
596 {
597 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
598 }
599 public override void UpdateDeactivation(BulletBody pBody, float timeStep)
600 {
601 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
602 body.UpdateDeactivation(timeStep);
603 }
604
605 public override bool WantsSleeping(BulletBody pBody)
606 {
607 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
608 return body.WantsSleeping();
609 }
610
611 public override void SetAngularFactor(BulletBody pBody, float factor)
612 {
613 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
614 body.SetAngularFactor(factor);
615 }
616
617 public override Vector3 GetAngularFactor(BulletBody pBody)
618 {
619 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
620 IndexedVector3 iv3 = body.GetAngularFactor();
621 return new Vector3(iv3.X, iv3.Y, iv3.Z);
622 }
623
624 public override bool IsInWorld(BulletWorld pWorld, BulletBody pBody)
625 {
626 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
627 CollisionObject body = ((BulletBodyXNA)pBody).body;
628 return world.IsInWorld(body);
629 }
630
631 public override void AddConstraintRef(BulletBody pBody, BulletConstraint pConstrain)
632 {
633 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
634 TypedConstraint constrain = ((BulletConstraintXNA)pConstrain).constrain;
635 body.AddConstraintRef(constrain);
636 }
637
638 public override void RemoveConstraintRef(BulletBody pBody, BulletConstraint pConstrain)
639 {
640 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
641 TypedConstraint constrain = ((BulletConstraintXNA)pConstrain).constrain;
642 body.RemoveConstraintRef(constrain);
643 }
644
645 public override BulletConstraint GetConstraintRef(BulletBody pBody, int index)
646 {
647 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
648 return new BulletConstraintXNA(body.GetConstraintRef(index));
649 }
650
651 public override int GetNumConstraintRefs(BulletBody pBody)
652 {
653 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
654 return body.GetNumConstraintRefs();
655 }
656
657 public override void SetInterpolationLinearVelocity(BulletBody pBody, Vector3 VehicleVelocity)
658 {
659 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
660 IndexedVector3 velocity = new IndexedVector3(VehicleVelocity.X, VehicleVelocity.Y, VehicleVelocity.Z);
661 body.SetInterpolationLinearVelocity(ref velocity);
662 }
663
664 public override bool UseFrameOffset(BulletConstraint pConstraint, float onOff)
665 {
666 Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint;
667 constraint.SetUseFrameOffset((onOff == 0) ? false : true);
668 return true;
669 }
670 //SetBreakingImpulseThreshold(m_constraint.ptr, threshold);
671 public override bool SetBreakingImpulseThreshold(BulletConstraint pConstraint, float threshold)
672 {
673 Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint;
674 constraint.SetBreakingImpulseThreshold(threshold);
675 return true;
676 }
677 //BulletSimAPI.SetAngularDamping(Prim.PhysBody.ptr, angularDamping);
678 public override void SetAngularDamping(BulletBody pBody, float angularDamping)
679 {
680 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
681 float lineardamping = body.GetLinearDamping();
682 body.SetDamping(lineardamping, angularDamping);
683
684 }
685
686 public override void UpdateInertiaTensor(BulletBody pBody)
687 {
688 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
689 body.UpdateInertiaTensor();
690 }
691
692 public override void RecalculateCompoundShapeLocalAabb(BulletShape pCompoundShape)
693 {
694 CompoundShape shape = ((BulletShapeXNA)pCompoundShape).shape as CompoundShape;
695 shape.RecalculateLocalAabb();
696 }
697
698 //BulletSimAPI.GetCollisionFlags(PhysBody.ptr)
699 public override CollisionFlags GetCollisionFlags(BulletBody pBody)
700 {
701 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
702 uint flags = (uint)body.GetCollisionFlags();
703 return (CollisionFlags) flags;
704 }
705
706 public override void SetDamping(BulletBody pBody, float pLinear, float pAngular)
707 {
708 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
709 body.SetDamping(pLinear, pAngular);
710 }
711 //PhysBody.ptr, PhysicsScene.Params.deactivationTime);
712 public override void SetDeactivationTime(BulletBody pBody, float pDeactivationTime)
713 {
714 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
715 body.SetDeactivationTime(pDeactivationTime);
716 }
717 //SetSleepingThresholds(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold);
718 public override void SetSleepingThresholds(BulletBody pBody, float plinearSleepingThreshold, float pangularSleepingThreshold)
719 {
720 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
721 body.SetSleepingThresholds(plinearSleepingThreshold, pangularSleepingThreshold);
722 }
723
724 public override CollisionObjectTypes GetBodyType(BulletBody pBody)
725 {
726 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
727 return (CollisionObjectTypes)(int) body.GetInternalType();
728 }
729
730 public override void ApplyGravity(BulletBody obj) { /* TODO */ }
731
732 public override Vector3 GetGravity(BulletBody obj) { /* TODO */ return Vector3.Zero; }
733
734 public override void SetLinearDamping(BulletBody obj, float lin_damping) { /* TODO */ }
735
736 public override float GetLinearDamping(BulletBody obj) { /* TODO */ return 0f; }
737
738 public override float GetAngularDamping(BulletBody obj) { /* TODO */ return 0f; }
739
740 public override float GetLinearSleepingThreshold(BulletBody obj) { /* TODO */ return 0f; }
741
742 public override void ApplyDamping(BulletBody obj, float timeStep) { /* TODO */ }
743
744 public override Vector3 GetLinearFactor(BulletBody obj) { /* TODO */ return Vector3.Zero; }
745
746 public override void SetLinearFactor(BulletBody obj, Vector3 factor) { /* TODO */ }
747
748 public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot) { /* TODO */ }
749
750 //BulletSimAPI.ApplyCentralForce(PhysBody.ptr, fSum);
751 public override void ApplyCentralForce(BulletBody pBody, Vector3 pfSum)
752 {
753 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
754 IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
755 body.ApplyCentralForce(ref fSum);
756 }
757 public override void ApplyCentralImpulse(BulletBody pBody, Vector3 pfSum)
758 {
759 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
760 IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
761 body.ApplyCentralImpulse(ref fSum);
762 }
763 public override void ApplyTorque(BulletBody pBody, Vector3 pfSum)
764 {
765 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
766 IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
767 body.ApplyTorque(ref fSum);
768 }
769 public override void ApplyTorqueImpulse(BulletBody pBody, Vector3 pfSum)
770 {
771 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
772 IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
773 body.ApplyTorqueImpulse(ref fSum);
774 }
775
776 public override void DumpRigidBody(BulletWorld p, BulletBody p_2)
777 {
778 //TODO:
779 }
780
781 public override void DumpCollisionShape(BulletWorld p, BulletShape p_2)
782 {
783 //TODO:
784 }
785 public override void DumpConstraint(BulletWorld world, BulletConstraint constrain)
786 {
787 //TODO:
788 }
789
790 public override void DumpActivationInfo(BulletWorld world)
791 {
792 //TODO:
793 }
794
795 public override void DumpAllInfo(BulletWorld world)
796 {
797 //TODO:
798 }
799
800 public override void DumpPhysicsStatistics(BulletWorld world)
801 {
802 //TODO:
803 }
804
805 public override void DestroyObject(BulletWorld p, BulletBody p_2)
806 {
807 //TODO:
808 }
809
810 public override void Shutdown(BulletWorld pWorld)
811 {
812 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
813 world.Cleanup();
814 }
815
816 public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id)
817 {
818 return null;
819 }
820
821 public override bool DeleteCollisionShape(BulletWorld p, BulletShape p_2)
822 {
823 //TODO:
824 return false;
825 }
826 //(sim.ptr, shape.ptr, prim.LocalID, prim.RawPosition, prim.RawOrientation);
827
828 public override BulletBody CreateBodyFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
829 {
830 CollisionWorld world = ((BulletWorldXNA)pWorld).world;
831 IndexedMatrix mat =
832 IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
833 pRawOrientation.Z, pRawOrientation.W));
834 mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
835 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
836 //UpdateSingleAabb(world, shape);
837 // TODO: Feed Update array into null
838 RigidBody body = new RigidBody(0,new SimMotionState(world,pLocalID,mat,null),shape,IndexedVector3.Zero);
839
840 body.SetUserPointer(pLocalID);
841 return new BulletBodyXNA(pLocalID, body);
842 }
843
844
845 public override BulletBody CreateBodyWithDefaultMotionState( BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
846 {
847
848 IndexedMatrix mat =
849 IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
850 pRawOrientation.Z, pRawOrientation.W));
851 mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
852
853 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
854
855 // TODO: Feed Update array into null
856 RigidBody body = new RigidBody(0, new DefaultMotionState( mat, IndexedMatrix.Identity), shape, IndexedVector3.Zero);
857 body.SetWorldTransform(mat);
858 body.SetUserPointer(pLocalID);
859 return new BulletBodyXNA(pLocalID, body);
860 }
861 //(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
862 public override CollisionFlags SetCollisionFlags(BulletBody pBody, CollisionFlags collisionFlags)
863 {
864 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
865 body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags) (uint) collisionFlags);
866 return (CollisionFlags)body.GetCollisionFlags();
867 }
868
869 public override Vector3 GetAnisotripicFriction(BulletConstraint pconstrain) { /* TODO */ return Vector3.Zero; }
870 public override Vector3 SetAnisotripicFriction(BulletConstraint pconstrain, Vector3 frict) { /* TODO */ return Vector3.Zero; }
871 public override bool HasAnisotripicFriction(BulletConstraint pconstrain) { /* TODO */ return false; }
872 public override float GetContactProcessingThreshold(BulletBody pBody) { /* TODO */ return 0f; }
873 public override bool IsStaticObject(BulletBody pBody) { /* TODO */ return false; }
874 public override bool IsKinematicObject(BulletBody pBody) { /* TODO */ return false; }
875 public override bool IsStaticOrKinematicObject(BulletBody pBody) { /* TODO */ return false; }
876 public override bool HasContactResponse(BulletBody pBody) { /* TODO */ return false; }
877 public override int GetActivationState(BulletBody pBody) { /* TODO */ return 0; }
878 public override void SetActivationState(BulletBody pBody, int state) { /* TODO */ }
879 public override float GetDeactivationTime(BulletBody pBody) { /* TODO */ return 0f; }
880 public override bool IsActive(BulletBody pBody) { /* TODO */ return false; }
881 public override float GetRestitution(BulletBody pBody) { /* TODO */ return 0f; }
882 public override float GetFriction(BulletBody pBody) { /* TODO */ return 0f; }
883 public override void SetInterpolationVelocity(BulletBody pBody, Vector3 linearVel, Vector3 angularVel) { /* TODO */ }
884 public override float GetHitFraction(BulletBody pBody) { /* TODO */ return 0f; }
885
886 //(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainHitFraction);
887 public override void SetHitFraction(BulletBody pBody, float pHitFraction)
888 {
889 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
890 body.SetHitFraction(pHitFraction);
891 }
892 //BuildCapsuleShape(physicsScene.World.ptr, 1f, 1f, prim.Scale);
893 public override BulletShape BuildCapsuleShape(BulletWorld pWorld, float pRadius, float pHeight, Vector3 pScale)
894 {
895 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
896 IndexedVector3 scale = new IndexedVector3(pScale.X, pScale.Y, pScale.Z);
897 CapsuleShapeZ capsuleShapeZ = new CapsuleShapeZ(pRadius, pHeight);
898 capsuleShapeZ.SetMargin(world.WorldSettings.Params.collisionMargin);
899 capsuleShapeZ.SetLocalScaling(ref scale);
900
901 return new BulletShapeXNA(capsuleShapeZ, BSPhysicsShapeType.SHAPE_CAPSULE); ;
902 }
903
904 public override BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms,
905 int maxCollisions, ref CollisionDesc[] collisionArray,
906 int maxUpdates, ref EntityProperties[] updateArray
907 )
908 {
909 /* TODO */
910 return new BulletWorldXNA(1, null, null);
911 }
912
913 private static object Initialize2(Vector3 worldExtent,
914 ConfigurationParameters[] o,
915 int mMaxCollisionsPerFrame, ref List<BulletXNA.CollisionDesc> collisionArray,
916 int mMaxUpdatesPerFrame, ref List<BulletXNA.EntityProperties> updateArray,
917 object mDebugLogCallbackHandle)
918 {
919 CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData();
920
921 p.angularDamping = o[0].XangularDamping;
922 p.defaultFriction = o[0].defaultFriction;
923 p.defaultFriction = o[0].defaultFriction;
924 p.defaultDensity = o[0].defaultDensity;
925 p.defaultRestitution = o[0].defaultRestitution;
926 p.collisionMargin = o[0].collisionMargin;
927 p.gravity = o[0].gravity;
928
929 p.linearDamping = o[0].XlinearDamping;
930 p.angularDamping = o[0].XangularDamping;
931 p.deactivationTime = o[0].XdeactivationTime;
932 p.linearSleepingThreshold = o[0].XlinearSleepingThreshold;
933 p.angularSleepingThreshold = o[0].XangularSleepingThreshold;
934 p.ccdMotionThreshold = o[0].XccdMotionThreshold;
935 p.ccdSweptSphereRadius = o[0].XccdSweptSphereRadius;
936 p.contactProcessingThreshold = o[0].XcontactProcessingThreshold;
937
938 p.terrainImplementation = o[0].XterrainImplementation;
939 p.terrainFriction = o[0].XterrainFriction;
940
941 p.terrainHitFraction = o[0].XterrainHitFraction;
942 p.terrainRestitution = o[0].XterrainRestitution;
943 p.terrainCollisionMargin = o[0].XterrainCollisionMargin;
944
945 p.avatarFriction = o[0].XavatarFriction;
946 p.avatarStandingFriction = o[0].XavatarStandingFriction;
947 p.avatarDensity = o[0].XavatarDensity;
948 p.avatarRestitution = o[0].XavatarRestitution;
949 p.avatarCapsuleWidth = o[0].XavatarCapsuleWidth;
950 p.avatarCapsuleDepth = o[0].XavatarCapsuleDepth;
951 p.avatarCapsuleHeight = o[0].XavatarCapsuleHeight;
952 p.avatarContactProcessingThreshold = o[0].XavatarContactProcessingThreshold;
953
954 p.vehicleAngularDamping = o[0].XvehicleAngularDamping;
955
956 p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize;
957 p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize;
958 p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation;
959 p.shouldForceUpdateAllAabbs = o[0].shouldForceUpdateAllAabbs;
960 p.shouldRandomizeSolverOrder = o[0].shouldRandomizeSolverOrder;
961 p.shouldSplitSimulationIslands = o[0].shouldSplitSimulationIslands;
962 p.shouldEnableFrictionCaching = o[0].shouldEnableFrictionCaching;
963 p.numberOfSolverIterations = o[0].numberOfSolverIterations;
964
965 p.linksetImplementation = o[0].XlinksetImplementation;
966 p.linkConstraintUseFrameOffset = o[0].XlinkConstraintUseFrameOffset;
967 p.linkConstraintEnableTransMotor = o[0].XlinkConstraintEnableTransMotor;
968 p.linkConstraintTransMotorMaxVel = o[0].XlinkConstraintTransMotorMaxVel;
969 p.linkConstraintTransMotorMaxForce = o[0].XlinkConstraintTransMotorMaxForce;
970 p.linkConstraintERP = o[0].XlinkConstraintERP;
971 p.linkConstraintCFM = o[0].XlinkConstraintCFM;
972 p.linkConstraintSolverIterations = o[0].XlinkConstraintSolverIterations;
973 p.physicsLoggingFrames = o[0].XphysicsLoggingFrames;
974 DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo();
975
976 DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration();
977 CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci);
978
979
980 if (p.maxPersistantManifoldPoolSize > 0)
981 cci.m_persistentManifoldPoolSize = (int)p.maxPersistantManifoldPoolSize;
982 if (p.shouldDisableContactPoolDynamicAllocation !=0)
983 m_dispatcher.SetDispatcherFlags(DispatcherFlags.CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION);
984 //if (p.maxCollisionAlgorithmPoolSize >0 )
985
986 DbvtBroadphase m_broadphase = new DbvtBroadphase();
987 //IndexedVector3 aabbMin = new IndexedVector3(0, 0, 0);
988 //IndexedVector3 aabbMax = new IndexedVector3(256, 256, 256);
989
990 //AxisSweep3Internal m_broadphase2 = new AxisSweep3Internal(ref aabbMin, ref aabbMax, Convert.ToInt32(0xfffe), 0xffff, ushort.MaxValue/2, null, true);
991 m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback());
992
993 SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver();
994
995 DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci);
996 world.UpdatedObjects = updateArray;
997 world.UpdatedCollisions = collisionArray;
998 world.WorldSettings.Params = p;
999 world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0);
1000 world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD;
1001 if (p.shouldRandomizeSolverOrder != 0)
1002 world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_RANDMIZE_ORDER;
1003
1004 world.GetSimulationIslandManager().SetSplitIslands(p.shouldSplitSimulationIslands != 0);
1005 //world.GetDispatchInfo().m_enableSatConvex Not implemented in C# port
1006
1007 if (p.shouldEnableFrictionCaching != 0)
1008 world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_ENABLE_FRICTION_DIRECTION_CACHING;
1009
1010 if (p.numberOfSolverIterations > 0)
1011 world.GetSolverInfo().m_numIterations = (int) p.numberOfSolverIterations;
1012
1013
1014 world.GetSolverInfo().m_damping = world.WorldSettings.Params.linearDamping;
1015 world.GetSolverInfo().m_restitution = world.WorldSettings.Params.defaultRestitution;
1016 world.GetSolverInfo().m_globalCfm = 0.0f;
1017 world.GetSolverInfo().m_tau = 0.6f;
1018 world.GetSolverInfo().m_friction = 0.3f;
1019 world.GetSolverInfo().m_maxErrorReduction = 20f;
1020 world.GetSolverInfo().m_numIterations = 10;
1021 world.GetSolverInfo().m_erp = 0.2f;
1022 world.GetSolverInfo().m_erp2 = 0.1f;
1023 world.GetSolverInfo().m_sor = 1.0f;
1024 world.GetSolverInfo().m_splitImpulse = false;
1025 world.GetSolverInfo().m_splitImpulsePenetrationThreshold = -0.02f;
1026 world.GetSolverInfo().m_linearSlop = 0.0f;
1027 world.GetSolverInfo().m_warmstartingFactor = 0.85f;
1028 world.GetSolverInfo().m_restingContactRestitutionThreshold = 2;
1029 world.SetForceUpdateAllAabbs(true);
1030
1031
1032 world.SetGravity(new IndexedVector3(0,0,p.gravity));
1033
1034 return world;
1035 }
1036 //m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL
1037 public override bool SetConstraintParam(BulletConstraint pConstraint, ConstraintParams paramIndex, float paramvalue, ConstraintParamAxis axis)
1038 {
1039 Generic6DofConstraint constrain = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint;
1040 if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL || axis == ConstraintParamAxis.AXIS_ALL)
1041 {
1042 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 0);
1043 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 1);
1044 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 2);
1045 }
1046 if (axis == ConstraintParamAxis.AXIS_ANGULAR_ALL || axis == ConstraintParamAxis.AXIS_ALL)
1047 {
1048 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 3);
1049 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 4);
1050 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 5);
1051 }
1052 if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL)
1053 {
1054 constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, (int)axis);
1055 }
1056 return true;
1057 }
1058
1059 public override bool PushUpdate(BulletBody pCollisionObject)
1060 {
1061 bool ret = false;
1062 RigidBody rb = ((BulletBodyXNA)pCollisionObject).rigidBody;
1063 if (rb != null)
1064 {
1065 SimMotionState sms = rb.GetMotionState() as SimMotionState;
1066 if (sms != null)
1067 {
1068 IndexedMatrix wt = IndexedMatrix.Identity;
1069 sms.GetWorldTransform(out wt);
1070 sms.SetWorldTransform(ref wt, true);
1071 ret = true;
1072 }
1073 }
1074 return ret;
1075
1076 }
1077
1078 public override float GetAngularMotionDisc(BulletShape pShape)
1079 {
1080 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1081 return shape.GetAngularMotionDisc();
1082 }
1083 public override float GetContactBreakingThreshold(BulletShape pShape, float defaultFactor)
1084 {
1085 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1086 return shape.GetContactBreakingThreshold(defaultFactor);
1087 }
1088 public override bool IsCompound(BulletShape pShape)
1089 {
1090 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1091 return shape.IsCompound();
1092 }
1093 public override bool IsSoftBody(BulletShape pShape)
1094 {
1095 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1096 return shape.IsSoftBody();
1097 }
1098 public override bool IsPolyhedral(BulletShape pShape)
1099 {
1100 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1101 return shape.IsPolyhedral();
1102 }
1103 public override bool IsConvex2d(BulletShape pShape)
1104 {
1105 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1106 return shape.IsConvex2d();
1107 }
1108 public override bool IsConvex(BulletShape pShape)
1109 {
1110 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1111 return shape.IsConvex();
1112 }
1113 public override bool IsNonMoving(BulletShape pShape)
1114 {
1115 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1116 return shape.IsNonMoving();
1117 }
1118 public override bool IsConcave(BulletShape pShape)
1119 {
1120 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1121 return shape.IsConcave();
1122 }
1123 public override bool IsInfinite(BulletShape pShape)
1124 {
1125 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1126 return shape.IsInfinite();
1127 }
1128 public override bool IsNativeShape(BulletShape pShape)
1129 {
1130 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1131 bool ret;
1132 switch (shape.GetShapeType())
1133 {
1134 case BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE:
1135 case BroadphaseNativeTypes.CONE_SHAPE_PROXYTYPE:
1136 case BroadphaseNativeTypes.SPHERE_SHAPE_PROXYTYPE:
1137 case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE:
1138 ret = true;
1139 break;
1140 default:
1141 ret = false;
1142 break;
1143 }
1144 return ret;
1145 }
1146
1147 public override void SetShapeCollisionMargin(BulletShape shape, float margin) { /* TODO */ }
1148
1149 //sim.ptr, shape.ptr,prim.LocalID, prim.RawPosition, prim.RawOrientation
1150 public override BulletBody CreateGhostFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
1151 {
1152 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
1153 IndexedMatrix bodyTransform = new IndexedMatrix();
1154 bodyTransform._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
1155 bodyTransform.SetRotation(new IndexedQuaternion(pRawOrientation.X,pRawOrientation.Y,pRawOrientation.Z,pRawOrientation.W));
1156 GhostObject gObj = new PairCachingGhostObject();
1157 gObj.SetWorldTransform(bodyTransform);
1158 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1159 gObj.SetCollisionShape(shape);
1160 gObj.SetUserPointer(pLocalID);
1161 // TODO: Add to Special CollisionObjects!
1162 return new BulletBodyXNA(pLocalID, gObj);
1163 }
1164
1165 public override void SetCollisionShape(BulletWorld pWorld, BulletBody pObj, BulletShape pShape)
1166 {
1167 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
1168 CollisionObject obj = ((BulletBodyXNA)pObj).body;
1169 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1170 obj.SetCollisionShape(shape);
1171
1172 }
1173 public override BulletShape GetCollisionShape(BulletBody obj) { /* TODO */ return null; }
1174
1175 //(PhysicsScene.World.ptr, nativeShapeData)
1176 public override BulletShape BuildNativeShape(BulletWorld pWorld, ShapeData pShapeData)
1177 {
1178 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
1179 CollisionShape shape = null;
1180 switch (pShapeData.Type)
1181 {
1182 case BSPhysicsShapeType.SHAPE_BOX:
1183 shape = new BoxShape(new IndexedVector3(0.5f,0.5f,0.5f));
1184 break;
1185 case BSPhysicsShapeType.SHAPE_CONE:
1186 shape = new ConeShapeZ(0.5f, 1.0f);
1187 break;
1188 case BSPhysicsShapeType.SHAPE_CYLINDER:
1189 shape = new CylinderShapeZ(new IndexedVector3(0.5f, 0.5f, 0.5f));
1190 break;
1191 case BSPhysicsShapeType.SHAPE_SPHERE:
1192 shape = new SphereShape(0.5f);
1193 break;
1194
1195 }
1196 if (shape != null)
1197 {
1198 IndexedVector3 scaling = new IndexedVector3(pShapeData.Scale.X, pShapeData.Scale.Y, pShapeData.Scale.Z);
1199 shape.SetMargin(world.WorldSettings.Params.collisionMargin);
1200 shape.SetLocalScaling(ref scaling);
1201
1202 }
1203 return new BulletShapeXNA(shape, pShapeData.Type);
1204 }
1205 //PhysicsScene.World.ptr, false
1206 public override BulletShape CreateCompoundShape(BulletWorld pWorld, bool enableDynamicAabbTree)
1207 {
1208 return new BulletShapeXNA(new CompoundShape(enableDynamicAabbTree), BSPhysicsShapeType.SHAPE_COMPOUND);
1209 }
1210
1211 public override int GetNumberOfCompoundChildren(BulletShape pCompoundShape)
1212 {
1213 CompoundShape compoundshape = ((BulletShapeXNA)pCompoundShape).shape as CompoundShape;
1214 return compoundshape.GetNumChildShapes();
1215 }
1216 //LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot
1217 public override void AddChildShapeToCompoundShape(BulletShape pCShape, BulletShape paddShape, Vector3 displacementPos, Quaternion displacementRot)
1218 {
1219 IndexedMatrix relativeTransform = new IndexedMatrix();
1220 CompoundShape compoundshape = ((BulletShapeXNA)pCShape).shape as CompoundShape;
1221 CollisionShape addshape = ((BulletShapeXNA)paddShape).shape;
1222
1223 relativeTransform._origin = new IndexedVector3(displacementPos.X, displacementPos.Y, displacementPos.Z);
1224 relativeTransform.SetRotation(new IndexedQuaternion(displacementRot.X,displacementRot.Y,displacementRot.Z,displacementRot.W));
1225 compoundshape.AddChildShape(ref relativeTransform, addshape);
1226
1227 }
1228
1229 public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape pCShape, int pii)
1230 {
1231 CompoundShape compoundshape = ((BulletShapeXNA)pCShape).shape as CompoundShape;
1232 CollisionShape ret = null;
1233 ret = compoundshape.GetChildShape(pii);
1234 compoundshape.RemoveChildShapeByIndex(pii);
1235 return new BulletShapeXNA(ret, BSPhysicsShapeType.SHAPE_UNKNOWN);
1236 }
1237
1238 public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) { /* TODO */ return null; }
1239 public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape) { /* TODO */ }
1240
1241 public override BulletShape CreateGroundPlaneShape(uint pLocalId, float pheight, float pcollisionMargin)
1242 {
1243 StaticPlaneShape m_planeshape = new StaticPlaneShape(new IndexedVector3(0,0,1),(int)pheight );
1244 m_planeshape.SetMargin(pcollisionMargin);
1245 m_planeshape.SetUserPointer(pLocalId);
1246 return new BulletShapeXNA(m_planeshape, BSPhysicsShapeType.SHAPE_GROUNDPLANE);
1247 }
1248
1249 public override BulletConstraint CreateHingeConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody ppBody2, Vector3 ppivotInA, Vector3 ppivotInB, Vector3 paxisInA, Vector3 paxisInB, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
1250 {
1251 HingeConstraint constrain = null;
1252 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
1253 RigidBody rb1 = ((BulletBodyXNA)pBody1).rigidBody;
1254 RigidBody rb2 = ((BulletBodyXNA)ppBody2).rigidBody;
1255 if (rb1 != null && rb2 != null)
1256 {
1257 IndexedVector3 pivotInA = new IndexedVector3(ppivotInA.X, ppivotInA.Y, ppivotInA.Z);
1258 IndexedVector3 pivotInB = new IndexedVector3(ppivotInB.X, ppivotInB.Y, ppivotInB.Z);
1259 IndexedVector3 axisInA = new IndexedVector3(paxisInA.X, paxisInA.Y, paxisInA.Z);
1260 IndexedVector3 axisInB = new IndexedVector3(paxisInB.X, paxisInB.Y, paxisInB.Z);
1261 world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies);
1262 }
1263 return new BulletConstraintXNA(constrain);
1264 }
1265
1266 public override BulletShape CreateHullShape(BulletWorld pWorld, int pHullCount, float[] pConvHulls)
1267 {
1268 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
1269 CompoundShape compoundshape = new CompoundShape(false);
1270
1271 compoundshape.SetMargin(world.WorldSettings.Params.collisionMargin);
1272 int ii = 1;
1273
1274 for (int i = 0; i < pHullCount; i++)
1275 {
1276 int vertexCount = (int) pConvHulls[ii];
1277
1278 IndexedVector3 centroid = new IndexedVector3(pConvHulls[ii + 1], pConvHulls[ii + 2], pConvHulls[ii + 3]);
1279 IndexedMatrix childTrans = IndexedMatrix.Identity;
1280 childTrans._origin = centroid;
1281
1282 List<IndexedVector3> virts = new List<IndexedVector3>();
1283 int ender = ((ii + 4) + (vertexCount*3));
1284 for (int iii = ii + 4; iii < ender; iii+=3)
1285 {
1286
1287 virts.Add(new IndexedVector3(pConvHulls[iii], pConvHulls[iii + 1], pConvHulls[iii +2]));
1288 }
1289 ConvexHullShape convexShape = new ConvexHullShape(virts, vertexCount);
1290 convexShape.SetMargin(world.WorldSettings.Params.collisionMargin);
1291 compoundshape.AddChildShape(ref childTrans, convexShape);
1292 ii += (vertexCount*3 + 4);
1293 }
1294
1295 return new BulletShapeXNA(compoundshape, BSPhysicsShapeType.SHAPE_HULL);
1296 }
1297
1298 public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) { /* TODO */ return null; }
1299
1300 public override BulletShape CreateMeshShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats)
1301 {
1302 //DumpRaw(indices,verticesAsFloats,pIndicesCount,pVerticesCount);
1303
1304 for (int iter = 0; iter < pVerticesCount; iter++)
1305 {
1306 if (verticesAsFloats[iter] > 0 && verticesAsFloats[iter] < 0.0001) verticesAsFloats[iter] = 0;
1307 if (verticesAsFloats[iter] < 0 && verticesAsFloats[iter] > -0.0001) verticesAsFloats[iter] = 0;
1308 }
1309
1310 ObjectArray<int> indicesarr = new ObjectArray<int>(indices);
1311 ObjectArray<float> vertices = new ObjectArray<float>(verticesAsFloats);
1312 DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount);
1313 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
1314 IndexedMesh mesh = new IndexedMesh();
1315 mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
1316 mesh.m_numTriangles = pIndicesCount/3;
1317 mesh.m_numVertices = pVerticesCount;
1318 mesh.m_triangleIndexBase = indicesarr;
1319 mesh.m_vertexBase = vertices;
1320 mesh.m_vertexStride = 3;
1321 mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
1322 mesh.m_triangleIndexStride = 3;
1323
1324 TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
1325 tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
1326 BvhTriangleMeshShape meshShape = new BvhTriangleMeshShape(tribuilder, true,true);
1327 meshShape.SetMargin(world.WorldSettings.Params.collisionMargin);
1328 // world.UpdateSingleAabb(meshShape);
1329 return new BulletShapeXNA(meshShape, BSPhysicsShapeType.SHAPE_MESH);
1330
1331 }
1332 public static void DumpRaw(ObjectArray<int>indices, ObjectArray<float> vertices, int pIndicesCount,int pVerticesCount )
1333 {
1334
1335 String fileName = "objTest3.raw";
1336 String completePath = System.IO.Path.Combine(Util.configDir(), fileName);
1337 StreamWriter sw = new StreamWriter(completePath);
1338 IndexedMesh mesh = new IndexedMesh();
1339
1340 mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
1341 mesh.m_numTriangles = pIndicesCount / 3;
1342 mesh.m_numVertices = pVerticesCount;
1343 mesh.m_triangleIndexBase = indices;
1344 mesh.m_vertexBase = vertices;
1345 mesh.m_vertexStride = 3;
1346 mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
1347 mesh.m_triangleIndexStride = 3;
1348
1349 TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
1350 tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
1351
1352
1353
1354 for (int i = 0; i < pVerticesCount; i++)
1355 {
1356
1357 string s = vertices[indices[i * 3]].ToString("0.0000");
1358 s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000");
1359 s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000");
1360
1361 sw.Write(s + "\n");
1362 }
1363
1364 sw.Close();
1365 }
1366 public static void DumpRaw(int[] indices, float[] vertices, int pIndicesCount, int pVerticesCount)
1367 {
1368
1369 String fileName = "objTest6.raw";
1370 String completePath = System.IO.Path.Combine(Util.configDir(), fileName);
1371 StreamWriter sw = new StreamWriter(completePath);
1372 IndexedMesh mesh = new IndexedMesh();
1373
1374 mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
1375 mesh.m_numTriangles = pIndicesCount / 3;
1376 mesh.m_numVertices = pVerticesCount;
1377 mesh.m_triangleIndexBase = indices;
1378 mesh.m_vertexBase = vertices;
1379 mesh.m_vertexStride = 3;
1380 mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
1381 mesh.m_triangleIndexStride = 3;
1382
1383 TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
1384 tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
1385
1386
1387 sw.WriteLine("Indices");
1388 sw.WriteLine(string.Format("int[] indices = new int[{0}];",pIndicesCount));
1389 for (int iter = 0; iter < indices.Length; iter++)
1390 {
1391 sw.WriteLine(string.Format("indices[{0}]={1};",iter,indices[iter]));
1392 }
1393 sw.WriteLine("VerticesFloats");
1394 sw.WriteLine(string.Format("float[] vertices = new float[{0}];", pVerticesCount));
1395 for (int iter = 0; iter < vertices.Length; iter++)
1396 {
1397 sw.WriteLine(string.Format("Vertices[{0}]={1};", iter, vertices[iter].ToString("0.0000")));
1398 }
1399
1400 // for (int i = 0; i < pVerticesCount; i++)
1401 // {
1402 //
1403 // string s = vertices[indices[i * 3]].ToString("0.0000");
1404 // s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000");
1405 // s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000");
1406 //
1407 // sw.Write(s + "\n");
1408 //}
1409
1410 sw.Close();
1411 }
1412
1413 public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
1414 float scaleFactor, float collisionMargin)
1415 {
1416 const int upAxis = 2;
1417 HeightfieldTerrainShape terrainShape = new HeightfieldTerrainShape((int)size.X, (int)size.Y,
1418 heightMap, scaleFactor,
1419 minHeight, maxHeight, upAxis,
1420 false);
1421 terrainShape.SetMargin(collisionMargin + 0.5f);
1422 terrainShape.SetUseDiamondSubdivision(true);
1423 terrainShape.SetUserPointer(id);
1424 return new BulletShapeXNA(terrainShape, BSPhysicsShapeType.SHAPE_TERRAIN);
1425 }
1426
1427 public override bool TranslationalLimitMotor(BulletConstraint pConstraint, float ponOff, float targetVelocity, float maxMotorForce)
1428 {
1429 TypedConstraint tconstrain = ((BulletConstraintXNA)pConstraint).constrain;
1430 bool onOff = ponOff != 0;
1431 bool ret = false;
1432
1433 switch (tconstrain.GetConstraintType())
1434 {
1435 case TypedConstraintType.D6_CONSTRAINT_TYPE:
1436 Generic6DofConstraint constrain = tconstrain as Generic6DofConstraint;
1437 constrain.GetTranslationalLimitMotor().m_enableMotor[0] = onOff;
1438 constrain.GetTranslationalLimitMotor().m_targetVelocity[0] = targetVelocity;
1439 constrain.GetTranslationalLimitMotor().m_maxMotorForce[0] = maxMotorForce;
1440 ret = true;
1441 break;
1442 }
1443
1444
1445 return ret;
1446
1447 }
1448
1449 public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
1450 out int updatedEntityCount, out int collidersCount)
1451 {
1452 /* TODO */
1453 updatedEntityCount = 0;
1454 collidersCount = 0;
1455 return 1;
1456 }
1457
1458 private int PhysicsStep2(BulletWorld pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep,
1459 out int updatedEntityCount, out List<BulletXNA.EntityProperties> updatedEntities,
1460 out int collidersCount, out List<BulletXNA.CollisionDesc>colliders)
1461 {
1462 int epic = PhysicsStepint(pWorld, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out updatedEntities,
1463 out collidersCount, out colliders);
1464 return epic;
1465 }
1466
1467 private static int PhysicsStepint(BulletWorld 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)
1468 {
1469 int numSimSteps = 0;
1470
1471
1472 //if (updatedEntities is null)
1473 // updatedEntities = new List<BulletXNA.EntityProperties>();
1474
1475 //if (colliders is null)
1476 // colliders = new List<BulletXNA.CollisionDesc>();
1477
1478
1479 if (pWorld is BulletWorldXNA)
1480 {
1481 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
1482
1483 numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep);
1484 int updates = 0;
1485
1486 updatedEntityCount = world.UpdatedObjects.Count;
1487 updatedEntities = new List<BulletXNA.EntityProperties>(world.UpdatedObjects);
1488 updatedEntityCount = updatedEntities.Count;
1489 world.UpdatedObjects.Clear();
1490
1491
1492 collidersCount = world.UpdatedCollisions.Count;
1493 colliders = new List<BulletXNA.CollisionDesc>(world.UpdatedCollisions);
1494
1495 world.UpdatedCollisions.Clear();
1496 m_collisionsThisFrame = 0;
1497 int numManifolds = world.GetDispatcher().GetNumManifolds();
1498 for (int j = 0; j < numManifolds; j++)
1499 {
1500 PersistentManifold contactManifold = world.GetDispatcher().GetManifoldByIndexInternal(j);
1501 int numContacts = contactManifold.GetNumContacts();
1502 if (numContacts == 0)
1503 continue;
1504
1505 CollisionObject objA = contactManifold.GetBody0() as CollisionObject;
1506 CollisionObject objB = contactManifold.GetBody1() as CollisionObject;
1507
1508 ManifoldPoint manifoldPoint = contactManifold.GetContactPoint(0);
1509 IndexedVector3 contactPoint = manifoldPoint.GetPositionWorldOnB();
1510 IndexedVector3 contactNormal = -manifoldPoint.m_normalWorldOnB; // make relative to A
1511
1512 RecordCollision(world, objA, objB, contactPoint, contactNormal);
1513 m_collisionsThisFrame ++;
1514 if (m_collisionsThisFrame >= 9999999)
1515 break;
1516
1517
1518 }
1519
1520
1521 }
1522 else
1523 {
1524 //if (updatedEntities is null)
1525 updatedEntities = new List<BulletXNA.EntityProperties>();
1526 updatedEntityCount = 0;
1527 //if (colliders is null)
1528 colliders = new List<BulletXNA.CollisionDesc>();
1529 collidersCount = 0;
1530 }
1531 return numSimSteps;
1532 }
1533
1534 private static void RecordCollision(CollisionWorld world, CollisionObject objA, CollisionObject objB, IndexedVector3 contact, IndexedVector3 norm)
1535 {
1536
1537 IndexedVector3 contactNormal = norm;
1538 if ((objA.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0 &&
1539 (objB.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0)
1540 {
1541 return;
1542 }
1543 uint idA = (uint)objA.GetUserPointer();
1544 uint idB = (uint)objB.GetUserPointer();
1545 if (idA > idB)
1546 {
1547 uint temp = idA;
1548 idA = idB;
1549 idB = temp;
1550 contactNormal = -contactNormal;
1551 }
1552
1553 ulong collisionID = ((ulong) idA << 32) | idB;
1554
1555 BulletXNA.CollisionDesc cDesc = new BulletXNA.CollisionDesc()
1556 {
1557 aID = idA,
1558 bID = idB,
1559 point = contact,
1560 normal = contactNormal
1561 };
1562 world.UpdatedCollisions.Add(cDesc);
1563 m_collisionsThisFrame++;
1564
1565
1566 }
1567 private static EntityProperties GetDebugProperties(BulletWorld pWorld, BulletBody pBody)
1568 {
1569 EntityProperties ent = new EntityProperties();
1570 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
1571 RigidBody body = ((BulletBodyXNA)pBody).rigidBody;
1572 IndexedMatrix transform = body.GetWorldTransform();
1573 IndexedVector3 LinearVelocity = body.GetInterpolationLinearVelocity();
1574 IndexedVector3 AngularVelocity = body.GetInterpolationAngularVelocity();
1575 IndexedQuaternion rotation = transform.GetRotation();
1576 ent.Acceleration = Vector3.Zero;
1577 ent.ID = (uint)body.GetUserPointer();
1578 ent.Position = new Vector3(transform._origin.X,transform._origin.Y,transform._origin.Z);
1579 ent.Rotation = new Quaternion(rotation.X,rotation.Y,rotation.Z,rotation.W);
1580 ent.Velocity = new Vector3(LinearVelocity.X, LinearVelocity.Y, LinearVelocity.Z);
1581 ent.RotationalVelocity = new Vector3(AngularVelocity.X, AngularVelocity.Y, AngularVelocity.Z);
1582 return ent;
1583 }
1584
1585 public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value) { /* TODO */ return false; }
1586
1587 public override Vector3 GetLocalScaling(BulletShape pShape)
1588 {
1589 CollisionShape shape = ((BulletShapeXNA)pShape).shape;
1590 IndexedVector3 scale = shape.GetLocalScaling();
1591 return new Vector3(scale.X,scale.Y,scale.Z);
1592 }
1593
1594 public bool RayCastGround(BulletWorld pWorld, Vector3 _RayOrigin, float pRayHeight, BulletBody NotMe)
1595 {
1596 DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world;
1597 if (world != null)
1598 {
1599 if (NotMe is BulletBodyXNA && NotMe.HasPhysicalBody)
1600 {
1601 CollisionObject AvoidBody = ((BulletBodyXNA)NotMe).body;
1602
1603 IndexedVector3 rOrigin = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z);
1604 IndexedVector3 rEnd = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z - pRayHeight);
1605 using (
1606 ClosestNotMeRayResultCallback rayCallback =
1607 new ClosestNotMeRayResultCallback(rOrigin, rEnd, AvoidBody)
1608 )
1609 {
1610 world.RayTest(ref rOrigin, ref rEnd, rayCallback);
1611 if (rayCallback.HasHit())
1612 {
1613 IndexedVector3 hitLocation = rayCallback.m_hitPointWorld;
1614 }
1615 return rayCallback.HasHit();
1616 }
1617 }
1618 }
1619 return false;
1620 }
1621}
1622}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
new file mode 100644
index 0000000..8ad78ca
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
@@ -0,0 +1,662 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyrightD
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.Runtime.InteropServices;
30using System.Security;
31using System.Text;
32using OpenMetaverse;
33
34namespace OpenSim.Region.Physics.BulletSPlugin {
35
36 // Constraint type values as defined by Bullet
37public enum ConstraintType : int
38{
39 POINT2POINT_CONSTRAINT_TYPE = 3,
40 HINGE_CONSTRAINT_TYPE,
41 CONETWIST_CONSTRAINT_TYPE,
42 D6_CONSTRAINT_TYPE,
43 SLIDER_CONSTRAINT_TYPE,
44 CONTACT_CONSTRAINT_TYPE,
45 D6_SPRING_CONSTRAINT_TYPE,
46 MAX_CONSTRAINT_TYPE
47}
48
49// ===============================================================================
50[StructLayout(LayoutKind.Sequential)]
51public struct ConvexHull
52{
53 Vector3 Offset;
54 int VertexCount;
55 Vector3[] Vertices;
56}
57public enum BSPhysicsShapeType
58{
59 SHAPE_UNKNOWN = 0,
60 SHAPE_CAPSULE = 1,
61 SHAPE_BOX = 2,
62 SHAPE_CONE = 3,
63 SHAPE_CYLINDER = 4,
64 SHAPE_SPHERE = 5,
65 SHAPE_MESH = 6,
66 SHAPE_HULL = 7,
67 // following defined by BulletSim
68 SHAPE_GROUNDPLANE = 20,
69 SHAPE_TERRAIN = 21,
70 SHAPE_COMPOUND = 22,
71 SHAPE_HEIGHTMAP = 23,
72 SHAPE_AVATAR = 24,
73};
74
75// The native shapes have predefined shape hash keys
76public enum FixedShapeKey : ulong
77{
78 KEY_NONE = 0,
79 KEY_BOX = 1,
80 KEY_SPHERE = 2,
81 KEY_CONE = 3,
82 KEY_CYLINDER = 4,
83 KEY_CAPSULE = 5,
84 KEY_AVATAR = 6,
85}
86
87[StructLayout(LayoutKind.Sequential)]
88public struct ShapeData
89{
90 public uint ID;
91 public BSPhysicsShapeType Type;
92 public Vector3 Position;
93 public Quaternion Rotation;
94 public Vector3 Velocity;
95 public Vector3 Scale;
96 public float Mass;
97 public float Buoyancy;
98 public System.UInt64 HullKey;
99 public System.UInt64 MeshKey;
100 public float Friction;
101 public float Restitution;
102 public float Collidable; // true of things bump into this
103 public float Static; // true if a static object. Otherwise gravity, etc.
104 public float Solid; // true if object cannot be passed through
105 public Vector3 Size;
106
107 // note that bools are passed as floats since bool size changes by language and architecture
108 public const float numericTrue = 1f;
109 public const float numericFalse = 0f;
110}
111[StructLayout(LayoutKind.Sequential)]
112public struct SweepHit
113{
114 public uint ID;
115 public float Fraction;
116 public Vector3 Normal;
117 public Vector3 Point;
118}
119[StructLayout(LayoutKind.Sequential)]
120public struct RaycastHit
121{
122 public uint ID;
123 public float Fraction;
124 public Vector3 Normal;
125}
126[StructLayout(LayoutKind.Sequential)]
127public struct CollisionDesc
128{
129 public uint aID;
130 public uint bID;
131 public Vector3 point;
132 public Vector3 normal;
133}
134[StructLayout(LayoutKind.Sequential)]
135public struct EntityProperties
136{
137 public uint ID;
138 public Vector3 Position;
139 public Quaternion Rotation;
140 public Vector3 Velocity;
141 public Vector3 Acceleration;
142 public Vector3 RotationalVelocity;
143}
144
145// Format of this structure must match the definition in the C++ code
146// NOTE: adding the X causes compile breaks if used. These are unused symbols
147// that can be removed from both here and the unmanaged definition of this structure.
148[StructLayout(LayoutKind.Sequential)]
149public struct ConfigurationParameters
150{
151 public float defaultFriction;
152 public float defaultDensity;
153 public float defaultRestitution;
154 public float collisionMargin;
155 public float gravity;
156
157 public float XlinearDamping;
158 public float XangularDamping;
159 public float XdeactivationTime;
160 public float XlinearSleepingThreshold;
161 public float XangularSleepingThreshold;
162 public float XccdMotionThreshold;
163 public float XccdSweptSphereRadius;
164 public float XcontactProcessingThreshold;
165
166 public float XterrainImplementation;
167 public float XterrainFriction;
168 public float XterrainHitFraction;
169 public float XterrainRestitution;
170 public float XterrainCollisionMargin;
171
172 public float XavatarFriction;
173 public float XavatarStandingFriction;
174 public float XavatarDensity;
175 public float XavatarRestitution;
176 public float XavatarCapsuleWidth;
177 public float XavatarCapsuleDepth;
178 public float XavatarCapsuleHeight;
179 public float XavatarContactProcessingThreshold;
180
181 public float XvehicleAngularDamping;
182
183 public float maxPersistantManifoldPoolSize;
184 public float maxCollisionAlgorithmPoolSize;
185 public float shouldDisableContactPoolDynamicAllocation;
186 public float shouldForceUpdateAllAabbs;
187 public float shouldRandomizeSolverOrder;
188 public float shouldSplitSimulationIslands;
189 public float shouldEnableFrictionCaching;
190 public float numberOfSolverIterations;
191
192 public float XlinksetImplementation;
193 public float XlinkConstraintUseFrameOffset;
194 public float XlinkConstraintEnableTransMotor;
195 public float XlinkConstraintTransMotorMaxVel;
196 public float XlinkConstraintTransMotorMaxForce;
197 public float XlinkConstraintERP;
198 public float XlinkConstraintCFM;
199 public float XlinkConstraintSolverIterations;
200
201 public float XphysicsLoggingFrames;
202
203 public const float numericTrue = 1f;
204 public const float numericFalse = 0f;
205}
206
207
208// The states a bullet collision object can have
209public enum ActivationState : uint
210{
211 ACTIVE_TAG = 1,
212 ISLAND_SLEEPING,
213 WANTS_DEACTIVATION,
214 DISABLE_DEACTIVATION,
215 DISABLE_SIMULATION,
216}
217
218public enum CollisionObjectTypes : int
219{
220 CO_COLLISION_OBJECT = 1 << 0,
221 CO_RIGID_BODY = 1 << 1,
222 CO_GHOST_OBJECT = 1 << 2,
223 CO_SOFT_BODY = 1 << 3,
224 CO_HF_FLUID = 1 << 4,
225 CO_USER_TYPE = 1 << 5,
226}
227
228// Values used by Bullet and BulletSim to control object properties.
229// Bullet's "CollisionFlags" has more to do with operations on the
230// object (if collisions happen, if gravity effects it, ...).
231public enum CollisionFlags : uint
232{
233 CF_STATIC_OBJECT = 1 << 0,
234 CF_KINEMATIC_OBJECT = 1 << 1,
235 CF_NO_CONTACT_RESPONSE = 1 << 2,
236 CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3,
237 CF_CHARACTER_OBJECT = 1 << 4,
238 CF_DISABLE_VISUALIZE_OBJECT = 1 << 5,
239 CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6,
240 // Following used by BulletSim to control collisions and updates
241 BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10,
242 BS_FLOATS_ON_WATER = 1 << 11,
243 BS_VEHICLE_COLLISIONS = 1 << 12,
244 BS_NONE = 0,
245 BS_ALL = 0xFFFFFFFF
246};
247
248// Values f collisions groups and masks
249public enum CollisionFilterGroups : uint
250{
251 // Don't use the bit definitions!! Define the use in a
252 // filter/mask definition below. This way collision interactions
253 // are more easily found and debugged.
254 BNoneGroup = 0,
255 BDefaultGroup = 1 << 0, // 0001
256 BStaticGroup = 1 << 1, // 0002
257 BKinematicGroup = 1 << 2, // 0004
258 BDebrisGroup = 1 << 3, // 0008
259 BSensorTrigger = 1 << 4, // 0010
260 BCharacterGroup = 1 << 5, // 0020
261 BAllGroup = 0x000FFFFF,
262 // Filter groups defined by BulletSim
263 BGroundPlaneGroup = 1 << 10, // 0400
264 BTerrainGroup = 1 << 11, // 0800
265 BRaycastGroup = 1 << 12, // 1000
266 BSolidGroup = 1 << 13, // 2000
267 // BLinksetGroup = xx // a linkset proper is either static or dynamic
268 BLinksetChildGroup = 1 << 14, // 4000
269};
270
271// CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0
272// ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2.
273public enum ConstraintParams : int
274{
275 BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730
276 BT_CONSTRAINT_STOP_ERP,
277 BT_CONSTRAINT_CFM,
278 BT_CONSTRAINT_STOP_CFM,
279};
280public enum ConstraintParamAxis : int
281{
282 AXIS_LINEAR_X = 0,
283 AXIS_LINEAR_Y,
284 AXIS_LINEAR_Z,
285 AXIS_ANGULAR_X,
286 AXIS_ANGULAR_Y,
287 AXIS_ANGULAR_Z,
288 AXIS_LINEAR_ALL = 20, // these last three added by BulletSim so we don't have to do zillions of calls
289 AXIS_ANGULAR_ALL,
290 AXIS_ALL
291};
292
293public abstract class BSAPITemplate
294{
295// Returns the name of the underlying Bullet engine
296public abstract string BulletEngineName { get; }
297public abstract string BulletEngineVersion { get; protected set;}
298
299// Initialization and simulation
300public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms,
301 int maxCollisions, ref CollisionDesc[] collisionArray,
302 int maxUpdates, ref EntityProperties[] updateArray
303 );
304
305public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
306 out int updatedEntityCount, out int collidersCount);
307
308public abstract bool UpdateParameter(BulletWorld world, uint localID, String parm, float value);
309
310public abstract void Shutdown(BulletWorld sim);
311
312public abstract bool PushUpdate(BulletBody obj);
313
314// =====================================================================================
315// Mesh, hull, shape and body creation helper routines
316public abstract BulletShape CreateMeshShape(BulletWorld world,
317 int indicesCount, int[] indices,
318 int verticesCount, float[] vertices );
319
320public abstract BulletShape CreateHullShape(BulletWorld world,
321 int hullCount, float[] hulls);
322
323public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape);
324
325public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData);
326
327public abstract bool IsNativeShape(BulletShape shape);
328
329public abstract void SetShapeCollisionMargin(BulletShape shape, float margin);
330
331public abstract BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale);
332
333public abstract BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree);
334
335public abstract int GetNumberOfCompoundChildren(BulletShape cShape);
336
337public abstract void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot);
338
339public abstract BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
340
341public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
342
343public abstract void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape);
344
345public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape);
346
347public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id);
348
349public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape);
350
351public abstract CollisionObjectTypes GetBodyType(BulletBody obj);
352
353public abstract BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
354
355public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot);
356
357public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
358
359public abstract void DestroyObject(BulletWorld sim, BulletBody obj);
360
361// =====================================================================================
362public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin);
363
364public abstract BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
365 float scaleFactor, float collisionMargin);
366
367// =====================================================================================
368// Constraint creation and helper routines
369public abstract BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
370 Vector3 frame1loc, Quaternion frame1rot,
371 Vector3 frame2loc, Quaternion frame2rot,
372 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
373
374public abstract BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2,
375 Vector3 joinPoint,
376 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
377
378public abstract BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
379 Vector3 pivotinA, Vector3 pivotinB,
380 Vector3 axisInA, Vector3 axisInB,
381 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
382
383public abstract void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse);
384
385public abstract void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations);
386
387public abstract bool SetFrames(BulletConstraint constrain,
388 Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
389
390public abstract bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
391
392public abstract bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
393
394public abstract bool UseFrameOffset(BulletConstraint constrain, float enable);
395
396public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce);
397
398public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold);
399
400public abstract bool CalculateTransforms(BulletConstraint constrain);
401
402public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
403
404public abstract bool DestroyConstraint(BulletWorld world, BulletConstraint constrain);
405
406// =====================================================================================
407// btCollisionWorld entries
408public abstract void UpdateSingleAabb(BulletWorld world, BulletBody obj);
409
410public abstract void UpdateAabbs(BulletWorld world);
411
412public abstract bool GetForceUpdateAllAabbs(BulletWorld world);
413
414public abstract void SetForceUpdateAllAabbs(BulletWorld world, bool force);
415
416// =====================================================================================
417// btDynamicsWorld entries
418// public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj, Vector3 pos, Quaternion rot);
419public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj);
420
421public abstract bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj);
422
423public abstract bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects);
424
425public abstract bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain);
426// =====================================================================================
427// btCollisionObject entries
428public abstract Vector3 GetAnisotripicFriction(BulletConstraint constrain);
429
430public abstract Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict);
431
432public abstract bool HasAnisotripicFriction(BulletConstraint constrain);
433
434public abstract void SetContactProcessingThreshold(BulletBody obj, float val);
435
436public abstract float GetContactProcessingThreshold(BulletBody obj);
437
438public abstract bool IsStaticObject(BulletBody obj);
439
440public abstract bool IsKinematicObject(BulletBody obj);
441
442public abstract bool IsStaticOrKinematicObject(BulletBody obj);
443
444public abstract bool HasContactResponse(BulletBody obj);
445
446public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape);
447
448public abstract BulletShape GetCollisionShape(BulletBody obj);
449
450public abstract int GetActivationState(BulletBody obj);
451
452public abstract void SetActivationState(BulletBody obj, int state);
453
454public abstract void SetDeactivationTime(BulletBody obj, float dtime);
455
456public abstract float GetDeactivationTime(BulletBody obj);
457
458public abstract void ForceActivationState(BulletBody obj, ActivationState state);
459
460public abstract void Activate(BulletBody obj, bool forceActivation);
461
462public abstract bool IsActive(BulletBody obj);
463
464public abstract void SetRestitution(BulletBody obj, float val);
465
466public abstract float GetRestitution(BulletBody obj);
467
468public abstract void SetFriction(BulletBody obj, float val);
469
470public abstract float GetFriction(BulletBody obj);
471
472public abstract Vector3 GetPosition(BulletBody obj);
473
474public abstract Quaternion GetOrientation(BulletBody obj);
475
476public abstract void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation);
477
478// public abstract IntPtr GetBroadphaseHandle(BulletBody obj);
479
480// public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle);
481
482public abstract void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel);
483
484public abstract void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel);
485
486public abstract void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel);
487
488public abstract float GetHitFraction(BulletBody obj);
489
490public abstract void SetHitFraction(BulletBody obj, float val);
491
492public abstract CollisionFlags GetCollisionFlags(BulletBody obj);
493
494public abstract CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags);
495
496public abstract CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags);
497
498public abstract CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags);
499
500public abstract float GetCcdMotionThreshold(BulletBody obj);
501
502public abstract void SetCcdMotionThreshold(BulletBody obj, float val);
503
504public abstract float GetCcdSweptSphereRadius(BulletBody obj);
505
506public abstract void SetCcdSweptSphereRadius(BulletBody obj, float val);
507
508public abstract IntPtr GetUserPointer(BulletBody obj);
509
510public abstract void SetUserPointer(BulletBody obj, IntPtr val);
511
512// =====================================================================================
513// btRigidBody entries
514public abstract void ApplyGravity(BulletBody obj);
515
516public abstract void SetGravity(BulletBody obj, Vector3 val);
517
518public abstract Vector3 GetGravity(BulletBody obj);
519
520public abstract void SetDamping(BulletBody obj, float lin_damping, float ang_damping);
521
522public abstract void SetLinearDamping(BulletBody obj, float lin_damping);
523
524public abstract void SetAngularDamping(BulletBody obj, float ang_damping);
525
526public abstract float GetLinearDamping(BulletBody obj);
527
528public abstract float GetAngularDamping(BulletBody obj);
529
530public abstract float GetLinearSleepingThreshold(BulletBody obj);
531
532public abstract void ApplyDamping(BulletBody obj, float timeStep);
533
534public abstract void SetMassProps(BulletBody obj, float mass, Vector3 inertia);
535
536public abstract Vector3 GetLinearFactor(BulletBody obj);
537
538public abstract void SetLinearFactor(BulletBody obj, Vector3 factor);
539
540public abstract void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot);
541
542// Add a force to the object as if its mass is one.
543public abstract void ApplyCentralForce(BulletBody obj, Vector3 force);
544
545// Set the force being applied to the object as if its mass is one.
546public abstract void SetObjectForce(BulletBody obj, Vector3 force);
547
548public abstract Vector3 GetTotalForce(BulletBody obj);
549
550public abstract Vector3 GetTotalTorque(BulletBody obj);
551
552public abstract Vector3 GetInvInertiaDiagLocal(BulletBody obj);
553
554public abstract void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert);
555
556public abstract void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold);
557
558public abstract void ApplyTorque(BulletBody obj, Vector3 torque);
559
560// Apply force at the given point. Will add torque to the object.
561public abstract void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos);
562
563// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
564public abstract void ApplyCentralImpulse(BulletBody obj, Vector3 imp);
565
566// Apply impulse to the object's torque. Force is scaled by object's mass.
567public abstract void ApplyTorqueImpulse(BulletBody obj, Vector3 imp);
568
569// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
570public abstract void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos);
571
572public abstract void ClearForces(BulletBody obj);
573
574public abstract void ClearAllForces(BulletBody obj);
575
576public abstract void UpdateInertiaTensor(BulletBody obj);
577
578public abstract Vector3 GetLinearVelocity(BulletBody obj);
579
580public abstract Vector3 GetAngularVelocity(BulletBody obj);
581
582public abstract void SetLinearVelocity(BulletBody obj, Vector3 val);
583
584public abstract void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity);
585
586public abstract Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos);
587
588public abstract void Translate(BulletBody obj, Vector3 trans);
589
590public abstract void UpdateDeactivation(BulletBody obj, float timeStep);
591
592public abstract bool WantsSleeping(BulletBody obj);
593
594public abstract void SetAngularFactor(BulletBody obj, float factor);
595
596public abstract void SetAngularFactorV(BulletBody obj, Vector3 factor);
597
598public abstract Vector3 GetAngularFactor(BulletBody obj);
599
600public abstract bool IsInWorld(BulletWorld world, BulletBody obj);
601
602public abstract void AddConstraintRef(BulletBody obj, BulletConstraint constrain);
603
604public abstract void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain);
605
606public abstract BulletConstraint GetConstraintRef(BulletBody obj, int index);
607
608public abstract int GetNumConstraintRefs(BulletBody obj);
609
610public abstract bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask);
611
612// =====================================================================================
613// btCollisionShape entries
614
615public abstract float GetAngularMotionDisc(BulletShape shape);
616
617public abstract float GetContactBreakingThreshold(BulletShape shape, float defaultFactor);
618
619public abstract bool IsPolyhedral(BulletShape shape);
620
621public abstract bool IsConvex2d(BulletShape shape);
622
623public abstract bool IsConvex(BulletShape shape);
624
625public abstract bool IsNonMoving(BulletShape shape);
626
627public abstract bool IsConcave(BulletShape shape);
628
629public abstract bool IsCompound(BulletShape shape);
630
631public abstract bool IsSoftBody(BulletShape shape);
632
633public abstract bool IsInfinite(BulletShape shape);
634
635public abstract void SetLocalScaling(BulletShape shape, Vector3 scale);
636
637public abstract Vector3 GetLocalScaling(BulletShape shape);
638
639public abstract Vector3 CalculateLocalInertia(BulletShape shape, float mass);
640
641public abstract int GetShapeType(BulletShape shape);
642
643public abstract void SetMargin(BulletShape shape, float val);
644
645public abstract float GetMargin(BulletShape shape);
646
647// =====================================================================================
648// Debugging
649public abstract void DumpRigidBody(BulletWorld sim, BulletBody collisionObject);
650
651public abstract void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape);
652
653public abstract void DumpConstraint(BulletWorld sim, BulletConstraint constrain);
654
655public abstract void DumpActivationInfo(BulletWorld sim);
656
657public abstract void DumpAllInfo(BulletWorld sim);
658
659public abstract void DumpPhysicsStatistics(BulletWorld sim);
660
661};
662}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 3b77e49..103d8fc 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -137,7 +137,7 @@ public sealed class BSCharacter : BSPhysObject
137 137
138 private void SetPhysicalProperties() 138 private void SetPhysicalProperties()
139 { 139 {
140 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); 140 PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody);
141 141
142 ZeroMotion(true); 142 ZeroMotion(true);
143 ForcePosition = _position; 143 ForcePosition = _position;
@@ -152,32 +152,32 @@ public sealed class BSCharacter : BSPhysObject
152 // Needs to be reset especially when an avatar is recreated after crossing a region boundry. 152 // Needs to be reset especially when an avatar is recreated after crossing a region boundry.
153 Flying = _flying; 153 Flying = _flying;
154 154
155 BulletSimAPI.SetRestitution2(PhysBody.ptr, BSParam.AvatarRestitution); 155 PhysicsScene.PE.SetRestitution(PhysBody, BSParam.AvatarRestitution);
156 BulletSimAPI.SetMargin2(PhysShape.ptr, PhysicsScene.Params.collisionMargin); 156 PhysicsScene.PE.SetMargin(PhysShape, PhysicsScene.Params.collisionMargin);
157 BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); 157 PhysicsScene.PE.SetLocalScaling(PhysShape, Scale);
158 BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, BSParam.ContactProcessingThreshold); 158 PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold);
159 if (BSParam.CcdMotionThreshold > 0f) 159 if (BSParam.CcdMotionThreshold > 0f)
160 { 160 {
161 BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold); 161 PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold);
162 BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius); 162 PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius);
163 } 163 }
164 164
165 UpdatePhysicalMassProperties(RawMass, false); 165 UpdatePhysicalMassProperties(RawMass, false);
166 166
167 // Make so capsule does not fall over 167 // Make so capsule does not fall over
168 BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero); 168 PhysicsScene.PE.SetAngularFactorV(PhysBody, OMV.Vector3.Zero);
169 169
170 BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_CHARACTER_OBJECT); 170 PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_CHARACTER_OBJECT);
171 171
172 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); 172 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
173 173
174 // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ACTIVE_TAG); 174 // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG);
175 BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_DEACTIVATION); 175 PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_DEACTIVATION);
176 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); 176 PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody);
177 177
178 // Do this after the object has been added to the world 178 // Do this after the object has been added to the world
179 PhysBody.collisionType = CollisionType.Avatar; 179 PhysBody.collisionType = CollisionType.Avatar;
180 PhysBody.ApplyCollisionMask(); 180 PhysBody.ApplyCollisionMask(PhysicsScene);
181 } 181 }
182 182
183 // The avatar's movement is controlled by this motor that speeds up and slows down 183 // The avatar's movement is controlled by this motor that speeds up and slows down
@@ -210,8 +210,7 @@ public sealed class BSCharacter : BSPhysObject
210 if (!Flying && !IsColliding) 210 if (!Flying && !IsColliding)
211 { 211 {
212 stepVelocity.Z = _velocity.Z; 212 stepVelocity.Z = _velocity.Z;
213 DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", 213 // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity);
214 LocalID, stepVelocity);
215 } 214 }
216 215
217 // 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force. 216 // 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force.
@@ -231,8 +230,7 @@ public sealed class BSCharacter : BSPhysObject
231 AddForce(moveForce, false, true); 230 AddForce(moveForce, false, true);
232 } 231 }
233 */ 232 */
234 DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", 233 // DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce);
235 LocalID, stepVelocity, _velocity, Mass, moveForce);
236 AddForce(moveForce, false, true); 234 AddForce(moveForce, false, true);
237 }); 235 });
238 } 236 }
@@ -267,10 +265,10 @@ public sealed class BSCharacter : BSPhysObject
267 { 265 {
268 if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape) 266 if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape)
269 { 267 {
270 BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); 268 PhysicsScene.PE.SetLocalScaling(PhysShape, Scale);
271 UpdatePhysicalMassProperties(RawMass, true); 269 UpdatePhysicalMassProperties(RawMass, true);
272 // Make sure this change appears as a property update event 270 // Make sure this change appears as a property update event
273 BulletSimAPI.PushUpdate2(PhysBody.ptr); 271 PhysicsScene.PE.PushUpdate(PhysBody);
274 } 272 }
275 }); 273 });
276 274
@@ -311,7 +309,7 @@ public sealed class BSCharacter : BSPhysObject
311 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() 309 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate()
312 { 310 {
313 if (PhysBody.HasPhysicalBody) 311 if (PhysBody.HasPhysicalBody)
314 BulletSimAPI.ClearAllForces2(PhysBody.ptr); 312 PhysicsScene.PE.ClearAllForces(PhysBody);
315 }); 313 });
316 } 314 }
317 public override void ZeroAngularMotion(bool inTaintTime) 315 public override void ZeroAngularMotion(bool inTaintTime)
@@ -322,10 +320,10 @@ public sealed class BSCharacter : BSPhysObject
322 { 320 {
323 if (PhysBody.HasPhysicalBody) 321 if (PhysBody.HasPhysicalBody)
324 { 322 {
325 BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); 323 PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, OMV.Vector3.Zero);
326 BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); 324 PhysicsScene.PE.SetAngularVelocity(PhysBody, OMV.Vector3.Zero);
327 // The next also get rid of applied linear force but the linear velocity is untouched. 325 // The next also get rid of applied linear force but the linear velocity is untouched.
328 BulletSimAPI.ClearForces2(PhysBody.ptr); 326 PhysicsScene.PE.ClearForces(PhysBody);
329 } 327 }
330 }); 328 });
331 } 329 }
@@ -341,7 +339,7 @@ public sealed class BSCharacter : BSPhysObject
341 public override OMV.Vector3 Position { 339 public override OMV.Vector3 Position {
342 get { 340 get {
343 // Don't refetch the position because this function is called a zillion times 341 // Don't refetch the position because this function is called a zillion times
344 // _position = BulletSimAPI.GetObjectPosition2(Scene.World.ptr, LocalID); 342 // _position = PhysicsScene.PE.GetObjectPosition(Scene.World, LocalID);
345 return _position; 343 return _position;
346 } 344 }
347 set { 345 set {
@@ -352,19 +350,19 @@ public sealed class BSCharacter : BSPhysObject
352 { 350 {
353 DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 351 DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
354 if (PhysBody.HasPhysicalBody) 352 if (PhysBody.HasPhysicalBody)
355 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 353 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
356 }); 354 });
357 } 355 }
358 } 356 }
359 public override OMV.Vector3 ForcePosition { 357 public override OMV.Vector3 ForcePosition {
360 get { 358 get {
361 _position = BulletSimAPI.GetPosition2(PhysBody.ptr); 359 _position = PhysicsScene.PE.GetPosition(PhysBody);
362 return _position; 360 return _position;
363 } 361 }
364 set { 362 set {
365 _position = value; 363 _position = value;
366 PositionSanityCheck(); 364 PositionSanityCheck();
367 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 365 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
368 } 366 }
369 } 367 }
370 368
@@ -420,7 +418,7 @@ public sealed class BSCharacter : BSPhysObject
420 { 418 {
421 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); 419 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation);
422 if (PhysBody.HasPhysicalBody) 420 if (PhysBody.HasPhysicalBody)
423 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 421 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
424 }); 422 });
425 ret = true; 423 ret = true;
426 } 424 }
@@ -435,8 +433,8 @@ public sealed class BSCharacter : BSPhysObject
435 } 433 }
436 public override void UpdatePhysicalMassProperties(float physMass, bool inWorld) 434 public override void UpdatePhysicalMassProperties(float physMass, bool inWorld)
437 { 435 {
438 OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); 436 OMV.Vector3 localInertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass);
439 BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, localInertia); 437 PhysicsScene.PE.SetMassProps(PhysBody, physMass, localInertia);
440 } 438 }
441 439
442 public override OMV.Vector3 Force { 440 public override OMV.Vector3 Force {
@@ -448,7 +446,7 @@ public sealed class BSCharacter : BSPhysObject
448 { 446 {
449 DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); 447 DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force);
450 if (PhysBody.HasPhysicalBody) 448 if (PhysBody.HasPhysicalBody)
451 BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); 449 PhysicsScene.PE.SetObjectForce(PhysBody, _force);
452 }); 450 });
453 } 451 }
454 } 452 }
@@ -522,7 +520,7 @@ public sealed class BSCharacter : BSPhysObject
522 { 520 {
523 _currentFriction = BSParam.AvatarStandingFriction; 521 _currentFriction = BSParam.AvatarStandingFriction;
524 if (PhysBody.HasPhysicalBody) 522 if (PhysBody.HasPhysicalBody)
525 BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); 523 PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
526 } 524 }
527 } 525 }
528 else 526 else
@@ -531,12 +529,12 @@ public sealed class BSCharacter : BSPhysObject
531 { 529 {
532 _currentFriction = BSParam.AvatarFriction; 530 _currentFriction = BSParam.AvatarFriction;
533 if (PhysBody.HasPhysicalBody) 531 if (PhysBody.HasPhysicalBody)
534 BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); 532 PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
535 } 533 }
536 } 534 }
537 535
538 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); 536 PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity);
539 BulletSimAPI.Activate2(PhysBody.ptr, true); 537 PhysicsScene.PE.Activate(PhysBody, true);
540 } 538 }
541 } 539 }
542 public override OMV.Vector3 Torque { 540 public override OMV.Vector3 Torque {
@@ -578,7 +576,7 @@ public sealed class BSCharacter : BSPhysObject
578 { 576 {
579 get 577 get
580 { 578 {
581 _orientation = BulletSimAPI.GetOrientation2(PhysBody.ptr); 579 _orientation = PhysicsScene.PE.GetOrientation(PhysBody);
582 return _orientation; 580 return _orientation;
583 } 581 }
584 set 582 set
@@ -586,8 +584,8 @@ public sealed class BSCharacter : BSPhysObject
586 _orientation = value; 584 _orientation = value;
587 if (PhysBody.HasPhysicalBody) 585 if (PhysBody.HasPhysicalBody)
588 { 586 {
589 // _position = BulletSimAPI.GetPosition2(BSBody.ptr); 587 // _position = PhysicsScene.PE.GetPosition(BSBody);
590 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 588 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
591 } 589 }
592 } 590 }
593 } 591 }
@@ -638,9 +636,9 @@ public sealed class BSCharacter : BSPhysObject
638 if (PhysBody.HasPhysicalBody) 636 if (PhysBody.HasPhysicalBody)
639 { 637 {
640 if (_floatOnWater) 638 if (_floatOnWater)
641 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); 639 CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER);
642 else 640 else
643 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); 641 CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER);
644 } 642 }
645 }); 643 });
646 } 644 }
@@ -678,7 +676,7 @@ public sealed class BSCharacter : BSPhysObject
678 // Buoyancy is faked by changing the gravity applied to the object 676 // Buoyancy is faked by changing the gravity applied to the object
679 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); 677 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
680 if (PhysBody.HasPhysicalBody) 678 if (PhysBody.HasPhysicalBody)
681 BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); 679 PhysicsScene.PE.SetGravity(PhysBody, new OMV.Vector3(0f, 0f, grav));
682 } 680 }
683 } 681 }
684 682
@@ -736,10 +734,10 @@ public sealed class BSCharacter : BSPhysObject
736 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.AddForce", delegate() 734 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.AddForce", delegate()
737 { 735 {
738 // Bullet adds this central force to the total force for this tick 736 // Bullet adds this central force to the total force for this tick
739 DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce); 737 // DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce);
740 if (PhysBody.HasPhysicalBody) 738 if (PhysBody.HasPhysicalBody)
741 { 739 {
742 BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce); 740 PhysicsScene.PE.ApplyCentralForce(PhysBody, addForce);
743 } 741 }
744 }); 742 });
745 } 743 }
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
index 59584b2..b813974 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
@@ -37,6 +37,7 @@ public abstract class BSConstraint : IDisposable
37 private static string LogHeader = "[BULLETSIM CONSTRAINT]"; 37 private static string LogHeader = "[BULLETSIM CONSTRAINT]";
38 38
39 protected BulletWorld m_world; 39 protected BulletWorld m_world;
40 protected BSScene PhysicsScene;
40 protected BulletBody m_body1; 41 protected BulletBody m_body1;
41 protected BulletBody m_body2; 42 protected BulletBody m_body2;
42 protected BulletConstraint m_constraint; 43 protected BulletConstraint m_constraint;
@@ -48,8 +49,10 @@ public abstract class BSConstraint : IDisposable
48 public abstract ConstraintType Type { get; } 49 public abstract ConstraintType Type { get; }
49 public bool IsEnabled { get { return m_enabled; } } 50 public bool IsEnabled { get { return m_enabled; } }
50 51
51 public BSConstraint() 52 public BSConstraint(BulletWorld world)
52 { 53 {
54 m_world = world;
55 PhysicsScene = m_world.physicsScene;
53 } 56 }
54 57
55 public virtual void Dispose() 58 public virtual void Dispose()
@@ -59,11 +62,11 @@ public abstract class BSConstraint : IDisposable
59 m_enabled = false; 62 m_enabled = false;
60 if (m_constraint.HasPhysicalConstraint) 63 if (m_constraint.HasPhysicalConstraint)
61 { 64 {
62 bool success = BulletSimAPI.DestroyConstraint2(m_world.ptr, m_constraint.ptr); 65 bool success = PhysicsScene.PE.DestroyConstraint(m_world, m_constraint);
63 m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}", 66 m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}",
64 BSScene.DetailLogZero, 67 BSScene.DetailLogZero,
65 m_body1.ID, m_body1.ptr.ToString("X"), 68 m_body1.ID, m_body1.AddrString,
66 m_body2.ID, m_body2.ptr.ToString("X"), 69 m_body2.ID, m_body2.AddrString,
67 success); 70 success);
68 m_constraint.Clear(); 71 m_constraint.Clear();
69 } 72 }
@@ -74,7 +77,7 @@ public abstract class BSConstraint : IDisposable
74 { 77 {
75 bool ret = false; 78 bool ret = false;
76 if (m_enabled) 79 if (m_enabled)
77 ret = BulletSimAPI.SetLinearLimits2(m_constraint.ptr, low, high); 80 ret = PhysicsScene.PE.SetLinearLimits(m_constraint, low, high);
78 return ret; 81 return ret;
79 } 82 }
80 83
@@ -82,7 +85,7 @@ public abstract class BSConstraint : IDisposable
82 { 85 {
83 bool ret = false; 86 bool ret = false;
84 if (m_enabled) 87 if (m_enabled)
85 ret = BulletSimAPI.SetAngularLimits2(m_constraint.ptr, low, high); 88 ret = PhysicsScene.PE.SetAngularLimits(m_constraint, low, high);
86 return ret; 89 return ret;
87 } 90 }
88 91
@@ -91,7 +94,7 @@ public abstract class BSConstraint : IDisposable
91 bool ret = false; 94 bool ret = false;
92 if (m_enabled) 95 if (m_enabled)
93 { 96 {
94 BulletSimAPI.SetConstraintNumSolverIterations2(m_constraint.ptr, cnt); 97 PhysicsScene.PE.SetConstraintNumSolverIterations(m_constraint, cnt);
95 ret = true; 98 ret = true;
96 } 99 }
97 return ret; 100 return ret;
@@ -103,7 +106,7 @@ public abstract class BSConstraint : IDisposable
103 if (m_enabled) 106 if (m_enabled)
104 { 107 {
105 // Recompute the internal transforms 108 // Recompute the internal transforms
106 BulletSimAPI.CalculateTransforms2(m_constraint.ptr); 109 PhysicsScene.PE.CalculateTransforms(m_constraint);
107 ret = true; 110 ret = true;
108 } 111 }
109 return ret; 112 return ret;
@@ -122,7 +125,7 @@ public abstract class BSConstraint : IDisposable
122 // Setting an object's mass to zero (making it static like when it's selected) 125 // Setting an object's mass to zero (making it static like when it's selected)
123 // automatically disables the constraints. 126 // automatically disables the constraints.
124 // If the link is enabled, be sure to set the constraint itself to enabled. 127 // If the link is enabled, be sure to set the constraint itself to enabled.
125 BulletSimAPI.SetConstraintEnable2(m_constraint.ptr, BSParam.NumericBool(true)); 128 PhysicsScene.PE.SetConstraintEnable(m_constraint, BSParam.NumericBool(true));
126 } 129 }
127 else 130 else
128 { 131 {
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
index b946870..ecb1b32 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
@@ -43,46 +43,44 @@ public sealed class BSConstraint6Dof : BSConstraint
43 Vector3 frame1, Quaternion frame1rot, 43 Vector3 frame1, Quaternion frame1rot,
44 Vector3 frame2, Quaternion frame2rot, 44 Vector3 frame2, Quaternion frame2rot,
45 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) 45 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
46 : base(world)
46 { 47 {
47 m_world = world;
48 m_body1 = obj1; 48 m_body1 = obj1;
49 m_body2 = obj2; 49 m_body2 = obj2;
50 m_constraint = new BulletConstraint( 50 m_constraint = PhysicsScene.PE.Create6DofConstraint(m_world, m_body1, m_body2,
51 BulletSimAPI.Create6DofConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr,
52 frame1, frame1rot, 51 frame1, frame1rot,
53 frame2, frame2rot, 52 frame2, frame2rot,
54 useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); 53 useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
55 m_enabled = true; 54 m_enabled = true;
56 world.physicsScene.DetailLog("{0},BS6DofConstraint,createFrame,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", 55 world.physicsScene.DetailLog("{0},BS6DofConstraint,createFrame,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
57 BSScene.DetailLogZero, world.worldID, 56 BSScene.DetailLogZero, world.worldID,
58 obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); 57 obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
59 } 58 }
60 59
61 public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2, 60 public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2,
62 Vector3 joinPoint, 61 Vector3 joinPoint,
63 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) 62 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
63 : base(world)
64 { 64 {
65 m_world = world;
66 m_body1 = obj1; 65 m_body1 = obj1;
67 m_body2 = obj2; 66 m_body2 = obj2;
68 if (!obj1.HasPhysicalBody || !obj2.HasPhysicalBody) 67 if (!obj1.HasPhysicalBody || !obj2.HasPhysicalBody)
69 { 68 {
70 world.physicsScene.DetailLog("{0},BS6DOFConstraint,badBodyPtr,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", 69 world.physicsScene.DetailLog("{0},BS6DOFConstraint,badBodyPtr,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
71 BSScene.DetailLogZero, world.worldID, 70 BSScene.DetailLogZero, world.worldID,
72 obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); 71 obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
73 world.physicsScene.Logger.ErrorFormat("{0} Attempt to build 6DOF constraint with missing bodies: wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", 72 world.physicsScene.Logger.ErrorFormat("{0} Attempt to build 6DOF constraint with missing bodies: wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
74 LogHeader, world.worldID, obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); 73 LogHeader, world.worldID, obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
75 m_enabled = false; 74 m_enabled = false;
76 } 75 }
77 else 76 else
78 { 77 {
79 m_constraint = new BulletConstraint( 78 m_constraint = PhysicsScene.PE.Create6DofConstraintToPoint(m_world, m_body1, m_body2,
80 BulletSimAPI.Create6DofConstraintToPoint2(m_world.ptr, m_body1.ptr, m_body2.ptr,
81 joinPoint, 79 joinPoint,
82 useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); 80 useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
83 world.physicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}", 81 PhysicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}",
84 BSScene.DetailLogZero, world.worldID, m_constraint.ptr.ToString("X"), 82 BSScene.DetailLogZero, world.worldID, m_constraint.AddrString,
85 obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); 83 obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
86 if (!m_constraint.HasPhysicalConstraint) 84 if (!m_constraint.HasPhysicalConstraint)
87 { 85 {
88 world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}", 86 world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}",
@@ -101,7 +99,7 @@ public sealed class BSConstraint6Dof : BSConstraint
101 bool ret = false; 99 bool ret = false;
102 if (m_enabled) 100 if (m_enabled)
103 { 101 {
104 BulletSimAPI.SetFrames2(m_constraint.ptr, frameA, frameArot, frameB, frameBrot); 102 PhysicsScene.PE.SetFrames(m_constraint, frameA, frameArot, frameB, frameBrot);
105 ret = true; 103 ret = true;
106 } 104 }
107 return ret; 105 return ret;
@@ -112,9 +110,9 @@ public sealed class BSConstraint6Dof : BSConstraint
112 bool ret = false; 110 bool ret = false;
113 if (m_enabled) 111 if (m_enabled)
114 { 112 {
115 BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL); 113 PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
116 BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL); 114 PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL);
117 BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL); 115 PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
118 ret = true; 116 ret = true;
119 } 117 }
120 return ret; 118 return ret;
@@ -125,7 +123,7 @@ public sealed class BSConstraint6Dof : BSConstraint
125 bool ret = false; 123 bool ret = false;
126 float onOff = useOffset ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse; 124 float onOff = useOffset ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse;
127 if (m_enabled) 125 if (m_enabled)
128 ret = BulletSimAPI.UseFrameOffset2(m_constraint.ptr, onOff); 126 ret = PhysicsScene.PE.UseFrameOffset(m_constraint, onOff);
129 return ret; 127 return ret;
130 } 128 }
131 129
@@ -135,7 +133,7 @@ public sealed class BSConstraint6Dof : BSConstraint
135 float onOff = enable ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse; 133 float onOff = enable ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse;
136 if (m_enabled) 134 if (m_enabled)
137 { 135 {
138 ret = BulletSimAPI.TranslationalLimitMotor2(m_constraint.ptr, onOff, targetVelocity, maxMotorForce); 136 ret = PhysicsScene.PE.TranslationalLimitMotor(m_constraint, onOff, targetVelocity, maxMotorForce);
139 m_world.physicsScene.DetailLog("{0},BS6DOFConstraint,TransLimitMotor,enable={1},vel={2},maxForce={3}", 137 m_world.physicsScene.DetailLog("{0},BS6DOFConstraint,TransLimitMotor,enable={1},vel={2},maxForce={3}",
140 BSScene.DetailLogZero, enable, targetVelocity, maxMotorForce); 138 BSScene.DetailLogZero, enable, targetVelocity, maxMotorForce);
141 } 139 }
@@ -146,7 +144,7 @@ public sealed class BSConstraint6Dof : BSConstraint
146 { 144 {
147 bool ret = false; 145 bool ret = false;
148 if (m_enabled) 146 if (m_enabled)
149 ret = BulletSimAPI.SetBreakingImpulseThreshold2(m_constraint.ptr, threshold); 147 ret = PhysicsScene.PE.SetBreakingImpulseThreshold(m_constraint, threshold);
150 return ret; 148 return ret;
151 } 149 }
152} 150}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs
index a5378b9..7714a03 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs
@@ -40,15 +40,13 @@ public sealed class BSConstraintHinge : BSConstraint
40 Vector3 pivotInA, Vector3 pivotInB, 40 Vector3 pivotInA, Vector3 pivotInB,
41 Vector3 axisInA, Vector3 axisInB, 41 Vector3 axisInA, Vector3 axisInB,
42 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) 42 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
43 : base(world)
43 { 44 {
44 m_world = world;
45 m_body1 = obj1; 45 m_body1 = obj1;
46 m_body2 = obj2; 46 m_body2 = obj2;
47 m_constraint = new BulletConstraint( 47 m_constraint = PhysicsScene.PE.CreateHingeConstraint(world, obj1, obj2,
48 BulletSimAPI.CreateHingeConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr, 48 pivotInA, pivotInB, axisInA, axisInB,
49 pivotInA, pivotInB, 49 useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
50 axisInA, axisInB,
51 useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
52 m_enabled = true; 50 m_enabled = true;
53 } 51 }
54 52
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 0bdfbe3..13c2539 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -558,30 +558,30 @@ namespace OpenSim.Region.Physics.BulletSPlugin
558 558
559 // Friction affects are handled by this vehicle code 559 // Friction affects are handled by this vehicle code
560 float friction = 0f; 560 float friction = 0f;
561 BulletSimAPI.SetFriction2(Prim.PhysBody.ptr, friction); 561 PhysicsScene.PE.SetFriction(Prim.PhysBody, friction);
562 562
563 // Moderate angular movement introduced by Bullet. 563 // Moderate angular movement introduced by Bullet.
564 // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. 564 // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle.
565 // Maybe compute linear and angular factor and damping from params. 565 // Maybe compute linear and angular factor and damping from params.
566 float angularDamping = BSParam.VehicleAngularDamping; 566 float angularDamping = BSParam.VehicleAngularDamping;
567 BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping); 567 PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, angularDamping);
568 568
569 // Vehicles report collision events so we know when it's on the ground 569 // Vehicles report collision events so we know when it's on the ground
570 BulletSimAPI.AddToCollisionFlags2(Prim.PhysBody.ptr, CollisionFlags.BS_VEHICLE_COLLISIONS); 570 PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS);
571 571
572 Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(Prim.PhysShape.ptr, m_vehicleMass); 572 Vector3 localInertia = PhysicsScene.PE.CalculateLocalInertia(Prim.PhysShape, m_vehicleMass);
573 BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia); 573 PhysicsScene.PE.SetMassProps(Prim.PhysBody, m_vehicleMass, localInertia);
574 BulletSimAPI.UpdateInertiaTensor2(Prim.PhysBody.ptr); 574 PhysicsScene.PE.UpdateInertiaTensor(Prim.PhysBody);
575 575
576 Vector3 grav = PhysicsScene.DefaultGravity * (1f - Prim.Buoyancy); 576 Vector3 grav = PhysicsScene.DefaultGravity * (1f - Prim.Buoyancy);
577 BulletSimAPI.SetGravity2(Prim.PhysBody.ptr, grav); 577 PhysicsScene.PE.SetGravity(Prim.PhysBody, grav);
578 578
579 VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4}", 579 VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4}",
580 Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping); 580 Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping);
581 } 581 }
582 else 582 else
583 { 583 {
584 BulletSimAPI.RemoveFromCollisionFlags2(Prim.PhysBody.ptr, CollisionFlags.BS_VEHICLE_COLLISIONS); 584 PhysicsScene.PE.RemoveFromCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS);
585 } 585 }
586 } 586 }
587 587
@@ -651,7 +651,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
651 if ((m_knownChanged & m_knownChangedVelocity) != 0) 651 if ((m_knownChanged & m_knownChangedVelocity) != 0)
652 { 652 {
653 Prim.ForceVelocity = m_knownVelocity; 653 Prim.ForceVelocity = m_knownVelocity;
654 BulletSimAPI.SetInterpolationLinearVelocity2(Prim.PhysBody.ptr, VehicleVelocity); 654 PhysicsScene.PE.SetInterpolationLinearVelocity(Prim.PhysBody, VehicleVelocity);
655 } 655 }
656 656
657 if ((m_knownChanged & m_knownChangedForce) != 0) 657 if ((m_knownChanged & m_knownChangedForce) != 0)
@@ -661,7 +661,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
661 { 661 {
662 Prim.ForceRotationalVelocity = m_knownRotationalVelocity; 662 Prim.ForceRotationalVelocity = m_knownRotationalVelocity;
663 // Fake out Bullet by making it think the velocity is the same as last time. 663 // Fake out Bullet by making it think the velocity is the same as last time.
664 BulletSimAPI.SetInterpolationAngularVelocity2(Prim.PhysBody.ptr, m_knownRotationalVelocity); 664 PhysicsScene.PE.SetInterpolationAngularVelocity(Prim.PhysBody, m_knownRotationalVelocity);
665 } 665 }
666 666
667 if ((m_knownChanged & m_knownChangedRotationalForce) != 0) 667 if ((m_knownChanged & m_knownChangedRotationalForce) != 0)
@@ -669,7 +669,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
669 669
670 // If we set one of the values (ie, the physics engine didn't do it) we must force 670 // If we set one of the values (ie, the physics engine didn't do it) we must force
671 // an UpdateProperties event to send the changes up to the simulator. 671 // an UpdateProperties event to send the changes up to the simulator.
672 BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr); 672 PhysicsScene.PE.PushUpdate(Prim.PhysBody);
673 } 673 }
674 m_knownChanged = 0; 674 m_knownChanged = 0;
675 } 675 }
@@ -823,7 +823,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
823 if (!IsActive) return; 823 if (!IsActive) return;
824 824
825 if (PhysicsScene.VehiclePhysicalLoggingEnabled) 825 if (PhysicsScene.VehiclePhysicalLoggingEnabled)
826 BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, Prim.PhysBody.ptr); 826 PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody);
827 827
828 ForgetKnownVehicleProperties(); 828 ForgetKnownVehicleProperties();
829 829
@@ -840,7 +840,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
840 PushKnownChanged(); 840 PushKnownChanged();
841 841
842 if (PhysicsScene.VehiclePhysicalLoggingEnabled) 842 if (PhysicsScene.VehiclePhysicalLoggingEnabled)
843 BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, Prim.PhysBody.ptr); 843 PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody);
844 844
845 VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}", 845 VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}",
846 Prim.LocalID, VehiclePosition, Prim.Force, VehicleVelocity, VehicleRotationalVelocity); 846 Prim.LocalID, VehiclePosition, Prim.Force, VehicleVelocity, VehicleRotationalVelocity);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 19ce62b..bd03d31 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -131,10 +131,10 @@ public sealed class BSLinksetCompound : BSLinkset
131 { 131 {
132 // The origional prims are removed from the world as the shape of the root compound 132 // The origional prims are removed from the world as the shape of the root compound
133 // shape takes over. 133 // shape takes over.
134 BulletSimAPI.AddToCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); 134 PhysicsScene.PE.AddToCollisionFlags(child.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE);
135 BulletSimAPI.ForceActivationState2(child.PhysBody.ptr, ActivationState.DISABLE_SIMULATION); 135 PhysicsScene.PE.ForceActivationState(child.PhysBody, ActivationState.DISABLE_SIMULATION);
136 // We don't want collisions from the old linkset children. 136 // We don't want collisions from the old linkset children.
137 BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 137 PhysicsScene.PE.RemoveFromCollisionFlags(child.PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
138 138
139 child.PhysBody.collisionType = CollisionType.LinksetChild; 139 child.PhysBody.collisionType = CollisionType.LinksetChild;
140 140
@@ -159,12 +159,12 @@ public sealed class BSLinksetCompound : BSLinkset
159 else 159 else
160 { 160 {
161 // The non-physical children can come back to life. 161 // The non-physical children can come back to life.
162 BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); 162 PhysicsScene.PE.RemoveFromCollisionFlags(child.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE);
163 163
164 child.PhysBody.collisionType = CollisionType.LinksetChild; 164 child.PhysBody.collisionType = CollisionType.LinksetChild;
165 165
166 // Don't force activation so setting of DISABLE_SIMULATION can stay if used. 166 // Don't force activation so setting of DISABLE_SIMULATION can stay if used.
167 BulletSimAPI.Activate2(child.PhysBody.ptr, false); 167 PhysicsScene.PE.Activate(child.PhysBody, false);
168 ret = true; 168 ret = true;
169 } 169 }
170 return ret; 170 return ret;
@@ -196,7 +196,7 @@ public sealed class BSLinksetCompound : BSLinkset
196 bool ret = false; 196 bool ret = false;
197 197
198 DetailLog("{0},BSLinksetCompound.RemoveBodyDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}", 198 DetailLog("{0},BSLinksetCompound.RemoveBodyDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}",
199 child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), IsRoot(child)); 199 child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, IsRoot(child));
200 200
201 if (!IsRoot(child)) 201 if (!IsRoot(child))
202 { 202 {
@@ -280,8 +280,8 @@ public sealed class BSLinksetCompound : BSLinkset
280 { 280 {
281 DetailLog("{0},BSLinksetCompound.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}", 281 DetailLog("{0},BSLinksetCompound.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}",
282 child.LocalID, 282 child.LocalID,
283 LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), 283 LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString,
284 child.LocalID, child.PhysBody.ptr.ToString("X")); 284 child.LocalID, child.PhysBody.AddrString);
285 285
286 // Cause the child's body to be rebuilt and thus restored to normal operation 286 // Cause the child's body to be rebuilt and thus restored to normal operation
287 RecomputeChildWorldPosition(child, false); 287 RecomputeChildWorldPosition(child, false);
@@ -359,7 +359,7 @@ public sealed class BSLinksetCompound : BSLinkset
359 PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); 359 PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null);
360 BulletShape newShape = cPrim.PhysShape; 360 BulletShape newShape = cPrim.PhysShape;
361 cPrim.PhysShape = saveShape; 361 cPrim.PhysShape = saveShape;
362 BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, lci.OffsetPos, lci.OffsetRot); 362 PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, newShape, lci.OffsetPos, lci.OffsetRot);
363 } 363 }
364 else 364 else
365 { 365 {
@@ -371,7 +371,7 @@ public sealed class BSLinksetCompound : BSLinkset
371 PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", 371 PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}",
372 LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); 372 LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape);
373 } 373 }
374 BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, lci.OffsetPos, lci.OffsetRot); 374 PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot);
375 } 375 }
376 } 376 }
377 return false; // 'false' says to move onto the next child in the list 377 return false; // 'false' says to move onto the next child in the list
@@ -386,12 +386,7 @@ public sealed class BSLinksetCompound : BSLinkset
386 Rebuilding = false; 386 Rebuilding = false;
387 } 387 }
388 388
389 BulletSimAPI.RecalculateCompoundShapeLocalAabb2(LinksetRoot.PhysShape.ptr); 389 PhysicsScene.PE.RecalculateCompoundShapeLocalAabb(LinksetRoot.PhysShape);
390
391 // DEBUG: see of inter-linkset collisions are causing problems for constraint linksets.
392 // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr,
393 // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);
394
395 } 390 }
396} 391}
397} \ No newline at end of file 392} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
index 6b592e7..d0b2a56 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
@@ -48,12 +48,15 @@ public sealed class BSLinksetConstraints : BSLinkset
48 { 48 {
49 base.Refresh(requestor); 49 base.Refresh(requestor);
50 50
51 // Queue to happen after all the other taint processing 51 if (HasAnyChildren && IsRoot(requestor))
52 PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate() 52 {
53 { 53 // Queue to happen after all the other taint processing
54 if (HasAnyChildren && IsRoot(requestor)) 54 PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate()
55 RecomputeLinksetConstraints(); 55 {
56 }); 56 if (HasAnyChildren && IsRoot(requestor))
57 RecomputeLinksetConstraints();
58 });
59 }
57 } 60 }
58 61
59 // The object is going dynamic (physical). Do any setup necessary 62 // The object is going dynamic (physical). Do any setup necessary
@@ -95,7 +98,7 @@ public sealed class BSLinksetConstraints : BSLinkset
95 bool ret = false; 98 bool ret = false;
96 99
97 DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}", 100 DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}",
98 child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X")); 101 child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString);
99 102
100 lock (m_linksetActivityLock) 103 lock (m_linksetActivityLock)
101 { 104 {
@@ -144,8 +147,8 @@ public sealed class BSLinksetConstraints : BSLinkset
144 147
145 DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}", 148 DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}",
146 childx.LocalID, 149 childx.LocalID,
147 rootx.LocalID, rootx.PhysBody.ptr.ToString("X"), 150 rootx.LocalID, rootx.PhysBody.AddrString,
148 childx.LocalID, childx.PhysBody.ptr.ToString("X")); 151 childx.LocalID, childx.PhysBody.AddrString);
149 152
150 PhysicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate() 153 PhysicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate()
151 { 154 {
@@ -184,8 +187,8 @@ public sealed class BSLinksetConstraints : BSLinkset
184 187
185 DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}", 188 DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}",
186 rootPrim.LocalID, 189 rootPrim.LocalID,
187 rootPrim.LocalID, rootPrim.PhysBody.ptr.ToString("X"), 190 rootPrim.LocalID, rootPrim.PhysBody.AddrString,
188 childPrim.LocalID, childPrim.PhysBody.ptr.ToString("X"), 191 childPrim.LocalID, childPrim.PhysBody.AddrString,
189 rootPrim.Position, childPrim.Position, midPoint); 192 rootPrim.Position, childPrim.Position, midPoint);
190 193
191 // create a constraint that allows no freedom of movement between the two objects 194 // create a constraint that allows no freedom of movement between the two objects
@@ -249,14 +252,14 @@ public sealed class BSLinksetConstraints : BSLinkset
249 bool ret = false; 252 bool ret = false;
250 DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}", 253 DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}",
251 rootPrim.LocalID, 254 rootPrim.LocalID,
252 rootPrim.LocalID, rootPrim.PhysBody.ptr.ToString("X"), 255 rootPrim.LocalID, rootPrim.PhysBody.AddrString,
253 childPrim.LocalID, childPrim.PhysBody.ptr.ToString("X")); 256 childPrim.LocalID, childPrim.PhysBody.AddrString);
254 257
255 // Find the constraint for this link and get rid of it from the overall collection and from my list 258 // Find the constraint for this link and get rid of it from the overall collection and from my list
256 if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody)) 259 if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody))
257 { 260 {
258 // Make the child refresh its location 261 // Make the child refresh its location
259 BulletSimAPI.PushUpdate2(childPrim.PhysBody.ptr); 262 PhysicsScene.PE.PushUpdate(childPrim.PhysBody);
260 ret = true; 263 ret = true;
261 } 264 }
262 265
@@ -283,11 +286,8 @@ public sealed class BSLinksetConstraints : BSLinkset
283 float linksetMass = LinksetMass; 286 float linksetMass = LinksetMass;
284 LinksetRoot.UpdatePhysicalMassProperties(linksetMass, true); 287 LinksetRoot.UpdatePhysicalMassProperties(linksetMass, true);
285 288
286 // DEBUG: see of inter-linkset collisions are causing problems
287 // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr,
288 // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);
289 DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}", 289 DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}",
290 LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), linksetMass); 290 LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, linksetMass);
291 291
292 foreach (BSPhysObject child in m_children) 292 foreach (BSPhysObject child in m_children)
293 { 293 {
@@ -304,11 +304,7 @@ public sealed class BSLinksetConstraints : BSLinkset
304 } 304 }
305 constrain.RecomputeConstraintVariables(linksetMass); 305 constrain.RecomputeConstraintVariables(linksetMass);
306 306
307 // DEBUG: see of inter-linkset collisions are causing problems 307 // PhysicsScene.PE.DumpConstraint(PhysicsScene.World, constrain.Constraint); // DEBUG DEBUG
308 // BulletSimAPI.SetCollisionFilterMask2(child.BSBody.ptr,
309 // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);
310
311 // BulletSimAPI.DumpConstraint2(PhysicsScene.World.ptr, constrain.Constraint.ptr); // DEBUG DEBUG
312 } 308 }
313 309
314 } 310 }
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
index 5c8553a..69ac8cd 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
@@ -280,7 +280,7 @@ public static class BSParam
280 (s,cf,p,v) => { s.UnmanagedParams[0].gravity = cf.GetFloat(p, v); }, 280 (s,cf,p,v) => { s.UnmanagedParams[0].gravity = cf.GetFloat(p, v); },
281 (s) => { return s.UnmanagedParams[0].gravity; }, 281 (s) => { return s.UnmanagedParams[0].gravity; },
282 (s,p,l,v) => { s.UpdateParameterObject((x)=>{s.UnmanagedParams[0].gravity=x;}, p, PhysParameterEntry.APPLY_TO_NONE, v); }, 282 (s,p,l,v) => { s.UpdateParameterObject((x)=>{s.UnmanagedParams[0].gravity=x;}, p, PhysParameterEntry.APPLY_TO_NONE, v); },
283 (s,o,v) => { BulletSimAPI.SetGravity2(s.World.ptr, new Vector3(0f,0f,v)); } ), 283 (s,o,v) => { s.PE.SetGravity(o.PhysBody, new Vector3(0f,0f,v)); } ),
284 284
285 285
286 new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)", 286 new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)",
@@ -288,49 +288,49 @@ public static class BSParam
288 (s,cf,p,v) => { LinearDamping = cf.GetFloat(p, v); }, 288 (s,cf,p,v) => { LinearDamping = cf.GetFloat(p, v); },
289 (s) => { return LinearDamping; }, 289 (s) => { return LinearDamping; },
290 (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearDamping=x;}, p, l, v); }, 290 (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearDamping=x;}, p, l, v); },
291 (s,o,v) => { BulletSimAPI.SetDamping2(o.PhysBody.ptr, v, AngularDamping); } ), 291 (s,o,v) => { s.PE.SetDamping(o.PhysBody, v, AngularDamping); } ),
292 new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)", 292 new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)",
293 0f, 293 0f,
294 (s,cf,p,v) => { AngularDamping = cf.GetFloat(p, v); }, 294 (s,cf,p,v) => { AngularDamping = cf.GetFloat(p, v); },
295 (s) => { return AngularDamping; }, 295 (s) => { return AngularDamping; },
296 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularDamping=x;}, p, l, v); }, 296 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularDamping=x;}, p, l, v); },
297 (s,o,v) => { BulletSimAPI.SetDamping2(o.PhysBody.ptr, LinearDamping, v); } ), 297 (s,o,v) => { s.PE.SetDamping(o.PhysBody, LinearDamping, v); } ),
298 new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static", 298 new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static",
299 0.2f, 299 0.2f,
300 (s,cf,p,v) => { DeactivationTime = cf.GetFloat(p, v); }, 300 (s,cf,p,v) => { DeactivationTime = cf.GetFloat(p, v); },
301 (s) => { return DeactivationTime; }, 301 (s) => { return DeactivationTime; },
302 (s,p,l,v) => { s.UpdateParameterObject((x)=>{DeactivationTime=x;}, p, l, v); }, 302 (s,p,l,v) => { s.UpdateParameterObject((x)=>{DeactivationTime=x;}, p, l, v); },
303 (s,o,v) => { BulletSimAPI.SetDeactivationTime2(o.PhysBody.ptr, v); } ), 303 (s,o,v) => { s.PE.SetDeactivationTime(o.PhysBody, v); } ),
304 new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static", 304 new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static",
305 0.8f, 305 0.8f,
306 (s,cf,p,v) => { LinearSleepingThreshold = cf.GetFloat(p, v); }, 306 (s,cf,p,v) => { LinearSleepingThreshold = cf.GetFloat(p, v); },
307 (s) => { return LinearSleepingThreshold; }, 307 (s) => { return LinearSleepingThreshold; },
308 (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearSleepingThreshold=x;}, p, l, v); }, 308 (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearSleepingThreshold=x;}, p, l, v); },
309 (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.PhysBody.ptr, v, v); } ), 309 (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ),
310 new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static", 310 new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static",
311 1.0f, 311 1.0f,
312 (s,cf,p,v) => { AngularSleepingThreshold = cf.GetFloat(p, v); }, 312 (s,cf,p,v) => { AngularSleepingThreshold = cf.GetFloat(p, v); },
313 (s) => { return AngularSleepingThreshold; }, 313 (s) => { return AngularSleepingThreshold; },
314 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularSleepingThreshold=x;}, p, l, v); }, 314 (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularSleepingThreshold=x;}, p, l, v); },
315 (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.PhysBody.ptr, v, v); } ), 315 (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ),
316 new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" , 316 new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" ,
317 0f, // set to zero to disable 317 0f, // set to zero to disable
318 (s,cf,p,v) => { CcdMotionThreshold = cf.GetFloat(p, v); }, 318 (s,cf,p,v) => { CcdMotionThreshold = cf.GetFloat(p, v); },
319 (s) => { return CcdMotionThreshold; }, 319 (s) => { return CcdMotionThreshold; },
320 (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdMotionThreshold=x;}, p, l, v); }, 320 (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdMotionThreshold=x;}, p, l, v); },
321 (s,o,v) => { BulletSimAPI.SetCcdMotionThreshold2(o.PhysBody.ptr, v); } ), 321 (s,o,v) => { s.PE.SetCcdMotionThreshold(o.PhysBody, v); } ),
322 new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" , 322 new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" ,
323 0f, 323 0f,
324 (s,cf,p,v) => { CcdSweptSphereRadius = cf.GetFloat(p, v); }, 324 (s,cf,p,v) => { CcdSweptSphereRadius = cf.GetFloat(p, v); },
325 (s) => { return CcdSweptSphereRadius; }, 325 (s) => { return CcdSweptSphereRadius; },
326 (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdSweptSphereRadius=x;}, p, l, v); }, 326 (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdSweptSphereRadius=x;}, p, l, v); },
327 (s,o,v) => { BulletSimAPI.SetCcdSweptSphereRadius2(o.PhysBody.ptr, v); } ), 327 (s,o,v) => { s.PE.SetCcdSweptSphereRadius(o.PhysBody, v); } ),
328 new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" , 328 new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" ,
329 0.1f, 329 0.1f,
330 (s,cf,p,v) => { ContactProcessingThreshold = cf.GetFloat(p, v); }, 330 (s,cf,p,v) => { ContactProcessingThreshold = cf.GetFloat(p, v); },
331 (s) => { return ContactProcessingThreshold; }, 331 (s) => { return ContactProcessingThreshold; },
332 (s,p,l,v) => { s.UpdateParameterObject((x)=>{ContactProcessingThreshold=x;}, p, l, v); }, 332 (s,p,l,v) => { s.UpdateParameterObject((x)=>{ContactProcessingThreshold=x;}, p, l, v); },
333 (s,o,v) => { BulletSimAPI.SetContactProcessingThreshold2(o.PhysBody.ptr, v); } ), 333 (s,o,v) => { s.PE.SetContactProcessingThreshold(o.PhysBody, v); } ),
334 334
335 new ParameterDefn("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)", 335 new ParameterDefn("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)",
336 (float)BSTerrainPhys.TerrainImplementation.Mesh, 336 (float)BSTerrainPhys.TerrainImplementation.Mesh,
@@ -492,11 +492,11 @@ public static class BSParam
492 (s) => { return LinkConstraintSolverIterations; }, 492 (s) => { return LinkConstraintSolverIterations; },
493 (s,p,l,v) => { LinkConstraintSolverIterations = v; } ), 493 (s,p,l,v) => { LinkConstraintSolverIterations = v; } ),
494 494
495 new ParameterDefn("LogPhysicsStatisticsFrames", "Frames between outputting detailed phys stats. (0 is off)", 495 new ParameterDefn("PhysicsMetricFrames", "Frames between outputting detailed phys metrics. (0 is off)",
496 0f, 496 0f,
497 (s,cf,p,v) => { s.UnmanagedParams[0].physicsLoggingFrames = cf.GetInt(p, (int)v); }, 497 (s,cf,p,v) => { s.PhysicsMetricDumpFrames = cf.GetFloat(p, (int)v); },
498 (s) => { return (float)s.UnmanagedParams[0].physicsLoggingFrames; }, 498 (s) => { return (float)s.PhysicsMetricDumpFrames; },
499 (s,p,l,v) => { s.UnmanagedParams[0].physicsLoggingFrames = (int)v; } ), 499 (s,p,l,v) => { s.PhysicsMetricDumpFrames = (int)v; } ),
500 }; 500 };
501 501
502 // Convert a boolean to our numeric true and false values 502 // Convert a boolean to our numeric true and false values
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index 73b5764..e7cb3e0 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -67,6 +67,11 @@ public abstract class BSPhysObject : PhysicsActor
67 PhysObjectName = name; 67 PhysObjectName = name;
68 TypeName = typeName; 68 TypeName = typeName;
69 69
70 // We don't have any physical representation yet.
71 PhysBody = new BulletBody(localID);
72 PhysShape = new BulletShape();
73
74 // A linkset of just me
70 Linkset = BSLinkset.Factory(PhysicsScene, this); 75 Linkset = BSLinkset.Factory(PhysicsScene, this);
71 LastAssetBuildFailed = false; 76 LastAssetBuildFailed = false;
72 77
@@ -303,7 +308,7 @@ public abstract class BSPhysObject : PhysicsActor
303 PhysicsScene.TaintedObject(TypeName+".SubscribeEvents", delegate() 308 PhysicsScene.TaintedObject(TypeName+".SubscribeEvents", delegate()
304 { 309 {
305 if (PhysBody.HasPhysicalBody) 310 if (PhysBody.HasPhysicalBody)
306 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 311 CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
307 }); 312 });
308 } 313 }
309 else 314 else
@@ -319,7 +324,7 @@ public abstract class BSPhysObject : PhysicsActor
319 { 324 {
320 // Make sure there is a body there because sometimes destruction happens in an un-ideal order. 325 // Make sure there is a body there because sometimes destruction happens in an un-ideal order.
321 if (PhysBody.HasPhysicalBody) 326 if (PhysBody.HasPhysicalBody)
322 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 327 CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
323 }); 328 });
324 } 329 }
325 // Return 'true' if the simulator wants collision events 330 // Return 'true' if the simulator wants collision events
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs
index 20f5180..65be52a 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs
@@ -59,12 +59,6 @@ public class BSPlugin : IPhysicsPlugin
59 { 59 {
60 if (_mScene == null) 60 if (_mScene == null)
61 { 61 {
62 if (Util.IsWindows())
63 Util.LoadArchSpecificWindowsDll("BulletSim.dll");
64 // If not Windows, loading is performed by the
65 // Mono loader as specified in
66 // "bin/Physics/OpenSim.Region.Physics.BulletSPlugin.dll.config".
67
68 _mScene = new BSScene(sceneIdentifier); 62 _mScene = new BSScene(sceneIdentifier);
69 } 63 }
70 return (_mScene); 64 return (_mScene);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 5f3f0d1..826261c 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -111,10 +111,7 @@ public sealed class BSPrim : BSPhysObject
111 111
112 _mass = CalculateMass(); 112 _mass = CalculateMass();
113 113
114 // No body or shape yet 114 // Cause linkset variables to be initialized (like mass)
115 PhysBody = new BulletBody(LocalID);
116 PhysShape = new BulletShape();
117
118 Linkset.Refresh(this); 115 Linkset.Refresh(this);
119 116
120 DetailLog("{0},BSPrim.constructor,call", LocalID); 117 DetailLog("{0},BSPrim.constructor,call", LocalID);
@@ -123,7 +120,7 @@ public sealed class BSPrim : BSPhysObject
123 { 120 {
124 CreateGeomAndObject(true); 121 CreateGeomAndObject(true);
125 122
126 CurrentCollisionFlags = BulletSimAPI.GetCollisionFlags2(PhysBody.ptr); 123 CurrentCollisionFlags = PhysicsScene.PE.GetCollisionFlags(PhysBody);
127 }); 124 });
128 } 125 }
129 126
@@ -256,7 +253,7 @@ public sealed class BSPrim : BSPhysObject
256 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() 253 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate()
257 { 254 {
258 if (PhysBody.HasPhysicalBody) 255 if (PhysBody.HasPhysicalBody)
259 BulletSimAPI.ClearAllForces2(PhysBody.ptr); 256 PhysicsScene.PE.ClearAllForces(PhysBody);
260 }); 257 });
261 } 258 }
262 public override void ZeroAngularMotion(bool inTaintTime) 259 public override void ZeroAngularMotion(bool inTaintTime)
@@ -268,8 +265,8 @@ public sealed class BSPrim : BSPhysObject
268 // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity); 265 // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity);
269 if (PhysBody.HasPhysicalBody) 266 if (PhysBody.HasPhysicalBody)
270 { 267 {
271 BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, _rotationalVelocity); 268 PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity);
272 BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); 269 PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity);
273 } 270 }
274 }); 271 });
275 } 272 }
@@ -295,7 +292,7 @@ public sealed class BSPrim : BSPhysObject
295 */ 292 */
296 293
297 // don't do the GetObjectPosition for root elements because this function is called a zillion times. 294 // don't do the GetObjectPosition for root elements because this function is called a zillion times.
298 // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); 295 // _position = PhysicsScene.PE.GetObjectPosition2(PhysicsScene.World, BSBody);
299 return _position; 296 return _position;
300 } 297 }
301 set { 298 set {
@@ -303,7 +300,7 @@ public sealed class BSPrim : BSPhysObject
303 // All positions are given in world positions. 300 // All positions are given in world positions.
304 if (_position == value) 301 if (_position == value)
305 { 302 {
306 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);
307 return; 304 return;
308 } 305 }
309 _position = value; 306 _position = value;
@@ -321,14 +318,14 @@ public sealed class BSPrim : BSPhysObject
321 } 318 }
322 public override OMV.Vector3 ForcePosition { 319 public override OMV.Vector3 ForcePosition {
323 get { 320 get {
324 _position = BulletSimAPI.GetPosition2(PhysBody.ptr); 321 _position = PhysicsScene.PE.GetPosition(PhysBody);
325 return _position; 322 return _position;
326 } 323 }
327 set { 324 set {
328 _position = value; 325 _position = value;
329 if (PhysBody.HasPhysicalBody) 326 if (PhysBody.HasPhysicalBody)
330 { 327 {
331 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 328 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
332 ActivateIfPhysical(false); 329 ActivateIfPhysical(false);
333 } 330 }
334 } 331 }
@@ -408,10 +405,10 @@ public sealed class BSPrim : BSPhysObject
408 { 405 {
409 if (IsStatic) 406 if (IsStatic)
410 { 407 {
411 BulletSimAPI.SetGravity2(PhysBody.ptr, PhysicsScene.DefaultGravity); 408 PhysicsScene.PE.SetGravity(PhysBody, PhysicsScene.DefaultGravity);
412 Inertia = OMV.Vector3.Zero; 409 Inertia = OMV.Vector3.Zero;
413 BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); 410 PhysicsScene.PE.SetMassProps(PhysBody, 0f, Inertia);
414 BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); 411 PhysicsScene.PE.UpdateInertiaTensor(PhysBody);
415 } 412 }
416 else 413 else
417 { 414 {
@@ -422,18 +419,18 @@ public sealed class BSPrim : BSPhysObject
422 // Changing interesting properties doesn't change proxy and collision cache 419 // Changing interesting properties doesn't change proxy and collision cache
423 // information. The Bullet solution is to re-add the object to the world 420 // information. The Bullet solution is to re-add the object to the world
424 // after parameters are changed. 421 // after parameters are changed.
425 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); 422 PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody);
426 } 423 }
427 424
428 // The computation of mass props requires gravity to be set on the object. 425 // The computation of mass props requires gravity to be set on the object.
429 BulletSimAPI.SetGravity2(PhysBody.ptr, grav); 426 PhysicsScene.PE.SetGravity(PhysBody, grav);
430 427
431 Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); 428 Inertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass);
432 BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); 429 PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia);
433 BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); 430 PhysicsScene.PE.UpdateInertiaTensor(PhysBody);
434 431
435 // center of mass is at the zero of the object 432 // center of mass is at the zero of the object
436 // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); 433 // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(PhysBody, ForcePosition, ForceOrientation);
437 DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld); 434 DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld);
438 435
439 if (inWorld) 436 if (inWorld)
@@ -443,7 +440,7 @@ public sealed class BSPrim : BSPhysObject
443 440
444 // Must set gravity after it has been added to the world because, for unknown reasons, 441 // Must set gravity after it has been added to the world because, for unknown reasons,
445 // adding the object resets the object's gravity to world gravity 442 // adding the object resets the object's gravity to world gravity
446 BulletSimAPI.SetGravity2(PhysBody.ptr, grav); 443 PhysicsScene.PE.SetGravity(PhysBody, grav);
447 444
448 } 445 }
449 } 446 }
@@ -486,7 +483,7 @@ public sealed class BSPrim : BSPhysObject
486 DetailLog("{0},BSPrim.setForce,preStep,force={1}", LocalID, _force); 483 DetailLog("{0},BSPrim.setForce,preStep,force={1}", LocalID, _force);
487 if (PhysBody.HasPhysicalBody) 484 if (PhysBody.HasPhysicalBody)
488 { 485 {
489 BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, _force); 486 PhysicsScene.PE.ApplyCentralForce(PhysBody, _force);
490 ActivateIfPhysical(false); 487 ActivateIfPhysical(false);
491 } 488 }
492 } 489 }
@@ -586,7 +583,7 @@ public sealed class BSPrim : BSPhysObject
586 _velocity = value; 583 _velocity = value;
587 if (PhysBody.HasPhysicalBody) 584 if (PhysBody.HasPhysicalBody)
588 { 585 {
589 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); 586 PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity);
590 ActivateIfPhysical(false); 587 ActivateIfPhysical(false);
591 } 588 }
592 } 589 }
@@ -652,9 +649,9 @@ public sealed class BSPrim : BSPhysObject
652 { 649 {
653 if (PhysBody.HasPhysicalBody) 650 if (PhysBody.HasPhysicalBody)
654 { 651 {
655 // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); 652 // _position = PhysicsScene.PE.GetObjectPosition(PhysicsScene.World, BSBody);
656 // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); 653 // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation);
657 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 654 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
658 } 655 }
659 }); 656 });
660 } 657 }
@@ -664,13 +661,13 @@ public sealed class BSPrim : BSPhysObject
664 { 661 {
665 get 662 get
666 { 663 {
667 _orientation = BulletSimAPI.GetOrientation2(PhysBody.ptr); 664 _orientation = PhysicsScene.PE.GetOrientation(PhysBody);
668 return _orientation; 665 return _orientation;
669 } 666 }
670 set 667 set
671 { 668 {
672 _orientation = value; 669 _orientation = value;
673 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 670 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
674 } 671 }
675 } 672 }
676 public override int PhysicsActorType { 673 public override int PhysicsActorType {
@@ -726,7 +723,7 @@ public sealed class BSPrim : BSPhysObject
726 723
727 // Mangling all the physical properties requires the object not be in the physical world. 724 // Mangling all the physical properties requires the object not be in the physical world.
728 // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). 725 // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found).
729 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); 726 PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody);
730 727
731 // Set up the object physicalness (does gravity and collisions move this object) 728 // Set up the object physicalness (does gravity and collisions move this object)
732 MakeDynamic(IsStatic); 729 MakeDynamic(IsStatic);
@@ -743,7 +740,7 @@ public sealed class BSPrim : BSPhysObject
743 AddObjectToPhysicalWorld(); 740 AddObjectToPhysicalWorld();
744 741
745 // Rebuild its shape 742 // Rebuild its shape
746 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); 743 PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody);
747 744
748 // Recompute any linkset parameters. 745 // Recompute any linkset parameters.
749 // When going from non-physical to physical, this re-enables the constraints that 746 // When going from non-physical to physical, this re-enables the constraints that
@@ -765,28 +762,28 @@ public sealed class BSPrim : BSPhysObject
765 if (makeStatic) 762 if (makeStatic)
766 { 763 {
767 // Become a Bullet 'static' object type 764 // Become a Bullet 'static' object type
768 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT); 765 CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT);
769 // Stop all movement 766 // Stop all movement
770 ZeroMotion(true); 767 ZeroMotion(true);
771 768
772 // Set various physical properties so other object interact properly 769 // Set various physical properties so other object interact properly
773 MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); 770 MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false);
774 BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction); 771 PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction);
775 BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); 772 PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution);
776 773
777 // Mass is zero which disables a bunch of physics stuff in Bullet 774 // Mass is zero which disables a bunch of physics stuff in Bullet
778 UpdatePhysicalMassProperties(0f, false); 775 UpdatePhysicalMassProperties(0f, false);
779 // Set collision detection parameters 776 // Set collision detection parameters
780 if (BSParam.CcdMotionThreshold > 0f) 777 if (BSParam.CcdMotionThreshold > 0f)
781 { 778 {
782 BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold); 779 PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold);
783 BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius); 780 PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius);
784 } 781 }
785 782
786 // The activation state is 'disabled' so Bullet will not try to act on it. 783 // The activation state is 'disabled' so Bullet will not try to act on it.
787 // BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_SIMULATION); 784 // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_SIMULATION);
788 // Start it out sleeping and physical actions could wake it up. 785 // Start it out sleeping and physical actions could wake it up.
789 BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ISLAND_SLEEPING); 786 PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ISLAND_SLEEPING);
790 787
791 // This collides like a static object 788 // This collides like a static object
792 PhysBody.collisionType = CollisionType.Static; 789 PhysBody.collisionType = CollisionType.Static;
@@ -797,22 +794,22 @@ public sealed class BSPrim : BSPhysObject
797 else 794 else
798 { 795 {
799 // Not a Bullet static object 796 // Not a Bullet static object
800 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT); 797 CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT);
801 798
802 // Set various physical properties so other object interact properly 799 // Set various physical properties so other object interact properly
803 MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true); 800 MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true);
804 BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction); 801 PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction);
805 BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); 802 PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution);
806 803
807 // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 804 // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382
808 // Since this can be called multiple times, only zero forces when becoming physical 805 // Since this can be called multiple times, only zero forces when becoming physical
809 // BulletSimAPI.ClearAllForces2(BSBody.ptr); 806 // PhysicsScene.PE.ClearAllForces(BSBody);
810 807
811 // For good measure, make sure the transform is set through to the motion state 808 // For good measure, make sure the transform is set through to the motion state
812 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 809 PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
813 810
814 // Center of mass is at the center of the object 811 // Center of mass is at the center of the object
815 // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); 812 // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(Linkset.LinksetRoot.PhysBody, _position, _orientation);
816 813
817 // A dynamic object has mass 814 // A dynamic object has mass
818 UpdatePhysicalMassProperties(RawMass, false); 815 UpdatePhysicalMassProperties(RawMass, false);
@@ -820,22 +817,22 @@ public sealed class BSPrim : BSPhysObject
820 // Set collision detection parameters 817 // Set collision detection parameters
821 if (BSParam.CcdMotionThreshold > 0f) 818 if (BSParam.CcdMotionThreshold > 0f)
822 { 819 {
823 BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold); 820 PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold);
824 BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius); 821 PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius);
825 } 822 }
826 823
827 // Various values for simulation limits 824 // Various values for simulation limits
828 BulletSimAPI.SetDamping2(PhysBody.ptr, BSParam.LinearDamping, BSParam.AngularDamping); 825 PhysicsScene.PE.SetDamping(PhysBody, BSParam.LinearDamping, BSParam.AngularDamping);
829 BulletSimAPI.SetDeactivationTime2(PhysBody.ptr, BSParam.DeactivationTime); 826 PhysicsScene.PE.SetDeactivationTime(PhysBody, BSParam.DeactivationTime);
830 BulletSimAPI.SetSleepingThresholds2(PhysBody.ptr, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold); 827 PhysicsScene.PE.SetSleepingThresholds(PhysBody, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold);
831 BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, BSParam.ContactProcessingThreshold); 828 PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold);
832 829
833 // This collides like an object. 830 // This collides like an object.
834 PhysBody.collisionType = CollisionType.Dynamic; 831 PhysBody.collisionType = CollisionType.Dynamic;
835 832
836 // Force activation of the object so Bullet will act on it. 833 // Force activation of the object so Bullet will act on it.
837 // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects. 834 // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects.
838 BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ACTIVE_TAG); 835 PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG);
839 836
840 // There might be special things needed for implementing linksets. 837 // There might be special things needed for implementing linksets.
841 Linkset.MakeDynamic(this); 838 Linkset.MakeDynamic(this);
@@ -848,7 +845,7 @@ public sealed class BSPrim : BSPhysObject
848 // the functions after this one set up the state of a possibly newly created collision body. 845 // the functions after this one set up the state of a possibly newly created collision body.
849 private void MakeSolid(bool makeSolid) 846 private void MakeSolid(bool makeSolid)
850 { 847 {
851 CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(PhysBody.ptr); 848 CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(PhysBody);
852 if (makeSolid) 849 if (makeSolid)
853 { 850 {
854 // Verify the previous code created the correct shape for this type of thing. 851 // Verify the previous code created the correct shape for this type of thing.
@@ -856,7 +853,7 @@ public sealed class BSPrim : BSPhysObject
856 { 853 {
857 m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for solidity. id={1}, type={2}", LogHeader, LocalID, bodyType); 854 m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for solidity. id={1}, type={2}", LogHeader, LocalID, bodyType);
858 } 855 }
859 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); 856 CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE);
860 } 857 }
861 else 858 else
862 { 859 {
@@ -864,7 +861,7 @@ public sealed class BSPrim : BSPhysObject
864 { 861 {
865 m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); 862 m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType);
866 } 863 }
867 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); 864 CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE);
868 865
869 // Change collision info from a static object to a ghosty collision object 866 // Change collision info from a static object to a ghosty collision object
870 PhysBody.collisionType = CollisionType.VolumeDetect; 867 PhysBody.collisionType = CollisionType.VolumeDetect;
@@ -877,7 +874,7 @@ public sealed class BSPrim : BSPhysObject
877 private void ActivateIfPhysical(bool forceIt) 874 private void ActivateIfPhysical(bool forceIt)
878 { 875 {
879 if (IsPhysical && PhysBody.HasPhysicalBody) 876 if (IsPhysical && PhysBody.HasPhysicalBody)
880 BulletSimAPI.Activate2(PhysBody.ptr, forceIt); 877 PhysicsScene.PE.Activate(PhysBody, forceIt);
881 } 878 }
882 879
883 // Turn on or off the flag controlling whether collision events are returned to the simulator. 880 // Turn on or off the flag controlling whether collision events are returned to the simulator.
@@ -885,11 +882,11 @@ public sealed class BSPrim : BSPhysObject
885 { 882 {
886 if (wantsCollisionEvents) 883 if (wantsCollisionEvents)
887 { 884 {
888 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 885 CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
889 } 886 }
890 else 887 else
891 { 888 {
892 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 889 CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
893 } 890 }
894 } 891 }
895 892
@@ -900,18 +897,12 @@ public sealed class BSPrim : BSPhysObject
900 { 897 {
901 if (PhysBody.HasPhysicalBody) 898 if (PhysBody.HasPhysicalBody)
902 { 899 {
903 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); 900 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
904 901 }
905 // TODO: Fix this. Total kludge because adding object to world resets its gravity to default. 902 else
906 // Replace this when the new AddObjectToWorld function is complete. 903 {
907 BulletSimAPI.SetGravity2(PhysBody.ptr, ComputeGravity()); 904 m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID);
908 905 DetailLog("{0},BSPrim.UpdatePhysicalParameters,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType);
909 // Collision filter can be set only when the object is in the world
910 if (!PhysBody.ApplyCollisionMask())
911 {
912 m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID);
913 DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType);
914 }
915 } 906 }
916 } 907 }
917 908
@@ -944,9 +935,9 @@ public sealed class BSPrim : BSPhysObject
944 PhysicsScene.TaintedObject("BSPrim.setFloatOnWater", delegate() 935 PhysicsScene.TaintedObject("BSPrim.setFloatOnWater", delegate()
945 { 936 {
946 if (_floatOnWater) 937 if (_floatOnWater)
947 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); 938 CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER);
948 else 939 else
949 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); 940 CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER);
950 }); 941 });
951 } 942 }
952 } 943 }
@@ -972,7 +963,7 @@ public sealed class BSPrim : BSPhysObject
972 _rotationalVelocity = value; 963 _rotationalVelocity = value;
973 if (PhysBody.HasPhysicalBody) 964 if (PhysBody.HasPhysicalBody)
974 { 965 {
975 BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); 966 PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity);
976 ActivateIfPhysical(false); 967 ActivateIfPhysical(false);
977 } 968 }
978 } 969 }
@@ -1064,7 +1055,7 @@ public sealed class BSPrim : BSPhysObject
1064 DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce); 1055 DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce);
1065 if (PhysBody.HasPhysicalBody) 1056 if (PhysBody.HasPhysicalBody)
1066 { 1057 {
1067 BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce); 1058 PhysicsScene.PE.ApplyCentralForce(PhysBody, addForce);
1068 ActivateIfPhysical(false); 1059 ActivateIfPhysical(false);
1069 } 1060 }
1070 }); 1061 });
@@ -1088,7 +1079,7 @@ public sealed class BSPrim : BSPhysObject
1088 { 1079 {
1089 if (PhysBody.HasPhysicalBody) 1080 if (PhysBody.HasPhysicalBody)
1090 { 1081 {
1091 BulletSimAPI.ApplyTorque2(PhysBody.ptr, angForce); 1082 PhysicsScene.PE.ApplyTorque(PhysBody, angForce);
1092 ActivateIfPhysical(false); 1083 ActivateIfPhysical(false);
1093 } 1084 }
1094 }); 1085 });
@@ -1111,7 +1102,7 @@ public sealed class BSPrim : BSPhysObject
1111 { 1102 {
1112 if (PhysBody.HasPhysicalBody) 1103 if (PhysBody.HasPhysicalBody)
1113 { 1104 {
1114 BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse); 1105 PhysicsScene.PE.ApplyTorqueImpulse(PhysBody, applyImpulse);
1115 ActivateIfPhysical(false); 1106 ActivateIfPhysical(false);
1116 } 1107 }
1117 }); 1108 });
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 4133107..7017194 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Reflection;
29using System.Runtime.InteropServices; 30using System.Runtime.InteropServices;
30using System.Text; 31using System.Text;
31using System.Threading; 32using System.Threading;
@@ -42,14 +43,18 @@ namespace OpenSim.Region.Physics.BulletSPlugin
42{ 43{
43public sealed class BSScene : PhysicsScene, IPhysicsParameters 44public sealed class BSScene : PhysicsScene, IPhysicsParameters
44{ 45{
45 private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 46 internal static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
46 private static readonly string LogHeader = "[BULLETS SCENE]"; 47 internal static readonly string LogHeader = "[BULLETS SCENE]";
47 48
48 // The name of the region we're working for. 49 // The name of the region we're working for.
49 public string RegionName { get; private set; } 50 public string RegionName { get; private set; }
50 51
51 public string BulletSimVersion = "?"; 52 public string BulletSimVersion = "?";
52 53
54 // The handle to the underlying managed or unmanaged version of Bullet being used.
55 public string BulletEngineName { get; private set; }
56 public BSAPITemplate PE;
57
53 public Dictionary<uint, BSPhysObject> PhysObjects; 58 public Dictionary<uint, BSPhysObject> PhysObjects;
54 public BSShapeCollection Shapes; 59 public BSShapeCollection Shapes;
55 60
@@ -99,11 +104,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
99 // Pinned memory used to pass step information between managed and unmanaged 104 // Pinned memory used to pass step information between managed and unmanaged
100 internal int m_maxCollisionsPerFrame; 105 internal int m_maxCollisionsPerFrame;
101 internal CollisionDesc[] m_collisionArray; 106 internal CollisionDesc[] m_collisionArray;
102 internal GCHandle m_collisionArrayPinnedHandle;
103 107
104 internal int m_maxUpdatesPerFrame; 108 internal int m_maxUpdatesPerFrame;
105 internal EntityProperties[] m_updateArray; 109 internal EntityProperties[] m_updateArray;
106 internal GCHandle m_updateArrayPinnedHandle;
107 110
108 public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero 111 public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero
109 public const uint GROUNDPLANE_ID = 1; 112 public const uint GROUNDPLANE_ID = 1;
@@ -149,12 +152,6 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
149 // A pointer to an instance if this structure is passed to the C++ code 152 // A pointer to an instance if this structure is passed to the C++ code
150 // Used to pass basic configuration values to the unmanaged code. 153 // Used to pass basic configuration values to the unmanaged code.
151 internal ConfigurationParameters[] UnmanagedParams; 154 internal ConfigurationParameters[] UnmanagedParams;
152 GCHandle m_paramsHandle;
153
154 // Handle to the callback used by the unmanaged code to call into the managed code.
155 // Used for debug logging.
156 // Need to store the handle in a persistant variable so it won't be freed.
157 private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle;
158 155
159 // Sometimes you just have to log everything. 156 // Sometimes you just have to log everything.
160 public Logging.LogWriter PhysicsLogging; 157 public Logging.LogWriter PhysicsLogging;
@@ -164,6 +161,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
164 private int m_physicsLoggingFileMinutes; 161 private int m_physicsLoggingFileMinutes;
165 private bool m_physicsLoggingDoFlush; 162 private bool m_physicsLoggingDoFlush;
166 private bool m_physicsPhysicalDumpEnabled; 163 private bool m_physicsPhysicalDumpEnabled;
164 public float PhysicsMetricDumpFrames { get; set; }
167 // 'true' of the vehicle code is to log lots of details 165 // 'true' of the vehicle code is to log lots of details
168 public bool VehicleLoggingEnabled { get; private set; } 166 public bool VehicleLoggingEnabled { get; private set; }
169 public bool VehiclePhysicalLoggingEnabled { get; private set; } 167 public bool VehiclePhysicalLoggingEnabled { get; private set; }
@@ -187,16 +185,12 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
187 185
188 // Allocate pinned memory to pass parameters. 186 // Allocate pinned memory to pass parameters.
189 UnmanagedParams = new ConfigurationParameters[1]; 187 UnmanagedParams = new ConfigurationParameters[1];
190 m_paramsHandle = GCHandle.Alloc(UnmanagedParams, GCHandleType.Pinned);
191 188
192 // Set default values for physics parameters plus any overrides from the ini file 189 // Set default values for physics parameters plus any overrides from the ini file
193 GetInitialParameterValues(config); 190 GetInitialParameterValues(config);
194 191
195 // allocate more pinned memory close to the above in an attempt to get the memory all together 192 // Get the connection to the physics engine (could be native or one of many DLLs)
196 m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame]; 193 PE = SelectUnderlyingBulletEngine(BulletEngineName);
197 m_collisionArrayPinnedHandle = GCHandle.Alloc(m_collisionArray, GCHandleType.Pinned);
198 m_updateArray = new EntityProperties[m_maxUpdatesPerFrame];
199 m_updateArrayPinnedHandle = GCHandle.Alloc(m_updateArray, GCHandleType.Pinned);
200 194
201 // Enable very detailed logging. 195 // Enable very detailed logging.
202 // By creating an empty logger when not logging, the log message invocation code 196 // By creating an empty logger when not logging, the log message invocation code
@@ -211,22 +205,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
211 PhysicsLogging = new Logging.LogWriter(); 205 PhysicsLogging = new Logging.LogWriter();
212 } 206 }
213 207
214 // If Debug logging level, enable logging from the unmanaged code 208 // Allocate memory for returning of the updates and collisions from the physics engine
215 m_DebugLogCallbackHandle = null; 209 m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame];
216 if (m_log.IsDebugEnabled || PhysicsLogging.Enabled) 210 m_updateArray = new EntityProperties[m_maxUpdatesPerFrame];
217 {
218 m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader);
219 if (PhysicsLogging.Enabled)
220 // The handle is saved in a variable to make sure it doesn't get freed after this call
221 m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLoggerPhysLog);
222 else
223 m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger);
224 }
225
226 // Get the version of the DLL
227 // TODO: this doesn't work yet. Something wrong with marshaling the returned string.
228 // BulletSimVersion = BulletSimAPI.GetVersion();
229 // m_log.WarnFormat("{0}: BulletSim.dll version='{1}'", LogHeader, BulletSimVersion);
230 211
231 // The bounding box for the simulated world. The origin is 0,0,0 unless we're 212 // The bounding box for the simulated world. The origin is 0,0,0 unless we're
232 // a child in a mega-region. 213 // a child in a mega-region.
@@ -234,11 +215,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
234 // area. It tracks active objects no matter where they are. 215 // area. It tracks active objects no matter where they are.
235 Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); 216 Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);
236 217
237 // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader); 218 World = PE.Initialize(worldExtent, Params, m_maxCollisionsPerFrame, ref m_collisionArray, m_maxUpdatesPerFrame, ref m_updateArray);
238 World = new BulletWorld(0, this, BulletSimAPI.Initialize2(worldExtent, m_paramsHandle.AddrOfPinnedObject(),
239 m_maxCollisionsPerFrame, m_collisionArrayPinnedHandle.AddrOfPinnedObject(),
240 m_maxUpdatesPerFrame, m_updateArrayPinnedHandle.AddrOfPinnedObject(),
241 m_DebugLogCallbackHandle));
242 219
243 Constraints = new BSConstraintCollection(World); 220 Constraints = new BSConstraintCollection(World);
244 221
@@ -268,6 +245,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
268 { 245 {
269 BSParam.SetParameterConfigurationValues(this, pConfig); 246 BSParam.SetParameterConfigurationValues(this, pConfig);
270 247
248 // There are two Bullet implementations to choose from
249 BulletEngineName = pConfig.GetString("BulletEngine", "BulletUnmanaged");
250
271 // Very detailed logging for physics debugging 251 // Very detailed logging for physics debugging
272 // TODO: the boolean values can be moved to the normal parameter processing. 252 // TODO: the boolean values can be moved to the normal parameter processing.
273 m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false); 253 m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false);
@@ -309,16 +289,41 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
309 return ret; 289 return ret;
310 } 290 }
311 291
312 // Called directly from unmanaged code so don't do much 292 // Select the connection to the actual Bullet implementation.
313 private void BulletLogger(string msg) 293 // The main engine selection is the engineName up to the first hypen.
294 // So "Bullet-2.80-OpenCL-Intel" specifies the 'bullet' class here and the whole name
295 // is passed to the engine to do its special selection, etc.
296 private BSAPITemplate SelectUnderlyingBulletEngine(string engineName)
314 { 297 {
315 m_log.Debug("[BULLETS UNMANAGED]:" + msg); 298 // For the moment, do a simple switch statement.
316 } 299 // Someday do fancyness with looking up the interfaces in the assembly.
300 BSAPITemplate ret = null;
317 301
318 // Called directly from unmanaged code so don't do much 302 string selectionName = engineName.ToLower();
319 private void BulletLoggerPhysLog(string msg) 303 int hyphenIndex = engineName.IndexOf("-");
320 { 304 if (hyphenIndex > 0)
321 DetailLog("[BULLETS UNMANAGED]:" + msg); 305 selectionName = engineName.ToLower().Substring(0, hyphenIndex - 1);
306
307 switch (selectionName)
308 {
309 case "bulletunmanaged":
310 ret = new BSAPIUnman(engineName, this);
311 break;
312 case "bulletxna":
313 ret = new BSAPIXNA(engineName, this);
314 break;
315 }
316
317 if (ret == null)
318 {
319 m_log.ErrorFormat("{0) COULD NOT SELECT BULLET ENGINE: '[BulletSim]PhysicsEngine' must be either 'BulletUnmanaged-*' or 'BulletXNA-*'", LogHeader);
320 }
321 else
322 {
323 m_log.WarnFormat("{0} Selected bullet engine {1} -> {2}/{3}", LogHeader, engineName, ret.BulletEngineName, ret.BulletEngineVersion);
324 }
325
326 return ret;
322 } 327 }
323 328
324 public override void Dispose() 329 public override void Dispose()
@@ -355,7 +360,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
355 } 360 }
356 361
357 // Anything left in the unmanaged code should be cleaned out 362 // Anything left in the unmanaged code should be cleaned out
358 BulletSimAPI.Shutdown2(World.ptr); 363 PE.Shutdown(World);
359 364
360 // Not logging any more 365 // Not logging any more
361 PhysicsLogging.Close(); 366 PhysicsLogging.Close();
@@ -468,9 +473,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
468 LastTimeStep = timeStep; 473 LastTimeStep = timeStep;
469 474
470 int updatedEntityCount = 0; 475 int updatedEntityCount = 0;
471 IntPtr updatedEntitiesPtr;
472 int collidersCount = 0; 476 int collidersCount = 0;
473 IntPtr collidersPtr;
474 477
475 int beforeTime = 0; 478 int beforeTime = 0;
476 int simTime = 0; 479 int simTime = 0;
@@ -486,6 +489,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
486 TriggerPreStepEvent(timeStep); 489 TriggerPreStepEvent(timeStep);
487 490
488 // the prestep actions might have added taints 491 // the prestep actions might have added taints
492 numTaints += _taintOperations.Count;
489 ProcessTaints(); 493 ProcessTaints();
490 494
491 InTaintTime = false; // Only used for debugging so locking is not necessary. 495 InTaintTime = false; // Only used for debugging so locking is not necessary.
@@ -493,23 +497,25 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
493 // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. 497 // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world.
494 // Only enable this in a limited test world with few objects. 498 // Only enable this in a limited test world with few objects.
495 if (m_physicsPhysicalDumpEnabled) 499 if (m_physicsPhysicalDumpEnabled)
496 BulletSimAPI.DumpAllInfo2(World.ptr); 500 PE.DumpAllInfo(World);
497 501
498 // step the physical world one interval 502 // step the physical world one interval
499 m_simulationStep++; 503 m_simulationStep++;
500 int numSubSteps = 0; 504 int numSubSteps = 0;
501
502 try 505 try
503 { 506 {
504 if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount(); 507 if (PhysicsLogging.Enabled)
508 beforeTime = Util.EnvironmentTickCount();
505 509
506 numSubSteps = BulletSimAPI.PhysicsStep2(World.ptr, timeStep, m_maxSubSteps, m_fixedTimeStep, 510 numSubSteps = PE.PhysicsStep(World, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out collidersCount);
507 out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr);
508 511
509 if (PhysicsLogging.Enabled) simTime = Util.EnvironmentTickCountSubtract(beforeTime); 512 if (PhysicsLogging.Enabled)
510 DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}, objWColl={7}", 513 {
511 DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps, 514 simTime = Util.EnvironmentTickCountSubtract(beforeTime);
512 updatedEntityCount, collidersCount, ObjectsWithCollisions.Count); 515 DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}, objWColl={7}",
516 DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps,
517 updatedEntityCount, collidersCount, ObjectsWithCollisions.Count);
518 }
513 } 519 }
514 catch (Exception e) 520 catch (Exception e)
515 { 521 {
@@ -521,7 +527,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
521 collidersCount = 0; 527 collidersCount = 0;
522 } 528 }
523 529
524 // Don't have to use the pointers passed back since we know it is the same pinned memory we passed in. 530 if ((m_simulationStep % PhysicsMetricDumpFrames) == 0)
531 PE.DumpPhysicsStatistics(World);
525 532
526 // Get a value for 'now' so all the collision and update routines don't have to get their own. 533 // Get a value for 'now' so all the collision and update routines don't have to get their own.
527 SimulationNowTime = Util.EnvironmentTickCount(); 534 SimulationNowTime = Util.EnvironmentTickCount();
@@ -564,7 +571,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
564 // Objects that are done colliding are removed from the ObjectsWithCollisions list. 571 // Objects that are done colliding are removed from the ObjectsWithCollisions list.
565 // Not done above because it is inside an iteration of ObjectWithCollisions. 572 // Not done above because it is inside an iteration of ObjectWithCollisions.
566 // This complex collision processing is required to create an empty collision 573 // This complex collision processing is required to create an empty collision
567 // event call after all collisions have happened on an object. This enables 574 // event call after all real collisions have happened on an object. This enables
568 // the simulator to generate the 'collision end' event. 575 // the simulator to generate the 'collision end' event.
569 if (ObjectsWithNoMoreCollisions.Count > 0) 576 if (ObjectsWithNoMoreCollisions.Count > 0)
570 { 577 {
@@ -593,11 +600,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
593 // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. 600 // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world.
594 // Only enable this in a limited test world with few objects. 601 // Only enable this in a limited test world with few objects.
595 if (m_physicsPhysicalDumpEnabled) 602 if (m_physicsPhysicalDumpEnabled)
596 BulletSimAPI.DumpAllInfo2(World.ptr); 603 PE.DumpAllInfo(World);
597 604
598 // The physics engine returns the number of milliseconds it simulated this call. 605 // The physics engine returns the number of milliseconds it simulated this call.
599 // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS. 606 // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS.
600 // Multiply by 55 to give a nominal frame rate of 55. 607 // Multiply by a fixed nominal frame rate to give a rate similar to the simulator (usually 55).
601 return (float)numSubSteps * m_fixedTimeStep * 1000f * NominalFrameRate; 608 return (float)numSubSteps * m_fixedTimeStep * 1000f * NominalFrameRate;
602 } 609 }
603 610
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 4008ff6..a7855f0 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;
@@ -141,9 +141,9 @@ public sealed class BSShapeCollection : IDisposable
141 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); 141 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body);
142 PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate() 142 PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate()
143 { 143 {
144 if (!BulletSimAPI.IsInWorld2(body.ptr)) 144 if (!PhysicsScene.PE.IsInWorld(PhysicsScene.World, body))
145 { 145 {
146 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, body.ptr); 146 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, body);
147 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body); 147 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body);
148 } 148 }
149 }); 149 });
@@ -166,15 +166,15 @@ public sealed class BSShapeCollection : IDisposable
166 // If the caller needs to know the old body is going away, pass the event up. 166 // If the caller needs to know the old body is going away, pass the event up.
167 if (bodyCallback != null) bodyCallback(body); 167 if (bodyCallback != null) bodyCallback(body);
168 168
169 if (BulletSimAPI.IsInWorld2(body.ptr)) 169 if (PhysicsScene.PE.IsInWorld(PhysicsScene.World, body))
170 { 170 {
171 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr); 171 PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, body);
172 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body); 172 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body);
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 BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero); 176 PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, null);
177 BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, body.ptr); 177 PhysicsScene.PE.DestroyObject(PhysicsScene.World, body);
178 }); 178 });
179 } 179 }
180 } 180 }
@@ -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}",
@@ -259,9 +259,9 @@ public sealed class BSShapeCollection : IDisposable
259 { 259 {
260 // Native shapes are not tracked and are released immediately 260 // Native shapes are not tracked and are released immediately
261 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}", 261 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}",
262 BSScene.DetailLogZero, shape.ptr.ToString("X"), inTaintTime); 262 BSScene.DetailLogZero, shape.AddrString, inTaintTime);
263 if (shapeCallback != null) shapeCallback(shape); 263 if (shapeCallback != null) shapeCallback(shape);
264 BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr); 264 PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape);
265 } 265 }
266 else 266 else
267 { 267 {
@@ -332,57 +332,56 @@ public sealed class BSShapeCollection : IDisposable
332 // Called at taint-time. 332 // Called at taint-time.
333 private void DereferenceCompound(BulletShape shape, ShapeDestructionCallback shapeCallback) 333 private void DereferenceCompound(BulletShape shape, ShapeDestructionCallback shapeCallback)
334 { 334 {
335 if (!BulletSimAPI.IsCompound2(shape.ptr)) 335 if (!PhysicsScene.PE.IsCompound(shape))
336 { 336 {
337 // Failed the sanity check!! 337 // Failed the sanity check!!
338 PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", 338 PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}",
339 LogHeader, shape.type, shape.ptr.ToString("X")); 339 LogHeader, shape.type, shape.AddrString);
340 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", 340 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}",
341 BSScene.DetailLogZero, shape.type, shape.ptr.ToString("X")); 341 BSScene.DetailLogZero, shape.type, shape.AddrString);
342 return; 342 return;
343 } 343 }
344 344
345 int numChildren = BulletSimAPI.GetNumberOfCompoundChildren2(shape.ptr); 345 int numChildren = PhysicsScene.PE.GetNumberOfCompoundChildren(shape);
346 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren); 346 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren);
347 347
348 for (int ii = numChildren - 1; ii >= 0; ii--) 348 for (int ii = numChildren - 1; ii >= 0; ii--)
349 { 349 {
350 IntPtr childShape = BulletSimAPI.RemoveChildShapeFromCompoundShapeIndex2(shape.ptr, ii); 350 BulletShape childShape = PhysicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(shape, ii);
351 DereferenceAnonCollisionShape(childShape); 351 DereferenceAnonCollisionShape(childShape);
352 } 352 }
353 BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr); 353 PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape);
354 } 354 }
355 355
356 // Sometimes we have a pointer to a collision shape but don't know what type it is. 356 // Sometimes we have a pointer to a collision shape but don't know what type it is.
357 // Figure out type and call the correct dereference routine. 357 // Figure out type and call the correct dereference routine.
358 // Called at taint-time. 358 // Called at taint-time.
359 private void DereferenceAnonCollisionShape(IntPtr cShape) 359 private void DereferenceAnonCollisionShape(BulletShape shapeInfo)
360 { 360 {
361 MeshDesc meshDesc; 361 MeshDesc meshDesc;
362 HullDesc hullDesc; 362 HullDesc hullDesc;
363 363
364 BulletShape shapeInfo = new BulletShape(cShape); 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;
376 } 375 }
377 else 376 else
378 { 377 {
379 if (BulletSimAPI.IsCompound2(cShape)) 378 if (PhysicsScene.PE.IsCompound(shapeInfo))
380 { 379 {
381 shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND; 380 shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND;
382 } 381 }
383 else 382 else
384 { 383 {
385 if (BulletSimAPI.IsNativeShape2(cShape)) 384 if (PhysicsScene.PE.IsNativeShape(shapeInfo))
386 { 385 {
387 shapeInfo.isNativeShape = true; 386 shapeInfo.isNativeShape = true;
388 shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) 387 shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter)
@@ -400,7 +399,7 @@ public sealed class BSShapeCollection : IDisposable
400 else 399 else
401 { 400 {
402 PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}", 401 PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}",
403 LogHeader, PhysicsScene.RegionName, cShape.ToString("X")); 402 LogHeader, PhysicsScene.RegionName, shapeInfo.AddrString);
404 } 403 }
405 } 404 }
406 405
@@ -467,7 +466,7 @@ public sealed class BSShapeCollection : IDisposable
467 // Get the scale of any existing shape so we can see if the new shape is same native type and same size. 466 // Get the scale of any existing shape so we can see if the new shape is same native type and same size.
468 OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero; 467 OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero;
469 if (prim.PhysShape.HasPhysicalShape) 468 if (prim.PhysShape.HasPhysicalShape)
470 scaleOfExistingShape = BulletSimAPI.GetLocalScaling2(prim.PhysShape.ptr); 469 scaleOfExistingShape = PhysicsScene.PE.GetLocalScaling(prim.PhysShape);
471 470
472 if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}", 471 if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}",
473 prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type); 472 prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type);
@@ -570,19 +569,15 @@ public sealed class BSShapeCollection : IDisposable
570 569
571 if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) 570 if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE)
572 { 571 {
573 // The proper scale has been calculated in the prim. 572
574 newShape = new BulletShape( 573 newShape = PhysicsScene.PE.BuildCapsuleShape(PhysicsScene.World, 1f, 1f, prim.Scale);
575 // Bullet's capsule total height is the passed "height + (radius * 2)" so, the base
576 // capsule is radius of 0.5f (1 diameter) and height of two (1.0f + 0.5f * 2)".
577 // This must be taken into account when computing the scaling of the capsule.
578 BulletSimAPI.BuildCapsuleShape2(PhysicsScene.World.ptr, 1f, 1f, prim.Scale)
579 , shapeType);
580 if (DDetail) DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); 574 if (DDetail) DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale);
581 } 575 }
582 else 576 else
583 { 577 {
584 // Native shapes are scaled in Bullet so set the scaling to the size 578 // Native shapes are scaled in Bullet so set the scaling to the size
585 newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, nativeShapeData), shapeType); 579 newShape = PhysicsScene.PE.BuildNativeShape(PhysicsScene.World, nativeShapeData);
580
586 } 581 }
587 if (!newShape.HasPhysicalShape) 582 if (!newShape.HasPhysicalShape)
588 { 583 {
@@ -629,13 +624,14 @@ public sealed class BSShapeCollection : IDisposable
629 624
630 private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) 625 private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
631 { 626 {
627 BulletShape newShape = new BulletShape();
632 IMesh meshData = null; 628 IMesh meshData = null;
633 IntPtr meshPtr = IntPtr.Zero; 629
634 MeshDesc meshDesc; 630 MeshDesc meshDesc;
635 if (Meshes.TryGetValue(newMeshKey, out meshDesc)) 631 if (Meshes.TryGetValue(newMeshKey, out meshDesc))
636 { 632 {
637 // If the mesh has already been built just use it. 633 // If the mesh has already been built just use it.
638 meshPtr = meshDesc.ptr; 634 newShape = meshDesc.shape.Clone();
639 } 635 }
640 else 636 else
641 { 637 {
@@ -658,11 +654,10 @@ public sealed class BSShapeCollection : IDisposable
658 // m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", 654 // m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}",
659 // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count); 655 // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count);
660 656
661 meshPtr = BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, 657 newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World,
662 indices.GetLength(0), indices, vertices.Count, verticesAsFloats); 658 indices.GetLength(0), indices, vertices.Count, verticesAsFloats);
663 } 659 }
664 } 660 }
665 BulletShape newShape = new BulletShape(meshPtr, BSPhysicsShapeType.SHAPE_MESH);
666 newShape.shapeKey = newMeshKey; 661 newShape.shapeKey = newMeshKey;
667 662
668 return newShape; 663 return newShape;
@@ -700,12 +695,14 @@ public sealed class BSShapeCollection : IDisposable
700 private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) 695 private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
701 { 696 {
702 697
698 BulletShape newShape = new BulletShape();
703 IntPtr hullPtr = IntPtr.Zero; 699 IntPtr hullPtr = IntPtr.Zero;
700
704 HullDesc hullDesc; 701 HullDesc hullDesc;
705 if (Hulls.TryGetValue(newHullKey, out hullDesc)) 702 if (Hulls.TryGetValue(newHullKey, out hullDesc))
706 { 703 {
707 // If the hull shape already is created, just use it. 704 // If the hull shape already is created, just use it.
708 hullPtr = hullDesc.ptr; 705 newShape = hullDesc.shape.Clone();
709 } 706 }
710 else 707 else
711 { 708 {
@@ -793,11 +790,10 @@ public sealed class BSShapeCollection : IDisposable
793 } 790 }
794 } 791 }
795 // create the hull data structure in Bullet 792 // create the hull data structure in Bullet
796 hullPtr = BulletSimAPI.CreateHullShape2(PhysicsScene.World.ptr, hullCount, convHulls); 793 newShape = PhysicsScene.PE.CreateHullShape(PhysicsScene.World, hullCount, convHulls);
797 } 794 }
798 } 795 }
799 796
800 BulletShape newShape = new BulletShape(hullPtr, BSPhysicsShapeType.SHAPE_HULL);
801 newShape.shapeKey = newHullKey; 797 newShape.shapeKey = newHullKey;
802 798
803 return newShape; 799 return newShape;
@@ -819,12 +815,12 @@ public sealed class BSShapeCollection : IDisposable
819 // Don't need to do this as the shape is freed when the new root shape is created below. 815 // Don't need to do this as the shape is freed when the new root shape is created below.
820 // DereferenceShape(prim.PhysShape, true, shapeCallback); 816 // DereferenceShape(prim.PhysShape, true, shapeCallback);
821 817
822 BulletShape cShape = new BulletShape( 818
823 BulletSimAPI.CreateCompoundShape2(PhysicsScene.World.ptr, false), BSPhysicsShapeType.SHAPE_COMPOUND); 819 BulletShape cShape = PhysicsScene.PE.CreateCompoundShape(PhysicsScene.World, false);
824 820
825 // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape. 821 // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape.
826 CreateGeomMeshOrHull(prim, shapeCallback); 822 CreateGeomMeshOrHull(prim, shapeCallback);
827 BulletSimAPI.AddChildShapeToCompoundShape2(cShape.ptr, prim.PhysShape.ptr, OMV.Vector3.Zero, OMV.Quaternion.Identity); 823 PhysicsScene.PE.AddChildShapeToCompoundShape(cShape, prim.PhysShape, OMV.Vector3.Zero, OMV.Quaternion.Identity);
828 if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}", 824 if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}",
829 prim.LocalID, cShape, prim.PhysShape); 825 prim.LocalID, cShape, prim.PhysShape);
830 826
@@ -932,7 +928,7 @@ public sealed class BSShapeCollection : IDisposable
932 // If not a solid object, body is a GhostObject. Otherwise a RigidBody. 928 // If not a solid object, body is a GhostObject. Otherwise a RigidBody.
933 if (!mustRebuild) 929 if (!mustRebuild)
934 { 930 {
935 CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(prim.PhysBody.ptr); 931 CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(prim.PhysBody);
936 if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY 932 if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY
937 || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT) 933 || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT)
938 { 934 {
@@ -947,20 +943,16 @@ public sealed class BSShapeCollection : IDisposable
947 DereferenceBody(prim.PhysBody, true, bodyCallback); 943 DereferenceBody(prim.PhysBody, true, bodyCallback);
948 944
949 BulletBody aBody; 945 BulletBody aBody;
950 IntPtr bodyPtr = IntPtr.Zero;
951 if (prim.IsSolid) 946 if (prim.IsSolid)
952 { 947 {
953 bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, 948 aBody = PhysicsScene.PE.CreateBodyFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation);
954 prim.LocalID, prim.RawPosition, prim.RawOrientation); 949 if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,body={1}", prim.LocalID, aBody);
955 if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X"));
956 } 950 }
957 else 951 else
958 { 952 {
959 bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, 953 aBody = PhysicsScene.PE.CreateGhostFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation);
960 prim.LocalID, prim.RawPosition, prim.RawOrientation); 954 if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,body={1}", prim.LocalID, aBody);
961 if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X"));
962 } 955 }
963 aBody = new BulletBody(prim.LocalID, bodyPtr);
964 956
965 ReferenceBody(aBody, true); 957 ReferenceBody(aBody, true);
966 958
@@ -972,13 +964,13 @@ public sealed class BSShapeCollection : IDisposable
972 return ret; 964 return ret;
973 } 965 }
974 966
975 private bool TryGetMeshByPtr(IntPtr addr, out MeshDesc outDesc) 967 private bool TryGetMeshByPtr(BulletShape shape, out MeshDesc outDesc)
976 { 968 {
977 bool ret = false; 969 bool ret = false;
978 MeshDesc foundDesc = new MeshDesc(); 970 MeshDesc foundDesc = new MeshDesc();
979 foreach (MeshDesc md in Meshes.Values) 971 foreach (MeshDesc md in Meshes.Values)
980 { 972 {
981 if (md.ptr == addr) 973 if (md.shape.ReferenceSame(shape))
982 { 974 {
983 foundDesc = md; 975 foundDesc = md;
984 ret = true; 976 ret = true;
@@ -990,13 +982,13 @@ public sealed class BSShapeCollection : IDisposable
990 return ret; 982 return ret;
991 } 983 }
992 984
993 private bool TryGetHullByPtr(IntPtr addr, out HullDesc outDesc) 985 private bool TryGetHullByPtr(BulletShape shape, out HullDesc outDesc)
994 { 986 {
995 bool ret = false; 987 bool ret = false;
996 HullDesc foundDesc = new HullDesc(); 988 HullDesc foundDesc = new HullDesc();
997 foreach (HullDesc hd in Hulls.Values) 989 foreach (HullDesc hd in Hulls.Values)
998 { 990 {
999 if (hd.ptr == addr) 991 if (hd.shape.ReferenceSame(shape))
1000 { 992 {
1001 foundDesc = hd; 993 foundDesc = hd;
1002 ret = true; 994 ret = true;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
index c7885c6..c75eb9b 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
@@ -91,11 +91,17 @@ public abstract class BSShape
91 // All shapes have a static call to get a reference to the physical shape 91 // All shapes have a static call to get a reference to the physical shape
92 // protected abstract static BSShape GetReference(); 92 // protected abstract static BSShape GetReference();
93 93
94 // Returns a string for debugging that uniquily identifies the memory used by this instance
95 public string AddrString
96 {
97 get { return ptr.ToString("X"); }
98 }
99
94 public override string ToString() 100 public override string ToString()
95 { 101 {
96 StringBuilder buff = new StringBuilder(); 102 StringBuilder buff = new StringBuilder();
97 buff.Append("<p="); 103 buff.Append("<p=");
98 buff.Append(ptr.ToString("X")); 104 buff.Append(AddrString);
99 buff.Append(",s="); 105 buff.Append(",s=");
100 buff.Append(type.ToString()); 106 buff.Append(type.ToString());
101 buff.Append(",k="); 107 buff.Append(",k=");
@@ -126,7 +132,8 @@ public class BSShapeNative : BSShape
126 BSPhysicsShapeType shapeType, FixedShapeKey shapeKey) 132 BSPhysicsShapeType shapeType, FixedShapeKey shapeKey)
127 { 133 {
128 // Native shapes are not shared and are always built anew. 134 // Native shapes are not shared and are always built anew.
129 return new BSShapeNative(physicsScene, prim, shapeType, shapeKey); 135 //return new BSShapeNative(physicsScene, prim, shapeType, shapeKey);
136 return null;
130 } 137 }
131 138
132 private BSShapeNative(BSScene physicsScene, BSPhysObject prim, 139 private BSShapeNative(BSScene physicsScene, BSPhysObject prim,
@@ -141,14 +148,15 @@ public class BSShapeNative : BSShape
141 nativeShapeData.HullKey = (ulong)shapeKey; 148 nativeShapeData.HullKey = (ulong)shapeKey;
142 149
143 150
151 /*
144 if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) 152 if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE)
145 { 153 {
146 ptr = BulletSimAPI.BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale); 154 ptr = PhysicsScene.PE.BuildCapsuleShape(physicsScene.World, 1f, 1f, prim.Scale);
147 physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); 155 physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale);
148 } 156 }
149 else 157 else
150 { 158 {
151 ptr = BulletSimAPI.BuildNativeShape2(physicsScene.World.ptr, nativeShapeData); 159 ptr = PhysicsScene.PE.BuildNativeShape(physicsScene.World, nativeShapeData);
152 } 160 }
153 if (ptr == IntPtr.Zero) 161 if (ptr == IntPtr.Zero)
154 { 162 {
@@ -157,15 +165,18 @@ public class BSShapeNative : BSShape
157 } 165 }
158 type = shapeType; 166 type = shapeType;
159 key = (UInt64)shapeKey; 167 key = (UInt64)shapeKey;
168 */
160 } 169 }
161 // Make this reference to the physical shape go away since native shapes are not shared. 170 // Make this reference to the physical shape go away since native shapes are not shared.
162 public override void Dereference(BSScene physicsScene) 171 public override void Dereference(BSScene physicsScene)
163 { 172 {
173 /*
164 // Native shapes are not tracked and are released immediately 174 // Native shapes are not tracked and are released immediately
165 physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this); 175 physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this);
166 BulletSimAPI.DeleteCollisionShape2(physicsScene.World.ptr, ptr); 176 PhysicsScene.PE.DeleteCollisionShape(physicsScene.World, this);
167 ptr = IntPtr.Zero; 177 ptr = IntPtr.Zero;
168 // Garbage collection will free up this instance. 178 // Garbage collection will free up this instance.
179 */
169 } 180 }
170} 181}
171 182
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
index 07a9fd8..e4fecc3 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
@@ -44,7 +44,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
44{ 44{
45 static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]"; 45 static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]";
46 46
47 BulletHeightMapInfo m_mapInfo = null; 47 BulletHMapInfo m_mapInfo = null;
48 48
49 // Constructor to build a default, flat heightmap terrain. 49 // Constructor to build a default, flat heightmap terrain.
50 public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize) 50 public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize)
@@ -58,7 +58,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
58 { 58 {
59 initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION; 59 initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION;
60 } 60 }
61 m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); 61 m_mapInfo = new BulletHMapInfo(id, initialMap);
62 m_mapInfo.minCoords = minTerrainCoords; 62 m_mapInfo.minCoords = minTerrainCoords;
63 m_mapInfo.maxCoords = maxTerrainCoords; 63 m_mapInfo.maxCoords = maxTerrainCoords;
64 m_mapInfo.terrainRegionBase = TerrainBase; 64 m_mapInfo.terrainRegionBase = TerrainBase;
@@ -72,7 +72,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
72 Vector3 minCoords, Vector3 maxCoords) 72 Vector3 minCoords, Vector3 maxCoords)
73 : base(physicsScene, regionBase, id) 73 : base(physicsScene, regionBase, id)
74 { 74 {
75 m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); 75 m_mapInfo = new BulletHMapInfo(id, initialMap);
76 m_mapInfo.minCoords = minCoords; 76 m_mapInfo.minCoords = minCoords;
77 m_mapInfo.maxCoords = maxCoords; 77 m_mapInfo.maxCoords = maxCoords;
78 m_mapInfo.minZ = minCoords.Z; 78 m_mapInfo.minZ = minCoords.Z;
@@ -91,13 +91,11 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
91 // Using the information in m_mapInfo, create the physical representation of the heightmap. 91 // Using the information in m_mapInfo, create the physical representation of the heightmap.
92 private void BuildHeightmapTerrain() 92 private void BuildHeightmapTerrain()
93 { 93 {
94 m_mapInfo.Ptr = BulletSimAPI.CreateHeightMapInfo2(PhysicsScene.World.ptr, m_mapInfo.ID,
95 m_mapInfo.minCoords, m_mapInfo.maxCoords,
96 m_mapInfo.heightMap, BSParam.TerrainCollisionMargin);
97
98 // Create the terrain shape from the mapInfo 94 // Create the terrain shape from the mapInfo
99 m_mapInfo.terrainShape = new BulletShape(BulletSimAPI.CreateTerrainShape2(m_mapInfo.Ptr), 95 m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape( m_mapInfo.ID,
100 BSPhysicsShapeType.SHAPE_TERRAIN); 96 new Vector3(m_mapInfo.sizeX, m_mapInfo.sizeY, 0), m_mapInfo.minZ, m_mapInfo.maxZ,
97 m_mapInfo.heightMap, 1f, BSParam.TerrainCollisionMargin);
98
101 99
102 // The terrain object initial position is at the center of the object 100 // The terrain object initial position is at the center of the object
103 Vector3 centerPos; 101 Vector3 centerPos;
@@ -105,27 +103,26 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
105 centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f); 103 centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f);
106 centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f); 104 centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f);
107 105
108 m_mapInfo.terrainBody = new BulletBody(m_mapInfo.ID, 106 m_mapInfo.terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_mapInfo.terrainShape,
109 BulletSimAPI.CreateBodyWithDefaultMotionState2(m_mapInfo.terrainShape.ptr, 107 m_mapInfo.ID, centerPos, Quaternion.Identity);
110 m_mapInfo.ID, centerPos, Quaternion.Identity));
111 108
112 // Set current terrain attributes 109 // Set current terrain attributes
113 BulletSimAPI.SetFriction2(m_mapInfo.terrainBody.ptr, BSParam.TerrainFriction); 110 PhysicsScene.PE.SetFriction(m_mapInfo.terrainBody, BSParam.TerrainFriction);
114 BulletSimAPI.SetHitFraction2(m_mapInfo.terrainBody.ptr, BSParam.TerrainHitFraction); 111 PhysicsScene.PE.SetHitFraction(m_mapInfo.terrainBody, BSParam.TerrainHitFraction);
115 BulletSimAPI.SetRestitution2(m_mapInfo.terrainBody.ptr, BSParam.TerrainRestitution); 112 PhysicsScene.PE.SetRestitution(m_mapInfo.terrainBody, BSParam.TerrainRestitution);
116 BulletSimAPI.SetCollisionFlags2(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); 113 PhysicsScene.PE.SetCollisionFlags(m_mapInfo.terrainBody, CollisionFlags.CF_STATIC_OBJECT);
117 114
118 // Return the new terrain to the world of physical objects 115 // Return the new terrain to the world of physical objects
119 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); 116 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_mapInfo.terrainBody);
120 117
121 // redo its bounding box now that it is in the world 118 // redo its bounding box now that it is in the world
122 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); 119 PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_mapInfo.terrainBody);
123 120
124 m_mapInfo.terrainBody.collisionType = CollisionType.Terrain; 121 m_mapInfo.terrainBody.collisionType = CollisionType.Terrain;
125 m_mapInfo.terrainBody.ApplyCollisionMask(); 122 m_mapInfo.terrainBody.ApplyCollisionMask(PhysicsScene);
126 123
127 // Make it so the terrain will not move or be considered for movement. 124 // Make it so the terrain will not move or be considered for movement.
128 BulletSimAPI.ForceActivationState2(m_mapInfo.terrainBody.ptr, ActivationState.DISABLE_SIMULATION); 125 PhysicsScene.PE.ForceActivationState(m_mapInfo.terrainBody, ActivationState.DISABLE_SIMULATION);
129 126
130 return; 127 return;
131 } 128 }
@@ -137,10 +134,9 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
137 { 134 {
138 if (m_mapInfo.terrainBody.HasPhysicalBody) 135 if (m_mapInfo.terrainBody.HasPhysicalBody)
139 { 136 {
140 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); 137 PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_mapInfo.terrainBody);
141 // Frees both the body and the shape. 138 // Frees both the body and the shape.
142 BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); 139 PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody);
143 BulletSimAPI.ReleaseHeightMapInfo2(m_mapInfo.Ptr);
144 } 140 }
145 } 141 }
146 m_mapInfo = null; 142 m_mapInfo = null;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
index 86ccfbb..2e9db39 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
@@ -133,20 +133,17 @@ public sealed class BSTerrainManager : IDisposable
133 public void CreateInitialGroundPlaneAndTerrain() 133 public void CreateInitialGroundPlaneAndTerrain()
134 { 134 {
135 // The ground plane is here to catch things that are trying to drop to negative infinity 135 // The ground plane is here to catch things that are trying to drop to negative infinity
136 BulletShape groundPlaneShape = new BulletShape( 136 BulletShape groundPlaneShape = PhysicsScene.PE.CreateGroundPlaneShape(BSScene.GROUNDPLANE_ID, 1f, BSParam.TerrainCollisionMargin);
137 BulletSimAPI.CreateGroundPlaneShape2(BSScene.GROUNDPLANE_ID, 1f, 137 m_groundPlane = PhysicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape,
138 BSParam.TerrainCollisionMargin), 138 BSScene.GROUNDPLANE_ID, Vector3.Zero, Quaternion.Identity);
139 BSPhysicsShapeType.SHAPE_GROUNDPLANE); 139
140 m_groundPlane = new BulletBody(BSScene.GROUNDPLANE_ID, 140 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_groundPlane);
141 BulletSimAPI.CreateBodyWithDefaultMotionState2(groundPlaneShape.ptr, BSScene.GROUNDPLANE_ID, 141 PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_groundPlane);
142 Vector3.Zero, Quaternion.Identity));
143 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr);
144 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_groundPlane.ptr);
145 // Ground plane does not move 142 // Ground plane does not move
146 BulletSimAPI.ForceActivationState2(m_groundPlane.ptr, ActivationState.DISABLE_SIMULATION); 143 PhysicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION);
147 // Everything collides with the ground plane. 144 // Everything collides with the ground plane.
148 m_groundPlane.collisionType = CollisionType.Groundplane; 145 m_groundPlane.collisionType = CollisionType.Groundplane;
149 m_groundPlane.ApplyCollisionMask(); 146 m_groundPlane.ApplyCollisionMask(PhysicsScene);
150 147
151 // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain. 148 // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain.
152 BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize); 149 BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize);
@@ -158,9 +155,9 @@ public sealed class BSTerrainManager : IDisposable
158 { 155 {
159 if (m_groundPlane.HasPhysicalBody) 156 if (m_groundPlane.HasPhysicalBody)
160 { 157 {
161 if (BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr)) 158 if (PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_groundPlane))
162 { 159 {
163 BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_groundPlane.ptr); 160 PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_groundPlane);
164 } 161 }
165 m_groundPlane.Clear(); 162 m_groundPlane.Clear();
166 } 163 }
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
index 061e232..1d55ce3 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
@@ -91,9 +91,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys
91 PhysicsScene.DetailLog("{0},BSTerrainMesh.create,meshed,indices={1},indSz={2},vertices={3},vertSz={4}", 91 PhysicsScene.DetailLog("{0},BSTerrainMesh.create,meshed,indices={1},indSz={2},vertices={3},vertSz={4}",
92 ID, indicesCount, indices.Length, verticesCount, vertices.Length); 92 ID, indicesCount, indices.Length, verticesCount, vertices.Length);
93 93
94 m_terrainShape = new BulletShape(BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, 94 m_terrainShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, indicesCount, indices, verticesCount, vertices);
95 indicesCount, indices, verticesCount, vertices),
96 BSPhysicsShapeType.SHAPE_MESH);
97 if (!m_terrainShape.HasPhysicalShape) 95 if (!m_terrainShape.HasPhysicalShape)
98 { 96 {
99 // DISASTER!! 97 // DISASTER!!
@@ -106,7 +104,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys
106 Vector3 pos = regionBase; 104 Vector3 pos = regionBase;
107 Quaternion rot = Quaternion.Identity; 105 Quaternion rot = Quaternion.Identity;
108 106
109 m_terrainBody = new BulletBody(id, BulletSimAPI.CreateBodyWithDefaultMotionState2( m_terrainShape.ptr, ID, pos, rot)); 107 m_terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_terrainShape, ID, pos, rot);
110 if (!m_terrainBody.HasPhysicalBody) 108 if (!m_terrainBody.HasPhysicalBody)
111 { 109 {
112 // DISASTER!! 110 // DISASTER!!
@@ -116,34 +114,34 @@ public sealed class BSTerrainMesh : BSTerrainPhys
116 } 114 }
117 115
118 // Set current terrain attributes 116 // Set current terrain attributes
119 BulletSimAPI.SetFriction2(m_terrainBody.ptr, BSParam.TerrainFriction); 117 PhysicsScene.PE.SetFriction(m_terrainBody, BSParam.TerrainFriction);
120 BulletSimAPI.SetHitFraction2(m_terrainBody.ptr, BSParam.TerrainHitFraction); 118 PhysicsScene.PE.SetHitFraction(m_terrainBody, BSParam.TerrainHitFraction);
121 BulletSimAPI.SetRestitution2(m_terrainBody.ptr, BSParam.TerrainRestitution); 119 PhysicsScene.PE.SetRestitution(m_terrainBody, BSParam.TerrainRestitution);
122 BulletSimAPI.SetCollisionFlags2(m_terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); 120 PhysicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT);
123 121
124 // Static objects are not very massive. 122 // Static objects are not very massive.
125 BulletSimAPI.SetMassProps2(m_terrainBody.ptr, 0f, Vector3.Zero); 123 PhysicsScene.PE.SetMassProps(m_terrainBody, 0f, Vector3.Zero);
126 124
127 // Put the new terrain to the world of physical objects 125 // Put the new terrain to the world of physical objects
128 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); 126 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_terrainBody);
129 127
130 // Redo its bounding box now that it is in the world 128 // Redo its bounding box now that it is in the world
131 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_terrainBody.ptr); 129 PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_terrainBody);
132 130
133 m_terrainBody.collisionType = CollisionType.Terrain; 131 m_terrainBody.collisionType = CollisionType.Terrain;
134 m_terrainBody.ApplyCollisionMask(); 132 m_terrainBody.ApplyCollisionMask(PhysicsScene);
135 133
136 // Make it so the terrain will not move or be considered for movement. 134 // Make it so the terrain will not move or be considered for movement.
137 BulletSimAPI.ForceActivationState2(m_terrainBody.ptr, ActivationState.DISABLE_SIMULATION); 135 PhysicsScene.PE.ForceActivationState(m_terrainBody, ActivationState.DISABLE_SIMULATION);
138 } 136 }
139 137
140 public override void Dispose() 138 public override void Dispose()
141 { 139 {
142 if (m_terrainBody.HasPhysicalBody) 140 if (m_terrainBody.HasPhysicalBody)
143 { 141 {
144 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); 142 PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_terrainBody);
145 // Frees both the body and the shape. 143 // Frees both the body and the shape.
146 BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_terrainBody.ptr); 144 PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_terrainBody);
147 } 145 }
148 } 146 }
149 147
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
deleted file mode 100644
index b361498..0000000
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
+++ /dev/null
@@ -1,1276 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyrightD
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.Runtime.InteropServices;
30using System.Security;
31using System.Text;
32using OpenMetaverse;
33
34namespace OpenSim.Region.Physics.BulletSPlugin {
35
36 // Constraint type values as defined by Bullet
37public enum ConstraintType : int
38{
39 POINT2POINT_CONSTRAINT_TYPE = 3,
40 HINGE_CONSTRAINT_TYPE,
41 CONETWIST_CONSTRAINT_TYPE,
42 D6_CONSTRAINT_TYPE,
43 SLIDER_CONSTRAINT_TYPE,
44 CONTACT_CONSTRAINT_TYPE,
45 D6_SPRING_CONSTRAINT_TYPE,
46 MAX_CONSTRAINT_TYPE
47}
48
49// ===============================================================================
50[StructLayout(LayoutKind.Sequential)]
51public struct ConvexHull
52{
53 Vector3 Offset;
54 int VertexCount;
55 Vector3[] Vertices;
56}
57public enum BSPhysicsShapeType
58{
59 SHAPE_UNKNOWN = 0,
60 SHAPE_CAPSULE = 1,
61 SHAPE_BOX = 2,
62 SHAPE_CONE = 3,
63 SHAPE_CYLINDER = 4,
64 SHAPE_SPHERE = 5,
65 SHAPE_MESH = 6,
66 SHAPE_HULL = 7,
67 // following defined by BulletSim
68 SHAPE_GROUNDPLANE = 20,
69 SHAPE_TERRAIN = 21,
70 SHAPE_COMPOUND = 22,
71 SHAPE_HEIGHTMAP = 23,
72 SHAPE_AVATAR = 24,
73};
74
75// The native shapes have predefined shape hash keys
76public enum FixedShapeKey : ulong
77{
78 KEY_NONE = 0,
79 KEY_BOX = 1,
80 KEY_SPHERE = 2,
81 KEY_CONE = 3,
82 KEY_CYLINDER = 4,
83 KEY_CAPSULE = 5,
84 KEY_AVATAR = 6,
85}
86
87[StructLayout(LayoutKind.Sequential)]
88public struct ShapeData
89{
90 public uint ID;
91 public BSPhysicsShapeType Type;
92 public Vector3 Position;
93 public Quaternion Rotation;
94 public Vector3 Velocity;
95 public Vector3 Scale;
96 public float Mass;
97 public float Buoyancy;
98 public System.UInt64 HullKey;
99 public System.UInt64 MeshKey;
100 public float Friction;
101 public float Restitution;
102 public float Collidable; // true of things bump into this
103 public float Static; // true if a static object. Otherwise gravity, etc.
104 public float Solid; // true if object cannot be passed through
105 public Vector3 Size;
106
107 // note that bools are passed as floats since bool size changes by language and architecture
108 public const float numericTrue = 1f;
109 public const float numericFalse = 0f;
110}
111[StructLayout(LayoutKind.Sequential)]
112public struct SweepHit
113{
114 public uint ID;
115 public float Fraction;
116 public Vector3 Normal;
117 public Vector3 Point;
118}
119[StructLayout(LayoutKind.Sequential)]
120public struct RaycastHit
121{
122 public uint ID;
123 public float Fraction;
124 public Vector3 Normal;
125}
126[StructLayout(LayoutKind.Sequential)]
127public struct CollisionDesc
128{
129 public uint aID;
130 public uint bID;
131 public Vector3 point;
132 public Vector3 normal;
133}
134[StructLayout(LayoutKind.Sequential)]
135public struct EntityProperties
136{
137 public uint ID;
138 public Vector3 Position;
139 public Quaternion Rotation;
140 public Vector3 Velocity;
141 public Vector3 Acceleration;
142 public Vector3 RotationalVelocity;
143}
144
145// Format of this structure must match the definition in the C++ code
146// NOTE: adding the X causes compile breaks if used. These are unused symbols
147// that can be removed from both here and the unmanaged definition of this structure.
148[StructLayout(LayoutKind.Sequential)]
149public struct ConfigurationParameters
150{
151 public float defaultFriction;
152 public float defaultDensity;
153 public float defaultRestitution;
154 public float collisionMargin;
155 public float gravity;
156
157 public float XlinearDamping;
158 public float XangularDamping;
159 public float XdeactivationTime;
160 public float XlinearSleepingThreshold;
161 public float XangularSleepingThreshold;
162 public float XccdMotionThreshold;
163 public float XccdSweptSphereRadius;
164 public float XcontactProcessingThreshold;
165
166 public float XterrainImplementation;
167 public float XterrainFriction;
168 public float XterrainHitFraction;
169 public float XterrainRestitution;
170 public float XterrainCollisionMargin;
171
172 public float XavatarFriction;
173 public float XavatarStandingFriction;
174 public float XavatarDensity;
175 public float XavatarRestitution;
176 public float XavatarCapsuleWidth;
177 public float XavatarCapsuleDepth;
178 public float XavatarCapsuleHeight;
179 public float XavatarContactProcessingThreshold;
180
181 public float XvehicleAngularDamping;
182
183 public float maxPersistantManifoldPoolSize;
184 public float maxCollisionAlgorithmPoolSize;
185 public float shouldDisableContactPoolDynamicAllocation;
186 public float shouldForceUpdateAllAabbs;
187 public float shouldRandomizeSolverOrder;
188 public float shouldSplitSimulationIslands;
189 public float shouldEnableFrictionCaching;
190 public float numberOfSolverIterations;
191
192 public float XlinksetImplementation;
193 public float XlinkConstraintUseFrameOffset;
194 public float XlinkConstraintEnableTransMotor;
195 public float XlinkConstraintTransMotorMaxVel;
196 public float XlinkConstraintTransMotorMaxForce;
197 public float XlinkConstraintERP;
198 public float XlinkConstraintCFM;
199 public float XlinkConstraintSolverIterations;
200
201 public float physicsLoggingFrames;
202
203 public const float numericTrue = 1f;
204 public const float numericFalse = 0f;
205}
206
207
208// The states a bullet collision object can have
209public enum ActivationState : uint
210{
211 ACTIVE_TAG = 1,
212 ISLAND_SLEEPING,
213 WANTS_DEACTIVATION,
214 DISABLE_DEACTIVATION,
215 DISABLE_SIMULATION,
216}
217
218public enum CollisionObjectTypes : int
219{
220 CO_COLLISION_OBJECT = 1 << 0,
221 CO_RIGID_BODY = 1 << 1,
222 CO_GHOST_OBJECT = 1 << 2,
223 CO_SOFT_BODY = 1 << 3,
224 CO_HF_FLUID = 1 << 4,
225 CO_USER_TYPE = 1 << 5,
226}
227
228// Values used by Bullet and BulletSim to control object properties.
229// Bullet's "CollisionFlags" has more to do with operations on the
230// object (if collisions happen, if gravity effects it, ...).
231public enum CollisionFlags : uint
232{
233 CF_STATIC_OBJECT = 1 << 0,
234 CF_KINEMATIC_OBJECT = 1 << 1,
235 CF_NO_CONTACT_RESPONSE = 1 << 2,
236 CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3,
237 CF_CHARACTER_OBJECT = 1 << 4,
238 CF_DISABLE_VISUALIZE_OBJECT = 1 << 5,
239 CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6,
240 // Following used by BulletSim to control collisions and updates
241 BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10,
242 BS_FLOATS_ON_WATER = 1 << 11,
243 BS_VEHICLE_COLLISIONS = 1 << 12,
244 BS_NONE = 0,
245 BS_ALL = 0xFFFFFFFF
246};
247
248// Values f collisions groups and masks
249public enum CollisionFilterGroups : uint
250{
251 // Don't use the bit definitions!! Define the use in a
252 // filter/mask definition below. This way collision interactions
253 // are more easily found and debugged.
254 BNoneGroup = 0,
255 BDefaultGroup = 1 << 0, // 0001
256 BStaticGroup = 1 << 1, // 0002
257 BKinematicGroup = 1 << 2, // 0004
258 BDebrisGroup = 1 << 3, // 0008
259 BSensorTrigger = 1 << 4, // 0010
260 BCharacterGroup = 1 << 5, // 0020
261 BAllGroup = 0x000FFFFF,
262 // Filter groups defined by BulletSim
263 BGroundPlaneGroup = 1 << 10, // 0400
264 BTerrainGroup = 1 << 11, // 0800
265 BRaycastGroup = 1 << 12, // 1000
266 BSolidGroup = 1 << 13, // 2000
267 // BLinksetGroup = xx // a linkset proper is either static or dynamic
268 BLinksetChildGroup = 1 << 14, // 4000
269};
270
271// CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0
272// ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2.
273public enum ConstraintParams : int
274{
275 BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730
276 BT_CONSTRAINT_STOP_ERP,
277 BT_CONSTRAINT_CFM,
278 BT_CONSTRAINT_STOP_CFM,
279};
280public enum ConstraintParamAxis : int
281{
282 AXIS_LINEAR_X = 0,
283 AXIS_LINEAR_Y,
284 AXIS_LINEAR_Z,
285 AXIS_ANGULAR_X,
286 AXIS_ANGULAR_Y,
287 AXIS_ANGULAR_Z,
288 AXIS_LINEAR_ALL = 20, // these last three added by BulletSim so we don't have to do zillions of calls
289 AXIS_ANGULAR_ALL,
290 AXIS_ALL
291};
292
293public abstract class BulletSimAPITemplate
294{
295// Initialization and simulation
296public abstract BulletWorld Initialize2(Vector3 maxPosition, IntPtr parms,
297 int maxCollisions, IntPtr collisionArray,
298 int maxUpdates, IntPtr updateArray
299 );
300
301public abstract bool UpdateParameter2(BulletWorld world, uint localID, String parm, float value);
302
303public abstract void SetHeightMap2(BulletWorld world, float[] heightmap);
304
305public abstract void Shutdown2(BulletWorld sim);
306
307public abstract int PhysicsStep2(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
308 out int updatedEntityCount,
309 out IntPtr updatedEntitiesPtr,
310 out int collidersCount,
311 out IntPtr collidersPtr);
312
313public abstract bool PushUpdate2(BulletBody obj);
314
315// =====================================================================================
316// Mesh, hull, shape and body creation helper routines
317public abstract BulletShape CreateMeshShape2(BulletWorld world,
318 int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
319 int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
320
321public abstract BulletShape CreateHullShape2(BulletWorld world,
322 int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls);
323
324public abstract BulletShape BuildHullShapeFromMesh2(BulletWorld world, BulletShape meshShape);
325
326public abstract BulletShape BuildNativeShape2(BulletWorld world, ShapeData shapeData);
327
328public abstract bool IsNativeShape2(BulletShape shape);
329
330public abstract void SetShapeCollisionMargin(BulletShape shape, float margin);
331
332public abstract BulletShape BuildCapsuleShape2(BulletWorld world, float radius, float height, Vector3 scale);
333
334public abstract BulletShape CreateCompoundShape2(BulletWorld sim, bool enableDynamicAabbTree);
335
336public abstract int GetNumberOfCompoundChildren2(BulletShape cShape);
337
338public abstract void AddChildShapeToCompoundShape2(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot);
339
340public abstract BulletShape GetChildShapeFromCompoundShapeIndex2(BulletShape cShape, int indx);
341
342public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex2(BulletShape cShape, int indx);
343
344public abstract void RemoveChildShapeFromCompoundShape2(BulletShape cShape, BulletShape removeShape);
345
346public abstract void RecalculateCompoundShapeLocalAabb2(BulletShape cShape);
347
348public abstract BulletShape DuplicateCollisionShape2(BulletWorld sim, BulletShape srcShape, uint id);
349
350public abstract BulletBody CreateBodyFromShapeAndInfo2(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo);
351
352public abstract bool DeleteCollisionShape2(BulletWorld world, BulletShape shape);
353
354public abstract int GetBodyType2(BulletBody obj);
355
356public abstract BulletBody CreateBodyFromShape2(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
357
358public abstract BulletBody CreateBodyWithDefaultMotionState2(BulletShape shape, uint id, Vector3 pos, Quaternion rot);
359
360public abstract BulletBody CreateGhostFromShape2(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
361
362public abstract IntPtr AllocateBodyInfo2(BulletBody obj);
363
364public abstract void ReleaseBodyInfo2(IntPtr obj);
365
366public abstract void DestroyObject2(BulletWorld sim, BulletBody obj);
367
368// =====================================================================================
369// Terrain creation and helper routines
370public abstract IntPtr CreateHeightMapInfo2(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
371 [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
372
373public abstract IntPtr FillHeightMapInfo2(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
374 [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
375
376public abstract bool ReleaseHeightMapInfo2(IntPtr heightMapInfo);
377
378public abstract BulletBody CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
379
380public abstract BulletBody CreateTerrainShape2(IntPtr mapInfo);
381
382// =====================================================================================
383// Constraint creation and helper routines
384public abstract BulletConstraint Create6DofConstraint2(BulletWorld world, BulletBody obj1, BulletBody obj2,
385 Vector3 frame1loc, Quaternion frame1rot,
386 Vector3 frame2loc, Quaternion frame2rot,
387 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
388
389public abstract BulletConstraint Create6DofConstraintToPoint2(BulletWorld world, BulletBody obj1, BulletBody obj2,
390 Vector3 joinPoint,
391 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
392
393public abstract BulletConstraint CreateHingeConstraint2(BulletWorld world, BulletBody obj1, BulletBody obj2,
394 Vector3 pivotinA, Vector3 pivotinB,
395 Vector3 axisInA, Vector3 axisInB,
396 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
397
398public abstract void SetConstraintEnable2(BulletConstraint constrain, float numericTrueFalse);
399
400public abstract void SetConstraintNumSolverIterations2(BulletConstraint constrain, float iterations);
401
402public abstract bool SetFrames2(BulletConstraint constrain,
403 Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
404
405public abstract bool SetLinearLimits2(BulletConstraint constrain, Vector3 low, Vector3 hi);
406
407public abstract bool SetAngularLimits2(BulletConstraint constrain, Vector3 low, Vector3 hi);
408
409public abstract bool UseFrameOffset2(BulletConstraint constrain, float enable);
410
411public abstract bool TranslationalLimitMotor2(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce);
412
413public abstract bool SetBreakingImpulseThreshold2(BulletConstraint constrain, float threshold);
414
415public abstract bool CalculateTransforms2(BulletConstraint constrain);
416
417public abstract bool SetConstraintParam2(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
418
419public abstract bool DestroyConstraint2(BulletWorld world, BulletConstraint constrain);
420
421// =====================================================================================
422// btCollisionWorld entries
423public abstract void UpdateSingleAabb2(BulletWorld world, BulletBody obj);
424
425public abstract void UpdateAabbs2(BulletWorld world);
426
427public abstract bool GetForceUpdateAllAabbs2(BulletWorld world);
428
429public abstract void SetForceUpdateAllAabbs2(BulletWorld world, bool force);
430
431// =====================================================================================
432// btDynamicsWorld entries
433public abstract bool AddObjectToWorld2(BulletWorld world, BulletBody obj);
434
435public abstract bool RemoveObjectFromWorld2(BulletWorld world, BulletBody obj);
436
437public abstract bool AddConstraintToWorld2(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects);
438
439public abstract bool RemoveConstraintFromWorld2(BulletWorld world, BulletConstraint constrain);
440// =====================================================================================
441// btCollisionObject entries
442public abstract Vector3 GetAnisotripicFriction2(BulletConstraint constrain);
443
444public abstract Vector3 SetAnisotripicFriction2(BulletConstraint constrain, Vector3 frict);
445
446public abstract bool HasAnisotripicFriction2(BulletConstraint constrain);
447
448public abstract void SetContactProcessingThreshold2(BulletBody obj, float val);
449
450public abstract float GetContactProcessingThreshold2(BulletBody obj);
451
452public abstract bool IsStaticObject2(BulletBody obj);
453
454public abstract bool IsKinematicObject2(BulletBody obj);
455
456public abstract bool IsStaticOrKinematicObject2(BulletBody obj);
457
458public abstract bool HasContactResponse2(BulletBody obj);
459
460public abstract void SetCollisionShape2(BulletWorld sim, BulletBody obj, BulletBody shape);
461
462public abstract BulletShape GetCollisionShape2(BulletBody obj);
463
464public abstract int GetActivationState2(BulletBody obj);
465
466public abstract void SetActivationState2(BulletBody obj, int state);
467
468public abstract void SetDeactivationTime2(BulletBody obj, float dtime);
469
470public abstract float GetDeactivationTime2(BulletBody obj);
471
472public abstract void ForceActivationState2(BulletBody obj, ActivationState state);
473
474public abstract void Activate2(BulletBody obj, bool forceActivation);
475
476public abstract bool IsActive2(BulletBody obj);
477
478public abstract void SetRestitution2(BulletBody obj, float val);
479
480public abstract float GetRestitution2(BulletBody obj);
481
482public abstract void SetFriction2(BulletBody obj, float val);
483
484public abstract float GetFriction2(BulletBody obj);
485
486 /* Haven't defined the type 'Transform'
487public abstract Transform GetWorldTransform2(BulletBody obj);
488
489public abstract void setWorldTransform2(BulletBody obj, Transform trans);
490 */
491
492public abstract Vector3 GetPosition2(BulletBody obj);
493
494public abstract Quaternion GetOrientation2(BulletBody obj);
495
496public abstract void SetTranslation2(BulletBody obj, Vector3 position, Quaternion rotation);
497
498public abstract IntPtr GetBroadphaseHandle2(BulletBody obj);
499
500public abstract void SetBroadphaseHandle2(BulletBody obj, IntPtr handle);
501
502 /*
503public abstract Transform GetInterpolationWorldTransform2(IntPtr obj);
504
505public abstract void SetInterpolationWorldTransform2(IntPtr obj, Transform trans);
506 */
507
508public abstract void SetInterpolationLinearVelocity2(BulletBody obj, Vector3 vel);
509
510public abstract void SetInterpolationAngularVelocity2(BulletBody obj, Vector3 vel);
511
512public abstract void SetInterpolationVelocity2(BulletBody obj, Vector3 linearVel, Vector3 angularVel);
513
514public abstract float GetHitFraction2(BulletBody obj);
515
516public abstract void SetHitFraction2(BulletBody obj, float val);
517
518public abstract CollisionFlags GetCollisionFlags2(BulletBody obj);
519
520public abstract CollisionFlags SetCollisionFlags2(BulletBody obj, CollisionFlags flags);
521
522public abstract CollisionFlags AddToCollisionFlags2(BulletBody obj, CollisionFlags flags);
523
524public abstract CollisionFlags RemoveFromCollisionFlags2(BulletBody obj, CollisionFlags flags);
525
526public abstract float GetCcdMotionThreshold2(BulletBody obj);
527
528public abstract void SetCcdMotionThreshold2(BulletBody obj, float val);
529
530public abstract float GetCcdSweptSphereRadius2(BulletBody obj);
531
532public abstract void SetCcdSweptSphereRadius2(BulletBody obj, float val);
533
534public abstract IntPtr GetUserPointer2(BulletBody obj);
535
536public abstract void SetUserPointer2(BulletBody obj, IntPtr val);
537
538// =====================================================================================
539// btRigidBody entries
540public abstract void ApplyGravity2(BulletBody obj);
541
542public abstract void SetGravity2(BulletBody obj, Vector3 val);
543
544public abstract Vector3 GetGravity2(BulletBody obj);
545
546public abstract void SetDamping2(BulletBody obj, float lin_damping, float ang_damping);
547
548public abstract void SetLinearDamping2(BulletBody obj, float lin_damping);
549
550public abstract void SetAngularDamping2(BulletBody obj, float ang_damping);
551
552public abstract float GetLinearDamping2(BulletBody obj);
553
554public abstract float GetAngularDamping2(BulletBody obj);
555
556public abstract float GetLinearSleepingThreshold2(BulletBody obj);
557
558
559public abstract void ApplyDamping2(BulletBody obj, float timeStep);
560
561public abstract void SetMassProps2(BulletBody obj, float mass, Vector3 inertia);
562
563public abstract Vector3 GetLinearFactor2(BulletBody obj);
564
565public abstract void SetLinearFactor2(BulletBody obj, Vector3 factor);
566
567 /*
568public abstract void SetCenterOfMassTransform2(BulletBody obj, Transform trans);
569 */
570
571public abstract void SetCenterOfMassByPosRot2(BulletBody obj, Vector3 pos, Quaternion rot);
572
573// Add a force to the object as if its mass is one.
574public abstract void ApplyCentralForce2(BulletBody obj, Vector3 force);
575
576// Set the force being applied to the object as if its mass is one.
577public abstract void SetObjectForce2(BulletBody obj, Vector3 force);
578
579public abstract Vector3 GetTotalForce2(BulletBody obj);
580
581public abstract Vector3 GetTotalTorque2(BulletBody obj);
582
583public abstract Vector3 GetInvInertiaDiagLocal2(BulletBody obj);
584
585public abstract void SetInvInertiaDiagLocal2(BulletBody obj, Vector3 inert);
586
587public abstract void SetSleepingThresholds2(BulletBody obj, float lin_threshold, float ang_threshold);
588
589public abstract void ApplyTorque2(BulletBody obj, Vector3 torque);
590
591// Apply force at the given point. Will add torque to the object.
592public abstract void ApplyForce2(BulletBody obj, Vector3 force, Vector3 pos);
593
594// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
595public abstract void ApplyCentralImpulse2(BulletBody obj, Vector3 imp);
596
597// Apply impulse to the object's torque. Force is scaled by object's mass.
598public abstract void ApplyTorqueImpulse2(BulletBody obj, Vector3 imp);
599
600// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
601public abstract void ApplyImpulse2(BulletBody obj, Vector3 imp, Vector3 pos);
602
603public abstract void ClearForces2(BulletBody obj);
604
605public abstract void ClearAllForces2(BulletBody obj);
606
607public abstract void UpdateInertiaTensor2(BulletBody obj);
608
609
610 /*
611public abstract Transform GetCenterOfMassTransform2(BulletBody obj);
612 */
613
614public abstract Vector3 GetLinearVelocity2(BulletBody obj);
615
616public abstract Vector3 GetAngularVelocity2(BulletBody obj);
617
618public abstract void SetLinearVelocity2(BulletBody obj, Vector3 val);
619
620public abstract void SetAngularVelocity2(BulletBody obj, Vector3 angularVelocity);
621
622public abstract Vector3 GetVelocityInLocalPoint2(BulletBody obj, Vector3 pos);
623
624public abstract void Translate2(BulletBody obj, Vector3 trans);
625
626public abstract void UpdateDeactivation2(BulletBody obj, float timeStep);
627
628public abstract bool WantsSleeping2(BulletBody obj);
629
630public abstract void SetAngularFactor2(BulletBody obj, float factor);
631
632public abstract void SetAngularFactorV2(BulletBody obj, Vector3 factor);
633
634public abstract Vector3 GetAngularFactor2(BulletBody obj);
635
636public abstract bool IsInWorld2(BulletBody obj);
637
638public abstract void AddConstraintRef2(BulletBody obj, BulletConstraint constrain);
639
640public abstract void RemoveConstraintRef2(BulletBody obj, BulletConstraint constrain);
641
642public abstract BulletConstraint GetConstraintRef2(BulletBody obj, int index);
643
644public abstract int GetNumConstraintRefs2(BulletBody obj);
645
646public abstract bool SetCollisionGroupMask2(BulletBody body, uint filter, uint mask);
647
648// =====================================================================================
649// btCollisionShape entries
650
651public abstract float GetAngularMotionDisc2(BulletShape shape);
652
653public abstract float GetContactBreakingThreshold2(BulletShape shape, float defaultFactor);
654
655public abstract bool IsPolyhedral2(BulletShape shape);
656
657public abstract bool IsConvex2d2(BulletShape shape);
658
659public abstract bool IsConvex2(BulletShape shape);
660
661public abstract bool IsNonMoving2(BulletShape shape);
662
663public abstract bool IsConcave2(BulletShape shape);
664
665public abstract bool IsCompound2(BulletShape shape);
666
667public abstract bool IsSoftBody2(BulletShape shape);
668
669public abstract bool IsInfinite2(BulletShape shape);
670
671public abstract void SetLocalScaling2(BulletShape shape, Vector3 scale);
672
673public abstract Vector3 GetLocalScaling2(BulletShape shape);
674
675public abstract Vector3 CalculateLocalInertia2(BulletShape shape, float mass);
676
677public abstract int GetShapeType2(BulletShape shape);
678
679public abstract void SetMargin2(BulletShape shape, float val);
680
681public abstract float GetMargin2(BulletShape shape);
682
683};
684
685// ===============================================================================
686static class BulletSimAPI {
687// ===============================================================================
688// Link back to the managed code for outputting log messages
689[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
690public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
691
692// ===============================================================================
693// Initialization and simulation
694[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
695public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
696 int maxCollisions, IntPtr collisionArray,
697 int maxUpdates, IntPtr updateArray,
698 DebugLogCallback logRoutine);
699
700[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
701public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
702
703[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
704public static extern void SetHeightMap2(IntPtr world, float[] heightmap);
705
706[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
707public static extern void Shutdown2(IntPtr sim);
708
709[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
710public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
711 out int updatedEntityCount,
712 out IntPtr updatedEntitiesPtr,
713 out int collidersCount,
714 out IntPtr collidersPtr);
715
716[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
717public static extern bool PushUpdate2(IntPtr obj);
718
719// =====================================================================================
720// Mesh, hull, shape and body creation helper routines
721[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
722public static extern IntPtr CreateMeshShape2(IntPtr world,
723 int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
724 int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
725
726[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
727public static extern IntPtr CreateHullShape2(IntPtr world,
728 int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls);
729
730[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
731public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape);
732
733[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
734public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData);
735
736[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
737public static extern bool IsNativeShape2(IntPtr shape);
738
739[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
740public static extern void SetShapeCollisionMargin(IntPtr shape, float margin);
741
742[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
743public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale);
744
745[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
746public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree);
747
748[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
749public static extern int GetNumberOfCompoundChildren2(IntPtr cShape);
750
751[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
752public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot);
753
754[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
755public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
756
757[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
758public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
759
760[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
761public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape);
762
763[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
764public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape);
765
766[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
767public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id);
768
769[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
770public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo);
771
772[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
773public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape);
774
775[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
776public static extern int GetBodyType2(IntPtr obj);
777
778[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
779public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
780
781[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
782public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot);
783
784[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
785public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
786
787[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
788public static extern IntPtr AllocateBodyInfo2(IntPtr obj);
789
790[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
791public static extern void ReleaseBodyInfo2(IntPtr obj);
792
793[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
794public static extern void DestroyObject2(IntPtr sim, IntPtr obj);
795
796// =====================================================================================
797// Terrain creation and helper routines
798[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
799public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords,
800 [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
801
802[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
803public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
804 [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
805
806[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
807public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo);
808
809[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
810public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
811
812[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
813public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo);
814
815// =====================================================================================
816// Constraint creation and helper routines
817[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
818public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
819 Vector3 frame1loc, Quaternion frame1rot,
820 Vector3 frame2loc, Quaternion frame2rot,
821 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
822
823[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
824public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2,
825 Vector3 joinPoint,
826 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
827
828[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
829public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
830 Vector3 pivotinA, Vector3 pivotinB,
831 Vector3 axisInA, Vector3 axisInB,
832 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
833
834[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
835public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse);
836
837[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
838public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations);
839
840[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
841public static extern bool SetFrames2(IntPtr constrain,
842 Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
843
844[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
845public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
846
847[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
848public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
849
850[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
851public static extern bool UseFrameOffset2(IntPtr constrain, float enable);
852
853[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
854public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce);
855
856[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
857public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold);
858
859[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
860public static extern bool CalculateTransforms2(IntPtr constrain);
861
862[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
863public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
864
865[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
866public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain);
867
868// =====================================================================================
869// btCollisionWorld entries
870[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
871public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj);
872
873[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
874public static extern void UpdateAabbs2(IntPtr world);
875
876[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
877public static extern bool GetForceUpdateAllAabbs2(IntPtr world);
878
879[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
880public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force);
881
882// =====================================================================================
883// btDynamicsWorld entries
884[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
885public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj);
886
887[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
888public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj);
889
890[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
891public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects);
892
893[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
894public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain);
895// =====================================================================================
896// btCollisionObject entries
897[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
898public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain);
899
900[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
901public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict);
902
903[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
904public static extern bool HasAnisotripicFriction2(IntPtr constrain);
905
906[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
907public static extern void SetContactProcessingThreshold2(IntPtr obj, float val);
908
909[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
910public static extern float GetContactProcessingThreshold2(IntPtr obj);
911
912[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
913public static extern bool IsStaticObject2(IntPtr obj);
914
915[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
916public static extern bool IsKinematicObject2(IntPtr obj);
917
918[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
919public static extern bool IsStaticOrKinematicObject2(IntPtr obj);
920
921[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
922public static extern bool HasContactResponse2(IntPtr obj);
923
924[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
925public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape);
926
927[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
928public static extern IntPtr GetCollisionShape2(IntPtr obj);
929
930[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
931public static extern int GetActivationState2(IntPtr obj);
932
933[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
934public static extern void SetActivationState2(IntPtr obj, int state);
935
936[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
937public static extern void SetDeactivationTime2(IntPtr obj, float dtime);
938
939[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
940public static extern float GetDeactivationTime2(IntPtr obj);
941
942[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
943public static extern void ForceActivationState2(IntPtr obj, ActivationState state);
944
945[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
946public static extern void Activate2(IntPtr obj, bool forceActivation);
947
948[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
949public static extern bool IsActive2(IntPtr obj);
950
951[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
952public static extern void SetRestitution2(IntPtr obj, float val);
953
954[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
955public static extern float GetRestitution2(IntPtr obj);
956
957[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
958public static extern void SetFriction2(IntPtr obj, float val);
959
960[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
961public static extern float GetFriction2(IntPtr obj);
962
963 /* Haven't defined the type 'Transform'
964[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
965public static extern Transform GetWorldTransform2(IntPtr obj);
966
967[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
968public static extern void setWorldTransform2(IntPtr obj, Transform trans);
969 */
970
971[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
972public static extern Vector3 GetPosition2(IntPtr obj);
973
974[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
975public static extern Quaternion GetOrientation2(IntPtr obj);
976
977[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
978public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation);
979
980[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
981public static extern IntPtr GetBroadphaseHandle2(IntPtr obj);
982
983[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
984public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle);
985
986 /*
987[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
988public static extern Transform GetInterpolationWorldTransform2(IntPtr obj);
989
990[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
991public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans);
992 */
993
994[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
995public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel);
996
997[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
998public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel);
999
1000[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1001public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel);
1002
1003[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1004public static extern float GetHitFraction2(IntPtr obj);
1005
1006[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1007public static extern void SetHitFraction2(IntPtr obj, float val);
1008
1009[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1010public static extern CollisionFlags GetCollisionFlags2(IntPtr obj);
1011
1012[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1013public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags);
1014
1015[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1016public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags);
1017
1018[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1019public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags);
1020
1021[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1022public static extern float GetCcdMotionThreshold2(IntPtr obj);
1023
1024[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1025public static extern void SetCcdMotionThreshold2(IntPtr obj, float val);
1026
1027[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1028public static extern float GetCcdSweptSphereRadius2(IntPtr obj);
1029
1030[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1031public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val);
1032
1033[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1034public static extern IntPtr GetUserPointer2(IntPtr obj);
1035
1036[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1037public static extern void SetUserPointer2(IntPtr obj, IntPtr val);
1038
1039// =====================================================================================
1040// btRigidBody entries
1041[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1042public static extern void ApplyGravity2(IntPtr obj);
1043
1044[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1045public static extern void SetGravity2(IntPtr obj, Vector3 val);
1046
1047[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1048public static extern Vector3 GetGravity2(IntPtr obj);
1049
1050[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1051public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping);
1052
1053[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1054public static extern void SetLinearDamping2(IntPtr obj, float lin_damping);
1055
1056[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1057public static extern void SetAngularDamping2(IntPtr obj, float ang_damping);
1058
1059[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1060public static extern float GetLinearDamping2(IntPtr obj);
1061
1062[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1063public static extern float GetAngularDamping2(IntPtr obj);
1064
1065[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1066public static extern float GetLinearSleepingThreshold2(IntPtr obj);
1067
1068[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1069public static extern float GetAngularSleepingThreshold2(IntPtr obj);
1070
1071[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1072public static extern void ApplyDamping2(IntPtr obj, float timeStep);
1073
1074[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1075public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia);
1076
1077[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1078public static extern Vector3 GetLinearFactor2(IntPtr obj);
1079
1080[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1081public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor);
1082
1083 /*
1084[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1085public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans);
1086 */
1087
1088[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1089public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot);
1090
1091// Add a force to the object as if its mass is one.
1092[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1093public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force);
1094
1095// Set the force being applied to the object as if its mass is one.
1096[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1097public static extern void SetObjectForce2(IntPtr obj, Vector3 force);
1098
1099[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1100public static extern Vector3 GetTotalForce2(IntPtr obj);
1101
1102[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1103public static extern Vector3 GetTotalTorque2(IntPtr obj);
1104
1105[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1106public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj);
1107
1108[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1109public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert);
1110
1111[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1112public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold);
1113
1114[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1115public static extern void ApplyTorque2(IntPtr obj, Vector3 torque);
1116
1117// Apply force at the given point. Will add torque to the object.
1118[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1119public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos);
1120
1121// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
1122[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1123public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp);
1124
1125// Apply impulse to the object's torque. Force is scaled by object's mass.
1126[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1127public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp);
1128
1129// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
1130[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1131public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos);
1132
1133[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1134public static extern void ClearForces2(IntPtr obj);
1135
1136[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1137public static extern void ClearAllForces2(IntPtr obj);
1138
1139[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1140public static extern void UpdateInertiaTensor2(IntPtr obj);
1141
1142[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1143public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj);
1144
1145 /*
1146[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1147public static extern Transform GetCenterOfMassTransform2(IntPtr obj);
1148 */
1149
1150[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1151public static extern Vector3 GetLinearVelocity2(IntPtr obj);
1152
1153[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1154public static extern Vector3 GetAngularVelocity2(IntPtr obj);
1155
1156[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1157public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val);
1158
1159[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1160public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity);
1161
1162[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1163public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos);
1164
1165[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1166public static extern void Translate2(IntPtr obj, Vector3 trans);
1167
1168[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1169public static extern void UpdateDeactivation2(IntPtr obj, float timeStep);
1170
1171[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1172public static extern bool WantsSleeping2(IntPtr obj);
1173
1174[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1175public static extern void SetAngularFactor2(IntPtr obj, float factor);
1176
1177[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1178public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor);
1179
1180[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1181public static extern Vector3 GetAngularFactor2(IntPtr obj);
1182
1183[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1184public static extern bool IsInWorld2(IntPtr obj);
1185
1186[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1187public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain);
1188
1189[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1190public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain);
1191
1192[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1193public static extern IntPtr GetConstraintRef2(IntPtr obj, int index);
1194
1195[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1196public static extern int GetNumConstraintRefs2(IntPtr obj);
1197
1198[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1199public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask);
1200
1201// =====================================================================================
1202// btCollisionShape entries
1203
1204[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1205public static extern float GetAngularMotionDisc2(IntPtr shape);
1206
1207[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1208public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor);
1209
1210[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1211public static extern bool IsPolyhedral2(IntPtr shape);
1212
1213[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1214public static extern bool IsConvex2d2(IntPtr shape);
1215
1216[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1217public static extern bool IsConvex2(IntPtr shape);
1218
1219[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1220public static extern bool IsNonMoving2(IntPtr shape);
1221
1222[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1223public static extern bool IsConcave2(IntPtr shape);
1224
1225[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1226public static extern bool IsCompound2(IntPtr shape);
1227
1228[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1229public static extern bool IsSoftBody2(IntPtr shape);
1230
1231[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1232public static extern bool IsInfinite2(IntPtr shape);
1233
1234[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1235public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale);
1236
1237[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1238public static extern Vector3 GetLocalScaling2(IntPtr shape);
1239
1240[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1241public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass);
1242
1243[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1244public static extern int GetShapeType2(IntPtr shape);
1245
1246[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1247public static extern void SetMargin2(IntPtr shape, float val);
1248
1249[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1250public static extern float GetMargin2(IntPtr shape);
1251
1252// =====================================================================================
1253// Debugging
1254[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1255public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject);
1256
1257[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1258public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape);
1259
1260[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1261public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo);
1262
1263[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1264public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain);
1265
1266[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1267public static extern void DumpActivationInfo2(IntPtr sim);
1268
1269[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1270public static extern void DumpAllInfo2(IntPtr sim);
1271
1272[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
1273public static extern void DumpPhysicsStatistics2(IntPtr sim);
1274
1275}
1276}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
index 5ad6746..662dd68 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
@@ -33,62 +33,66 @@ 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").
36 39
37// The physics engine controller class created at initialization 40// Currently, the instances of these classes are a reference to a
38public struct BulletWorld 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.
45
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;
50} 56}
51 57
52// An allocated Bullet btRigidBody 58// An allocated Bullet btRigidBody
53public struct 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() 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
79 // a collision body that is in the world.) 77 // a collision body that is in the world.)
80 return BulletSimAPI.SetCollisionGroupMask2(ptr, 78 return physicsScene.PE.SetCollisionGroupMask(this,
81 BulletSimData.CollisionTypeMasks[collisionType].group, 79 BulletSimData.CollisionTypeMasks[collisionType].group,
82 BulletSimData.CollisionTypeMasks[collisionType].mask); 80 BulletSimData.CollisionTypeMasks[collisionType].mask);
83 } 81 }
84 82
83 // Used for log messages for a unique display of the memory/object allocated to this instance
84 public virtual string AddrString
85 {
86 get { return "unknown"; }
87 }
88
85 public override string ToString() 89 public override string ToString()
86 { 90 {
87 StringBuilder buff = new StringBuilder(); 91 StringBuilder buff = new StringBuilder();
88 buff.Append("<id="); 92 buff.Append("<id=");
89 buff.Append(ID.ToString()); 93 buff.Append(ID.ToString());
90 buff.Append(",p="); 94 buff.Append(",p=");
91 buff.Append(ptr.ToString("X")); 95 buff.Append(AddrString);
92 buff.Append(",c="); 96 buff.Append(",c=");
93 buff.Append(collisionType); 97 buff.Append(collisionType);
94 buff.Append(">"); 98 buff.Append(">");
@@ -96,34 +100,36 @@ public struct BulletBody
96 } 100 }
97} 101}
98 102
99public struct BulletShape 103public class BulletShape
100{ 104{
101 public BulletShape(IntPtr xx) : this(xx, BSPhysicsShapeType.SHAPE_UNKNOWN) 105 public BulletShape()
102 { 106 {
103 } 107 type = BSPhysicsShapeType.SHAPE_UNKNOWN;
104 public BulletShape(IntPtr xx, BSPhysicsShapeType typ)
105 {
106 ptr = xx;
107 type = typ;
108 shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; 108 shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE;
109 isNativeShape = false; 109 isNativeShape = false;
110 } 110 }
111 public IntPtr ptr;
112 public BSPhysicsShapeType type; 111 public BSPhysicsShapeType type;
113 public System.UInt64 shapeKey; 112 public System.UInt64 shapeKey;
114 public bool isNativeShape; 113 public bool isNativeShape;
115 114
116 public void Clear() 115 public virtual void Clear() { }
116 public virtual bool HasPhysicalShape { get { return false; } }
117 // Make another reference to this physical object.
118 public virtual BulletShape Clone() { return new BulletShape(); }
119 // Return 'true' if this and other refer to the same physical object
120 public virtual bool ReferenceSame(BulletShape xx) { return false; }
121
122 // Used for log messages for a unique display of the memory/object allocated to this instance
123 public virtual string AddrString
117 { 124 {
118 ptr = IntPtr.Zero; 125 get { return "unknown"; }
119 } 126 }
120 public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } }
121 127
122 public override string ToString() 128 public override string ToString()
123 { 129 {
124 StringBuilder buff = new StringBuilder(); 130 StringBuilder buff = new StringBuilder();
125 buff.Append("<p="); 131 buff.Append("<p=");
126 buff.Append(ptr.ToString("X")); 132 buff.Append(AddrString);
127 buff.Append(",s="); 133 buff.Append(",s=");
128 buff.Append(type.ToString()); 134 buff.Append(type.ToString());
129 buff.Append(",k="); 135 buff.Append(",k=");
@@ -136,30 +142,29 @@ public struct BulletShape
136} 142}
137 143
138// An allocated Bullet btConstraint 144// An allocated Bullet btConstraint
139public struct BulletConstraint 145public class BulletConstraint
140{ 146{
141 public BulletConstraint(IntPtr xx) 147 public BulletConstraint()
142 { 148 {
143 ptr = xx;
144 } 149 }
145 public IntPtr ptr; 150 public virtual void Clear() { }
151 public virtual bool HasPhysicalConstraint { get { return false; } }
146 152
147 public void Clear() 153 // Used for log messages for a unique display of the memory/object allocated to this instance
154 public virtual string AddrString
148 { 155 {
149 ptr = IntPtr.Zero; 156 get { return "unknown"; }
150 } 157 }
151 public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } }
152} 158}
153 159
154// An allocated HeightMapThing which holds various heightmap info. 160// An allocated HeightMapThing which holds various heightmap info.
155// Made a class rather than a struct so there would be only one 161// Made a class rather than a struct so there would be only one
156// instance of this and C# will pass around pointers rather 162// instance of this and C# will pass around pointers rather
157// than making copies. 163// than making copies.
158public class BulletHeightMapInfo 164public class BulletHMapInfo
159{ 165{
160 public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) { 166 public BulletHMapInfo(uint id, float[] hm) {
161 ID = id; 167 ID = id;
162 Ptr = xx;
163 heightMap = hm; 168 heightMap = hm;
164 terrainRegionBase = OMV.Vector3.Zero; 169 terrainRegionBase = OMV.Vector3.Zero;
165 minCoords = new OMV.Vector3(100f, 100f, 25f); 170 minCoords = new OMV.Vector3(100f, 100f, 25f);
@@ -168,7 +173,6 @@ public class BulletHeightMapInfo
168 sizeX = sizeY = 256f; 173 sizeX = sizeY = 256f;
169 } 174 }
170 public uint ID; 175 public uint ID;
171 public IntPtr Ptr;
172 public float[] heightMap; 176 public float[] heightMap;
173 public OMV.Vector3 terrainRegionBase; 177 public OMV.Vector3 terrainRegionBase;
174 public OMV.Vector3 minCoords; 178 public OMV.Vector3 minCoords;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index f805836..a8a4ff5 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -31,6 +31,7 @@ CRASHES
31 31
32VEHICLES TODO LIST: 32VEHICLES TODO LIST:
33================================================= 33=================================================
34Angular motor direction is global coordinates rather than local coordinates
34Border crossing with linked vehicle causes crash 35Border crossing with linked vehicle causes crash
35Vehicles (Move smoothly) 36Vehicles (Move smoothly)
36Add vehicle collisions so IsColliding is properly reported. 37Add vehicle collisions so IsColliding is properly reported.
@@ -60,7 +61,8 @@ Incorporate inter-relationship of angular corrections. For instance, angularDefl
60 61
61BULLETSIM TODO LIST: 62BULLETSIM TODO LIST:
62================================================= 63=================================================
63Avatar density is WAY off. Compare and calibrate with what's in SL. 64Implement an avatar mesh shape. The Bullet capsule is way too limited.
65 Consider just hand creating a vertex/index array in a new BSShapeAvatar.
64Revisit CollisionMargin. Builders notice the 0.04 spacing between prims. 66Revisit CollisionMargin. Builders notice the 0.04 spacing between prims.
65Duplicating a physical prim causes old prim to jump away 67Duplicating a physical prim causes old prim to jump away
66 Dup a phys prim and the original become unselected and thus interacts w/ selected prim. 68 Dup a phys prim and the original become unselected and thus interacts w/ selected prim.
@@ -78,7 +80,7 @@ Small physical objects do not interact correctly
78 Create chain of .5x.5x.1 torui and make all but top physical so to hang. 80 Create chain of .5x.5x.1 torui and make all but top physical so to hang.
79 The chain will fall apart and pairs will dance around on ground 81 The chain will fall apart and pairs will dance around on ground
80 Chains of 1x1x.2 will stay connected but will dance. 82 Chains of 1x1x.2 will stay connected but will dance.
81 Chains above 2x2x.4 are move stable and get stablier as torui get larger. 83 Chains above 2x2x.4 are more stable and get stablier as torui get larger.
82Add PID motor for avatar movement (slow to stop, ...) 84Add PID motor for avatar movement (slow to stop, ...)
83setForce should set a constant force. Different than AddImpulse. 85setForce should set a constant force. Different than AddImpulse.
84Implement raycast. 86Implement raycast.
@@ -97,9 +99,16 @@ Selecting and deselecting physical objects causes CPU processing time to jump
97Re-implement buoyancy as a separate force on the object rather than diddling gravity. 99Re-implement buoyancy as a separate force on the object rather than diddling gravity.
98 Register a pre-step event to add the force. 100 Register a pre-step event to add the force.
99More efficient memory usage when passing hull information from BSPrim to BulletSim 101More efficient memory usage when passing hull information from BSPrim to BulletSim
102Avatar movement motor check for zero or small movement. Somehow suppress small movements
103 when avatar has stopped and is just standing. Simple test for near zero has
104 the problem of preventing starting up (increase from zero) especially when falling.
105Physical and phantom will drop through the terrain
106
100 107
101LINKSETS 108LINKSETS
102====================================================== 109======================================================
110Offset the center of the linkset to be the geometric center of all the prims
111 Not quite the same as the center-of-gravity
103Linksets should allow collisions to individual children 112Linksets should allow collisions to individual children
104 Add LocalID to children shapes in LinksetCompound and create events for individuals 113 Add LocalID to children shapes in LinksetCompound and create events for individuals
105LinksetCompound: when one of the children changes orientation (like tires 114LinksetCompound: when one of the children changes orientation (like tires
@@ -162,6 +171,9 @@ Avatar attachments have no mass? http://forums-archive.secondlife.com/54/f0/3179
162 171
163INTERNAL IMPROVEMENT/CLEANUP 172INTERNAL IMPROVEMENT/CLEANUP
164================================================= 173=================================================
174Create the physical wrapper classes (BulletBody, BulletShape) by methods on
175 BSAPITemplate and make their actual implementation Bullet engine specific.
176 For the short term, just call the existing functions in ShapeCollection.
165Consider moving prim/character body and shape destruction in destroy() 177Consider moving prim/character body and shape destruction in destroy()
166 to postTimeTime rather than protecting all the potential sets that 178 to postTimeTime rather than protecting all the potential sets that
167 might have been queued up. 179 might have been queued up.
@@ -195,6 +207,9 @@ Should taints check for existance or activeness of target?
195 keeps the object from being freed, but that is just an accident. 207 keeps the object from being freed, but that is just an accident.
196 Possibly have and 'active' flag that is checked by the taint processor? 208 Possibly have and 'active' flag that is checked by the taint processor?
197Parameters for physics logging should be moved from BSScene to BSParam (at least boolean ones) 209Parameters for physics logging should be moved from BSScene to BSParam (at least boolean ones)
210Can some of the physical wrapper classes (BulletBody, BulletWorld, BulletShape) be 'sealed'?
211There are TOO MANY interfaces from BulletSim core to Bullet itself
212 Think of something to eliminate one or more of the layers
198 213
199THREADING 214THREADING
200================================================= 215=================================================
@@ -253,3 +268,5 @@ llApplyImpulse()
253 (Resolution: tested on SL and OS. AddForce scales the force for timestep) 268 (Resolution: tested on SL and OS. AddForce scales the force for timestep)
254llSetBuoyancy() (DONE) 269llSetBuoyancy() (DONE)
255 (Resolution: Bullet resets object gravity when added to world. Moved set gravity) 270 (Resolution: Bullet resets object gravity when added to world. Moved set gravity)
271Avatar density is WAY off. Compare and calibrate with what's in SL. (DONE)
272 (Resolution: set default density to 3.5 (from 60) which is closer to SL)
diff --git a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
index 8587a2b..8ccfda5 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
@@ -30,7 +30,7 @@ using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Reflection; 31using System.Reflection;
32using Nini.Config; 32using Nini.Config;
33using log4net; 33using log4net;
34using OpenSim.Framework; 34using OpenSim.Framework;
35 35
36namespace OpenSim.Region.Physics.Manager 36namespace OpenSim.Region.Physics.Manager
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 30bacc6..253d193 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -100,6 +100,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
100 protected float m_ScriptDelayFactor = 1.0f; 100 protected float m_ScriptDelayFactor = 1.0f;
101 protected float m_ScriptDistanceFactor = 1.0f; 101 protected float m_ScriptDistanceFactor = 1.0f;
102 protected float m_MinTimerInterval = 0.5f; 102 protected float m_MinTimerInterval = 0.5f;
103 protected float m_recoilScaleFactor = 0.0f;
103 104
104 protected DateTime m_timer = DateTime.Now; 105 protected DateTime m_timer = DateTime.Now;
105 protected bool m_waitingForScriptAnswer = false; 106 protected bool m_waitingForScriptAnswer = false;
@@ -187,6 +188,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
187 // there's an smtp config, so load in the snooze time. 188 // there's an smtp config, so load in the snooze time.
188 EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME); 189 EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
189 } 190 }
191 // Rezzing an object with a velocity can create recoil. This feature seems to have been
192 // removed from recent versions of SL. The code computes recoil (vel*mass) and scales
193 // it by this factor. May be zero to turn off recoil all together.
194 m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor);
190 } 195 }
191 196
192 public override Object InitializeLifetimeService() 197 public override Object InitializeLifetimeService()
@@ -3108,11 +3113,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3108 3113
3109 PhysicsActor pa = new_group.RootPart.PhysActor; 3114 PhysicsActor pa = new_group.RootPart.PhysActor;
3110 3115
3116 //Recoil.
3111 if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero) 3117 if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
3112 { 3118 {
3113 float groupmass = new_group.GetMass(); 3119 float groupmass = new_group.GetMass();
3114 vel *= -groupmass; 3120 Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
3115 llApplyImpulse(vel, 0); 3121 if (recoil != Vector3.Zero)
3122 {
3123 llApplyImpulse(recoil, 0);
3124 }
3116 } 3125 }
3117 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) 3126 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
3118 return; 3127 return;
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 0bd9a06..05dd7ab 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1576,6 +1576,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1576 startInfo.StartSuspended = true; 1576 startInfo.StartSuspended = true;
1577 1577
1578 m_ThreadPool = new SmartThreadPool(startInfo); 1578 m_ThreadPool = new SmartThreadPool(startInfo);
1579 m_ThreadPool.Name = "XEngine";
1579 } 1580 }
1580 1581
1581 // 1582 //