From 203588e3c0374505a6aa564d8f7a655d968653d7 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sat, 29 Dec 2012 18:34:46 -0800 Subject: BulletSim: change physical data structures to classes. Add default instantiations for PhysBody and PhysShape when BSPhysObject is created to account for them being classes and not structures. Update TODO list. --- .../Region/Physics/BulletSPlugin/BSLinksetConstraints.cs | 15 +++++++++------ OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 5 +++++ OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 5 +---- OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs | 15 ++++++++++----- OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | 4 ++++ 5 files changed, 29 insertions(+), 15 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs index 6b592e7..86c29c7 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs @@ -48,12 +48,15 @@ public sealed class BSLinksetConstraints : BSLinkset { base.Refresh(requestor); - // Queue to happen after all the other taint processing - PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate() - { - if (HasAnyChildren && IsRoot(requestor)) - RecomputeLinksetConstraints(); - }); + if (HasAnyChildren && IsRoot(requestor)) + { + // Queue to happen after all the other taint processing + PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate() + { + if (HasAnyChildren && IsRoot(requestor)) + RecomputeLinksetConstraints(); + }); + } } // The object is going dynamic (physical). Do any setup necessary diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 73b5764..b093890 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -67,6 +67,11 @@ public abstract class BSPhysObject : PhysicsActor PhysObjectName = name; TypeName = typeName; + // We don't have any physical representation yet. + PhysBody = new BulletBody(localID); + PhysShape = new BulletShape(); + + // A linkset of just me Linkset = BSLinkset.Factory(PhysicsScene, this); LastAssetBuildFailed = false; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 5f3f0d1..2de4717 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -111,10 +111,7 @@ public sealed class BSPrim : BSPhysObject _mass = CalculateMass(); - // No body or shape yet - PhysBody = new BulletBody(LocalID); - PhysShape = new BulletShape(); - + // Cause linkset variables to be initialized (like mass) Linkset.Refresh(this); DetailLog("{0},BSPrim.constructor,call", LocalID); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs index 5ad6746..cd5d170 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs @@ -35,7 +35,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // These hold pointers to allocated objects in the unmanaged space. // The physics engine controller class created at initialization -public struct BulletWorld +public class BulletWorld { public BulletWorld(uint worldId, BSScene bss, IntPtr xx) { @@ -50,7 +50,7 @@ public struct BulletWorld } // An allocated Bullet btRigidBody -public struct BulletBody +public class BulletBody { public BulletBody(uint id) : this(id, IntPtr.Zero) { @@ -96,9 +96,14 @@ public struct BulletBody } } -public struct BulletShape +public class BulletShape { - public BulletShape(IntPtr xx) : this(xx, BSPhysicsShapeType.SHAPE_UNKNOWN) + public BulletShape() + : this(IntPtr.Zero, BSPhysicsShapeType.SHAPE_UNKNOWN) + { + } + public BulletShape(IntPtr xx) + : this(xx, BSPhysicsShapeType.SHAPE_UNKNOWN) { } public BulletShape(IntPtr xx, BSPhysicsShapeType typ) @@ -136,7 +141,7 @@ public struct BulletShape } // An allocated Bullet btConstraint -public struct BulletConstraint +public class BulletConstraint { public BulletConstraint(IntPtr xx) { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index f805836..8ec9871 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -97,6 +97,9 @@ Selecting and deselecting physical objects causes CPU processing time to jump Re-implement buoyancy as a separate force on the object rather than diddling gravity. Register a pre-step event to add the force. More efficient memory usage when passing hull information from BSPrim to BulletSim +Avatar movement motor check for zero or small movement. Somehow suppress small movements + when avatar has stopped and is just standing. Simple test for near zero has + the problem of preventing starting up (increase from zero) especially when falling. LINKSETS ====================================================== @@ -195,6 +198,7 @@ Should taints check for existance or activeness of target? keeps the object from being freed, but that is just an accident. Possibly have and 'active' flag that is checked by the taint processor? Parameters for physics logging should be moved from BSScene to BSParam (at least boolean ones) +Can some of the physical wrapper classes (BulletBody, BulletWorld, BulletShape) be 'sealed'? THREADING ================================================= -- cgit v1.1 From 48f718f39fcd61501262878a8bcfbd98efed29d2 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sat, 29 Dec 2012 21:43:43 -0800 Subject: BulletSim: first round of conversion from direct BulletSimAPI interfacing by BulletSim core to using the BulletSimAPITemplate. Physical object creation and destruction first. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 8 +- .../Physics/BulletSPlugin/BSLinksetCompound.cs | 6 +- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 2 +- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 10 +- .../Physics/BulletSPlugin/BSShapeCollection.cs | 63 +- OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | 7 +- .../Physics/BulletSPlugin/BSTerrainHeightmap.cs | 7 +- .../Physics/BulletSPlugin/BSTerrainManager.cs | 8 +- .../Region/Physics/BulletSPlugin/BSTerrainMesh.cs | 8 +- .../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 947 ++++----------------- .../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 7 +- 11 files changed, 234 insertions(+), 839 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 3b77e49..d5ab245 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -210,8 +210,7 @@ public sealed class BSCharacter : BSPhysObject if (!Flying && !IsColliding) { stepVelocity.Z = _velocity.Z; - DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", - LocalID, stepVelocity); + // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); } // '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 AddForce(moveForce, false, true); } */ - DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", - LocalID, stepVelocity, _velocity, Mass, moveForce); + // DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce); AddForce(moveForce, false, true); }); } @@ -736,7 +734,7 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.AddForce", delegate() { // Bullet adds this central force to the total force for this tick - DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce); + // DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce); if (PhysBody.HasPhysicalBody) { BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 19ce62b..9bb951c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -359,7 +359,7 @@ public sealed class BSLinksetCompound : BSLinkset PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); BulletShape newShape = cPrim.PhysShape; cPrim.PhysShape = saveShape; - BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, lci.OffsetPos, lci.OffsetRot); + PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, newShape, lci.OffsetPos, lci.OffsetRot); } else { @@ -371,7 +371,7 @@ public sealed class BSLinksetCompound : BSLinkset PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); } - BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, lci.OffsetPos, lci.OffsetRot); + PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot); } } return false; // 'false' says to move onto the next child in the list @@ -386,7 +386,7 @@ public sealed class BSLinksetCompound : BSLinkset Rebuilding = false; } - BulletSimAPI.RecalculateCompoundShapeLocalAabb2(LinksetRoot.PhysShape.ptr); + PhysicsScene.PE.RecalculateCompoundShapeLocalAabb(LinksetRoot.PhysShape); // DEBUG: see of inter-linkset collisions are causing problems for constraint linksets. // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr, diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 2de4717..cf09be2 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -845,7 +845,7 @@ public sealed class BSPrim : BSPhysObject // the functions after this one set up the state of a possibly newly created collision body. private void MakeSolid(bool makeSolid) { - CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(PhysBody.ptr); + CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(PhysBody); if (makeSolid) { // Verify the previous code created the correct shape for this type of thing. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 4133107..bfc9df2 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -50,6 +50,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters public string BulletSimVersion = "?"; + // The handle to the underlying managed or unmanaged version of Bullet being used. + public BulletSimAPITemplate PE; + public Dictionary PhysObjects; public BSShapeCollection Shapes; @@ -187,12 +190,15 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters // Allocate pinned memory to pass parameters. UnmanagedParams = new ConfigurationParameters[1]; - m_paramsHandle = GCHandle.Alloc(UnmanagedParams, GCHandleType.Pinned); // Set default values for physics parameters plus any overrides from the ini file GetInitialParameterValues(config); - // allocate more pinned memory close to the above in an attempt to get the memory all together + // For the moment, only one version of the interface + PE = new BSAPIUnman(); + + // Allocate more pinned memory. Do this early to try and get all pinned memory close together. + m_paramsHandle = GCHandle.Alloc(UnmanagedParams, GCHandleType.Pinned); m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame]; m_collisionArrayPinnedHandle = GCHandle.Alloc(m_collisionArray, GCHandleType.Pinned); m_updateArray = new EntityProperties[m_maxUpdatesPerFrame]; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 0cc51b0..e7d8d14 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -174,7 +174,7 @@ public sealed class BSShapeCollection : IDisposable // Zero any reference to the shape so it is not freed when the body is deleted. BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero); - BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, body.ptr); + PhysicsScene.PE.DestroyObject(PhysicsScene.World, body); }); } } @@ -261,7 +261,7 @@ public sealed class BSShapeCollection : IDisposable if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}", BSScene.DetailLogZero, shape.ptr.ToString("X"), inTaintTime); if (shapeCallback != null) shapeCallback(shape); - BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr); + PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape); } else { @@ -342,26 +342,26 @@ public sealed class BSShapeCollection : IDisposable return; } - int numChildren = BulletSimAPI.GetNumberOfCompoundChildren2(shape.ptr); + int numChildren = PhysicsScene.PE.GetNumberOfCompoundChildren(shape); if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren); for (int ii = numChildren - 1; ii >= 0; ii--) { - IntPtr childShape = BulletSimAPI.RemoveChildShapeFromCompoundShapeIndex2(shape.ptr, ii); + BulletShape childShape = PhysicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(shape, ii); DereferenceAnonCollisionShape(childShape); } - BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr); + PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape); } // Sometimes we have a pointer to a collision shape but don't know what type it is. // Figure out type and call the correct dereference routine. // Called at taint-time. - private void DereferenceAnonCollisionShape(IntPtr cShape) + private void DereferenceAnonCollisionShape(BulletShape shapeInfo) { MeshDesc meshDesc; HullDesc hullDesc; - BulletShape shapeInfo = new BulletShape(cShape); + IntPtr cShape = shapeInfo.ptr; if (TryGetMeshByPtr(cShape, out meshDesc)) { shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH; @@ -382,7 +382,7 @@ public sealed class BSShapeCollection : IDisposable } else { - if (BulletSimAPI.IsNativeShape2(cShape)) + if (PhysicsScene.PE.IsNativeShape(shapeInfo)) { shapeInfo.isNativeShape = true; shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) @@ -570,19 +570,15 @@ public sealed class BSShapeCollection : IDisposable if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) { - // The proper scale has been calculated in the prim. - newShape = new BulletShape( - // Bullet's capsule total height is the passed "height + (radius * 2)" so, the base - // capsule is radius of 0.5f (1 diameter) and height of two (1.0f + 0.5f * 2)". - // This must be taken into account when computing the scaling of the capsule. - BulletSimAPI.BuildCapsuleShape2(PhysicsScene.World.ptr, 1f, 1f, prim.Scale) - , shapeType); + + newShape = PhysicsScene.PE.BuildCapsuleShape(PhysicsScene.World, 1f, 1f, prim.Scale); if (DDetail) DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); } else { // Native shapes are scaled in Bullet so set the scaling to the size - newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, nativeShapeData), shapeType); + newShape = PhysicsScene.PE.BuildNativeShape(PhysicsScene.World, nativeShapeData); + } if (!newShape.HasPhysicalShape) { @@ -629,13 +625,14 @@ public sealed class BSShapeCollection : IDisposable private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) { + BulletShape newShape = new BulletShape(); IMesh meshData = null; - IntPtr meshPtr = IntPtr.Zero; + MeshDesc meshDesc; if (Meshes.TryGetValue(newMeshKey, out meshDesc)) { // If the mesh has already been built just use it. - meshPtr = meshDesc.ptr; + newShape = new BulletShape(meshDesc.ptr, BSPhysicsShapeType.SHAPE_MESH); } else { @@ -658,11 +655,10 @@ public sealed class BSShapeCollection : IDisposable // m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count); - meshPtr = BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, + newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, indices.GetLength(0), indices, vertices.Count, verticesAsFloats); } } - BulletShape newShape = new BulletShape(meshPtr, BSPhysicsShapeType.SHAPE_MESH); newShape.shapeKey = newMeshKey; return newShape; @@ -700,12 +696,14 @@ public sealed class BSShapeCollection : IDisposable private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) { + BulletShape newShape = new BulletShape(); IntPtr hullPtr = IntPtr.Zero; + HullDesc hullDesc; if (Hulls.TryGetValue(newHullKey, out hullDesc)) { // If the hull shape already is created, just use it. - hullPtr = hullDesc.ptr; + newShape = new BulletShape(hullDesc.ptr, BSPhysicsShapeType.SHAPE_HULL); } else { @@ -793,11 +791,10 @@ public sealed class BSShapeCollection : IDisposable } } // create the hull data structure in Bullet - hullPtr = BulletSimAPI.CreateHullShape2(PhysicsScene.World.ptr, hullCount, convHulls); + newShape = PhysicsScene.PE.CreateHullShape(PhysicsScene.World, hullCount, convHulls); } } - BulletShape newShape = new BulletShape(hullPtr, BSPhysicsShapeType.SHAPE_HULL); newShape.shapeKey = newHullKey; return newShape; @@ -819,12 +816,12 @@ public sealed class BSShapeCollection : IDisposable // Don't need to do this as the shape is freed when the new root shape is created below. // DereferenceShape(prim.PhysShape, true, shapeCallback); - BulletShape cShape = new BulletShape( - BulletSimAPI.CreateCompoundShape2(PhysicsScene.World.ptr, false), BSPhysicsShapeType.SHAPE_COMPOUND); + + BulletShape cShape = PhysicsScene.PE.CreateCompoundShape(PhysicsScene.World, false); // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape. CreateGeomMeshOrHull(prim, shapeCallback); - BulletSimAPI.AddChildShapeToCompoundShape2(cShape.ptr, prim.PhysShape.ptr, OMV.Vector3.Zero, OMV.Quaternion.Identity); + PhysicsScene.PE.AddChildShapeToCompoundShape(cShape, prim.PhysShape, OMV.Vector3.Zero, OMV.Quaternion.Identity); if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}", prim.LocalID, cShape, prim.PhysShape); @@ -932,7 +929,7 @@ public sealed class BSShapeCollection : IDisposable // If not a solid object, body is a GhostObject. Otherwise a RigidBody. if (!mustRebuild) { - CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(prim.PhysBody.ptr); + CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(prim.PhysBody); if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT) { @@ -947,20 +944,16 @@ public sealed class BSShapeCollection : IDisposable DereferenceBody(prim.PhysBody, true, bodyCallback); BulletBody aBody; - IntPtr bodyPtr = IntPtr.Zero; if (prim.IsSolid) { - bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, - prim.LocalID, prim.RawPosition, prim.RawOrientation); - if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); + aBody = PhysicsScene.PE.CreateBodyFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation); + if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,body={1}", prim.LocalID, aBody); } else { - bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, - prim.LocalID, prim.RawPosition, prim.RawOrientation); - if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); + aBody = PhysicsScene.PE.CreateGhostFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation); + if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,body={1}", prim.LocalID, aBody); } - aBody = new BulletBody(prim.LocalID, bodyPtr); ReferenceBody(aBody, true); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs index c7885c6..cdaa869 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs @@ -126,7 +126,8 @@ public class BSShapeNative : BSShape BSPhysicsShapeType shapeType, FixedShapeKey shapeKey) { // Native shapes are not shared and are always built anew. - return new BSShapeNative(physicsScene, prim, shapeType, shapeKey); + //return new BSShapeNative(physicsScene, prim, shapeType, shapeKey); + return null; } private BSShapeNative(BSScene physicsScene, BSPhysObject prim, @@ -141,6 +142,7 @@ public class BSShapeNative : BSShape nativeShapeData.HullKey = (ulong)shapeKey; + /* if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) { ptr = BulletSimAPI.BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale); @@ -157,15 +159,18 @@ public class BSShapeNative : BSShape } type = shapeType; key = (UInt64)shapeKey; + */ } // Make this reference to the physical shape go away since native shapes are not shared. public override void Dereference(BSScene physicsScene) { + /* // Native shapes are not tracked and are released immediately physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this); BulletSimAPI.DeleteCollisionShape2(physicsScene.World.ptr, ptr); ptr = IntPtr.Zero; // Garbage collection will free up this instance. + */ } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index 07a9fd8..a2c085e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs @@ -105,9 +105,8 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f); centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f); - m_mapInfo.terrainBody = new BulletBody(m_mapInfo.ID, - BulletSimAPI.CreateBodyWithDefaultMotionState2(m_mapInfo.terrainShape.ptr, - m_mapInfo.ID, centerPos, Quaternion.Identity)); + m_mapInfo.terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_mapInfo.terrainShape, + m_mapInfo.ID, centerPos, Quaternion.Identity); // Set current terrain attributes BulletSimAPI.SetFriction2(m_mapInfo.terrainBody.ptr, BSParam.TerrainFriction); @@ -139,7 +138,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys { BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); // Frees both the body and the shape. - BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); + PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody); BulletSimAPI.ReleaseHeightMapInfo2(m_mapInfo.Ptr); } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index 86ccfbb..d99a50f 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs @@ -137,9 +137,9 @@ public sealed class BSTerrainManager : IDisposable BulletSimAPI.CreateGroundPlaneShape2(BSScene.GROUNDPLANE_ID, 1f, BSParam.TerrainCollisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE); - m_groundPlane = new BulletBody(BSScene.GROUNDPLANE_ID, - BulletSimAPI.CreateBodyWithDefaultMotionState2(groundPlaneShape.ptr, BSScene.GROUNDPLANE_ID, - Vector3.Zero, Quaternion.Identity)); + m_groundPlane = PhysicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape, + BSScene.GROUNDPLANE_ID, Vector3.Zero, Quaternion.Identity); + BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr); BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_groundPlane.ptr); // Ground plane does not move @@ -160,7 +160,7 @@ public sealed class BSTerrainManager : IDisposable { if (BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr)) { - BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_groundPlane.ptr); + PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_groundPlane); } m_groundPlane.Clear(); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs index 061e232..d8c4972 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs @@ -91,9 +91,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys PhysicsScene.DetailLog("{0},BSTerrainMesh.create,meshed,indices={1},indSz={2},vertices={3},vertSz={4}", ID, indicesCount, indices.Length, verticesCount, vertices.Length); - m_terrainShape = new BulletShape(BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, - indicesCount, indices, verticesCount, vertices), - BSPhysicsShapeType.SHAPE_MESH); + m_terrainShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, indicesCount, indices, verticesCount, vertices); if (!m_terrainShape.HasPhysicalShape) { // DISASTER!! @@ -106,7 +104,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys Vector3 pos = regionBase; Quaternion rot = Quaternion.Identity; - m_terrainBody = new BulletBody(id, BulletSimAPI.CreateBodyWithDefaultMotionState2( m_terrainShape.ptr, ID, pos, rot)); + m_terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_terrainShape, ID, pos, rot); if (!m_terrainBody.HasPhysicalBody) { // DISASTER!! @@ -143,7 +141,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys { BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); // Frees both the body and the shape. - BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_terrainBody.ptr); + PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_terrainBody); } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index b361498..6b76151 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs @@ -292,985 +292,376 @@ public enum ConstraintParamAxis : int public abstract class BulletSimAPITemplate { + /* // Initialization and simulation -public abstract BulletWorld Initialize2(Vector3 maxPosition, IntPtr parms, +public abstract BulletWorld Initialize(Vector3 maxPosition, IntPtr parms, int maxCollisions, IntPtr collisionArray, int maxUpdates, IntPtr updateArray ); -public abstract bool UpdateParameter2(BulletWorld world, uint localID, String parm, float value); +public abstract bool UpdateParameter(BulletWorld world, uint localID, String parm, float value); -public abstract void SetHeightMap2(BulletWorld world, float[] heightmap); +public abstract void SetHeightMap(BulletWorld world, float[] heightmap); -public abstract void Shutdown2(BulletWorld sim); +public abstract void Shutdown(BulletWorld sim); -public abstract int PhysicsStep2(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, +public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, out int updatedEntityCount, out IntPtr updatedEntitiesPtr, out int collidersCount, out IntPtr collidersPtr); -public abstract bool PushUpdate2(BulletBody obj); +public abstract bool PushUpdate(BulletBody obj); + */ // ===================================================================================== // Mesh, hull, shape and body creation helper routines -public abstract BulletShape CreateMeshShape2(BulletWorld world, - int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices, - int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); +public abstract BulletShape CreateMeshShape(BulletWorld world, + int indicesCount, int[] indices, + int verticesCount, float[] vertices ); -public abstract BulletShape CreateHullShape2(BulletWorld world, - int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); +public abstract BulletShape CreateHullShape(BulletWorld world, + int hullCount, float[] hulls); -public abstract BulletShape BuildHullShapeFromMesh2(BulletWorld world, BulletShape meshShape); +public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape); -public abstract BulletShape BuildNativeShape2(BulletWorld world, ShapeData shapeData); +public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData); -public abstract bool IsNativeShape2(BulletShape shape); +public abstract bool IsNativeShape(BulletShape shape); public abstract void SetShapeCollisionMargin(BulletShape shape, float margin); -public abstract BulletShape BuildCapsuleShape2(BulletWorld world, float radius, float height, Vector3 scale); - -public abstract BulletShape CreateCompoundShape2(BulletWorld sim, bool enableDynamicAabbTree); - -public abstract int GetNumberOfCompoundChildren2(BulletShape cShape); - -public abstract void AddChildShapeToCompoundShape2(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot); - -public abstract BulletShape GetChildShapeFromCompoundShapeIndex2(BulletShape cShape, int indx); - -public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex2(BulletShape cShape, int indx); - -public abstract void RemoveChildShapeFromCompoundShape2(BulletShape cShape, BulletShape removeShape); - -public abstract void RecalculateCompoundShapeLocalAabb2(BulletShape cShape); - -public abstract BulletShape DuplicateCollisionShape2(BulletWorld sim, BulletShape srcShape, uint id); - -public abstract BulletBody CreateBodyFromShapeAndInfo2(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo); - -public abstract bool DeleteCollisionShape2(BulletWorld world, BulletShape shape); - -public abstract int GetBodyType2(BulletBody obj); - -public abstract BulletBody CreateBodyFromShape2(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot); - -public abstract BulletBody CreateBodyWithDefaultMotionState2(BulletShape shape, uint id, Vector3 pos, Quaternion rot); - -public abstract BulletBody CreateGhostFromShape2(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot); - -public abstract IntPtr AllocateBodyInfo2(BulletBody obj); - -public abstract void ReleaseBodyInfo2(IntPtr obj); - -public abstract void DestroyObject2(BulletWorld sim, BulletBody obj); - -// ===================================================================================== -// Terrain creation and helper routines -public abstract IntPtr CreateHeightMapInfo2(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords, - [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); - -public abstract IntPtr FillHeightMapInfo2(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, - [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); - -public abstract bool ReleaseHeightMapInfo2(IntPtr heightMapInfo); - -public abstract BulletBody CreateGroundPlaneShape2(uint id, float height, float collisionMargin); - -public abstract BulletBody CreateTerrainShape2(IntPtr mapInfo); - -// ===================================================================================== -// Constraint creation and helper routines -public abstract BulletConstraint Create6DofConstraint2(BulletWorld world, BulletBody obj1, BulletBody obj2, - Vector3 frame1loc, Quaternion frame1rot, - Vector3 frame2loc, Quaternion frame2rot, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -public abstract BulletConstraint Create6DofConstraintToPoint2(BulletWorld world, BulletBody obj1, BulletBody obj2, - Vector3 joinPoint, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -public abstract BulletConstraint CreateHingeConstraint2(BulletWorld world, BulletBody obj1, BulletBody obj2, - Vector3 pivotinA, Vector3 pivotinB, - Vector3 axisInA, Vector3 axisInB, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -public abstract void SetConstraintEnable2(BulletConstraint constrain, float numericTrueFalse); - -public abstract void SetConstraintNumSolverIterations2(BulletConstraint constrain, float iterations); - -public abstract bool SetFrames2(BulletConstraint constrain, - Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot); - -public abstract bool SetLinearLimits2(BulletConstraint constrain, Vector3 low, Vector3 hi); - -public abstract bool SetAngularLimits2(BulletConstraint constrain, Vector3 low, Vector3 hi); - -public abstract bool UseFrameOffset2(BulletConstraint constrain, float enable); - -public abstract bool TranslationalLimitMotor2(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce); - -public abstract bool SetBreakingImpulseThreshold2(BulletConstraint constrain, float threshold); - -public abstract bool CalculateTransforms2(BulletConstraint constrain); - -public abstract bool SetConstraintParam2(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); - -public abstract bool DestroyConstraint2(BulletWorld world, BulletConstraint constrain); - -// ===================================================================================== -// btCollisionWorld entries -public abstract void UpdateSingleAabb2(BulletWorld world, BulletBody obj); - -public abstract void UpdateAabbs2(BulletWorld world); - -public abstract bool GetForceUpdateAllAabbs2(BulletWorld world); - -public abstract void SetForceUpdateAllAabbs2(BulletWorld world, bool force); - -// ===================================================================================== -// btDynamicsWorld entries -public abstract bool AddObjectToWorld2(BulletWorld world, BulletBody obj); - -public abstract bool RemoveObjectFromWorld2(BulletWorld world, BulletBody obj); - -public abstract bool AddConstraintToWorld2(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects); - -public abstract bool RemoveConstraintFromWorld2(BulletWorld world, BulletConstraint constrain); -// ===================================================================================== -// btCollisionObject entries -public abstract Vector3 GetAnisotripicFriction2(BulletConstraint constrain); - -public abstract Vector3 SetAnisotripicFriction2(BulletConstraint constrain, Vector3 frict); - -public abstract bool HasAnisotripicFriction2(BulletConstraint constrain); - -public abstract void SetContactProcessingThreshold2(BulletBody obj, float val); - -public abstract float GetContactProcessingThreshold2(BulletBody obj); - -public abstract bool IsStaticObject2(BulletBody obj); - -public abstract bool IsKinematicObject2(BulletBody obj); - -public abstract bool IsStaticOrKinematicObject2(BulletBody obj); - -public abstract bool HasContactResponse2(BulletBody obj); - -public abstract void SetCollisionShape2(BulletWorld sim, BulletBody obj, BulletBody shape); - -public abstract BulletShape GetCollisionShape2(BulletBody obj); - -public abstract int GetActivationState2(BulletBody obj); - -public abstract void SetActivationState2(BulletBody obj, int state); - -public abstract void SetDeactivationTime2(BulletBody obj, float dtime); - -public abstract float GetDeactivationTime2(BulletBody obj); - -public abstract void ForceActivationState2(BulletBody obj, ActivationState state); - -public abstract void Activate2(BulletBody obj, bool forceActivation); - -public abstract bool IsActive2(BulletBody obj); - -public abstract void SetRestitution2(BulletBody obj, float val); - -public abstract float GetRestitution2(BulletBody obj); - -public abstract void SetFriction2(BulletBody obj, float val); - -public abstract float GetFriction2(BulletBody obj); - - /* Haven't defined the type 'Transform' -public abstract Transform GetWorldTransform2(BulletBody obj); - -public abstract void setWorldTransform2(BulletBody obj, Transform trans); - */ - -public abstract Vector3 GetPosition2(BulletBody obj); - -public abstract Quaternion GetOrientation2(BulletBody obj); - -public abstract void SetTranslation2(BulletBody obj, Vector3 position, Quaternion rotation); - -public abstract IntPtr GetBroadphaseHandle2(BulletBody obj); - -public abstract void SetBroadphaseHandle2(BulletBody obj, IntPtr handle); - - /* -public abstract Transform GetInterpolationWorldTransform2(IntPtr obj); - -public abstract void SetInterpolationWorldTransform2(IntPtr obj, Transform trans); - */ - -public abstract void SetInterpolationLinearVelocity2(BulletBody obj, Vector3 vel); - -public abstract void SetInterpolationAngularVelocity2(BulletBody obj, Vector3 vel); - -public abstract void SetInterpolationVelocity2(BulletBody obj, Vector3 linearVel, Vector3 angularVel); - -public abstract float GetHitFraction2(BulletBody obj); - -public abstract void SetHitFraction2(BulletBody obj, float val); - -public abstract CollisionFlags GetCollisionFlags2(BulletBody obj); - -public abstract CollisionFlags SetCollisionFlags2(BulletBody obj, CollisionFlags flags); - -public abstract CollisionFlags AddToCollisionFlags2(BulletBody obj, CollisionFlags flags); - -public abstract CollisionFlags RemoveFromCollisionFlags2(BulletBody obj, CollisionFlags flags); - -public abstract float GetCcdMotionThreshold2(BulletBody obj); - -public abstract void SetCcdMotionThreshold2(BulletBody obj, float val); - -public abstract float GetCcdSweptSphereRadius2(BulletBody obj); - -public abstract void SetCcdSweptSphereRadius2(BulletBody obj, float val); - -public abstract IntPtr GetUserPointer2(BulletBody obj); - -public abstract void SetUserPointer2(BulletBody obj, IntPtr val); - -// ===================================================================================== -// btRigidBody entries -public abstract void ApplyGravity2(BulletBody obj); - -public abstract void SetGravity2(BulletBody obj, Vector3 val); - -public abstract Vector3 GetGravity2(BulletBody obj); - -public abstract void SetDamping2(BulletBody obj, float lin_damping, float ang_damping); - -public abstract void SetLinearDamping2(BulletBody obj, float lin_damping); - -public abstract void SetAngularDamping2(BulletBody obj, float ang_damping); - -public abstract float GetLinearDamping2(BulletBody obj); +public abstract BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale); -public abstract float GetAngularDamping2(BulletBody obj); +public abstract BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree); -public abstract float GetLinearSleepingThreshold2(BulletBody obj); +public abstract int GetNumberOfCompoundChildren(BulletShape cShape); +public abstract void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot); -public abstract void ApplyDamping2(BulletBody obj, float timeStep); +public abstract BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx); -public abstract void SetMassProps2(BulletBody obj, float mass, Vector3 inertia); +public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx); -public abstract Vector3 GetLinearFactor2(BulletBody obj); +public abstract void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape); -public abstract void SetLinearFactor2(BulletBody obj, Vector3 factor); +public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape); - /* -public abstract void SetCenterOfMassTransform2(BulletBody obj, Transform trans); - */ - -public abstract void SetCenterOfMassByPosRot2(BulletBody obj, Vector3 pos, Quaternion rot); - -// Add a force to the object as if its mass is one. -public abstract void ApplyCentralForce2(BulletBody obj, Vector3 force); - -// Set the force being applied to the object as if its mass is one. -public abstract void SetObjectForce2(BulletBody obj, Vector3 force); - -public abstract Vector3 GetTotalForce2(BulletBody obj); +public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id); -public abstract Vector3 GetTotalTorque2(BulletBody obj); +public abstract BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo); -public abstract Vector3 GetInvInertiaDiagLocal2(BulletBody obj); +public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape); -public abstract void SetInvInertiaDiagLocal2(BulletBody obj, Vector3 inert); +public abstract int GetBodyType(BulletBody obj); -public abstract void SetSleepingThresholds2(BulletBody obj, float lin_threshold, float ang_threshold); +public abstract BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot); -public abstract void ApplyTorque2(BulletBody obj, Vector3 torque); - -// Apply force at the given point. Will add torque to the object. -public abstract void ApplyForce2(BulletBody obj, Vector3 force, Vector3 pos); - -// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. -public abstract void ApplyCentralImpulse2(BulletBody obj, Vector3 imp); - -// Apply impulse to the object's torque. Force is scaled by object's mass. -public abstract void ApplyTorqueImpulse2(BulletBody obj, Vector3 imp); - -// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. -public abstract void ApplyImpulse2(BulletBody obj, Vector3 imp, Vector3 pos); +public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot); -public abstract void ClearForces2(BulletBody obj); +public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot); -public abstract void ClearAllForces2(BulletBody obj); +public abstract IntPtr AllocateBodyInfo(BulletBody obj); -public abstract void UpdateInertiaTensor2(BulletBody obj); +public abstract void ReleaseBodyInfo(IntPtr obj); +public abstract void DestroyObject(BulletWorld sim, BulletBody obj); /* -public abstract Transform GetCenterOfMassTransform2(BulletBody obj); - */ - -public abstract Vector3 GetLinearVelocity2(BulletBody obj); - -public abstract Vector3 GetAngularVelocity2(BulletBody obj); - -public abstract void SetLinearVelocity2(BulletBody obj, Vector3 val); - -public abstract void SetAngularVelocity2(BulletBody obj, Vector3 angularVelocity); - -public abstract Vector3 GetVelocityInLocalPoint2(BulletBody obj, Vector3 pos); - -public abstract void Translate2(BulletBody obj, Vector3 trans); - -public abstract void UpdateDeactivation2(BulletBody obj, float timeStep); - -public abstract bool WantsSleeping2(BulletBody obj); - -public abstract void SetAngularFactor2(BulletBody obj, float factor); - -public abstract void SetAngularFactorV2(BulletBody obj, Vector3 factor); - -public abstract Vector3 GetAngularFactor2(BulletBody obj); - -public abstract bool IsInWorld2(BulletBody obj); - -public abstract void AddConstraintRef2(BulletBody obj, BulletConstraint constrain); - -public abstract void RemoveConstraintRef2(BulletBody obj, BulletConstraint constrain); - -public abstract BulletConstraint GetConstraintRef2(BulletBody obj, int index); - -public abstract int GetNumConstraintRefs2(BulletBody obj); - -public abstract bool SetCollisionGroupMask2(BulletBody body, uint filter, uint mask); - -// ===================================================================================== -// btCollisionShape entries - -public abstract float GetAngularMotionDisc2(BulletShape shape); - -public abstract float GetContactBreakingThreshold2(BulletShape shape, float defaultFactor); - -public abstract bool IsPolyhedral2(BulletShape shape); - -public abstract bool IsConvex2d2(BulletShape shape); - -public abstract bool IsConvex2(BulletShape shape); - -public abstract bool IsNonMoving2(BulletShape shape); - -public abstract bool IsConcave2(BulletShape shape); - -public abstract bool IsCompound2(BulletShape shape); - -public abstract bool IsSoftBody2(BulletShape shape); - -public abstract bool IsInfinite2(BulletShape shape); - -public abstract void SetLocalScaling2(BulletShape shape, Vector3 scale); - -public abstract Vector3 GetLocalScaling2(BulletShape shape); - -public abstract Vector3 CalculateLocalInertia2(BulletShape shape, float mass); - -public abstract int GetShapeType2(BulletShape shape); - -public abstract void SetMargin2(BulletShape shape, float val); - -public abstract float GetMargin2(BulletShape shape); - -}; - -// =============================================================================== -static class BulletSimAPI { -// =============================================================================== -// Link back to the managed code for outputting log messages -[UnmanagedFunctionPointer(CallingConvention.Cdecl)] -public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); - -// =============================================================================== -// Initialization and simulation -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms, - int maxCollisions, IntPtr collisionArray, - int maxUpdates, IntPtr updateArray, - DebugLogCallback logRoutine); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetHeightMap2(IntPtr world, float[] heightmap); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void Shutdown2(IntPtr sim); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep, - out int updatedEntityCount, - out IntPtr updatedEntitiesPtr, - out int collidersCount, - out IntPtr collidersPtr); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool PushUpdate2(IntPtr obj); - -// ===================================================================================== -// Mesh, hull, shape and body creation helper routines -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateMeshShape2(IntPtr world, - int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices, - int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateHullShape2(IntPtr world, - int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsNativeShape2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetShapeCollisionMargin(IntPtr shape, float margin); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int GetNumberOfCompoundChildren2(IntPtr cShape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int GetBodyType2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr AllocateBodyInfo2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ReleaseBodyInfo2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DestroyObject2(IntPtr sim, IntPtr obj); - // ===================================================================================== // Terrain creation and helper routines -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords, - [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); +public abstract IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords, + float[] heightMap, float collisionMargin); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, - [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); +public abstract IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, + float[] heightMap, float collisionMargin); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo); +public abstract bool ReleaseHeightMapInfo(IntPtr heightMapInfo); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin); +public abstract BulletBody CreateGroundPlaneShape(uint id, float height, float collisionMargin); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo); +public abstract BulletBody CreateTerrainShape(IntPtr mapInfo); // ===================================================================================== // Constraint creation and helper routines -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, +public abstract BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, Vector3 frame1loc, Quaternion frame1rot, Vector3 frame2loc, Quaternion frame2rot, bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2, +public abstract BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2, Vector3 joinPoint, bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, +public abstract BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, Vector3 pivotinA, Vector3 pivotinB, Vector3 axisInA, Vector3 axisInB, bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse); +public abstract void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations); +public abstract void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetFrames2(IntPtr constrain, +public abstract bool SetFrames(BulletConstraint constrain, Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi); +public abstract bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi); +public abstract bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool UseFrameOffset2(IntPtr constrain, float enable); +public abstract bool UseFrameOffset(BulletConstraint constrain, float enable); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce); +public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold); +public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool CalculateTransforms2(IntPtr constrain); +public abstract bool CalculateTransforms(BulletConstraint constrain); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); +public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain); +public abstract bool DestroyConstraint(BulletWorld world, BulletConstraint constrain); // ===================================================================================== // btCollisionWorld entries -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj); +public abstract void UpdateSingleAabb(BulletWorld world, BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void UpdateAabbs2(IntPtr world); +public abstract void UpdateAabbs(BulletWorld world); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool GetForceUpdateAllAabbs2(IntPtr world); +public abstract bool GetForceUpdateAllAabbs(BulletWorld world); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force); +public abstract void SetForceUpdateAllAabbs(BulletWorld world, bool force); // ===================================================================================== // btDynamicsWorld entries -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj); +public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj); +public abstract bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects); +public abstract bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain); +public abstract bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain); // ===================================================================================== // btCollisionObject entries -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain); +public abstract Vector3 GetAnisotripicFriction(BulletConstraint constrain); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict); +public abstract Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool HasAnisotripicFriction2(IntPtr constrain); +public abstract bool HasAnisotripicFriction(BulletConstraint constrain); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetContactProcessingThreshold2(IntPtr obj, float val); +public abstract void SetContactProcessingThreshold(BulletBody obj, float val); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetContactProcessingThreshold2(IntPtr obj); +public abstract float GetContactProcessingThreshold(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsStaticObject2(IntPtr obj); +public abstract bool IsStaticObject(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsKinematicObject2(IntPtr obj); +public abstract bool IsKinematicObject(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsStaticOrKinematicObject2(IntPtr obj); +public abstract bool IsStaticOrKinematicObject(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool HasContactResponse2(IntPtr obj); +public abstract bool HasContactResponse(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape); +public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletBody shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr GetCollisionShape2(IntPtr obj); +public abstract BulletShape GetCollisionShape(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int GetActivationState2(IntPtr obj); +public abstract int GetActivationState(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetActivationState2(IntPtr obj, int state); +public abstract void SetActivationState(BulletBody obj, int state); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetDeactivationTime2(IntPtr obj, float dtime); +public abstract void SetDeactivationTime(BulletBody obj, float dtime); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetDeactivationTime2(IntPtr obj); +public abstract float GetDeactivationTime(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ForceActivationState2(IntPtr obj, ActivationState state); +public abstract void ForceActivationState(BulletBody obj, ActivationState state); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void Activate2(IntPtr obj, bool forceActivation); +public abstract void Activate(BulletBody obj, bool forceActivation); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsActive2(IntPtr obj); +public abstract bool IsActive(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetRestitution2(IntPtr obj, float val); +public abstract void SetRestitution(BulletBody obj, float val); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetRestitution2(IntPtr obj); +public abstract float GetRestitution(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetFriction2(IntPtr obj, float val); +public abstract void SetFriction(BulletBody obj, float val); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetFriction2(IntPtr obj); +public abstract float GetFriction(BulletBody obj); - /* Haven't defined the type 'Transform' -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Transform GetWorldTransform2(IntPtr obj); +public abstract Vector3 GetPosition(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void setWorldTransform2(IntPtr obj, Transform trans); - */ +public abstract Quaternion GetOrientation(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetPosition2(IntPtr obj); +public abstract void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Quaternion GetOrientation2(IntPtr obj); +public abstract IntPtr GetBroadphaseHandle(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation); +public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr GetBroadphaseHandle2(IntPtr obj); +public abstract void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle); +public abstract void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel); - /* -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Transform GetInterpolationWorldTransform2(IntPtr obj); +public abstract void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans); - */ - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel); +public abstract float GetHitFraction(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetHitFraction2(IntPtr obj); +public abstract void SetHitFraction(BulletBody obj, float val); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetHitFraction2(IntPtr obj, float val); +public abstract CollisionFlags GetCollisionFlags(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern CollisionFlags GetCollisionFlags2(IntPtr obj); +public abstract CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags); +public abstract CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags); +public abstract CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags); +public abstract float GetCcdMotionThreshold(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetCcdMotionThreshold2(IntPtr obj); +public abstract void SetCcdMotionThreshold(BulletBody obj, float val); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetCcdMotionThreshold2(IntPtr obj, float val); +public abstract float GetCcdSweptSphereRadius(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetCcdSweptSphereRadius2(IntPtr obj); +public abstract void SetCcdSweptSphereRadius(BulletBody obj, float val); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val); +public abstract IntPtr GetUserPointer(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr GetUserPointer2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetUserPointer2(IntPtr obj, IntPtr val); +public abstract void SetUserPointer(BulletBody obj, IntPtr val); // ===================================================================================== // btRigidBody entries -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyGravity2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetGravity2(IntPtr obj, Vector3 val); +public abstract void ApplyGravity(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetGravity2(IntPtr obj); +public abstract void SetGravity(BulletBody obj, Vector3 val); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping); +public abstract Vector3 GetGravity(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetLinearDamping2(IntPtr obj, float lin_damping); +public abstract void SetDamping(BulletBody obj, float lin_damping, float ang_damping); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetAngularDamping2(IntPtr obj, float ang_damping); +public abstract void SetLinearDamping(BulletBody obj, float lin_damping); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetLinearDamping2(IntPtr obj); +public abstract void SetAngularDamping(BulletBody obj, float ang_damping); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetAngularDamping2(IntPtr obj); +public abstract float GetLinearDamping(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetLinearSleepingThreshold2(IntPtr obj); +public abstract float GetAngularDamping(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetAngularSleepingThreshold2(IntPtr obj); +public abstract float GetLinearSleepingThreshold(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyDamping2(IntPtr obj, float timeStep); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia); +public abstract void ApplyDamping(BulletBody obj, float timeStep); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetLinearFactor2(IntPtr obj); +public abstract void SetMassProps(BulletBody obj, float mass, Vector3 inertia); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor); +public abstract Vector3 GetLinearFactor(BulletBody obj); - /* -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans); - */ +public abstract void SetLinearFactor(BulletBody obj, Vector3 factor); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot); +public abstract void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot); // Add a force to the object as if its mass is one. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force); +public abstract void ApplyCentralForce(BulletBody obj, Vector3 force); // Set the force being applied to the object as if its mass is one. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetObjectForce2(IntPtr obj, Vector3 force); +public abstract void SetObjectForce(BulletBody obj, Vector3 force); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetTotalForce2(IntPtr obj); +public abstract Vector3 GetTotalForce(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetTotalTorque2(IntPtr obj); +public abstract Vector3 GetTotalTorque(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj); +public abstract Vector3 GetInvInertiaDiagLocal(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert); +public abstract void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold); +public abstract void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyTorque2(IntPtr obj, Vector3 torque); +public abstract void ApplyTorque(BulletBody obj, Vector3 torque); // Apply force at the given point. Will add torque to the object. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos); +public abstract void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos); // Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp); +public abstract void ApplyCentralImpulse(BulletBody obj, Vector3 imp); // Apply impulse to the object's torque. Force is scaled by object's mass. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp); +public abstract void ApplyTorqueImpulse(BulletBody obj, Vector3 imp); // Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ClearForces2(IntPtr obj); +public abstract void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ClearAllForces2(IntPtr obj); +public abstract void ClearForces(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void UpdateInertiaTensor2(IntPtr obj); +public abstract void ClearAllForces(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj); - - /* -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Transform GetCenterOfMassTransform2(IntPtr obj); - */ +public abstract void UpdateInertiaTensor(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetLinearVelocity2(IntPtr obj); +public abstract Vector3 GetLinearVelocity(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetAngularVelocity2(IntPtr obj); +public abstract Vector3 GetAngularVelocity(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val); +public abstract void SetLinearVelocity(BulletBody obj, Vector3 val); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity); +public abstract void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos); +public abstract Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void Translate2(IntPtr obj, Vector3 trans); +public abstract void Translate(BulletBody obj, Vector3 trans); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void UpdateDeactivation2(IntPtr obj, float timeStep); +public abstract void UpdateDeactivation(BulletBody obj, float timeStep); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool WantsSleeping2(IntPtr obj); +public abstract bool WantsSleeping(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetAngularFactor2(IntPtr obj, float factor); +public abstract void SetAngularFactor(BulletBody obj, float factor); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor); +public abstract void SetAngularFactorV(BulletBody obj, Vector3 factor); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetAngularFactor2(IntPtr obj); +public abstract Vector3 GetAngularFactor(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsInWorld2(IntPtr obj); +public abstract bool IsInWorld(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain); +public abstract void AddConstraintRef(BulletBody obj, BulletConstraint constrain); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain); +public abstract void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr GetConstraintRef2(IntPtr obj, int index); +public abstract BulletConstraint GetConstraintRef(BulletBody obj, int index); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int GetNumConstraintRefs2(IntPtr obj); +public abstract int GetNumConstraintRefs(BulletBody obj); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask); +public abstract bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask); // ===================================================================================== // btCollisionShape entries -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetAngularMotionDisc2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor); +public abstract float GetAngularMotionDisc(BulletShape shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsPolyhedral2(IntPtr shape); +public abstract float GetContactBreakingThreshold(BulletShape shape, float defaultFactor); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsConvex2d2(IntPtr shape); +public abstract bool IsPolyhedral(BulletShape shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsConvex2(IntPtr shape); +public abstract bool IsConvex2d(BulletShape shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsNonMoving2(IntPtr shape); +public abstract bool IsConvex(BulletShape shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsConcave2(IntPtr shape); +public abstract bool IsNonMoving(BulletShape shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsCompound2(IntPtr shape); +public abstract bool IsConcave(BulletShape shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsSoftBody2(IntPtr shape); +public abstract bool IsCompound(BulletShape shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsInfinite2(IntPtr shape); +public abstract bool IsSoftBody(BulletShape shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale); +public abstract bool IsInfinite(BulletShape shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetLocalScaling2(IntPtr shape); +public abstract void SetLocalScaling(BulletShape shape, Vector3 scale); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass); +public abstract Vector3 GetLocalScaling(BulletShape shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int GetShapeType2(IntPtr shape); +public abstract Vector3 CalculateLocalInertia(BulletShape shape, float mass); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetMargin2(IntPtr shape, float val); +public abstract int GetShapeType(BulletShape shape); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetMargin2(IntPtr shape); - -// ===================================================================================== -// Debugging -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject); +public abstract void SetMargin(BulletShape shape, float val); -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape); +public abstract float GetMargin(BulletShape shape); + */ -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpActivationInfo2(IntPtr sim); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpAllInfo2(IntPtr sim); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpPhysicsStatistics2(IntPtr sim); - -} +}; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 8ec9871..4cb8e6d 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -31,6 +31,7 @@ CRASHES VEHICLES TODO LIST: ================================================= +Angular motor direction is global coordinates rather than local coordinates Border crossing with linked vehicle causes crash Vehicles (Move smoothly) Add vehicle collisions so IsColliding is properly reported. @@ -78,7 +79,7 @@ Small physical objects do not interact correctly Create chain of .5x.5x.1 torui and make all but top physical so to hang. The chain will fall apart and pairs will dance around on ground Chains of 1x1x.2 will stay connected but will dance. - Chains above 2x2x.4 are move stable and get stablier as torui get larger. + Chains above 2x2x.4 are more stable and get stablier as torui get larger. Add PID motor for avatar movement (slow to stop, ...) setForce should set a constant force. Different than AddImpulse. Implement raycast. @@ -100,9 +101,13 @@ More efficient memory usage when passing hull information from BSPrim to BulletS Avatar movement motor check for zero or small movement. Somehow suppress small movements when avatar has stopped and is just standing. Simple test for near zero has the problem of preventing starting up (increase from zero) especially when falling. +Physical and phantom will drop through the terrain + LINKSETS ====================================================== +Offset the center of the linkset to be the geometric center of all the prims + Not quite the same as the center-of-gravity Linksets should allow collisions to individual children Add LocalID to children shapes in LinksetCompound and create events for individuals LinksetCompound: when one of the children changes orientation (like tires -- cgit v1.1 From 9fd0e1b0805ccc97b8e4f19727d98b26fb5fa89d Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sat, 29 Dec 2012 21:44:13 -0800 Subject: BulletSim: add the implementation files for the two versions of Bullet: unmanaged (C++) and managed (C#). --- OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 1107 ++++++++++++++++++++ OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | 39 + 2 files changed, 1146 insertions(+) create mode 100755 OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs create mode 100755 OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs new file mode 100755 index 0000000..bbfc1f8 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs @@ -0,0 +1,1107 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyrightD + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; + +using OpenMetaverse; + +namespace OpenSim.Region.Physics.BulletSPlugin +{ +public sealed class BSAPIUnman : BulletSimAPITemplate +{ + /* +// Initialization and simulation +public BulletWorld Initialize(Vector3 maxPosition, IntPtr parms, + int maxCollisions, IntPtr collisionArray, + int maxUpdates, IntPtr updateArray + ); + +public bool UpdateParameter(BulletWorld world, uint localID, String parm, float value); + +public void SetHeightMap(BulletWorld world, float[] heightmap); + +public void Shutdown(BulletWorld sim); + +public int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, + out int updatedEntityCount, + out IntPtr updatedEntitiesPtr, + out int collidersCount, + out IntPtr collidersPtr); + +public bool PushUpdate(BulletBody obj); + */ + +// ===================================================================================== +// Mesh, hull, shape and body creation helper routines +public override BulletShape CreateMeshShape(BulletWorld world, + int indicesCount, int[] indices, + int verticesCount, float[] vertices) +{ + return new BulletShape( + BSAPI.CreateMeshShape2(world.ptr, indicesCount, indices, verticesCount, vertices), + BSPhysicsShapeType.SHAPE_MESH); +} + +public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls) +{ + return new BulletShape( + BSAPI.CreateHullShape2(world.ptr, hullCount, hulls), + BSPhysicsShapeType.SHAPE_HULL); +} + +public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) +{ + return new BulletShape( + BSAPI.BuildHullShapeFromMesh2(world.ptr, meshShape.ptr), + BSPhysicsShapeType.SHAPE_HULL); +} + +public override BulletShape BuildNativeShape( BulletWorld world, ShapeData shapeData) +{ + return new BulletShape( + BSAPI.BuildNativeShape2(world.ptr, shapeData), + shapeData.Type); +} + +public override bool IsNativeShape(BulletShape shape) +{ + if (shape.HasPhysicalShape) + return BSAPI.IsNativeShape2(shape.ptr); + return false; +} + +public override void SetShapeCollisionMargin(BulletShape shape, float margin) +{ + if (shape.HasPhysicalShape) + BSAPI.SetShapeCollisionMargin2(shape.ptr, margin); +} + +public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale) +{ + return new BulletShape( + BSAPI.BuildCapsuleShape2(world.ptr, radius, height, scale), + BSPhysicsShapeType.SHAPE_CAPSULE); +} + +public override BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree) +{ + return new BulletShape( + BSAPI.CreateCompoundShape2(sim.ptr, enableDynamicAabbTree), + BSPhysicsShapeType.SHAPE_COMPOUND); + +} + +public override int GetNumberOfCompoundChildren(BulletShape shape) +{ + if (shape.HasPhysicalShape) + return BSAPI.GetNumberOfCompoundChildren2(shape.ptr); + return 0; +} + +public override void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot) +{ + BSAPI.AddChildShapeToCompoundShape2(cShape.ptr, addShape.ptr, pos, rot); +} + +public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) +{ + return new BulletShape(BSAPI.GetChildShapeFromCompoundShapeIndex2(cShape.ptr, indx)); +} + +public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) +{ + return new BulletShape(BSAPI.RemoveChildShapeFromCompoundShapeIndex2(cShape.ptr, indx)); +} + +public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape) +{ + BSAPI.RemoveChildShapeFromCompoundShape2(cShape.ptr, removeShape.ptr); +} + +public override void RecalculateCompoundShapeLocalAabb(BulletShape cShape) +{ + BSAPI.RecalculateCompoundShapeLocalAabb2(cShape.ptr); +} + +public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id) +{ + return new BulletShape(BSAPI.DuplicateCollisionShape2(sim.ptr, srcShape.ptr, id), srcShape.type); +} + +public override BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo) +{ + return new BulletBody(id, BSAPI.CreateBodyFromShapeAndInfo2(sim.ptr, shape.ptr, id, constructionInfo)); +} + +public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape) +{ + return BSAPI.DeleteCollisionShape2(world.ptr, shape.ptr); +} + +public override int GetBodyType(BulletBody obj) +{ + return BSAPI.GetBodyType2(obj.ptr); +} + +public override BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot) +{ + return new BulletBody(id, BSAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, id, pos, rot)); +} + +public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot) +{ + return new BulletBody(id, BSAPI.CreateBodyWithDefaultMotionState2(shape.ptr, id, pos, rot)); +} + +public override BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot) +{ + return new BulletBody(id, BSAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, id, pos, rot)); +} + +public override IntPtr AllocateBodyInfo(BulletBody obj) +{ + return BSAPI.AllocateBodyInfo2(obj.ptr); +} + +public override void ReleaseBodyInfo(IntPtr obj) +{ + BSAPI.ReleaseBodyInfo2(obj); +} + +public override void DestroyObject(BulletWorld sim, BulletBody obj) +{ + BSAPI.DestroyObject2(sim.ptr, obj.ptr); +} + + /* +// ===================================================================================== +// Terrain creation and helper routines +public override IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords, + [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); + +public override IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, + [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); + +public override bool ReleaseHeightMapInfo(IntPtr heightMapInfo); + +public override BulletBody CreateGroundPlaneShape(uint id, float height, float collisionMargin); + +public override BulletBody CreateTerrainShape(IntPtr mapInfo); + +// ===================================================================================== +// Constraint creation and helper routines +public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, + Vector3 frame1loc, Quaternion frame1rot, + Vector3 frame2loc, Quaternion frame2rot, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); + +public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2, + Vector3 joinPoint, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); + +public override BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, + Vector3 pivotinA, Vector3 pivotinB, + Vector3 axisInA, Vector3 axisInB, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); + +public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse); + +public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations); + +public override bool SetFrames(BulletConstraint constrain, + Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot); + +public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi); + +public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi); + +public override bool UseFrameOffset(BulletConstraint constrain, float enable); + +public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce); + +public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold); + +public override bool CalculateTransforms(BulletConstraint constrain); + +public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); + +public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain); + +// ===================================================================================== +// btCollisionWorld entries +public override void UpdateSingleAabb(BulletWorld world, BulletBody obj); + +public override void UpdateAabbs(BulletWorld world); + +public override bool GetForceUpdateAllAabbs(BulletWorld world); + +public override void SetForceUpdateAllAabbs(BulletWorld world, bool force); + +// ===================================================================================== +// btDynamicsWorld entries +public override bool AddObjectToWorld(BulletWorld world, BulletBody obj); + +public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj); + +public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects); + +public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain); +// ===================================================================================== +// btCollisionObject entries +public override Vector3 GetAnisotripicFriction(BulletConstraint constrain); + +public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict); + +public override bool HasAnisotripicFriction(BulletConstraint constrain); + +public override void SetContactProcessingThreshold(BulletBody obj, float val); + +public override float GetContactProcessingThreshold(BulletBody obj); + +public override bool IsStaticObject(BulletBody obj); + +public override bool IsKinematicObject(BulletBody obj); + +public override bool IsStaticOrKinematicObject(BulletBody obj); + +public override bool HasContactResponse(BulletBody obj); + +public override void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletBody shape); + +public override BulletShape GetCollisionShape(BulletBody obj); + +public override int GetActivationState(BulletBody obj); + +public override void SetActivationState(BulletBody obj, int state); + +public override void SetDeactivationTime(BulletBody obj, float dtime); + +public override float GetDeactivationTime(BulletBody obj); + +public override void ForceActivationState(BulletBody obj, ActivationState state); + +public override void Activate(BulletBody obj, bool forceActivation); + +public override bool IsActive(BulletBody obj); + +public override void SetRestitution(BulletBody obj, float val); + +public override float GetRestitution(BulletBody obj); + +public override void SetFriction(BulletBody obj, float val); + +public override float GetFriction(BulletBody obj); + +public override Vector3 GetPosition(BulletBody obj); + +public override Quaternion GetOrientation(BulletBody obj); + +public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation); + +public override IntPtr GetBroadphaseHandle(BulletBody obj); + +public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle); + +public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel); + +public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel); + +public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel); + +public override float GetHitFraction(BulletBody obj); + +public override void SetHitFraction(BulletBody obj, float val); + +public override CollisionFlags GetCollisionFlags(BulletBody obj); + +public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags); + +public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags); + +public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags); + +public override float GetCcdMotionThreshold(BulletBody obj); + +public override void SetCcdMotionThreshold(BulletBody obj, float val); + +public override float GetCcdSweptSphereRadius(BulletBody obj); + +public override void SetCcdSweptSphereRadius(BulletBody obj, float val); + +public override IntPtr GetUserPointer(BulletBody obj); + +public override void SetUserPointer(BulletBody obj, IntPtr val); + +// ===================================================================================== +// btRigidBody entries +public override void ApplyGravity(BulletBody obj); + +public override void SetGravity(BulletBody obj, Vector3 val); + +public override Vector3 GetGravity(BulletBody obj); + +public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping); + +public override void SetLinearDamping(BulletBody obj, float lin_damping); + +public override void SetAngularDamping(BulletBody obj, float ang_damping); + +public override float GetLinearDamping(BulletBody obj); + +public override float GetAngularDamping(BulletBody obj); + +public override float GetLinearSleepingThreshold(BulletBody obj); + + +public override void ApplyDamping(BulletBody obj, float timeStep); + +public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia); + +public override Vector3 GetLinearFactor(BulletBody obj); + +public override void SetLinearFactor(BulletBody obj, Vector3 factor); + +public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot); + +// Add a force to the object as if its mass is one. +public override void ApplyCentralForce(BulletBody obj, Vector3 force); + +// Set the force being applied to the object as if its mass is one. +public override void SetObjectForce(BulletBody obj, Vector3 force); + +public override Vector3 GetTotalForce(BulletBody obj); + +public override Vector3 GetTotalTorque(BulletBody obj); + +public override Vector3 GetInvInertiaDiagLocal(BulletBody obj); + +public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert); + +public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold); + +public override void ApplyTorque(BulletBody obj, Vector3 torque); + +// Apply force at the given point. Will add torque to the object. +public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos); + +// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. +public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp); + +// Apply impulse to the object's torque. Force is scaled by object's mass. +public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp); + +// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. +public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos); + +public override void ClearForces(BulletBody obj); + +public override void ClearAllForces(BulletBody obj); + +public override void UpdateInertiaTensor(BulletBody obj); + +public override Vector3 GetLinearVelocity(BulletBody obj); + +public override Vector3 GetAngularVelocity(BulletBody obj); + +public override void SetLinearVelocity(BulletBody obj, Vector3 val); + +public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity); + +public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos); + +public override void Translate(BulletBody obj, Vector3 trans); + +public override void UpdateDeactivation(BulletBody obj, float timeStep); + +public override bool WantsSleeping(BulletBody obj); + +public override void SetAngularFactor(BulletBody obj, float factor); + +public override void SetAngularFactorV(BulletBody obj, Vector3 factor); + +public override Vector3 GetAngularFactor(BulletBody obj); + +public override bool IsInWorld(BulletBody obj); + +public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain); + +public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain); + +public override BulletConstraint GetConstraintRef(BulletBody obj, int index); + +public override int GetNumConstraintRefs(BulletBody obj); + +public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask); + +// ===================================================================================== +// btCollisionShape entries + +public override float GetAngularMotionDisc(BulletShape shape); + +public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor); + +public override bool IsPolyhedral(BulletShape shape); + +public override bool IsConvex2d(BulletShape shape); + +public override bool IsConvex(BulletShape shape); + +public override bool IsNonMoving(BulletShape shape); + +public override bool IsConcave(BulletShape shape); + +public override bool IsCompound(BulletShape shape); + +public override bool IsSoftBody(BulletShape shape); + +public override bool IsInfinite(BulletShape shape); + +public override void SetLocalScaling(BulletShape shape, Vector3 scale); + +public override Vector3 GetLocalScaling(BulletShape shape); + +public override Vector3 CalculateLocalInertia(BulletShape shape, float mass); + +public override int GetShapeType(BulletShape shape); + +public override void SetMargin(BulletShape shape, float val); + +public override float GetMargin(BulletShape shape); + */ + +static class BSAPI +{ +// ===================================================================================== +// Mesh, hull, shape and body creation helper routines +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateMeshShape2(IntPtr world, + int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices, + int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateHullShape2(IntPtr world, + int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsNativeShape2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetShapeCollisionMargin2(IntPtr shape, float margin); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int GetNumberOfCompoundChildren2(IntPtr cShape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int GetBodyType2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr AllocateBodyInfo2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ReleaseBodyInfo2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DestroyObject2(IntPtr sim, IntPtr obj); + +} +} + +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +static class BulletSimAPI { +// =============================================================================== +// Link back to the managed code for outputting log messages +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); + +// =============================================================================== +// Initialization and simulation +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms, + int maxCollisions, IntPtr collisionArray, + int maxUpdates, IntPtr updateArray, + DebugLogCallback logRoutine); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetHeightMap2(IntPtr world, float[] heightmap); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void Shutdown2(IntPtr sim); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep, + out int updatedEntityCount, + out IntPtr updatedEntitiesPtr, + out int collidersCount, + out IntPtr collidersPtr); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool PushUpdate2(IntPtr obj); + +// ===================================================================================== +// Terrain creation and helper routines +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords, + [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, + [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo); + +// ===================================================================================== +// Constraint creation and helper routines +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, + Vector3 frame1loc, Quaternion frame1rot, + Vector3 frame2loc, Quaternion frame2rot, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2, + Vector3 joinPoint, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, + Vector3 pivotinA, Vector3 pivotinB, + Vector3 axisInA, Vector3 axisInB, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetFrames2(IntPtr constrain, + Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool UseFrameOffset2(IntPtr constrain, float enable); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool CalculateTransforms2(IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain); + +// ===================================================================================== +// btCollisionWorld entries +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void UpdateAabbs2(IntPtr world); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool GetForceUpdateAllAabbs2(IntPtr world); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force); + +// ===================================================================================== +// btDynamicsWorld entries +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain); +// ===================================================================================== +// btCollisionObject entries +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool HasAnisotripicFriction2(IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetContactProcessingThreshold2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetContactProcessingThreshold2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsStaticObject2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsKinematicObject2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsStaticOrKinematicObject2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool HasContactResponse2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr GetCollisionShape2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int GetActivationState2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetActivationState2(IntPtr obj, int state); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetDeactivationTime2(IntPtr obj, float dtime); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetDeactivationTime2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ForceActivationState2(IntPtr obj, ActivationState state); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void Activate2(IntPtr obj, bool forceActivation); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsActive2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetRestitution2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetRestitution2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetFriction2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetFriction2(IntPtr obj); + + /* Haven't defined the type 'Transform' +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Transform GetWorldTransform2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void setWorldTransform2(IntPtr obj, Transform trans); + */ + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetPosition2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Quaternion GetOrientation2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr GetBroadphaseHandle2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle); + + /* +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Transform GetInterpolationWorldTransform2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans); + */ + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetHitFraction2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetHitFraction2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern CollisionFlags GetCollisionFlags2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetCcdMotionThreshold2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetCcdMotionThreshold2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetCcdSweptSphereRadius2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr GetUserPointer2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetUserPointer2(IntPtr obj, IntPtr val); + +// ===================================================================================== +// btRigidBody entries +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyGravity2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetGravity2(IntPtr obj, Vector3 val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetGravity2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetLinearDamping2(IntPtr obj, float lin_damping); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetAngularDamping2(IntPtr obj, float ang_damping); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetLinearDamping2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetAngularDamping2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetLinearSleepingThreshold2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetAngularSleepingThreshold2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyDamping2(IntPtr obj, float timeStep); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetLinearFactor2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor); + + /* +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans); + */ + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot); + +// Add a force to the object as if its mass is one. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force); + +// Set the force being applied to the object as if its mass is one. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetObjectForce2(IntPtr obj, Vector3 force); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetTotalForce2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetTotalTorque2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyTorque2(IntPtr obj, Vector3 torque); + +// Apply force at the given point. Will add torque to the object. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos); + +// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp); + +// Apply impulse to the object's torque. Force is scaled by object's mass. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp); + +// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ClearForces2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ClearAllForces2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void UpdateInertiaTensor2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj); + + /* +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Transform GetCenterOfMassTransform2(IntPtr obj); + */ + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetLinearVelocity2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetAngularVelocity2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void Translate2(IntPtr obj, Vector3 trans); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void UpdateDeactivation2(IntPtr obj, float timeStep); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool WantsSleeping2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetAngularFactor2(IntPtr obj, float factor); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetAngularFactor2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsInWorld2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr GetConstraintRef2(IntPtr obj, int index); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int GetNumConstraintRefs2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask); + +// ===================================================================================== +// btCollisionShape entries + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetAngularMotionDisc2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsPolyhedral2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsConvex2d2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsConvex2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsNonMoving2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsConcave2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsCompound2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsSoftBody2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsInfinite2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetLocalScaling2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int GetShapeType2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetMargin2(IntPtr shape, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetMargin2(IntPtr shape); + +// ===================================================================================== +// Debugging +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpActivationInfo2(IntPtr sim); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpAllInfo2(IntPtr sim); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpPhysicsStatistics2(IntPtr sim); + +} +} diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs new file mode 100755 index 0000000..a56a817 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs @@ -0,0 +1,39 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyrightD + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenSim.Region.Physics.BulletSPlugin +{ + /* +public sealed class BSAPIXNA : BulletSimAPITemplate +{ +} + */ +} -- cgit v1.1 From 9218748321519ed04da5cdffa1f29e69030171b5 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 30 Dec 2012 10:21:47 -0800 Subject: BulletSim: another round of conversion: dynamics world and collision object functions. --- OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 2425 +++++++++++--------- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 46 +- .../Region/Physics/BulletSPlugin/BSConstraint.cs | 17 +- .../Physics/BulletSPlugin/BSConstraint6Dof.cs | 30 +- .../Physics/BulletSPlugin/BSConstraintHinge.cs | 10 +- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 10 +- .../Physics/BulletSPlugin/BSLinksetCompound.cs | 12 +- OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 8 +- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 4 +- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 74 +- .../Physics/BulletSPlugin/BSShapeCollection.cs | 6 +- .../Physics/BulletSPlugin/BSTerrainHeightmap.cs | 23 +- .../Physics/BulletSPlugin/BSTerrainManager.cs | 13 +- .../Region/Physics/BulletSPlugin/BSTerrainMesh.cs | 16 +- .../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 8 +- 15 files changed, 1454 insertions(+), 1248 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs index bbfc1f8..9a8a2e8 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs @@ -1,1107 +1,1318 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyrightD - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Security; -using System.Text; - -using OpenMetaverse; - -namespace OpenSim.Region.Physics.BulletSPlugin -{ -public sealed class BSAPIUnman : BulletSimAPITemplate -{ - /* -// Initialization and simulation -public BulletWorld Initialize(Vector3 maxPosition, IntPtr parms, - int maxCollisions, IntPtr collisionArray, - int maxUpdates, IntPtr updateArray - ); - -public bool UpdateParameter(BulletWorld world, uint localID, String parm, float value); - -public void SetHeightMap(BulletWorld world, float[] heightmap); - -public void Shutdown(BulletWorld sim); - -public int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, - out int updatedEntityCount, - out IntPtr updatedEntitiesPtr, - out int collidersCount, - out IntPtr collidersPtr); - -public bool PushUpdate(BulletBody obj); - */ - -// ===================================================================================== -// Mesh, hull, shape and body creation helper routines -public override BulletShape CreateMeshShape(BulletWorld world, - int indicesCount, int[] indices, - int verticesCount, float[] vertices) -{ - return new BulletShape( - BSAPI.CreateMeshShape2(world.ptr, indicesCount, indices, verticesCount, vertices), - BSPhysicsShapeType.SHAPE_MESH); -} - -public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls) -{ - return new BulletShape( - BSAPI.CreateHullShape2(world.ptr, hullCount, hulls), - BSPhysicsShapeType.SHAPE_HULL); -} - -public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) -{ - return new BulletShape( - BSAPI.BuildHullShapeFromMesh2(world.ptr, meshShape.ptr), - BSPhysicsShapeType.SHAPE_HULL); -} - -public override BulletShape BuildNativeShape( BulletWorld world, ShapeData shapeData) -{ - return new BulletShape( - BSAPI.BuildNativeShape2(world.ptr, shapeData), - shapeData.Type); -} - -public override bool IsNativeShape(BulletShape shape) -{ - if (shape.HasPhysicalShape) - return BSAPI.IsNativeShape2(shape.ptr); - return false; -} - -public override void SetShapeCollisionMargin(BulletShape shape, float margin) -{ - if (shape.HasPhysicalShape) - BSAPI.SetShapeCollisionMargin2(shape.ptr, margin); -} - -public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale) -{ - return new BulletShape( - BSAPI.BuildCapsuleShape2(world.ptr, radius, height, scale), - BSPhysicsShapeType.SHAPE_CAPSULE); -} - -public override BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree) -{ - return new BulletShape( - BSAPI.CreateCompoundShape2(sim.ptr, enableDynamicAabbTree), - BSPhysicsShapeType.SHAPE_COMPOUND); - -} - -public override int GetNumberOfCompoundChildren(BulletShape shape) -{ - if (shape.HasPhysicalShape) - return BSAPI.GetNumberOfCompoundChildren2(shape.ptr); - return 0; -} - -public override void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot) -{ - BSAPI.AddChildShapeToCompoundShape2(cShape.ptr, addShape.ptr, pos, rot); -} - -public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) -{ - return new BulletShape(BSAPI.GetChildShapeFromCompoundShapeIndex2(cShape.ptr, indx)); -} - -public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) -{ - return new BulletShape(BSAPI.RemoveChildShapeFromCompoundShapeIndex2(cShape.ptr, indx)); -} - -public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape) -{ - BSAPI.RemoveChildShapeFromCompoundShape2(cShape.ptr, removeShape.ptr); -} - -public override void RecalculateCompoundShapeLocalAabb(BulletShape cShape) -{ - BSAPI.RecalculateCompoundShapeLocalAabb2(cShape.ptr); -} - -public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id) -{ - return new BulletShape(BSAPI.DuplicateCollisionShape2(sim.ptr, srcShape.ptr, id), srcShape.type); -} - -public override BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo) -{ - return new BulletBody(id, BSAPI.CreateBodyFromShapeAndInfo2(sim.ptr, shape.ptr, id, constructionInfo)); -} - -public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape) -{ - return BSAPI.DeleteCollisionShape2(world.ptr, shape.ptr); -} - -public override int GetBodyType(BulletBody obj) -{ - return BSAPI.GetBodyType2(obj.ptr); -} - -public override BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot) -{ - return new BulletBody(id, BSAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, id, pos, rot)); -} - -public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot) -{ - return new BulletBody(id, BSAPI.CreateBodyWithDefaultMotionState2(shape.ptr, id, pos, rot)); -} - -public override BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot) -{ - return new BulletBody(id, BSAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, id, pos, rot)); -} - -public override IntPtr AllocateBodyInfo(BulletBody obj) -{ - return BSAPI.AllocateBodyInfo2(obj.ptr); -} - -public override void ReleaseBodyInfo(IntPtr obj) -{ - BSAPI.ReleaseBodyInfo2(obj); -} - -public override void DestroyObject(BulletWorld sim, BulletBody obj) -{ - BSAPI.DestroyObject2(sim.ptr, obj.ptr); -} - - /* -// ===================================================================================== -// Terrain creation and helper routines -public override IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords, - [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); - -public override IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, - [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); - -public override bool ReleaseHeightMapInfo(IntPtr heightMapInfo); - -public override BulletBody CreateGroundPlaneShape(uint id, float height, float collisionMargin); - -public override BulletBody CreateTerrainShape(IntPtr mapInfo); - -// ===================================================================================== -// Constraint creation and helper routines -public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, - Vector3 frame1loc, Quaternion frame1rot, - Vector3 frame2loc, Quaternion frame2rot, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2, - Vector3 joinPoint, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -public override BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, - Vector3 pivotinA, Vector3 pivotinB, - Vector3 axisInA, Vector3 axisInB, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse); - -public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations); - -public override bool SetFrames(BulletConstraint constrain, - Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot); - -public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi); - -public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi); - -public override bool UseFrameOffset(BulletConstraint constrain, float enable); - -public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce); - -public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold); - -public override bool CalculateTransforms(BulletConstraint constrain); - -public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); - -public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain); - -// ===================================================================================== -// btCollisionWorld entries -public override void UpdateSingleAabb(BulletWorld world, BulletBody obj); - -public override void UpdateAabbs(BulletWorld world); - -public override bool GetForceUpdateAllAabbs(BulletWorld world); - -public override void SetForceUpdateAllAabbs(BulletWorld world, bool force); - -// ===================================================================================== -// btDynamicsWorld entries -public override bool AddObjectToWorld(BulletWorld world, BulletBody obj); - -public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj); - -public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects); - -public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain); -// ===================================================================================== -// btCollisionObject entries -public override Vector3 GetAnisotripicFriction(BulletConstraint constrain); - -public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict); - -public override bool HasAnisotripicFriction(BulletConstraint constrain); - -public override void SetContactProcessingThreshold(BulletBody obj, float val); - -public override float GetContactProcessingThreshold(BulletBody obj); - -public override bool IsStaticObject(BulletBody obj); - -public override bool IsKinematicObject(BulletBody obj); - -public override bool IsStaticOrKinematicObject(BulletBody obj); - -public override bool HasContactResponse(BulletBody obj); - -public override void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletBody shape); - -public override BulletShape GetCollisionShape(BulletBody obj); - -public override int GetActivationState(BulletBody obj); - -public override void SetActivationState(BulletBody obj, int state); - -public override void SetDeactivationTime(BulletBody obj, float dtime); - -public override float GetDeactivationTime(BulletBody obj); - -public override void ForceActivationState(BulletBody obj, ActivationState state); - -public override void Activate(BulletBody obj, bool forceActivation); - -public override bool IsActive(BulletBody obj); - -public override void SetRestitution(BulletBody obj, float val); - -public override float GetRestitution(BulletBody obj); - -public override void SetFriction(BulletBody obj, float val); - -public override float GetFriction(BulletBody obj); - -public override Vector3 GetPosition(BulletBody obj); - -public override Quaternion GetOrientation(BulletBody obj); - -public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation); - -public override IntPtr GetBroadphaseHandle(BulletBody obj); - -public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle); - -public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel); - -public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel); - -public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel); - -public override float GetHitFraction(BulletBody obj); - -public override void SetHitFraction(BulletBody obj, float val); - -public override CollisionFlags GetCollisionFlags(BulletBody obj); - -public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags); - -public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags); - -public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags); - -public override float GetCcdMotionThreshold(BulletBody obj); - -public override void SetCcdMotionThreshold(BulletBody obj, float val); - -public override float GetCcdSweptSphereRadius(BulletBody obj); - -public override void SetCcdSweptSphereRadius(BulletBody obj, float val); - -public override IntPtr GetUserPointer(BulletBody obj); - -public override void SetUserPointer(BulletBody obj, IntPtr val); - -// ===================================================================================== -// btRigidBody entries -public override void ApplyGravity(BulletBody obj); - -public override void SetGravity(BulletBody obj, Vector3 val); - -public override Vector3 GetGravity(BulletBody obj); - -public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping); - -public override void SetLinearDamping(BulletBody obj, float lin_damping); - -public override void SetAngularDamping(BulletBody obj, float ang_damping); - -public override float GetLinearDamping(BulletBody obj); - -public override float GetAngularDamping(BulletBody obj); - -public override float GetLinearSleepingThreshold(BulletBody obj); - - -public override void ApplyDamping(BulletBody obj, float timeStep); - -public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia); - -public override Vector3 GetLinearFactor(BulletBody obj); - -public override void SetLinearFactor(BulletBody obj, Vector3 factor); - -public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot); - -// Add a force to the object as if its mass is one. -public override void ApplyCentralForce(BulletBody obj, Vector3 force); - -// Set the force being applied to the object as if its mass is one. -public override void SetObjectForce(BulletBody obj, Vector3 force); - -public override Vector3 GetTotalForce(BulletBody obj); - -public override Vector3 GetTotalTorque(BulletBody obj); - -public override Vector3 GetInvInertiaDiagLocal(BulletBody obj); - -public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert); - -public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold); - -public override void ApplyTorque(BulletBody obj, Vector3 torque); - -// Apply force at the given point. Will add torque to the object. -public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos); - -// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. -public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp); - -// Apply impulse to the object's torque. Force is scaled by object's mass. -public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp); - -// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. -public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos); - -public override void ClearForces(BulletBody obj); - -public override void ClearAllForces(BulletBody obj); - -public override void UpdateInertiaTensor(BulletBody obj); - -public override Vector3 GetLinearVelocity(BulletBody obj); - -public override Vector3 GetAngularVelocity(BulletBody obj); - -public override void SetLinearVelocity(BulletBody obj, Vector3 val); - -public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity); - -public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos); - -public override void Translate(BulletBody obj, Vector3 trans); - -public override void UpdateDeactivation(BulletBody obj, float timeStep); - -public override bool WantsSleeping(BulletBody obj); - -public override void SetAngularFactor(BulletBody obj, float factor); - -public override void SetAngularFactorV(BulletBody obj, Vector3 factor); - -public override Vector3 GetAngularFactor(BulletBody obj); - -public override bool IsInWorld(BulletBody obj); - -public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain); - -public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain); - -public override BulletConstraint GetConstraintRef(BulletBody obj, int index); - -public override int GetNumConstraintRefs(BulletBody obj); - -public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask); - -// ===================================================================================== -// btCollisionShape entries - -public override float GetAngularMotionDisc(BulletShape shape); - -public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor); - -public override bool IsPolyhedral(BulletShape shape); - -public override bool IsConvex2d(BulletShape shape); - -public override bool IsConvex(BulletShape shape); - -public override bool IsNonMoving(BulletShape shape); - -public override bool IsConcave(BulletShape shape); - -public override bool IsCompound(BulletShape shape); - -public override bool IsSoftBody(BulletShape shape); - -public override bool IsInfinite(BulletShape shape); - -public override void SetLocalScaling(BulletShape shape, Vector3 scale); - -public override Vector3 GetLocalScaling(BulletShape shape); - -public override Vector3 CalculateLocalInertia(BulletShape shape, float mass); - -public override int GetShapeType(BulletShape shape); - -public override void SetMargin(BulletShape shape, float val); - -public override float GetMargin(BulletShape shape); - */ - -static class BSAPI -{ -// ===================================================================================== -// Mesh, hull, shape and body creation helper routines -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateMeshShape2(IntPtr world, - int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices, - int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateHullShape2(IntPtr world, - int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsNativeShape2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetShapeCollisionMargin2(IntPtr shape, float margin); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int GetNumberOfCompoundChildren2(IntPtr cShape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int GetBodyType2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr AllocateBodyInfo2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ReleaseBodyInfo2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DestroyObject2(IntPtr sim, IntPtr obj); - -} -} - -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -static class BulletSimAPI { -// =============================================================================== -// Link back to the managed code for outputting log messages -[UnmanagedFunctionPointer(CallingConvention.Cdecl)] -public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); - -// =============================================================================== -// Initialization and simulation -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms, - int maxCollisions, IntPtr collisionArray, - int maxUpdates, IntPtr updateArray, - DebugLogCallback logRoutine); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetHeightMap2(IntPtr world, float[] heightmap); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void Shutdown2(IntPtr sim); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep, - out int updatedEntityCount, - out IntPtr updatedEntitiesPtr, - out int collidersCount, - out IntPtr collidersPtr); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool PushUpdate2(IntPtr obj); - -// ===================================================================================== -// Terrain creation and helper routines -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords, - [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, - [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo); - -// ===================================================================================== -// Constraint creation and helper routines -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, - Vector3 frame1loc, Quaternion frame1rot, - Vector3 frame2loc, Quaternion frame2rot, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2, - Vector3 joinPoint, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, - Vector3 pivotinA, Vector3 pivotinB, - Vector3 axisInA, Vector3 axisInB, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetFrames2(IntPtr constrain, - Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool UseFrameOffset2(IntPtr constrain, float enable); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool CalculateTransforms2(IntPtr constrain); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain); - -// ===================================================================================== -// btCollisionWorld entries -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void UpdateAabbs2(IntPtr world); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool GetForceUpdateAllAabbs2(IntPtr world); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force); - -// ===================================================================================== -// btDynamicsWorld entries -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain); -// ===================================================================================== -// btCollisionObject entries -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool HasAnisotripicFriction2(IntPtr constrain); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetContactProcessingThreshold2(IntPtr obj, float val); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetContactProcessingThreshold2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsStaticObject2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsKinematicObject2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsStaticOrKinematicObject2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool HasContactResponse2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr GetCollisionShape2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int GetActivationState2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetActivationState2(IntPtr obj, int state); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetDeactivationTime2(IntPtr obj, float dtime); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetDeactivationTime2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ForceActivationState2(IntPtr obj, ActivationState state); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void Activate2(IntPtr obj, bool forceActivation); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsActive2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetRestitution2(IntPtr obj, float val); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetRestitution2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetFriction2(IntPtr obj, float val); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetFriction2(IntPtr obj); - - /* Haven't defined the type 'Transform' -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Transform GetWorldTransform2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void setWorldTransform2(IntPtr obj, Transform trans); - */ - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetPosition2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Quaternion GetOrientation2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr GetBroadphaseHandle2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle); - - /* -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Transform GetInterpolationWorldTransform2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans); - */ - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetHitFraction2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetHitFraction2(IntPtr obj, float val); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern CollisionFlags GetCollisionFlags2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetCcdMotionThreshold2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetCcdMotionThreshold2(IntPtr obj, float val); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetCcdSweptSphereRadius2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr GetUserPointer2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetUserPointer2(IntPtr obj, IntPtr val); - -// ===================================================================================== -// btRigidBody entries -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyGravity2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetGravity2(IntPtr obj, Vector3 val); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetGravity2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetLinearDamping2(IntPtr obj, float lin_damping); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetAngularDamping2(IntPtr obj, float ang_damping); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetLinearDamping2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetAngularDamping2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetLinearSleepingThreshold2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetAngularSleepingThreshold2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyDamping2(IntPtr obj, float timeStep); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetLinearFactor2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor); - - /* -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans); - */ - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot); - -// Add a force to the object as if its mass is one. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force); - -// Set the force being applied to the object as if its mass is one. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetObjectForce2(IntPtr obj, Vector3 force); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetTotalForce2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetTotalTorque2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyTorque2(IntPtr obj, Vector3 torque); - -// Apply force at the given point. Will add torque to the object. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos); - -// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp); - -// Apply impulse to the object's torque. Force is scaled by object's mass. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp); - -// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ClearForces2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ClearAllForces2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void UpdateInertiaTensor2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj); - - /* -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Transform GetCenterOfMassTransform2(IntPtr obj); - */ - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetLinearVelocity2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetAngularVelocity2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void Translate2(IntPtr obj, Vector3 trans); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void UpdateDeactivation2(IntPtr obj, float timeStep); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool WantsSleeping2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetAngularFactor2(IntPtr obj, float factor); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetAngularFactor2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsInWorld2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr GetConstraintRef2(IntPtr obj, int index); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int GetNumConstraintRefs2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask); - -// ===================================================================================== -// btCollisionShape entries - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetAngularMotionDisc2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsPolyhedral2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsConvex2d2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsConvex2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsNonMoving2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsConcave2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsCompound2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsSoftBody2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool IsInfinite2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 GetLocalScaling2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int GetShapeType2(IntPtr shape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetMargin2(IntPtr shape, float val); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern float GetMargin2(IntPtr shape); - -// ===================================================================================== -// Debugging -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpActivationInfo2(IntPtr sim); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpAllInfo2(IntPtr sim); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void DumpPhysicsStatistics2(IntPtr sim); - -} -} +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyrightD + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; + +using OpenMetaverse; + +namespace OpenSim.Region.Physics.BulletSPlugin +{ +public sealed class BSAPIUnman : BulletSimAPITemplate +{ + /* +// Initialization and simulation +public BulletWorld Initialize(Vector3 maxPosition, IntPtr parms, + int maxCollisions, IntPtr collisionArray, + int maxUpdates, IntPtr updateArray + ); + +public bool UpdateParameter(BulletWorld world, uint localID, String parm, float value); + +public void SetHeightMap(BulletWorld world, float[] heightmap); + +public void Shutdown(BulletWorld sim); + +public int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, + out int updatedEntityCount, + out IntPtr updatedEntitiesPtr, + out int collidersCount, + out IntPtr collidersPtr); + +public bool PushUpdate(BulletBody obj); + */ + +// ===================================================================================== +// Mesh, hull, shape and body creation helper routines +public override BulletShape CreateMeshShape(BulletWorld world, + int indicesCount, int[] indices, + int verticesCount, float[] vertices) +{ + return new BulletShape( + BSAPICPP.CreateMeshShape2(world.ptr, indicesCount, indices, verticesCount, vertices), + BSPhysicsShapeType.SHAPE_MESH); +} + +public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls) +{ + return new BulletShape( + BSAPICPP.CreateHullShape2(world.ptr, hullCount, hulls), + BSPhysicsShapeType.SHAPE_HULL); +} + +public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) +{ + return new BulletShape( + BSAPICPP.BuildHullShapeFromMesh2(world.ptr, meshShape.ptr), + BSPhysicsShapeType.SHAPE_HULL); +} + +public override BulletShape BuildNativeShape( BulletWorld world, ShapeData shapeData) +{ + return new BulletShape( + BSAPICPP.BuildNativeShape2(world.ptr, shapeData), + shapeData.Type); +} + +public override bool IsNativeShape(BulletShape shape) +{ + if (shape.HasPhysicalShape) + return BSAPICPP.IsNativeShape2(shape.ptr); + return false; +} + +public override void SetShapeCollisionMargin(BulletShape shape, float margin) +{ + if (shape.HasPhysicalShape) + BSAPICPP.SetShapeCollisionMargin2(shape.ptr, margin); +} + +public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale) +{ + return new BulletShape( + BSAPICPP.BuildCapsuleShape2(world.ptr, radius, height, scale), + BSPhysicsShapeType.SHAPE_CAPSULE); +} + +public override BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree) +{ + return new BulletShape( + BSAPICPP.CreateCompoundShape2(sim.ptr, enableDynamicAabbTree), + BSPhysicsShapeType.SHAPE_COMPOUND); + +} + +public override int GetNumberOfCompoundChildren(BulletShape shape) +{ + if (shape.HasPhysicalShape) + return BSAPICPP.GetNumberOfCompoundChildren2(shape.ptr); + return 0; +} + +public override void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot) +{ + BSAPICPP.AddChildShapeToCompoundShape2(cShape.ptr, addShape.ptr, pos, rot); +} + +public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) +{ + return new BulletShape(BSAPICPP.GetChildShapeFromCompoundShapeIndex2(cShape.ptr, indx)); +} + +public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx) +{ + return new BulletShape(BSAPICPP.RemoveChildShapeFromCompoundShapeIndex2(cShape.ptr, indx)); +} + +public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape) +{ + BSAPICPP.RemoveChildShapeFromCompoundShape2(cShape.ptr, removeShape.ptr); +} + +public override void RecalculateCompoundShapeLocalAabb(BulletShape cShape) +{ + BSAPICPP.RecalculateCompoundShapeLocalAabb2(cShape.ptr); +} + +public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id) +{ + return new BulletShape(BSAPICPP.DuplicateCollisionShape2(sim.ptr, srcShape.ptr, id), srcShape.type); +} + +public override BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo) +{ + return new BulletBody(id, BSAPICPP.CreateBodyFromShapeAndInfo2(sim.ptr, shape.ptr, id, constructionInfo)); +} + +public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape) +{ + return BSAPICPP.DeleteCollisionShape2(world.ptr, shape.ptr); +} + +public override int GetBodyType(BulletBody obj) +{ + return BSAPICPP.GetBodyType2(obj.ptr); +} + +public override BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot) +{ + return new BulletBody(id, BSAPICPP.CreateBodyFromShape2(sim.ptr, shape.ptr, id, pos, rot)); +} + +public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot) +{ + return new BulletBody(id, BSAPICPP.CreateBodyWithDefaultMotionState2(shape.ptr, id, pos, rot)); +} + +public override BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot) +{ + return new BulletBody(id, BSAPICPP.CreateGhostFromShape2(sim.ptr, shape.ptr, id, pos, rot)); +} + +public override IntPtr AllocateBodyInfo(BulletBody obj) +{ + return BSAPICPP.AllocateBodyInfo2(obj.ptr); +} + +public override void ReleaseBodyInfo(IntPtr obj) +{ + BSAPICPP.ReleaseBodyInfo2(obj); +} + +public override void DestroyObject(BulletWorld sim, BulletBody obj) +{ + BSAPICPP.DestroyObject2(sim.ptr, obj.ptr); +} + +// ===================================================================================== +// Terrain creation and helper routines +public override IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords, + float[] heightMap, float collisionMargin) +{ + return BSAPICPP.CreateHeightMapInfo2(sim.ptr, id, minCoords, maxCoords, heightMap, collisionMargin); +} + +public override IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, + float[] heightMap, float collisionMargin) +{ + return BSAPICPP.FillHeightMapInfo2(sim.ptr, mapInfo, id, minCoords, maxCoords, heightMap, collisionMargin); +} + +public override bool ReleaseHeightMapInfo(IntPtr heightMapInfo) +{ + return BSAPICPP.ReleaseHeightMapInfo2(heightMapInfo); +} + +public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin) +{ + return new BulletShape(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE); +} + +public override BulletShape CreateTerrainShape(IntPtr mapInfo) +{ + return new BulletShape(BSAPICPP.CreateTerrainShape2(mapInfo), BSPhysicsShapeType.SHAPE_TERRAIN); +} + +// ===================================================================================== +// Constraint creation and helper routines +public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, + Vector3 frame1loc, Quaternion frame1rot, + Vector3 frame2loc, Quaternion frame2rot, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) +{ + return new BulletConstraint(BSAPICPP.Create6DofConstraint2(world.ptr, obj1.ptr, obj2.ptr, frame1loc, frame1rot, + frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); +} + +public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2, + Vector3 joinPoint, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) +{ + return new BulletConstraint(BSAPICPP.Create6DofConstraintToPoint2(world.ptr, obj1.ptr, obj2.ptr, + joinPoint, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); +} + +public override BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, + Vector3 pivotinA, Vector3 pivotinB, + Vector3 axisInA, Vector3 axisInB, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) +{ + return new BulletConstraint(BSAPICPP.CreateHingeConstraint2(world.ptr, obj1.ptr, obj2.ptr, + pivotinA, pivotinB, axisInA, axisInB, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); +} + +public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse) +{ + BSAPICPP.SetConstraintEnable2(constrain.ptr, numericTrueFalse); +} + +public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations) +{ + BSAPICPP.SetConstraintNumSolverIterations2(constrain.ptr, iterations); +} + +public override bool SetFrames(BulletConstraint constrain, + Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot) +{ + return BSAPICPP.SetFrames2(constrain.ptr, frameA, frameArot, frameB, frameBrot); +} + +public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi) +{ + return BSAPICPP.SetLinearLimits2(constrain.ptr, low, hi); +} + +public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi) +{ + return BSAPICPP.SetAngularLimits2(constrain.ptr, low, hi); +} + +public override bool UseFrameOffset(BulletConstraint constrain, float enable) +{ + return BSAPICPP.UseFrameOffset2(constrain.ptr, enable); +} + +public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce) +{ + return BSAPICPP.TranslationalLimitMotor2(constrain.ptr, enable, targetVel, maxMotorForce); +} + +public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold) +{ + return BSAPICPP.SetBreakingImpulseThreshold2(constrain.ptr, threshold); +} + +public override bool CalculateTransforms(BulletConstraint constrain) +{ + return BSAPICPP.CalculateTransforms2(constrain.ptr); +} + +public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis) +{ + return BSAPICPP.SetConstraintParam2(constrain.ptr, paramIndex, value, axis); +} + +public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain) +{ + return BSAPICPP.DestroyConstraint2(world.ptr, constrain.ptr); +} + +// ===================================================================================== +// btCollisionWorld entries +public override void UpdateSingleAabb(BulletWorld world, BulletBody obj) +{ + BSAPICPP.UpdateSingleAabb2(world.ptr, obj.ptr); +} + +public override void UpdateAabbs(BulletWorld world) +{ + BSAPICPP.UpdateAabbs2(world.ptr); +} + +public override bool GetForceUpdateAllAabbs(BulletWorld world) +{ + return BSAPICPP.GetForceUpdateAllAabbs2(world.ptr); +} + +public override void SetForceUpdateAllAabbs(BulletWorld world, bool force) +{ + BSAPICPP.SetForceUpdateAllAabbs2(world.ptr, force); +} + +// ===================================================================================== +// btDynamicsWorld entries +public override bool AddObjectToWorld(BulletWorld world, BulletBody obj) +{ + return BSAPICPP.AddObjectToWorld2(world.ptr, obj.ptr); +} + +public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj) +{ + return BSAPICPP.RemoveObjectFromWorld2(world.ptr, obj.ptr); +} + +public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects) +{ + return BSAPICPP.AddConstraintToWorld2(world.ptr, constrain.ptr, disableCollisionsBetweenLinkedObjects); +} + +public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain) +{ + return BSAPICPP.RemoveConstraintFromWorld2(world.ptr, constrain.ptr); +} +// ===================================================================================== +// btCollisionObject entries +public override Vector3 GetAnisotripicFriction(BulletConstraint constrain) +{ + return BSAPICPP.GetAnisotripicFriction2(constrain.ptr); +} + +public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict) +{ + return BSAPICPP.SetAnisotripicFriction2(constrain.ptr, frict); +} + +public override bool HasAnisotripicFriction(BulletConstraint constrain) +{ + return BSAPICPP.HasAnisotripicFriction2(constrain.ptr); +} + +public override void SetContactProcessingThreshold(BulletBody obj, float val) +{ + BSAPICPP.SetContactProcessingThreshold2(obj.ptr, val); +} + +public override float GetContactProcessingThreshold(BulletBody obj) +{ + return BSAPICPP.GetContactProcessingThreshold2(obj.ptr); +} + +public override bool IsStaticObject(BulletBody obj) +{ + return BSAPICPP.IsStaticObject2(obj.ptr); +} + +public override bool IsKinematicObject(BulletBody obj) +{ + return BSAPICPP.IsKinematicObject2(obj.ptr); +} + +public override bool IsStaticOrKinematicObject(BulletBody obj) +{ + return BSAPICPP.IsStaticOrKinematicObject2(obj.ptr); +} + +public override bool HasContactResponse(BulletBody obj) +{ + return BSAPICPP.HasContactResponse2(obj.ptr); +} + +public override void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape) +{ + BSAPICPP.SetCollisionShape2(sim.ptr, obj.ptr, shape.ptr); +} + +public override BulletShape GetCollisionShape(BulletBody obj) +{ + return new BulletShape(BSAPICPP.GetCollisionShape2(obj.ptr)); +} + +public override int GetActivationState(BulletBody obj) +{ + return BSAPICPP.GetActivationState2(obj.ptr); +} + +public override void SetActivationState(BulletBody obj, int state) +{ + BSAPICPP.SetActivationState2(obj.ptr, state); +} + +public override void SetDeactivationTime(BulletBody obj, float dtime) +{ + BSAPICPP.SetDeactivationTime2(obj.ptr, dtime); +} + +public override float GetDeactivationTime(BulletBody obj) +{ + return BSAPICPP.GetDeactivationTime2(obj.ptr); +} + +public override void ForceActivationState(BulletBody obj, ActivationState state) +{ + BSAPICPP.ForceActivationState2(obj.ptr, state); +} + +public override void Activate(BulletBody obj, bool forceActivation) +{ + BSAPICPP.Activate2(obj.ptr, forceActivation); +} + +public override bool IsActive(BulletBody obj) +{ + return BSAPICPP.IsActive2(obj.ptr); +} + +public override void SetRestitution(BulletBody obj, float val) +{ + BSAPICPP.SetRestitution2(obj.ptr, val); +} + +public override float GetRestitution(BulletBody obj) +{ + return BSAPICPP.GetRestitution2(obj.ptr); +} + +public override void SetFriction(BulletBody obj, float val) +{ + BSAPICPP.SetFriction2(obj.ptr, val); +} + +public override float GetFriction(BulletBody obj) +{ + return BSAPICPP.GetFriction2(obj.ptr); +} + +public override Vector3 GetPosition(BulletBody obj) +{ + return BSAPICPP.GetPosition2(obj.ptr); +} + +public override Quaternion GetOrientation(BulletBody obj) +{ + return BSAPICPP.GetOrientation2(obj.ptr); +} + +public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation) +{ + BSAPICPP.SetTranslation2(obj.ptr, position, rotation); +} + +public override IntPtr GetBroadphaseHandle(BulletBody obj) +{ + return BSAPICPP.GetBroadphaseHandle2(obj.ptr); +} + +public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle) +{ + BSAPICPP.SetUserPointer2(obj.ptr, handle); +} + +public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel) +{ + BSAPICPP.SetInterpolationLinearVelocity2(obj.ptr, vel); +} + +public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel) +{ + BSAPICPP.SetInterpolationAngularVelocity2(obj.ptr, vel); +} + +public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel) +{ + BSAPICPP.SetInterpolationVelocity2(obj.ptr, linearVel, angularVel); +} + +public override float GetHitFraction(BulletBody obj) +{ + return BSAPICPP.GetHitFraction2(obj.ptr); +} + +public override void SetHitFraction(BulletBody obj, float val) +{ + BSAPICPP.SetHitFraction2(obj.ptr, val); +} + +public override CollisionFlags GetCollisionFlags(BulletBody obj) +{ + return BSAPICPP.GetCollisionFlags2(obj.ptr); +} + +public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags) +{ + return BSAPICPP.SetCollisionFlags2(obj.ptr, flags); +} + +public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags) +{ + return BSAPICPP.AddToCollisionFlags2(obj.ptr, flags); +} + +public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags) +{ + return BSAPICPP.RemoveFromCollisionFlags2(obj.ptr, flags); +} + +public override float GetCcdMotionThreshold(BulletBody obj) +{ + return BSAPICPP.GetCcdMotionThreshold2(obj.ptr); +} + + +public override void SetCcdMotionThreshold(BulletBody obj, float val) +{ + BSAPICPP.SetCcdMotionThreshold2(obj.ptr, val); +} + +public override float GetCcdSweptSphereRadius(BulletBody obj) +{ + return BSAPICPP.GetCcdSweptSphereRadius2(obj.ptr); +} + +public override void SetCcdSweptSphereRadius(BulletBody obj, float val) +{ + BSAPICPP.SetCcdSweptSphereRadius2(obj.ptr, val); +} + +public override IntPtr GetUserPointer(BulletBody obj) +{ + return BSAPICPP.GetUserPointer2(obj.ptr); +} + +public override void SetUserPointer(BulletBody obj, IntPtr val) +{ + BSAPICPP.SetUserPointer2(obj.ptr, val); +} + + /* +// ===================================================================================== +// btRigidBody entries +public override void ApplyGravity(BulletBody obj); + +public override void SetGravity(BulletBody obj, Vector3 val); + +public override Vector3 GetGravity(BulletBody obj); + +public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping); + +public override void SetLinearDamping(BulletBody obj, float lin_damping); + +public override void SetAngularDamping(BulletBody obj, float ang_damping); + +public override float GetLinearDamping(BulletBody obj); + +public override float GetAngularDamping(BulletBody obj); + +public override float GetLinearSleepingThreshold(BulletBody obj); + + +public override void ApplyDamping(BulletBody obj, float timeStep); + +public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia); + +public override Vector3 GetLinearFactor(BulletBody obj); + +public override void SetLinearFactor(BulletBody obj, Vector3 factor); + +public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot); + +// Add a force to the object as if its mass is one. +public override void ApplyCentralForce(BulletBody obj, Vector3 force); + +// Set the force being applied to the object as if its mass is one. +public override void SetObjectForce(BulletBody obj, Vector3 force); + +public override Vector3 GetTotalForce(BulletBody obj); + +public override Vector3 GetTotalTorque(BulletBody obj); + +public override Vector3 GetInvInertiaDiagLocal(BulletBody obj); + +public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert); + +public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold); + +public override void ApplyTorque(BulletBody obj, Vector3 torque); + +// Apply force at the given point. Will add torque to the object. +public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos); + +// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. +public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp); + +// Apply impulse to the object's torque. Force is scaled by object's mass. +public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp); + +// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. +public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos); + +public override void ClearForces(BulletBody obj); + +public override void ClearAllForces(BulletBody obj); + +public override void UpdateInertiaTensor(BulletBody obj); + +public override Vector3 GetLinearVelocity(BulletBody obj); + +public override Vector3 GetAngularVelocity(BulletBody obj); + +public override void SetLinearVelocity(BulletBody obj, Vector3 val); + +public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity); + +public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos); + +public override void Translate(BulletBody obj, Vector3 trans); + +public override void UpdateDeactivation(BulletBody obj, float timeStep); + +public override bool WantsSleeping(BulletBody obj); + +public override void SetAngularFactor(BulletBody obj, float factor); + +public override void SetAngularFactorV(BulletBody obj, Vector3 factor); + +public override Vector3 GetAngularFactor(BulletBody obj); + +public override bool IsInWorld(BulletBody obj); + +public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain); + +public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain); + +public override BulletConstraint GetConstraintRef(BulletBody obj, int index); + +public override int GetNumConstraintRefs(BulletBody obj); + +public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask); + +// ===================================================================================== +// btCollisionShape entries + +public override float GetAngularMotionDisc(BulletShape shape); + +public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor); + +public override bool IsPolyhedral(BulletShape shape); + +public override bool IsConvex2d(BulletShape shape); + +public override bool IsConvex(BulletShape shape); + +public override bool IsNonMoving(BulletShape shape); + +public override bool IsConcave(BulletShape shape); + +public override bool IsCompound(BulletShape shape); + +public override bool IsSoftBody(BulletShape shape); + +public override bool IsInfinite(BulletShape shape); + +public override void SetLocalScaling(BulletShape shape, Vector3 scale); + +public override Vector3 GetLocalScaling(BulletShape shape); + +public override Vector3 CalculateLocalInertia(BulletShape shape, float mass); + +public override int GetShapeType(BulletShape shape); + +public override void SetMargin(BulletShape shape, float val); + +public override float GetMargin(BulletShape shape); + */ + +static class BSAPICPP +{ +// ===================================================================================== +// Mesh, hull, shape and body creation helper routines +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateMeshShape2(IntPtr world, + int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices, + int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices ); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateHullShape2(IntPtr world, + int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsNativeShape2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetShapeCollisionMargin2(IntPtr shape, float margin); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int GetNumberOfCompoundChildren2(IntPtr cShape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int GetBodyType2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr AllocateBodyInfo2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ReleaseBodyInfo2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DestroyObject2(IntPtr sim, IntPtr obj); + +// ===================================================================================== +// Terrain creation and helper routines +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords, + [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, + [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo); + +// ===================================================================================== +// Constraint creation and helper routines +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, + Vector3 frame1loc, Quaternion frame1rot, + Vector3 frame2loc, Quaternion frame2rot, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2, + Vector3 joinPoint, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2, + Vector3 pivotinA, Vector3 pivotinB, + Vector3 axisInA, Vector3 axisInB, + bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetFrames2(IntPtr constrain, + Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool UseFrameOffset2(IntPtr constrain, float enable); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool CalculateTransforms2(IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain); + +// ===================================================================================== +// btCollisionWorld entries +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void UpdateAabbs2(IntPtr world); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool GetForceUpdateAllAabbs2(IntPtr world); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force); + +// ===================================================================================== +// btDynamicsWorld entries +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain); +// ===================================================================================== +// btCollisionObject entries +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool HasAnisotripicFriction2(IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetContactProcessingThreshold2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetContactProcessingThreshold2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsStaticObject2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsKinematicObject2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsStaticOrKinematicObject2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool HasContactResponse2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr GetCollisionShape2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int GetActivationState2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetActivationState2(IntPtr obj, int state); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetDeactivationTime2(IntPtr obj, float dtime); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetDeactivationTime2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ForceActivationState2(IntPtr obj, ActivationState state); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void Activate2(IntPtr obj, bool forceActivation); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsActive2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetRestitution2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetRestitution2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetFriction2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetFriction2(IntPtr obj); + + /* Haven't defined the type 'Transform' +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Transform GetWorldTransform2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void setWorldTransform2(IntPtr obj, Transform trans); + */ + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetPosition2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Quaternion GetOrientation2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr GetBroadphaseHandle2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle); + + /* +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Transform GetInterpolationWorldTransform2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans); + */ + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetHitFraction2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetHitFraction2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern CollisionFlags GetCollisionFlags2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetCcdMotionThreshold2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetCcdMotionThreshold2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetCcdSweptSphereRadius2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr GetUserPointer2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetUserPointer2(IntPtr obj, IntPtr val); + +} +} + +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +// =============================================================================== +static class BulletSimAPI { +// =============================================================================== +// Link back to the managed code for outputting log messages +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); + +// =============================================================================== +// Initialization and simulation +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms, + int maxCollisions, IntPtr collisionArray, + int maxUpdates, IntPtr updateArray, + DebugLogCallback logRoutine); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetHeightMap2(IntPtr world, float[] heightmap); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void Shutdown2(IntPtr sim); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep, + out int updatedEntityCount, + out IntPtr updatedEntitiesPtr, + out int collidersCount, + out IntPtr collidersPtr); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool PushUpdate2(IntPtr obj); + +// ===================================================================================== +// btRigidBody entries +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyGravity2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetGravity2(IntPtr obj, Vector3 val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetGravity2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetLinearDamping2(IntPtr obj, float lin_damping); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetAngularDamping2(IntPtr obj, float ang_damping); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetLinearDamping2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetAngularDamping2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetLinearSleepingThreshold2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetAngularSleepingThreshold2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyDamping2(IntPtr obj, float timeStep); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetLinearFactor2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor); + + /* +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans); + */ + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot); + +// Add a force to the object as if its mass is one. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force); + +// Set the force being applied to the object as if its mass is one. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetObjectForce2(IntPtr obj, Vector3 force); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetTotalForce2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetTotalTorque2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyTorque2(IntPtr obj, Vector3 torque); + +// Apply force at the given point. Will add torque to the object. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos); + +// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp); + +// Apply impulse to the object's torque. Force is scaled by object's mass. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp); + +// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ClearForces2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void ClearAllForces2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void UpdateInertiaTensor2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj); + + /* +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Transform GetCenterOfMassTransform2(IntPtr obj); + */ + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetLinearVelocity2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetAngularVelocity2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void Translate2(IntPtr obj, Vector3 trans); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void UpdateDeactivation2(IntPtr obj, float timeStep); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool WantsSleeping2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetAngularFactor2(IntPtr obj, float factor); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetAngularFactor2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsInWorld2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr GetConstraintRef2(IntPtr obj, int index); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int GetNumConstraintRefs2(IntPtr obj); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask); + +// ===================================================================================== +// btCollisionShape entries + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetAngularMotionDisc2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsPolyhedral2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsConvex2d2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsConvex2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsNonMoving2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsConcave2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsCompound2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsSoftBody2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool IsInfinite2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 GetLocalScaling2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int GetShapeType2(IntPtr shape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetMargin2(IntPtr shape, float val); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern float GetMargin2(IntPtr shape); + +// ===================================================================================== +// Debugging +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpActivationInfo2(IntPtr sim); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpAllInfo2(IntPtr sim); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void DumpPhysicsStatistics2(IntPtr sim); + +} +} diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index d5ab245..328164b 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -137,7 +137,7 @@ public sealed class BSCharacter : BSPhysObject private void SetPhysicalProperties() { - BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); + PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody); ZeroMotion(true); ForcePosition = _position; @@ -152,14 +152,14 @@ public sealed class BSCharacter : BSPhysObject // Needs to be reset especially when an avatar is recreated after crossing a region boundry. Flying = _flying; - BulletSimAPI.SetRestitution2(PhysBody.ptr, BSParam.AvatarRestitution); + PhysicsScene.PE.SetRestitution(PhysBody, BSParam.AvatarRestitution); BulletSimAPI.SetMargin2(PhysShape.ptr, PhysicsScene.Params.collisionMargin); BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); - BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, BSParam.ContactProcessingThreshold); + PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold); if (BSParam.CcdMotionThreshold > 0f) { - BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold); - BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius); + PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); + PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); } UpdatePhysicalMassProperties(RawMass, false); @@ -167,13 +167,13 @@ public sealed class BSCharacter : BSPhysObject // Make so capsule does not fall over BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero); - BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_CHARACTER_OBJECT); + PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_CHARACTER_OBJECT); - BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); + PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); - // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ACTIVE_TAG); - BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_DEACTIVATION); - BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); + // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG); + PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_DEACTIVATION); + PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody); // Do this after the object has been added to the world PhysBody.collisionType = CollisionType.Avatar; @@ -320,7 +320,7 @@ public sealed class BSCharacter : BSPhysObject { if (PhysBody.HasPhysicalBody) { - BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); + PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, OMV.Vector3.Zero); BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); // The next also get rid of applied linear force but the linear velocity is untouched. BulletSimAPI.ClearForces2(PhysBody.ptr); @@ -350,19 +350,19 @@ public sealed class BSCharacter : BSPhysObject { DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); if (PhysBody.HasPhysicalBody) - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); }); } } public override OMV.Vector3 ForcePosition { get { - _position = BulletSimAPI.GetPosition2(PhysBody.ptr); + _position = PhysicsScene.PE.GetPosition(PhysBody); return _position; } set { _position = value; PositionSanityCheck(); - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); } } @@ -418,7 +418,7 @@ public sealed class BSCharacter : BSPhysObject { DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); if (PhysBody.HasPhysicalBody) - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); }); ret = true; } @@ -520,7 +520,7 @@ public sealed class BSCharacter : BSPhysObject { _currentFriction = BSParam.AvatarStandingFriction; if (PhysBody.HasPhysicalBody) - BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); + PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); } } else @@ -529,12 +529,12 @@ public sealed class BSCharacter : BSPhysObject { _currentFriction = BSParam.AvatarFriction; if (PhysBody.HasPhysicalBody) - BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); + PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); } } BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); - BulletSimAPI.Activate2(PhysBody.ptr, true); + PhysicsScene.PE.Activate(PhysBody, true); } } public override OMV.Vector3 Torque { @@ -576,7 +576,7 @@ public sealed class BSCharacter : BSPhysObject { get { - _orientation = BulletSimAPI.GetOrientation2(PhysBody.ptr); + _orientation = PhysicsScene.PE.GetOrientation(PhysBody); return _orientation; } set @@ -584,8 +584,8 @@ public sealed class BSCharacter : BSPhysObject _orientation = value; if (PhysBody.HasPhysicalBody) { - // _position = BulletSimAPI.GetPosition2(BSBody.ptr); - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + // _position = PhysicsScene.PE.GetPosition(BSBody); + PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); } } } @@ -636,9 +636,9 @@ public sealed class BSCharacter : BSPhysObject if (PhysBody.HasPhysicalBody) { if (_floatOnWater) - CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); + CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); else - CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); + CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); } }); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs index 59584b2..c9c7c2e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs @@ -37,6 +37,7 @@ public abstract class BSConstraint : IDisposable private static string LogHeader = "[BULLETSIM CONSTRAINT]"; protected BulletWorld m_world; + protected BSScene PhysicsScene; protected BulletBody m_body1; protected BulletBody m_body2; protected BulletConstraint m_constraint; @@ -48,8 +49,10 @@ public abstract class BSConstraint : IDisposable public abstract ConstraintType Type { get; } public bool IsEnabled { get { return m_enabled; } } - public BSConstraint() + public BSConstraint(BulletWorld world) { + m_world = world; + PhysicsScene = m_world.physicsScene; } public virtual void Dispose() @@ -59,7 +62,7 @@ public abstract class BSConstraint : IDisposable m_enabled = false; if (m_constraint.HasPhysicalConstraint) { - bool success = BulletSimAPI.DestroyConstraint2(m_world.ptr, m_constraint.ptr); + bool success = PhysicsScene.PE.DestroyConstraint(m_world, m_constraint); m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}", BSScene.DetailLogZero, m_body1.ID, m_body1.ptr.ToString("X"), @@ -74,7 +77,7 @@ public abstract class BSConstraint : IDisposable { bool ret = false; if (m_enabled) - ret = BulletSimAPI.SetLinearLimits2(m_constraint.ptr, low, high); + ret = PhysicsScene.PE.SetLinearLimits(m_constraint, low, high); return ret; } @@ -82,7 +85,7 @@ public abstract class BSConstraint : IDisposable { bool ret = false; if (m_enabled) - ret = BulletSimAPI.SetAngularLimits2(m_constraint.ptr, low, high); + ret = PhysicsScene.PE.SetAngularLimits(m_constraint, low, high); return ret; } @@ -91,7 +94,7 @@ public abstract class BSConstraint : IDisposable bool ret = false; if (m_enabled) { - BulletSimAPI.SetConstraintNumSolverIterations2(m_constraint.ptr, cnt); + PhysicsScene.PE.SetConstraintNumSolverIterations(m_constraint, cnt); ret = true; } return ret; @@ -103,7 +106,7 @@ public abstract class BSConstraint : IDisposable if (m_enabled) { // Recompute the internal transforms - BulletSimAPI.CalculateTransforms2(m_constraint.ptr); + PhysicsScene.PE.CalculateTransforms(m_constraint); ret = true; } return ret; @@ -122,7 +125,7 @@ public abstract class BSConstraint : IDisposable // Setting an object's mass to zero (making it static like when it's selected) // automatically disables the constraints. // If the link is enabled, be sure to set the constraint itself to enabled. - BulletSimAPI.SetConstraintEnable2(m_constraint.ptr, BSParam.NumericBool(true)); + PhysicsScene.PE.SetConstraintEnable(m_constraint, BSParam.NumericBool(true)); } else { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs index b946870..aee93c9 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs @@ -43,15 +43,14 @@ public sealed class BSConstraint6Dof : BSConstraint Vector3 frame1, Quaternion frame1rot, Vector3 frame2, Quaternion frame2rot, bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) + : base(world) { - m_world = world; m_body1 = obj1; m_body2 = obj2; - m_constraint = new BulletConstraint( - BulletSimAPI.Create6DofConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr, + m_constraint = PhysicsScene.PE.Create6DofConstraint(m_world, m_body1, m_body2, frame1, frame1rot, frame2, frame2rot, - useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); + useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); m_enabled = true; world.physicsScene.DetailLog("{0},BS6DofConstraint,createFrame,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", BSScene.DetailLogZero, world.worldID, @@ -61,8 +60,8 @@ public sealed class BSConstraint6Dof : BSConstraint public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2, Vector3 joinPoint, bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) + : base(world) { - m_world = world; m_body1 = obj1; m_body2 = obj2; if (!obj1.HasPhysicalBody || !obj2.HasPhysicalBody) @@ -76,11 +75,10 @@ public sealed class BSConstraint6Dof : BSConstraint } else { - m_constraint = new BulletConstraint( - BulletSimAPI.Create6DofConstraintToPoint2(m_world.ptr, m_body1.ptr, m_body2.ptr, + m_constraint = PhysicsScene.PE.Create6DofConstraintToPoint(m_world, m_body1, m_body2, joinPoint, - useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); - world.physicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}", + useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); + PhysicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}", BSScene.DetailLogZero, world.worldID, m_constraint.ptr.ToString("X"), obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); if (!m_constraint.HasPhysicalConstraint) @@ -101,7 +99,7 @@ public sealed class BSConstraint6Dof : BSConstraint bool ret = false; if (m_enabled) { - BulletSimAPI.SetFrames2(m_constraint.ptr, frameA, frameArot, frameB, frameBrot); + PhysicsScene.PE.SetFrames(m_constraint, frameA, frameArot, frameB, frameBrot); ret = true; } return ret; @@ -112,9 +110,9 @@ public sealed class BSConstraint6Dof : BSConstraint bool ret = false; if (m_enabled) { - BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL); - BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL); - BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL); + PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL); + PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL); + PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL); ret = true; } return ret; @@ -125,7 +123,7 @@ public sealed class BSConstraint6Dof : BSConstraint bool ret = false; float onOff = useOffset ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse; if (m_enabled) - ret = BulletSimAPI.UseFrameOffset2(m_constraint.ptr, onOff); + ret = PhysicsScene.PE.UseFrameOffset(m_constraint, onOff); return ret; } @@ -135,7 +133,7 @@ public sealed class BSConstraint6Dof : BSConstraint float onOff = enable ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse; if (m_enabled) { - ret = BulletSimAPI.TranslationalLimitMotor2(m_constraint.ptr, onOff, targetVelocity, maxMotorForce); + ret = PhysicsScene.PE.TranslationalLimitMotor(m_constraint, onOff, targetVelocity, maxMotorForce); m_world.physicsScene.DetailLog("{0},BS6DOFConstraint,TransLimitMotor,enable={1},vel={2},maxForce={3}", BSScene.DetailLogZero, enable, targetVelocity, maxMotorForce); } @@ -146,7 +144,7 @@ public sealed class BSConstraint6Dof : BSConstraint { bool ret = false; if (m_enabled) - ret = BulletSimAPI.SetBreakingImpulseThreshold2(m_constraint.ptr, threshold); + ret = PhysicsScene.PE.SetBreakingImpulseThreshold(m_constraint, threshold); return ret; } } 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 Vector3 pivotInA, Vector3 pivotInB, Vector3 axisInA, Vector3 axisInB, bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) + : base(world) { - m_world = world; m_body1 = obj1; m_body2 = obj2; - m_constraint = new BulletConstraint( - BulletSimAPI.CreateHingeConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr, - pivotInA, pivotInB, - axisInA, axisInB, - useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); + m_constraint = PhysicsScene.PE.CreateHingeConstraint(world, obj1, obj2, + pivotInA, pivotInB, axisInA, axisInB, + useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); m_enabled = true; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 0bdfbe3..5d70ef7 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -558,7 +558,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Friction affects are handled by this vehicle code float friction = 0f; - BulletSimAPI.SetFriction2(Prim.PhysBody.ptr, friction); + PhysicsScene.PE.SetFriction(Prim.PhysBody, friction); // Moderate angular movement introduced by Bullet. // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. @@ -567,7 +567,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping); // Vehicles report collision events so we know when it's on the ground - BulletSimAPI.AddToCollisionFlags2(Prim.PhysBody.ptr, CollisionFlags.BS_VEHICLE_COLLISIONS); + PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(Prim.PhysShape.ptr, m_vehicleMass); BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia); @@ -581,7 +581,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin } else { - BulletSimAPI.RemoveFromCollisionFlags2(Prim.PhysBody.ptr, CollisionFlags.BS_VEHICLE_COLLISIONS); + PhysicsScene.PE.RemoveFromCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); } } @@ -651,7 +651,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin if ((m_knownChanged & m_knownChangedVelocity) != 0) { Prim.ForceVelocity = m_knownVelocity; - BulletSimAPI.SetInterpolationLinearVelocity2(Prim.PhysBody.ptr, VehicleVelocity); + PhysicsScene.PE.SetInterpolationLinearVelocity(Prim.PhysBody, VehicleVelocity); } if ((m_knownChanged & m_knownChangedForce) != 0) @@ -661,7 +661,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin { Prim.ForceRotationalVelocity = m_knownRotationalVelocity; // Fake out Bullet by making it think the velocity is the same as last time. - BulletSimAPI.SetInterpolationAngularVelocity2(Prim.PhysBody.ptr, m_knownRotationalVelocity); + PhysicsScene.PE.SetInterpolationAngularVelocity(Prim.PhysBody, m_knownRotationalVelocity); } if ((m_knownChanged & m_knownChangedRotationalForce) != 0) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 9bb951c..3c99ca7 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -131,10 +131,10 @@ public sealed class BSLinksetCompound : BSLinkset { // The origional prims are removed from the world as the shape of the root compound // shape takes over. - BulletSimAPI.AddToCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); - BulletSimAPI.ForceActivationState2(child.PhysBody.ptr, ActivationState.DISABLE_SIMULATION); + PhysicsScene.PE.AddToCollisionFlags(child.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); + PhysicsScene.PE.ForceActivationState(child.PhysBody, ActivationState.DISABLE_SIMULATION); // We don't want collisions from the old linkset children. - BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); + PhysicsScene.PE.RemoveFromCollisionFlags(child.PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); child.PhysBody.collisionType = CollisionType.LinksetChild; @@ -159,12 +159,12 @@ public sealed class BSLinksetCompound : BSLinkset else { // The non-physical children can come back to life. - BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); + PhysicsScene.PE.RemoveFromCollisionFlags(child.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); child.PhysBody.collisionType = CollisionType.LinksetChild; // Don't force activation so setting of DISABLE_SIMULATION can stay if used. - BulletSimAPI.Activate2(child.PhysBody.ptr, false); + PhysicsScene.PE.Activate(child.PhysBody, false); ret = true; } return ret; @@ -371,7 +371,7 @@ public sealed class BSLinksetCompound : BSLinkset PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); } - PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot); + PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot); } } return false; // 'false' says to move onto the next child in the list diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 5c8553a..c6c2946 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -300,7 +300,7 @@ public static class BSParam (s,cf,p,v) => { DeactivationTime = cf.GetFloat(p, v); }, (s) => { return DeactivationTime; }, (s,p,l,v) => { s.UpdateParameterObject((x)=>{DeactivationTime=x;}, p, l, v); }, - (s,o,v) => { BulletSimAPI.SetDeactivationTime2(o.PhysBody.ptr, v); } ), + (s,o,v) => { s.PE.SetDeactivationTime(o.PhysBody, v); } ), new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static", 0.8f, (s,cf,p,v) => { LinearSleepingThreshold = cf.GetFloat(p, v); }, @@ -318,19 +318,19 @@ public static class BSParam (s,cf,p,v) => { CcdMotionThreshold = cf.GetFloat(p, v); }, (s) => { return CcdMotionThreshold; }, (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdMotionThreshold=x;}, p, l, v); }, - (s,o,v) => { BulletSimAPI.SetCcdMotionThreshold2(o.PhysBody.ptr, v); } ), + (s,o,v) => { s.PE.SetCcdMotionThreshold(o.PhysBody, v); } ), new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" , 0f, (s,cf,p,v) => { CcdSweptSphereRadius = cf.GetFloat(p, v); }, (s) => { return CcdSweptSphereRadius; }, (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdSweptSphereRadius=x;}, p, l, v); }, - (s,o,v) => { BulletSimAPI.SetCcdSweptSphereRadius2(o.PhysBody.ptr, v); } ), + (s,o,v) => { s.PE.SetCcdSweptSphereRadius(o.PhysBody, v); } ), new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" , 0.1f, (s,cf,p,v) => { ContactProcessingThreshold = cf.GetFloat(p, v); }, (s) => { return ContactProcessingThreshold; }, (s,p,l,v) => { s.UpdateParameterObject((x)=>{ContactProcessingThreshold=x;}, p, l, v); }, - (s,o,v) => { BulletSimAPI.SetContactProcessingThreshold2(o.PhysBody.ptr, v); } ), + (s,o,v) => { s.PE.SetContactProcessingThreshold(o.PhysBody, v); } ), new ParameterDefn("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)", (float)BSTerrainPhys.TerrainImplementation.Mesh, diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index b093890..e7cb3e0 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -308,7 +308,7 @@ public abstract class BSPhysObject : PhysicsActor PhysicsScene.TaintedObject(TypeName+".SubscribeEvents", delegate() { if (PhysBody.HasPhysicalBody) - CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); + CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); }); } else @@ -324,7 +324,7 @@ public abstract class BSPhysObject : PhysicsActor { // Make sure there is a body there because sometimes destruction happens in an un-ideal order. if (PhysBody.HasPhysicalBody) - CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); + CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); }); } // Return 'true' if the simulator wants collision events diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index cf09be2..613606f 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -120,7 +120,7 @@ public sealed class BSPrim : BSPhysObject { CreateGeomAndObject(true); - CurrentCollisionFlags = BulletSimAPI.GetCollisionFlags2(PhysBody.ptr); + CurrentCollisionFlags = PhysicsScene.PE.GetCollisionFlags(PhysBody); }); } @@ -265,7 +265,7 @@ public sealed class BSPrim : BSPhysObject // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity); if (PhysBody.HasPhysicalBody) { - BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, _rotationalVelocity); + PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); } }); @@ -318,14 +318,14 @@ public sealed class BSPrim : BSPhysObject } public override OMV.Vector3 ForcePosition { get { - _position = BulletSimAPI.GetPosition2(PhysBody.ptr); + _position = PhysicsScene.PE.GetPosition(PhysBody); return _position; } set { _position = value; if (PhysBody.HasPhysicalBody) { - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); ActivateIfPhysical(false); } } @@ -419,7 +419,7 @@ public sealed class BSPrim : BSPhysObject // Changing interesting properties doesn't change proxy and collision cache // information. The Bullet solution is to re-add the object to the world // after parameters are changed. - BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); + PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody); } // The computation of mass props requires gravity to be set on the object. @@ -649,9 +649,9 @@ public sealed class BSPrim : BSPhysObject { if (PhysBody.HasPhysicalBody) { - // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); + // _position = PhysicsScene.PE.GetObjectPosition(PhysicsScene.World, BSBody); // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); } }); } @@ -661,13 +661,13 @@ public sealed class BSPrim : BSPhysObject { get { - _orientation = BulletSimAPI.GetOrientation2(PhysBody.ptr); + _orientation = PhysicsScene.PE.GetOrientation(PhysBody); return _orientation; } set { _orientation = value; - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); } } public override int PhysicsActorType { @@ -723,7 +723,7 @@ public sealed class BSPrim : BSPhysObject // Mangling all the physical properties requires the object not be in the physical world. // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). - BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); + PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody); // Set up the object physicalness (does gravity and collisions move this object) MakeDynamic(IsStatic); @@ -740,7 +740,7 @@ public sealed class BSPrim : BSPhysObject AddObjectToPhysicalWorld(); // Rebuild its shape - BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); + PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody); // Recompute any linkset parameters. // When going from non-physical to physical, this re-enables the constraints that @@ -762,28 +762,28 @@ public sealed class BSPrim : BSPhysObject if (makeStatic) { // Become a Bullet 'static' object type - CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT); + CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); // Stop all movement ZeroMotion(true); // Set various physical properties so other object interact properly MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); - BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction); - BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); + PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction); + PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution); // Mass is zero which disables a bunch of physics stuff in Bullet UpdatePhysicalMassProperties(0f, false); // Set collision detection parameters if (BSParam.CcdMotionThreshold > 0f) { - BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold); - BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius); + PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); + PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); } // The activation state is 'disabled' so Bullet will not try to act on it. - // BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_SIMULATION); + // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_SIMULATION); // Start it out sleeping and physical actions could wake it up. - BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ISLAND_SLEEPING); + PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ISLAND_SLEEPING); // This collides like a static object PhysBody.collisionType = CollisionType.Static; @@ -794,22 +794,22 @@ public sealed class BSPrim : BSPhysObject else { // Not a Bullet static object - CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT); + CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); // Set various physical properties so other object interact properly MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true); - BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction); - BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); + PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction); + PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution); // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 // Since this can be called multiple times, only zero forces when becoming physical - // BulletSimAPI.ClearAllForces2(BSBody.ptr); + // PhysicsScene.PE.ClearAllForces(BSBody); // For good measure, make sure the transform is set through to the motion state - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); // Center of mass is at the center of the object - // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); + // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody, _position, _orientation); // A dynamic object has mass UpdatePhysicalMassProperties(RawMass, false); @@ -817,22 +817,22 @@ public sealed class BSPrim : BSPhysObject // Set collision detection parameters if (BSParam.CcdMotionThreshold > 0f) { - BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold); - BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius); + PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold); + PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius); } // Various values for simulation limits BulletSimAPI.SetDamping2(PhysBody.ptr, BSParam.LinearDamping, BSParam.AngularDamping); - BulletSimAPI.SetDeactivationTime2(PhysBody.ptr, BSParam.DeactivationTime); + PhysicsScene.PE.SetDeactivationTime(PhysBody, BSParam.DeactivationTime); BulletSimAPI.SetSleepingThresholds2(PhysBody.ptr, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold); - BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, BSParam.ContactProcessingThreshold); + PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold); // This collides like an object. PhysBody.collisionType = CollisionType.Dynamic; // Force activation of the object so Bullet will act on it. // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects. - BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ACTIVE_TAG); + PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG); // There might be special things needed for implementing linksets. Linkset.MakeDynamic(this); @@ -853,7 +853,7 @@ public sealed class BSPrim : BSPhysObject { m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for solidity. id={1}, type={2}", LogHeader, LocalID, bodyType); } - CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); + CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); } else { @@ -861,7 +861,7 @@ public sealed class BSPrim : BSPhysObject { m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); } - CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); + CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE); // Change collision info from a static object to a ghosty collision object PhysBody.collisionType = CollisionType.VolumeDetect; @@ -874,7 +874,7 @@ public sealed class BSPrim : BSPhysObject private void ActivateIfPhysical(bool forceIt) { if (IsPhysical && PhysBody.HasPhysicalBody) - BulletSimAPI.Activate2(PhysBody.ptr, forceIt); + PhysicsScene.PE.Activate(PhysBody, forceIt); } // Turn on or off the flag controlling whether collision events are returned to the simulator. @@ -882,11 +882,11 @@ public sealed class BSPrim : BSPhysObject { if (wantsCollisionEvents) { - CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); + CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); } else { - CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); + CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); } } @@ -897,7 +897,7 @@ public sealed class BSPrim : BSPhysObject { if (PhysBody.HasPhysicalBody) { - BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); + PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); // TODO: Fix this. Total kludge because adding object to world resets its gravity to default. // Replace this when the new AddObjectToWorld function is complete. @@ -941,9 +941,9 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject("BSPrim.setFloatOnWater", delegate() { if (_floatOnWater) - CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); + CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); else - CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); + CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER); }); } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index e7d8d14..6f819d8 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -143,7 +143,7 @@ public sealed class BSShapeCollection : IDisposable { if (!BulletSimAPI.IsInWorld2(body.ptr)) { - BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, body.ptr); + PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, body); if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body); } }); @@ -168,12 +168,12 @@ public sealed class BSShapeCollection : IDisposable if (BulletSimAPI.IsInWorld2(body.ptr)) { - BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr); + PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, body); if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body); } // Zero any reference to the shape so it is not freed when the body is deleted. - BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero); + PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, new BulletShape()); PhysicsScene.PE.DestroyObject(PhysicsScene.World, body); }); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index a2c085e..01966c0 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs @@ -91,13 +91,12 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys // Using the information in m_mapInfo, create the physical representation of the heightmap. private void BuildHeightmapTerrain() { - m_mapInfo.Ptr = BulletSimAPI.CreateHeightMapInfo2(PhysicsScene.World.ptr, m_mapInfo.ID, + m_mapInfo.Ptr = PhysicsScene.PE.CreateHeightMapInfo(PhysicsScene.World, m_mapInfo.ID, m_mapInfo.minCoords, m_mapInfo.maxCoords, m_mapInfo.heightMap, BSParam.TerrainCollisionMargin); // Create the terrain shape from the mapInfo - m_mapInfo.terrainShape = new BulletShape(BulletSimAPI.CreateTerrainShape2(m_mapInfo.Ptr), - BSPhysicsShapeType.SHAPE_TERRAIN); + m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape(m_mapInfo.Ptr); // The terrain object initial position is at the center of the object Vector3 centerPos; @@ -109,22 +108,22 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys m_mapInfo.ID, centerPos, Quaternion.Identity); // Set current terrain attributes - BulletSimAPI.SetFriction2(m_mapInfo.terrainBody.ptr, BSParam.TerrainFriction); - BulletSimAPI.SetHitFraction2(m_mapInfo.terrainBody.ptr, BSParam.TerrainHitFraction); - BulletSimAPI.SetRestitution2(m_mapInfo.terrainBody.ptr, BSParam.TerrainRestitution); - BulletSimAPI.SetCollisionFlags2(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); + PhysicsScene.PE.SetFriction(m_mapInfo.terrainBody, BSParam.TerrainFriction); + PhysicsScene.PE.SetHitFraction(m_mapInfo.terrainBody, BSParam.TerrainHitFraction); + PhysicsScene.PE.SetRestitution(m_mapInfo.terrainBody, BSParam.TerrainRestitution); + PhysicsScene.PE.SetCollisionFlags(m_mapInfo.terrainBody, CollisionFlags.CF_STATIC_OBJECT); // Return the new terrain to the world of physical objects - BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); + PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_mapInfo.terrainBody); // redo its bounding box now that it is in the world - BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); + PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_mapInfo.terrainBody); m_mapInfo.terrainBody.collisionType = CollisionType.Terrain; m_mapInfo.terrainBody.ApplyCollisionMask(); // Make it so the terrain will not move or be considered for movement. - BulletSimAPI.ForceActivationState2(m_mapInfo.terrainBody.ptr, ActivationState.DISABLE_SIMULATION); + PhysicsScene.PE.ForceActivationState(m_mapInfo.terrainBody, ActivationState.DISABLE_SIMULATION); return; } @@ -136,10 +135,10 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys { if (m_mapInfo.terrainBody.HasPhysicalBody) { - BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); + PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_mapInfo.terrainBody); // Frees both the body and the shape. PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody); - BulletSimAPI.ReleaseHeightMapInfo2(m_mapInfo.Ptr); + PhysicsScene.PE.ReleaseHeightMapInfo(m_mapInfo.Ptr); } } m_mapInfo = null; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index d99a50f..590c687 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs @@ -133,17 +133,14 @@ public sealed class BSTerrainManager : IDisposable public void CreateInitialGroundPlaneAndTerrain() { // The ground plane is here to catch things that are trying to drop to negative infinity - BulletShape groundPlaneShape = new BulletShape( - BulletSimAPI.CreateGroundPlaneShape2(BSScene.GROUNDPLANE_ID, 1f, - BSParam.TerrainCollisionMargin), - BSPhysicsShapeType.SHAPE_GROUNDPLANE); + BulletShape groundPlaneShape = PhysicsScene.PE.CreateGroundPlaneShape(BSScene.GROUNDPLANE_ID, 1f, BSParam.TerrainCollisionMargin); m_groundPlane = PhysicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape, BSScene.GROUNDPLANE_ID, Vector3.Zero, Quaternion.Identity); - BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr); - BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_groundPlane.ptr); + PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_groundPlane); + PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_groundPlane); // Ground plane does not move - BulletSimAPI.ForceActivationState2(m_groundPlane.ptr, ActivationState.DISABLE_SIMULATION); + PhysicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION); // Everything collides with the ground plane. m_groundPlane.collisionType = CollisionType.Groundplane; m_groundPlane.ApplyCollisionMask(); @@ -158,7 +155,7 @@ public sealed class BSTerrainManager : IDisposable { if (m_groundPlane.HasPhysicalBody) { - if (BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr)) + if (PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_groundPlane)) { PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_groundPlane); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs index d8c4972..2f55fc3 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs @@ -114,32 +114,32 @@ public sealed class BSTerrainMesh : BSTerrainPhys } // Set current terrain attributes - BulletSimAPI.SetFriction2(m_terrainBody.ptr, BSParam.TerrainFriction); - BulletSimAPI.SetHitFraction2(m_terrainBody.ptr, BSParam.TerrainHitFraction); - BulletSimAPI.SetRestitution2(m_terrainBody.ptr, BSParam.TerrainRestitution); - BulletSimAPI.SetCollisionFlags2(m_terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); + PhysicsScene.PE.SetFriction(m_terrainBody, BSParam.TerrainFriction); + PhysicsScene.PE.SetHitFraction(m_terrainBody, BSParam.TerrainHitFraction); + PhysicsScene.PE.SetRestitution(m_terrainBody, BSParam.TerrainRestitution); + PhysicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT); // Static objects are not very massive. BulletSimAPI.SetMassProps2(m_terrainBody.ptr, 0f, Vector3.Zero); // Put the new terrain to the world of physical objects - BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); + PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_terrainBody); // Redo its bounding box now that it is in the world - BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_terrainBody.ptr); + PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_terrainBody); m_terrainBody.collisionType = CollisionType.Terrain; m_terrainBody.ApplyCollisionMask(); // Make it so the terrain will not move or be considered for movement. - BulletSimAPI.ForceActivationState2(m_terrainBody.ptr, ActivationState.DISABLE_SIMULATION); + PhysicsScene.PE.ForceActivationState(m_terrainBody, ActivationState.DISABLE_SIMULATION); } public override void Dispose() { if (m_terrainBody.HasPhysicalBody) { - BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); + PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_terrainBody); // Frees both the body and the shape. PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_terrainBody); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index 6b76151..b119f22 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs @@ -367,7 +367,6 @@ public abstract void ReleaseBodyInfo(IntPtr obj); public abstract void DestroyObject(BulletWorld sim, BulletBody obj); - /* // ===================================================================================== // Terrain creation and helper routines public abstract IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords, @@ -378,9 +377,9 @@ public abstract IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint i public abstract bool ReleaseHeightMapInfo(IntPtr heightMapInfo); -public abstract BulletBody CreateGroundPlaneShape(uint id, float height, float collisionMargin); +public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin); -public abstract BulletBody CreateTerrainShape(IntPtr mapInfo); +public abstract BulletShape CreateTerrainShape(IntPtr mapInfo); // ===================================================================================== // Constraint creation and helper routines @@ -460,7 +459,7 @@ public abstract bool IsStaticOrKinematicObject(BulletBody obj); public abstract bool HasContactResponse(BulletBody obj); -public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletBody shape); +public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape); public abstract BulletShape GetCollisionShape(BulletBody obj); @@ -526,6 +525,7 @@ public abstract IntPtr GetUserPointer(BulletBody obj); public abstract void SetUserPointer(BulletBody obj, IntPtr val); + /* // ===================================================================================== // btRigidBody entries public abstract void ApplyGravity(BulletBody obj); -- cgit v1.1 From 5379d6d112a8027c8f0f62ba77303e8b69e24332 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 30 Dec 2012 10:37:37 -0800 Subject: BulletSim: remove all the debug printing of pointer formatting (.ToString(X)) and replace it with a method on BulletBody, BulletShape, ... --- .../Region/Physics/BulletSPlugin/BSConstraint.cs | 4 +-- .../Physics/BulletSPlugin/BSConstraint6Dof.cs | 10 +++---- .../Physics/BulletSPlugin/BSLinksetCompound.cs | 6 ++--- .../Physics/BulletSPlugin/BSLinksetConstraints.cs | 16 +++++------ .../Physics/BulletSPlugin/BSShapeCollection.cs | 8 +++--- OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | 8 +++++- .../Region/Physics/BulletSPlugin/BulletSimData.cs | 31 ++++++++++++++++++++-- 7 files changed, 58 insertions(+), 25 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs index c9c7c2e..b813974 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs @@ -65,8 +65,8 @@ public abstract class BSConstraint : IDisposable bool success = PhysicsScene.PE.DestroyConstraint(m_world, m_constraint); m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}", BSScene.DetailLogZero, - m_body1.ID, m_body1.ptr.ToString("X"), - m_body2.ID, m_body2.ptr.ToString("X"), + m_body1.ID, m_body1.AddrString, + m_body2.ID, m_body2.AddrString, success); m_constraint.Clear(); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs index aee93c9..ecb1b32 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs @@ -54,7 +54,7 @@ public sealed class BSConstraint6Dof : BSConstraint m_enabled = true; world.physicsScene.DetailLog("{0},BS6DofConstraint,createFrame,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", BSScene.DetailLogZero, world.worldID, - obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); + obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); } public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2, @@ -68,9 +68,9 @@ public sealed class BSConstraint6Dof : BSConstraint { world.physicsScene.DetailLog("{0},BS6DOFConstraint,badBodyPtr,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", BSScene.DetailLogZero, world.worldID, - obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); + obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); world.physicsScene.Logger.ErrorFormat("{0} Attempt to build 6DOF constraint with missing bodies: wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", - LogHeader, world.worldID, obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); + LogHeader, world.worldID, obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); m_enabled = false; } else @@ -79,8 +79,8 @@ public sealed class BSConstraint6Dof : BSConstraint joinPoint, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); PhysicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}", - BSScene.DetailLogZero, world.worldID, m_constraint.ptr.ToString("X"), - obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X")); + BSScene.DetailLogZero, world.worldID, m_constraint.AddrString, + obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString); if (!m_constraint.HasPhysicalConstraint) { world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}", diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 3c99ca7..143c60c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -196,7 +196,7 @@ public sealed class BSLinksetCompound : BSLinkset bool ret = false; DetailLog("{0},BSLinksetCompound.RemoveBodyDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}", - child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), IsRoot(child)); + child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, IsRoot(child)); if (!IsRoot(child)) { @@ -280,8 +280,8 @@ public sealed class BSLinksetCompound : BSLinkset { DetailLog("{0},BSLinksetCompound.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}", child.LocalID, - LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), - child.LocalID, child.PhysBody.ptr.ToString("X")); + LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, + child.LocalID, child.PhysBody.AddrString); // Cause the child's body to be rebuilt and thus restored to normal operation RecomputeChildWorldPosition(child, false); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs index 86c29c7..629bc72 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs @@ -98,7 +98,7 @@ public sealed class BSLinksetConstraints : BSLinkset bool ret = false; DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}", - child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X")); + child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString); lock (m_linksetActivityLock) { @@ -147,8 +147,8 @@ public sealed class BSLinksetConstraints : BSLinkset DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}", childx.LocalID, - rootx.LocalID, rootx.PhysBody.ptr.ToString("X"), - childx.LocalID, childx.PhysBody.ptr.ToString("X")); + rootx.LocalID, rootx.PhysBody.AddrString, + childx.LocalID, childx.PhysBody.AddrString); PhysicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate() { @@ -187,8 +187,8 @@ public sealed class BSLinksetConstraints : BSLinkset DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}", rootPrim.LocalID, - rootPrim.LocalID, rootPrim.PhysBody.ptr.ToString("X"), - childPrim.LocalID, childPrim.PhysBody.ptr.ToString("X"), + rootPrim.LocalID, rootPrim.PhysBody.AddrString, + childPrim.LocalID, childPrim.PhysBody.AddrString, rootPrim.Position, childPrim.Position, midPoint); // create a constraint that allows no freedom of movement between the two objects @@ -252,8 +252,8 @@ public sealed class BSLinksetConstraints : BSLinkset bool ret = false; DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}", rootPrim.LocalID, - rootPrim.LocalID, rootPrim.PhysBody.ptr.ToString("X"), - childPrim.LocalID, childPrim.PhysBody.ptr.ToString("X")); + rootPrim.LocalID, rootPrim.PhysBody.AddrString, + childPrim.LocalID, childPrim.PhysBody.AddrString); // Find the constraint for this link and get rid of it from the overall collection and from my list if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody)) @@ -290,7 +290,7 @@ public sealed class BSLinksetConstraints : BSLinkset // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr, // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask); DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}", - LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), linksetMass); + LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, linksetMass); foreach (BSPhysObject child in m_children) { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 6f819d8..d59e455 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -259,7 +259,7 @@ public sealed class BSShapeCollection : IDisposable { // Native shapes are not tracked and are released immediately if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}", - BSScene.DetailLogZero, shape.ptr.ToString("X"), inTaintTime); + BSScene.DetailLogZero, shape.AddrString, inTaintTime); if (shapeCallback != null) shapeCallback(shape); PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape); } @@ -336,9 +336,9 @@ public sealed class BSShapeCollection : IDisposable { // Failed the sanity check!! PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", - LogHeader, shape.type, shape.ptr.ToString("X")); + LogHeader, shape.type, shape.AddrString); if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", - BSScene.DetailLogZero, shape.type, shape.ptr.ToString("X")); + BSScene.DetailLogZero, shape.type, shape.AddrString); return; } @@ -400,7 +400,7 @@ public sealed class BSShapeCollection : IDisposable else { PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}", - LogHeader, PhysicsScene.RegionName, cShape.ToString("X")); + LogHeader, PhysicsScene.RegionName, shapeInfo.AddrString); } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs index cdaa869..423e700 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs @@ -91,11 +91,17 @@ public abstract class BSShape // All shapes have a static call to get a reference to the physical shape // protected abstract static BSShape GetReference(); + // Returns a string for debugging that uniquily identifies the memory used by this instance + public string AddrString + { + get { return ptr.ToString("X"); } + } + public override string ToString() { StringBuilder buff = new StringBuilder(); buff.Append(""); @@ -124,11 +133,20 @@ public class BulletShape } public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } } + // Used for log messages for a unique display of the memory/object allocated to this instance + public string AddrString + { + get + { + return ptr.ToString("X"); + } + } + public override string ToString() { StringBuilder buff = new StringBuilder(); buff.Append(" 0f) { @@ -165,19 +165,19 @@ public sealed class BSCharacter : BSPhysObject UpdatePhysicalMassProperties(RawMass, false); // Make so capsule does not fall over - BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero); + PhysicsScene.PE.SetAngularFactorV(PhysBody, OMV.Vector3.Zero); PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_CHARACTER_OBJECT); PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); - // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG); + // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG); PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_DEACTIVATION); PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody); // Do this after the object has been added to the world PhysBody.collisionType = CollisionType.Avatar; - PhysBody.ApplyCollisionMask(); + PhysBody.ApplyCollisionMask(PhysicsScene); } // The avatar's movement is controlled by this motor that speeds up and slows down @@ -265,10 +265,10 @@ public sealed class BSCharacter : BSPhysObject { if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape) { - BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); + PhysicsScene.PE.SetLocalScaling(PhysShape, Scale); UpdatePhysicalMassProperties(RawMass, true); // Make sure this change appears as a property update event - BulletSimAPI.PushUpdate2(PhysBody.ptr); + PhysicsScene.PE.PushUpdate(PhysBody); } }); @@ -309,7 +309,7 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate() { if (PhysBody.HasPhysicalBody) - BulletSimAPI.ClearAllForces2(PhysBody.ptr); + PhysicsScene.PE.ClearAllForces(PhysBody); }); } public override void ZeroAngularMotion(bool inTaintTime) @@ -321,9 +321,9 @@ public sealed class BSCharacter : BSPhysObject if (PhysBody.HasPhysicalBody) { PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, OMV.Vector3.Zero); - BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero); + PhysicsScene.PE.SetAngularVelocity(PhysBody, OMV.Vector3.Zero); // The next also get rid of applied linear force but the linear velocity is untouched. - BulletSimAPI.ClearForces2(PhysBody.ptr); + PhysicsScene.PE.ClearForces(PhysBody); } }); } @@ -339,7 +339,7 @@ public sealed class BSCharacter : BSPhysObject public override OMV.Vector3 Position { get { // Don't refetch the position because this function is called a zillion times - // _position = BulletSimAPI.GetObjectPosition2(Scene.World.ptr, LocalID); + // _position = PhysicsScene.PE.GetObjectPosition(Scene.World, LocalID); return _position; } set { @@ -433,8 +433,8 @@ public sealed class BSCharacter : BSPhysObject } public override void UpdatePhysicalMassProperties(float physMass, bool inWorld) { - OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); - BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, localInertia); + OMV.Vector3 localInertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass); + PhysicsScene.PE.SetMassProps(PhysBody, physMass, localInertia); } public override OMV.Vector3 Force { @@ -446,7 +446,7 @@ public sealed class BSCharacter : BSPhysObject { DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); if (PhysBody.HasPhysicalBody) - BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); + PhysicsScene.PE.SetObjectForce(PhysBody, _force); }); } } @@ -533,7 +533,7 @@ public sealed class BSCharacter : BSPhysObject } } - BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); + PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity); PhysicsScene.PE.Activate(PhysBody, true); } } @@ -676,7 +676,7 @@ public sealed class BSCharacter : BSPhysObject // Buoyancy is faked by changing the gravity applied to the object float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); if (PhysBody.HasPhysicalBody) - BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); + PhysicsScene.PE.SetGravity(PhysBody, new OMV.Vector3(0f, 0f, grav)); } } @@ -737,7 +737,7 @@ public sealed class BSCharacter : BSPhysObject // DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce); if (PhysBody.HasPhysicalBody) { - BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce); + PhysicsScene.PE.ApplyCentralForce(PhysBody, addForce); } }); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 5d70ef7..e4e3edc 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -564,17 +564,17 @@ namespace OpenSim.Region.Physics.BulletSPlugin // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. // Maybe compute linear and angular factor and damping from params. float angularDamping = BSParam.VehicleAngularDamping; - BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping); + PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, angularDamping); // Vehicles report collision events so we know when it's on the ground PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); - Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(Prim.PhysShape.ptr, m_vehicleMass); - BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia); - BulletSimAPI.UpdateInertiaTensor2(Prim.PhysBody.ptr); + Vector3 localInertia = PhysicsScene.PE.CalculateLocalInertia(Prim.PhysShape, m_vehicleMass); + PhysicsScene.PE.SetMassProps(Prim.PhysBody, m_vehicleMass, localInertia); + PhysicsScene.PE.UpdateInertiaTensor(Prim.PhysBody); Vector3 grav = PhysicsScene.DefaultGravity * (1f - Prim.Buoyancy); - BulletSimAPI.SetGravity2(Prim.PhysBody.ptr, grav); + PhysicsScene.PE.SetGravity(Prim.PhysBody, grav); VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4}", Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping); @@ -669,7 +669,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // If we set one of the values (ie, the physics engine didn't do it) we must force // an UpdateProperties event to send the changes up to the simulator. - BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr); + PhysicsScene.PE.PushUpdate(Prim.PhysBody); } m_knownChanged = 0; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 143c60c..bd03d31 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -387,11 +387,6 @@ public sealed class BSLinksetCompound : BSLinkset } PhysicsScene.PE.RecalculateCompoundShapeLocalAabb(LinksetRoot.PhysShape); - - // DEBUG: see of inter-linkset collisions are causing problems for constraint linksets. - // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr, - // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask); - } } } \ No newline at end of file diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs index 629bc72..d0b2a56 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs @@ -259,7 +259,7 @@ public sealed class BSLinksetConstraints : BSLinkset if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody)) { // Make the child refresh its location - BulletSimAPI.PushUpdate2(childPrim.PhysBody.ptr); + PhysicsScene.PE.PushUpdate(childPrim.PhysBody); ret = true; } @@ -286,9 +286,6 @@ public sealed class BSLinksetConstraints : BSLinkset float linksetMass = LinksetMass; LinksetRoot.UpdatePhysicalMassProperties(linksetMass, true); - // DEBUG: see of inter-linkset collisions are causing problems - // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr, - // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask); DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}", LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, linksetMass); @@ -307,11 +304,7 @@ public sealed class BSLinksetConstraints : BSLinkset } constrain.RecomputeConstraintVariables(linksetMass); - // DEBUG: see of inter-linkset collisions are causing problems - // BulletSimAPI.SetCollisionFilterMask2(child.BSBody.ptr, - // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask); - - // BulletSimAPI.DumpConstraint2(PhysicsScene.World.ptr, constrain.Constraint.ptr); // DEBUG DEBUG + // PhysicsScene.PE.DumpConstraint(PhysicsScene.World, constrain.Constraint); // DEBUG DEBUG } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index c6c2946..339722e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -280,7 +280,7 @@ public static class BSParam (s,cf,p,v) => { s.UnmanagedParams[0].gravity = cf.GetFloat(p, v); }, (s) => { return s.UnmanagedParams[0].gravity; }, (s,p,l,v) => { s.UpdateParameterObject((x)=>{s.UnmanagedParams[0].gravity=x;}, p, PhysParameterEntry.APPLY_TO_NONE, v); }, - (s,o,v) => { BulletSimAPI.SetGravity2(s.World.ptr, new Vector3(0f,0f,v)); } ), + (s,o,v) => { s.PE.SetGravity(o.PhysBody, new Vector3(0f,0f,v)); } ), new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)", @@ -288,13 +288,13 @@ public static class BSParam (s,cf,p,v) => { LinearDamping = cf.GetFloat(p, v); }, (s) => { return LinearDamping; }, (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearDamping=x;}, p, l, v); }, - (s,o,v) => { BulletSimAPI.SetDamping2(o.PhysBody.ptr, v, AngularDamping); } ), + (s,o,v) => { s.PE.SetDamping(o.PhysBody, v, AngularDamping); } ), new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)", 0f, (s,cf,p,v) => { AngularDamping = cf.GetFloat(p, v); }, (s) => { return AngularDamping; }, (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularDamping=x;}, p, l, v); }, - (s,o,v) => { BulletSimAPI.SetDamping2(o.PhysBody.ptr, LinearDamping, v); } ), + (s,o,v) => { s.PE.SetDamping(o.PhysBody, LinearDamping, v); } ), new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static", 0.2f, (s,cf,p,v) => { DeactivationTime = cf.GetFloat(p, v); }, @@ -306,13 +306,13 @@ public static class BSParam (s,cf,p,v) => { LinearSleepingThreshold = cf.GetFloat(p, v); }, (s) => { return LinearSleepingThreshold; }, (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearSleepingThreshold=x;}, p, l, v); }, - (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.PhysBody.ptr, v, v); } ), + (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ), new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static", 1.0f, (s,cf,p,v) => { AngularSleepingThreshold = cf.GetFloat(p, v); }, (s) => { return AngularSleepingThreshold; }, (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularSleepingThreshold=x;}, p, l, v); }, - (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.PhysBody.ptr, v, v); } ), + (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ), new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" , 0f, // set to zero to disable (s,cf,p,v) => { CcdMotionThreshold = cf.GetFloat(p, v); }, diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 613606f..064ce3c 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -253,7 +253,7 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() { if (PhysBody.HasPhysicalBody) - BulletSimAPI.ClearAllForces2(PhysBody.ptr); + PhysicsScene.PE.ClearAllForces(PhysBody); }); } public override void ZeroAngularMotion(bool inTaintTime) @@ -266,7 +266,7 @@ public sealed class BSPrim : BSPhysObject if (PhysBody.HasPhysicalBody) { PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); - BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); + PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); } }); } @@ -292,7 +292,7 @@ public sealed class BSPrim : BSPhysObject */ // don't do the GetObjectPosition for root elements because this function is called a zillion times. - // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); + // _position = PhysicsScene.PE.GetObjectPosition2(PhysicsScene.World, BSBody); return _position; } set { @@ -405,10 +405,10 @@ public sealed class BSPrim : BSPhysObject { if (IsStatic) { - BulletSimAPI.SetGravity2(PhysBody.ptr, PhysicsScene.DefaultGravity); + PhysicsScene.PE.SetGravity(PhysBody, PhysicsScene.DefaultGravity); Inertia = OMV.Vector3.Zero; - BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); - BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); + PhysicsScene.PE.SetMassProps(PhysBody, 0f, Inertia); + PhysicsScene.PE.UpdateInertiaTensor(PhysBody); } else { @@ -423,14 +423,14 @@ public sealed class BSPrim : BSPhysObject } // The computation of mass props requires gravity to be set on the object. - BulletSimAPI.SetGravity2(PhysBody.ptr, grav); + PhysicsScene.PE.SetGravity(PhysBody, grav); - Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); - BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); - BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); + Inertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass); + PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia); + PhysicsScene.PE.UpdateInertiaTensor(PhysBody); // center of mass is at the zero of the object - // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); + // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(PhysBody, ForcePosition, ForceOrientation); DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld); if (inWorld) @@ -440,7 +440,7 @@ public sealed class BSPrim : BSPhysObject // Must set gravity after it has been added to the world because, for unknown reasons, // adding the object resets the object's gravity to world gravity - BulletSimAPI.SetGravity2(PhysBody.ptr, grav); + PhysicsScene.PE.SetGravity(PhysBody, grav); } } @@ -483,7 +483,7 @@ public sealed class BSPrim : BSPhysObject DetailLog("{0},BSPrim.setForce,preStep,force={1}", LocalID, _force); if (PhysBody.HasPhysicalBody) { - BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, _force); + PhysicsScene.PE.ApplyCentralForce(PhysBody, _force); ActivateIfPhysical(false); } } @@ -583,7 +583,7 @@ public sealed class BSPrim : BSPhysObject _velocity = value; if (PhysBody.HasPhysicalBody) { - BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); + PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity); ActivateIfPhysical(false); } } @@ -809,7 +809,7 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); // Center of mass is at the center of the object - // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody, _position, _orientation); + // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(Linkset.LinksetRoot.PhysBody, _position, _orientation); // A dynamic object has mass UpdatePhysicalMassProperties(RawMass, false); @@ -822,9 +822,9 @@ public sealed class BSPrim : BSPhysObject } // Various values for simulation limits - BulletSimAPI.SetDamping2(PhysBody.ptr, BSParam.LinearDamping, BSParam.AngularDamping); + PhysicsScene.PE.SetDamping(PhysBody, BSParam.LinearDamping, BSParam.AngularDamping); PhysicsScene.PE.SetDeactivationTime(PhysBody, BSParam.DeactivationTime); - BulletSimAPI.SetSleepingThresholds2(PhysBody.ptr, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold); + PhysicsScene.PE.SetSleepingThresholds(PhysBody, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold); PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold); // This collides like an object. @@ -901,10 +901,10 @@ public sealed class BSPrim : BSPhysObject // TODO: Fix this. Total kludge because adding object to world resets its gravity to default. // Replace this when the new AddObjectToWorld function is complete. - BulletSimAPI.SetGravity2(PhysBody.ptr, ComputeGravity()); + PhysicsScene.PE.SetGravity(PhysBody, ComputeGravity()); // Collision filter can be set only when the object is in the world - if (!PhysBody.ApplyCollisionMask()) + if (!PhysBody.ApplyCollisionMask(PhysicsScene)) { m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID); DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType); @@ -969,7 +969,7 @@ public sealed class BSPrim : BSPhysObject _rotationalVelocity = value; if (PhysBody.HasPhysicalBody) { - BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); + PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); ActivateIfPhysical(false); } } @@ -1061,7 +1061,7 @@ public sealed class BSPrim : BSPhysObject DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce); if (PhysBody.HasPhysicalBody) { - BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce); + PhysicsScene.PE.ApplyCentralForce(PhysBody, addForce); ActivateIfPhysical(false); } }); @@ -1085,7 +1085,7 @@ public sealed class BSPrim : BSPhysObject { if (PhysBody.HasPhysicalBody) { - BulletSimAPI.ApplyTorque2(PhysBody.ptr, angForce); + PhysicsScene.PE.ApplyTorque(PhysBody, angForce); ActivateIfPhysical(false); } }); @@ -1108,7 +1108,7 @@ public sealed class BSPrim : BSPhysObject { if (PhysBody.HasPhysicalBody) { - BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse); + PhysicsScene.PE.ApplyTorqueImpulse(PhysBody, applyImpulse); ActivateIfPhysical(false); } }); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index bfc9df2..28c6680 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -51,7 +51,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters public string BulletSimVersion = "?"; // The handle to the underlying managed or unmanaged version of Bullet being used. - public BulletSimAPITemplate PE; + public BSAPITemplate PE; public Dictionary PhysObjects; public BSShapeCollection Shapes; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index d59e455..cd77581 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -141,7 +141,7 @@ public sealed class BSShapeCollection : IDisposable if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate() { - if (!BulletSimAPI.IsInWorld2(body.ptr)) + if (!PhysicsScene.PE.IsInWorld(body)) { PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, body); if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body); @@ -166,7 +166,7 @@ public sealed class BSShapeCollection : IDisposable // If the caller needs to know the old body is going away, pass the event up. if (bodyCallback != null) bodyCallback(body); - if (BulletSimAPI.IsInWorld2(body.ptr)) + if (PhysicsScene.PE.IsInWorld(body)) { PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, body); if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body); @@ -332,7 +332,7 @@ public sealed class BSShapeCollection : IDisposable // Called at taint-time. private void DereferenceCompound(BulletShape shape, ShapeDestructionCallback shapeCallback) { - if (!BulletSimAPI.IsCompound2(shape.ptr)) + if (!PhysicsScene.PE.IsCompound(shape)) { // Failed the sanity check!! PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", @@ -376,7 +376,7 @@ public sealed class BSShapeCollection : IDisposable } else { - if (BulletSimAPI.IsCompound2(cShape)) + if (PhysicsScene.PE.IsCompound(shapeInfo)) { shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND; } @@ -467,7 +467,7 @@ public sealed class BSShapeCollection : IDisposable // Get the scale of any existing shape so we can see if the new shape is same native type and same size. OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero; if (prim.PhysShape.HasPhysicalShape) - scaleOfExistingShape = BulletSimAPI.GetLocalScaling2(prim.PhysShape.ptr); + scaleOfExistingShape = PhysicsScene.PE.GetLocalScaling(prim.PhysShape); if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}", prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs index 423e700..c75eb9b 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs @@ -151,12 +151,12 @@ public class BSShapeNative : BSShape /* if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE) { - ptr = BulletSimAPI.BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale); + ptr = PhysicsScene.PE.BuildCapsuleShape(physicsScene.World, 1f, 1f, prim.Scale); physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale); } else { - ptr = BulletSimAPI.BuildNativeShape2(physicsScene.World.ptr, nativeShapeData); + ptr = PhysicsScene.PE.BuildNativeShape(physicsScene.World, nativeShapeData); } if (ptr == IntPtr.Zero) { @@ -173,7 +173,7 @@ public class BSShapeNative : BSShape /* // Native shapes are not tracked and are released immediately physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this); - BulletSimAPI.DeleteCollisionShape2(physicsScene.World.ptr, ptr); + PhysicsScene.PE.DeleteCollisionShape(physicsScene.World, this); ptr = IntPtr.Zero; // Garbage collection will free up this instance. */ diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index 01966c0..cc28344 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs @@ -120,7 +120,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_mapInfo.terrainBody); m_mapInfo.terrainBody.collisionType = CollisionType.Terrain; - m_mapInfo.terrainBody.ApplyCollisionMask(); + m_mapInfo.terrainBody.ApplyCollisionMask(PhysicsScene); // Make it so the terrain will not move or be considered for movement. PhysicsScene.PE.ForceActivationState(m_mapInfo.terrainBody, ActivationState.DISABLE_SIMULATION); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index 590c687..2e9db39 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs @@ -143,7 +143,7 @@ public sealed class BSTerrainManager : IDisposable PhysicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION); // Everything collides with the ground plane. m_groundPlane.collisionType = CollisionType.Groundplane; - m_groundPlane.ApplyCollisionMask(); + m_groundPlane.ApplyCollisionMask(PhysicsScene); // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain. BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs index 2f55fc3..1d55ce3 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs @@ -120,7 +120,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys PhysicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT); // Static objects are not very massive. - BulletSimAPI.SetMassProps2(m_terrainBody.ptr, 0f, Vector3.Zero); + PhysicsScene.PE.SetMassProps(m_terrainBody, 0f, Vector3.Zero); // Put the new terrain to the world of physical objects PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_terrainBody); @@ -129,7 +129,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_terrainBody); m_terrainBody.collisionType = CollisionType.Terrain; - m_terrainBody.ApplyCollisionMask(); + m_terrainBody.ApplyCollisionMask(PhysicsScene); // Make it so the terrain will not move or be considered for movement. PhysicsScene.PE.ForceActivationState(m_terrainBody, ActivationState.DISABLE_SIMULATION); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs deleted file mode 100644 index b119f22..0000000 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ /dev/null @@ -1,667 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyrightD - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Security; -using System.Text; -using OpenMetaverse; - -namespace OpenSim.Region.Physics.BulletSPlugin { - - // Constraint type values as defined by Bullet -public enum ConstraintType : int -{ - POINT2POINT_CONSTRAINT_TYPE = 3, - HINGE_CONSTRAINT_TYPE, - CONETWIST_CONSTRAINT_TYPE, - D6_CONSTRAINT_TYPE, - SLIDER_CONSTRAINT_TYPE, - CONTACT_CONSTRAINT_TYPE, - D6_SPRING_CONSTRAINT_TYPE, - MAX_CONSTRAINT_TYPE -} - -// =============================================================================== -[StructLayout(LayoutKind.Sequential)] -public struct ConvexHull -{ - Vector3 Offset; - int VertexCount; - Vector3[] Vertices; -} -public enum BSPhysicsShapeType -{ - SHAPE_UNKNOWN = 0, - SHAPE_CAPSULE = 1, - SHAPE_BOX = 2, - SHAPE_CONE = 3, - SHAPE_CYLINDER = 4, - SHAPE_SPHERE = 5, - SHAPE_MESH = 6, - SHAPE_HULL = 7, - // following defined by BulletSim - SHAPE_GROUNDPLANE = 20, - SHAPE_TERRAIN = 21, - SHAPE_COMPOUND = 22, - SHAPE_HEIGHTMAP = 23, - SHAPE_AVATAR = 24, -}; - -// The native shapes have predefined shape hash keys -public enum FixedShapeKey : ulong -{ - KEY_NONE = 0, - KEY_BOX = 1, - KEY_SPHERE = 2, - KEY_CONE = 3, - KEY_CYLINDER = 4, - KEY_CAPSULE = 5, - KEY_AVATAR = 6, -} - -[StructLayout(LayoutKind.Sequential)] -public struct ShapeData -{ - public uint ID; - public BSPhysicsShapeType Type; - public Vector3 Position; - public Quaternion Rotation; - public Vector3 Velocity; - public Vector3 Scale; - public float Mass; - public float Buoyancy; - public System.UInt64 HullKey; - public System.UInt64 MeshKey; - public float Friction; - public float Restitution; - public float Collidable; // true of things bump into this - public float Static; // true if a static object. Otherwise gravity, etc. - public float Solid; // true if object cannot be passed through - public Vector3 Size; - - // note that bools are passed as floats since bool size changes by language and architecture - public const float numericTrue = 1f; - public const float numericFalse = 0f; -} -[StructLayout(LayoutKind.Sequential)] -public struct SweepHit -{ - public uint ID; - public float Fraction; - public Vector3 Normal; - public Vector3 Point; -} -[StructLayout(LayoutKind.Sequential)] -public struct RaycastHit -{ - public uint ID; - public float Fraction; - public Vector3 Normal; -} -[StructLayout(LayoutKind.Sequential)] -public struct CollisionDesc -{ - public uint aID; - public uint bID; - public Vector3 point; - public Vector3 normal; -} -[StructLayout(LayoutKind.Sequential)] -public struct EntityProperties -{ - public uint ID; - public Vector3 Position; - public Quaternion Rotation; - public Vector3 Velocity; - public Vector3 Acceleration; - public Vector3 RotationalVelocity; -} - -// Format of this structure must match the definition in the C++ code -// NOTE: adding the X causes compile breaks if used. These are unused symbols -// that can be removed from both here and the unmanaged definition of this structure. -[StructLayout(LayoutKind.Sequential)] -public struct ConfigurationParameters -{ - public float defaultFriction; - public float defaultDensity; - public float defaultRestitution; - public float collisionMargin; - public float gravity; - - public float XlinearDamping; - public float XangularDamping; - public float XdeactivationTime; - public float XlinearSleepingThreshold; - public float XangularSleepingThreshold; - public float XccdMotionThreshold; - public float XccdSweptSphereRadius; - public float XcontactProcessingThreshold; - - public float XterrainImplementation; - public float XterrainFriction; - public float XterrainHitFraction; - public float XterrainRestitution; - public float XterrainCollisionMargin; - - public float XavatarFriction; - public float XavatarStandingFriction; - public float XavatarDensity; - public float XavatarRestitution; - public float XavatarCapsuleWidth; - public float XavatarCapsuleDepth; - public float XavatarCapsuleHeight; - public float XavatarContactProcessingThreshold; - - public float XvehicleAngularDamping; - - public float maxPersistantManifoldPoolSize; - public float maxCollisionAlgorithmPoolSize; - public float shouldDisableContactPoolDynamicAllocation; - public float shouldForceUpdateAllAabbs; - public float shouldRandomizeSolverOrder; - public float shouldSplitSimulationIslands; - public float shouldEnableFrictionCaching; - public float numberOfSolverIterations; - - public float XlinksetImplementation; - public float XlinkConstraintUseFrameOffset; - public float XlinkConstraintEnableTransMotor; - public float XlinkConstraintTransMotorMaxVel; - public float XlinkConstraintTransMotorMaxForce; - public float XlinkConstraintERP; - public float XlinkConstraintCFM; - public float XlinkConstraintSolverIterations; - - public float physicsLoggingFrames; - - public const float numericTrue = 1f; - public const float numericFalse = 0f; -} - - -// The states a bullet collision object can have -public enum ActivationState : uint -{ - ACTIVE_TAG = 1, - ISLAND_SLEEPING, - WANTS_DEACTIVATION, - DISABLE_DEACTIVATION, - DISABLE_SIMULATION, -} - -public enum CollisionObjectTypes : int -{ - CO_COLLISION_OBJECT = 1 << 0, - CO_RIGID_BODY = 1 << 1, - CO_GHOST_OBJECT = 1 << 2, - CO_SOFT_BODY = 1 << 3, - CO_HF_FLUID = 1 << 4, - CO_USER_TYPE = 1 << 5, -} - -// Values used by Bullet and BulletSim to control object properties. -// Bullet's "CollisionFlags" has more to do with operations on the -// object (if collisions happen, if gravity effects it, ...). -public enum CollisionFlags : uint -{ - CF_STATIC_OBJECT = 1 << 0, - CF_KINEMATIC_OBJECT = 1 << 1, - CF_NO_CONTACT_RESPONSE = 1 << 2, - CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3, - CF_CHARACTER_OBJECT = 1 << 4, - CF_DISABLE_VISUALIZE_OBJECT = 1 << 5, - CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6, - // Following used by BulletSim to control collisions and updates - BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10, - BS_FLOATS_ON_WATER = 1 << 11, - BS_VEHICLE_COLLISIONS = 1 << 12, - BS_NONE = 0, - BS_ALL = 0xFFFFFFFF -}; - -// Values f collisions groups and masks -public enum CollisionFilterGroups : uint -{ - // Don't use the bit definitions!! Define the use in a - // filter/mask definition below. This way collision interactions - // are more easily found and debugged. - BNoneGroup = 0, - BDefaultGroup = 1 << 0, // 0001 - BStaticGroup = 1 << 1, // 0002 - BKinematicGroup = 1 << 2, // 0004 - BDebrisGroup = 1 << 3, // 0008 - BSensorTrigger = 1 << 4, // 0010 - BCharacterGroup = 1 << 5, // 0020 - BAllGroup = 0x000FFFFF, - // Filter groups defined by BulletSim - BGroundPlaneGroup = 1 << 10, // 0400 - BTerrainGroup = 1 << 11, // 0800 - BRaycastGroup = 1 << 12, // 1000 - BSolidGroup = 1 << 13, // 2000 - // BLinksetGroup = xx // a linkset proper is either static or dynamic - BLinksetChildGroup = 1 << 14, // 4000 -}; - -// CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 -// ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2. -public enum ConstraintParams : int -{ - BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730 - BT_CONSTRAINT_STOP_ERP, - BT_CONSTRAINT_CFM, - BT_CONSTRAINT_STOP_CFM, -}; -public enum ConstraintParamAxis : int -{ - AXIS_LINEAR_X = 0, - AXIS_LINEAR_Y, - AXIS_LINEAR_Z, - AXIS_ANGULAR_X, - AXIS_ANGULAR_Y, - AXIS_ANGULAR_Z, - AXIS_LINEAR_ALL = 20, // these last three added by BulletSim so we don't have to do zillions of calls - AXIS_ANGULAR_ALL, - AXIS_ALL -}; - -public abstract class BulletSimAPITemplate -{ - /* -// Initialization and simulation -public abstract BulletWorld Initialize(Vector3 maxPosition, IntPtr parms, - int maxCollisions, IntPtr collisionArray, - int maxUpdates, IntPtr updateArray - ); - -public abstract bool UpdateParameter(BulletWorld world, uint localID, String parm, float value); - -public abstract void SetHeightMap(BulletWorld world, float[] heightmap); - -public abstract void Shutdown(BulletWorld sim); - -public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, - out int updatedEntityCount, - out IntPtr updatedEntitiesPtr, - out int collidersCount, - out IntPtr collidersPtr); - -public abstract bool PushUpdate(BulletBody obj); - */ - -// ===================================================================================== -// Mesh, hull, shape and body creation helper routines -public abstract BulletShape CreateMeshShape(BulletWorld world, - int indicesCount, int[] indices, - int verticesCount, float[] vertices ); - -public abstract BulletShape CreateHullShape(BulletWorld world, - int hullCount, float[] hulls); - -public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape); - -public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData); - -public abstract bool IsNativeShape(BulletShape shape); - -public abstract void SetShapeCollisionMargin(BulletShape shape, float margin); - -public abstract BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale); - -public abstract BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree); - -public abstract int GetNumberOfCompoundChildren(BulletShape cShape); - -public abstract void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot); - -public abstract BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx); - -public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx); - -public abstract void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape); - -public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape); - -public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id); - -public abstract BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo); - -public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape); - -public abstract int GetBodyType(BulletBody obj); - -public abstract BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot); - -public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot); - -public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot); - -public abstract IntPtr AllocateBodyInfo(BulletBody obj); - -public abstract void ReleaseBodyInfo(IntPtr obj); - -public abstract void DestroyObject(BulletWorld sim, BulletBody obj); - -// ===================================================================================== -// Terrain creation and helper routines -public abstract IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords, - float[] heightMap, float collisionMargin); - -public abstract IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, - float[] heightMap, float collisionMargin); - -public abstract bool ReleaseHeightMapInfo(IntPtr heightMapInfo); - -public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin); - -public abstract BulletShape CreateTerrainShape(IntPtr mapInfo); - -// ===================================================================================== -// Constraint creation and helper routines -public abstract BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, - Vector3 frame1loc, Quaternion frame1rot, - Vector3 frame2loc, Quaternion frame2rot, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -public abstract BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2, - Vector3 joinPoint, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -public abstract BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2, - Vector3 pivotinA, Vector3 pivotinB, - Vector3 axisInA, Vector3 axisInB, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies); - -public abstract void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse); - -public abstract void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations); - -public abstract bool SetFrames(BulletConstraint constrain, - Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot); - -public abstract bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi); - -public abstract bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi); - -public abstract bool UseFrameOffset(BulletConstraint constrain, float enable); - -public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce); - -public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold); - -public abstract bool CalculateTransforms(BulletConstraint constrain); - -public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis); - -public abstract bool DestroyConstraint(BulletWorld world, BulletConstraint constrain); - -// ===================================================================================== -// btCollisionWorld entries -public abstract void UpdateSingleAabb(BulletWorld world, BulletBody obj); - -public abstract void UpdateAabbs(BulletWorld world); - -public abstract bool GetForceUpdateAllAabbs(BulletWorld world); - -public abstract void SetForceUpdateAllAabbs(BulletWorld world, bool force); - -// ===================================================================================== -// btDynamicsWorld entries -public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj); - -public abstract bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj); - -public abstract bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects); - -public abstract bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain); -// ===================================================================================== -// btCollisionObject entries -public abstract Vector3 GetAnisotripicFriction(BulletConstraint constrain); - -public abstract Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict); - -public abstract bool HasAnisotripicFriction(BulletConstraint constrain); - -public abstract void SetContactProcessingThreshold(BulletBody obj, float val); - -public abstract float GetContactProcessingThreshold(BulletBody obj); - -public abstract bool IsStaticObject(BulletBody obj); - -public abstract bool IsKinematicObject(BulletBody obj); - -public abstract bool IsStaticOrKinematicObject(BulletBody obj); - -public abstract bool HasContactResponse(BulletBody obj); - -public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape); - -public abstract BulletShape GetCollisionShape(BulletBody obj); - -public abstract int GetActivationState(BulletBody obj); - -public abstract void SetActivationState(BulletBody obj, int state); - -public abstract void SetDeactivationTime(BulletBody obj, float dtime); - -public abstract float GetDeactivationTime(BulletBody obj); - -public abstract void ForceActivationState(BulletBody obj, ActivationState state); - -public abstract void Activate(BulletBody obj, bool forceActivation); - -public abstract bool IsActive(BulletBody obj); - -public abstract void SetRestitution(BulletBody obj, float val); - -public abstract float GetRestitution(BulletBody obj); - -public abstract void SetFriction(BulletBody obj, float val); - -public abstract float GetFriction(BulletBody obj); - -public abstract Vector3 GetPosition(BulletBody obj); - -public abstract Quaternion GetOrientation(BulletBody obj); - -public abstract void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation); - -public abstract IntPtr GetBroadphaseHandle(BulletBody obj); - -public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle); - -public abstract void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel); - -public abstract void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel); - -public abstract void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel); - -public abstract float GetHitFraction(BulletBody obj); - -public abstract void SetHitFraction(BulletBody obj, float val); - -public abstract CollisionFlags GetCollisionFlags(BulletBody obj); - -public abstract CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags); - -public abstract CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags); - -public abstract CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags); - -public abstract float GetCcdMotionThreshold(BulletBody obj); - -public abstract void SetCcdMotionThreshold(BulletBody obj, float val); - -public abstract float GetCcdSweptSphereRadius(BulletBody obj); - -public abstract void SetCcdSweptSphereRadius(BulletBody obj, float val); - -public abstract IntPtr GetUserPointer(BulletBody obj); - -public abstract void SetUserPointer(BulletBody obj, IntPtr val); - - /* -// ===================================================================================== -// btRigidBody entries -public abstract void ApplyGravity(BulletBody obj); - -public abstract void SetGravity(BulletBody obj, Vector3 val); - -public abstract Vector3 GetGravity(BulletBody obj); - -public abstract void SetDamping(BulletBody obj, float lin_damping, float ang_damping); - -public abstract void SetLinearDamping(BulletBody obj, float lin_damping); - -public abstract void SetAngularDamping(BulletBody obj, float ang_damping); - -public abstract float GetLinearDamping(BulletBody obj); - -public abstract float GetAngularDamping(BulletBody obj); - -public abstract float GetLinearSleepingThreshold(BulletBody obj); - - -public abstract void ApplyDamping(BulletBody obj, float timeStep); - -public abstract void SetMassProps(BulletBody obj, float mass, Vector3 inertia); - -public abstract Vector3 GetLinearFactor(BulletBody obj); - -public abstract void SetLinearFactor(BulletBody obj, Vector3 factor); - -public abstract void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot); - -// Add a force to the object as if its mass is one. -public abstract void ApplyCentralForce(BulletBody obj, Vector3 force); - -// Set the force being applied to the object as if its mass is one. -public abstract void SetObjectForce(BulletBody obj, Vector3 force); - -public abstract Vector3 GetTotalForce(BulletBody obj); - -public abstract Vector3 GetTotalTorque(BulletBody obj); - -public abstract Vector3 GetInvInertiaDiagLocal(BulletBody obj); - -public abstract void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert); - -public abstract void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold); - -public abstract void ApplyTorque(BulletBody obj, Vector3 torque); - -// Apply force at the given point. Will add torque to the object. -public abstract void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos); - -// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass. -public abstract void ApplyCentralImpulse(BulletBody obj, Vector3 imp); - -// Apply impulse to the object's torque. Force is scaled by object's mass. -public abstract void ApplyTorqueImpulse(BulletBody obj, Vector3 imp); - -// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces. -public abstract void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos); - -public abstract void ClearForces(BulletBody obj); - -public abstract void ClearAllForces(BulletBody obj); - -public abstract void UpdateInertiaTensor(BulletBody obj); - -public abstract Vector3 GetLinearVelocity(BulletBody obj); - -public abstract Vector3 GetAngularVelocity(BulletBody obj); - -public abstract void SetLinearVelocity(BulletBody obj, Vector3 val); - -public abstract void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity); - -public abstract Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos); - -public abstract void Translate(BulletBody obj, Vector3 trans); - -public abstract void UpdateDeactivation(BulletBody obj, float timeStep); - -public abstract bool WantsSleeping(BulletBody obj); - -public abstract void SetAngularFactor(BulletBody obj, float factor); - -public abstract void SetAngularFactorV(BulletBody obj, Vector3 factor); - -public abstract Vector3 GetAngularFactor(BulletBody obj); - -public abstract bool IsInWorld(BulletBody obj); - -public abstract void AddConstraintRef(BulletBody obj, BulletConstraint constrain); - -public abstract void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain); - -public abstract BulletConstraint GetConstraintRef(BulletBody obj, int index); - -public abstract int GetNumConstraintRefs(BulletBody obj); - -public abstract bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask); - -// ===================================================================================== -// btCollisionShape entries - -public abstract float GetAngularMotionDisc(BulletShape shape); - -public abstract float GetContactBreakingThreshold(BulletShape shape, float defaultFactor); - -public abstract bool IsPolyhedral(BulletShape shape); - -public abstract bool IsConvex2d(BulletShape shape); - -public abstract bool IsConvex(BulletShape shape); - -public abstract bool IsNonMoving(BulletShape shape); - -public abstract bool IsConcave(BulletShape shape); - -public abstract bool IsCompound(BulletShape shape); - -public abstract bool IsSoftBody(BulletShape shape); - -public abstract bool IsInfinite(BulletShape shape); - -public abstract void SetLocalScaling(BulletShape shape, Vector3 scale); - -public abstract Vector3 GetLocalScaling(BulletShape shape); - -public abstract Vector3 CalculateLocalInertia(BulletShape shape, float mass); - -public abstract int GetShapeType(BulletShape shape); - -public abstract void SetMargin(BulletShape shape, float val); - -public abstract float GetMargin(BulletShape shape); - */ - -}; -} diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs index c10d75e..a040928 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs @@ -72,12 +72,12 @@ public class BulletBody public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } } // Apply the specificed collision mask into the physical world - public bool ApplyCollisionMask() + public bool ApplyCollisionMask(BSScene physicsScene) { // Should assert the body has been added to the physical world. // (The collision masks are stored in the collision proxy cache which only exists for // a collision body that is in the world.) - return BulletSimAPI.SetCollisionGroupMask2(ptr, + return physicsScene.PE.SetCollisionGroupMask(this, BulletSimData.CollisionTypeMasks[collisionType].group, BulletSimData.CollisionTypeMasks[collisionType].mask); } -- cgit v1.1 From 3d0fc708647ceb734385f90e2f22be9774e2171e Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 31 Dec 2012 16:22:45 -0800 Subject: BulletSim: complete movement of BulletSimAPI functions to BSAPITemplate. Update BulletSim DLLs and SOs with simplier step function interface. --- OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs | 4 - OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 217 +++++++++++++++------ OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | 78 ++++---- .../Region/Physics/BulletSPlugin/BSApiTemplate.cs | 43 ++-- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 4 +- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 127 ++++++------ .../Physics/BulletSPlugin/BSTerrainHeightmap.cs | 12 +- .../Region/Physics/BulletSPlugin/BulletSimData.cs | 8 +- .../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 10 +- .../Region/Physics/Manager/PhysicsPluginManager.cs | 2 +- 10 files changed, 311 insertions(+), 194 deletions(-) (limited to 'OpenSim/Region/Physics') 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 _mass = CalculateMass(); - // No body or shape yet - PhysBody = new BulletBody(LocalID); - PhysShape = new BulletShape(); - Linkset.Refresh(this); DetailLog("{0},BSPrim.constructor,call", LocalID); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs index 6e68053..0355b94 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs @@ -26,6 +26,7 @@ */ using System; using System.Collections.Generic; +using System.Reflection; using System.Runtime.InteropServices; using System.Security; using System.Text; @@ -36,31 +37,102 @@ namespace OpenSim.Region.Physics.BulletSPlugin { public sealed class BSAPIUnman : BSAPITemplate { - /* + +// We pin the memory passed between the managed and unmanaged code. +GCHandle m_paramsHandle; +private GCHandle m_collisionArrayPinnedHandle; +private GCHandle m_updateArrayPinnedHandle; + +// Handle to the callback used by the unmanaged code to call into the managed code. +// Used for debug logging. +// Need to store the handle in a persistant variable so it won't be freed. +private BSAPICPP.DebugLogCallback m_DebugLogCallbackHandle; + +private BSScene PhysicsScene { get; set; } + +public override string BulletEngineName { get { return "BulletUnmanaged"; } } +public override string BulletEngineVersion { get; protected set; } + +public BSAPIUnman(string paramName, BSScene physScene) +{ + PhysicsScene = physScene; + // Do something fancy with the paramName to get the right DLL implementation + // like "Bullet-2.80-OpenCL-Intel" loading the version for Intel based OpenCL implementation, etc. +} + // Initialization and simulation -public BulletWorld Initialize(Vector3 maxPosition, IntPtr parms, - int maxCollisions, IntPtr collisionArray, - int maxUpdates, IntPtr updateArray - ); +public override BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms, + int maxCollisions, ref CollisionDesc[] collisionArray, + int maxUpdates, ref EntityProperties[] updateArray + ) +{ + // Pin down the memory that will be used to pass object collisions and updates back from unmanaged code + m_paramsHandle = GCHandle.Alloc(parms, GCHandleType.Pinned); + m_collisionArrayPinnedHandle = GCHandle.Alloc(collisionArray, GCHandleType.Pinned); + m_updateArrayPinnedHandle = GCHandle.Alloc(updateArray, GCHandleType.Pinned); -public bool UpdateParameter(BulletWorld world, uint localID, String parm, float value); + // If Debug logging level, enable logging from the unmanaged code + m_DebugLogCallbackHandle = null; + if (BSScene.m_log.IsDebugEnabled || PhysicsScene.PhysicsLogging.Enabled) + { + BSScene.m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", BSScene.LogHeader); + if (PhysicsScene.PhysicsLogging.Enabled) + // The handle is saved in a variable to make sure it doesn't get freed after this call + m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLoggerPhysLog); + else + m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLogger); + } -public void SetHeightMap(BulletWorld world, float[] heightmap); + // Get the version of the DLL + // TODO: this doesn't work yet. Something wrong with marshaling the returned string. + // BulletEngineVersion = BulletSimAPI.GetVersion2(); + BulletEngineVersion = ""; + + // Call the unmanaged code with the buffers and other information + return new BulletWorld(0, PhysicsScene, BSAPICPP.Initialize2(maxPosition, m_paramsHandle.AddrOfPinnedObject(), + maxCollisions, m_collisionArrayPinnedHandle.AddrOfPinnedObject(), + maxUpdates, m_updateArrayPinnedHandle.AddrOfPinnedObject(), + m_DebugLogCallbackHandle)); -public void Shutdown(BulletWorld sim); +} -public int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, - out int updatedEntityCount, - out IntPtr updatedEntitiesPtr, - out int collidersCount, - out IntPtr collidersPtr); +// Called directly from unmanaged code so don't do much +private void BulletLogger(string msg) +{ + BSScene.m_log.Debug("[BULLETS UNMANAGED]:" + msg); +} + +// Called directly from unmanaged code so don't do much +private void BulletLoggerPhysLog(string msg) +{ + PhysicsScene.DetailLog("[BULLETS UNMANAGED]:" + msg); +} + + /* +public void SetHeightMap(BulletWorld world, float[] heightmap); */ +public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, + out int updatedEntityCount, out int collidersCount) +{ + return BSAPICPP.PhysicsStep2(world.ptr, timeStep, maxSubSteps, fixedTimeStep, out updatedEntityCount, out collidersCount); +} + +public override void Shutdown(BulletWorld sim) +{ + BSAPICPP.Shutdown2(sim.ptr); +} + public override bool PushUpdate(BulletBody obj) { return BSAPICPP.PushUpdate2(obj.ptr); } +public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value) +{ + return BSAPICPP.UpdateParameter2(world.ptr, localID, parm, value); +} + // ===================================================================================== // Mesh, hull, shape and body creation helper routines public override BulletShape CreateMeshShape(BulletWorld world, @@ -893,11 +965,81 @@ public override float GetMargin(BulletShape shape) return BSAPICPP.GetMargin2(shape.ptr); } +// ===================================================================================== +// Debugging +public override void DumpRigidBody(BulletWorld sim, BulletBody collisionObject) +{ + BSAPICPP.DumpRigidBody2(sim.ptr, collisionObject.ptr); +} + +public override void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape) +{ + BSAPICPP.DumpCollisionShape2(sim.ptr, collisionShape.ptr); +} + +public override void DumpMapInfo(BulletWorld sim, BulletHMapInfo mapInfo) +{ + BSAPICPP.DumpMapInfo2(sim.ptr, mapInfo.ptr); +} + +public override void DumpConstraint(BulletWorld sim, BulletConstraint constrain) +{ + BSAPICPP.DumpConstraint2(sim.ptr, constrain.ptr); +} + +public override void DumpActivationInfo(BulletWorld sim) +{ + BSAPICPP.DumpActivationInfo2(sim.ptr); +} + +public override void DumpAllInfo(BulletWorld sim) +{ + BSAPICPP.DumpAllInfo2(sim.ptr); +} + +public override void DumpPhysicsStatistics(BulletWorld sim) +{ + BSAPICPP.DumpPhysicsStatistics2(sim.ptr); +} + + +// ===================================================================================== +// ===================================================================================== +// ===================================================================================== +// ===================================================================================== +// ===================================================================================== +// The actual interface to the unmanaged code static class BSAPICPP { +// =============================================================================== +// Link back to the managed code for outputting log messages +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); + +// =============================================================================== +// Initialization and simulation +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms, + int maxCollisions, IntPtr collisionArray, + int maxUpdates, IntPtr updateArray, + DebugLogCallback logRoutine); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void SetHeightMap2(IntPtr world, float[] heightmap); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep, + out int updatedEntityCount, out int collidersCount); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern void Shutdown2(IntPtr sim); + [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern bool PushUpdate2(IntPtr obj); +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value); + // ===================================================================================== // Mesh, hull, shape and body creation helper routines [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] @@ -1431,52 +1573,6 @@ public static extern void SetMargin2(IntPtr shape, float val); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern float GetMargin2(IntPtr shape); -} -} - -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -// =============================================================================== -static class BulletSimAPI { -// =============================================================================== -// Link back to the managed code for outputting log messages -[UnmanagedFunctionPointer(CallingConvention.Cdecl)] -public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); - -// =============================================================================== -// Initialization and simulation -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms, - int maxCollisions, IntPtr collisionArray, - int maxUpdates, IntPtr updateArray, - DebugLogCallback logRoutine); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetHeightMap2(IntPtr world, float[] heightmap); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void Shutdown2(IntPtr sim); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep, - out int updatedEntityCount, - out IntPtr updatedEntitiesPtr, - out int collidersCount, - out IntPtr collidersPtr); - // ===================================================================================== // Debugging [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] @@ -1501,4 +1597,7 @@ public static extern void DumpAllInfo2(IntPtr sim); public static extern void DumpPhysicsStatistics2(IntPtr sim); } + +} + } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs index a56a817..8ed791e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs @@ -1,39 +1,39 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyrightD - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace OpenSim.Region.Physics.BulletSPlugin -{ - /* -public sealed class BSAPIXNA : BulletSimAPITemplate -{ -} - */ -} +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyrightD + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenSim.Region.Physics.BulletSPlugin +{ + /* +public sealed class BSAPIXNA : BSAPITemplate +{ +} + */ +} diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs index fbf362d..64a886b 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs @@ -292,26 +292,27 @@ public enum ConstraintParamAxis : int public abstract class BSAPITemplate { - /* +// Returns the name of the underlying Bullet engine +public abstract string BulletEngineName { get; } +public abstract string BulletEngineVersion { get; protected set;} + // Initialization and simulation -public abstract BulletWorld Initialize(Vector3 maxPosition, IntPtr parms, - int maxCollisions, IntPtr collisionArray, - int maxUpdates, IntPtr updateArray +public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms, + int maxCollisions, ref CollisionDesc[] collisionArray, + int maxUpdates, ref EntityProperties[] updateArray ); -public abstract bool UpdateParameter(BulletWorld world, uint localID, String parm, float value); - + /* public abstract void SetHeightMap(BulletWorld world, float[] heightmap); -public abstract void Shutdown(BulletWorld sim); - + */ public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, - out int updatedEntityCount, - out IntPtr updatedEntitiesPtr, - out int collidersCount, - out IntPtr collidersPtr); + out int updatedEntityCount, out int collidersCount); + +public abstract bool UpdateParameter(BulletWorld world, uint localID, String parm, float value); + +public abstract void Shutdown(BulletWorld sim); - */ public abstract bool PushUpdate(BulletBody obj); // ===================================================================================== @@ -660,5 +661,21 @@ public abstract void SetMargin(BulletShape shape, float val); public abstract float GetMargin(BulletShape shape); +// ===================================================================================== +// Debugging +public abstract void DumpRigidBody(BulletWorld sim, BulletBody collisionObject); + +public abstract void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape); + +public abstract void DumpMapInfo(BulletWorld sim, BulletHMapInfo mapInfo); + +public abstract void DumpConstraint(BulletWorld sim, BulletConstraint constrain); + +public abstract void DumpActivationInfo(BulletWorld sim); + +public abstract void DumpAllInfo(BulletWorld sim); + +public abstract void DumpPhysicsStatistics(BulletWorld sim); + }; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index e4e3edc..13c2539 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -823,7 +823,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin if (!IsActive) return; if (PhysicsScene.VehiclePhysicalLoggingEnabled) - BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, Prim.PhysBody.ptr); + PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); ForgetKnownVehicleProperties(); @@ -840,7 +840,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin PushKnownChanged(); if (PhysicsScene.VehiclePhysicalLoggingEnabled) - BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, Prim.PhysBody.ptr); + PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}", Prim.LocalID, VehiclePosition, Prim.Force, VehicleVelocity, VehicleRotationalVelocity); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 28c6680..258b72f 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -26,6 +26,7 @@ */ using System; using System.Collections.Generic; +using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Threading; @@ -42,8 +43,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin { public sealed class BSScene : PhysicsScene, IPhysicsParameters { - private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private static readonly string LogHeader = "[BULLETS SCENE]"; + internal static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + internal static readonly string LogHeader = "[BULLETS SCENE]"; // The name of the region we're working for. public string RegionName { get; private set; } @@ -51,6 +52,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters public string BulletSimVersion = "?"; // The handle to the underlying managed or unmanaged version of Bullet being used. + public string BulletEngineName { get; private set; } public BSAPITemplate PE; public Dictionary PhysObjects; @@ -102,11 +104,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters // Pinned memory used to pass step information between managed and unmanaged internal int m_maxCollisionsPerFrame; internal CollisionDesc[] m_collisionArray; - internal GCHandle m_collisionArrayPinnedHandle; internal int m_maxUpdatesPerFrame; internal EntityProperties[] m_updateArray; - internal GCHandle m_updateArrayPinnedHandle; public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero public const uint GROUNDPLANE_ID = 1; @@ -152,12 +152,6 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters // A pointer to an instance if this structure is passed to the C++ code // Used to pass basic configuration values to the unmanaged code. internal ConfigurationParameters[] UnmanagedParams; - GCHandle m_paramsHandle; - - // Handle to the callback used by the unmanaged code to call into the managed code. - // Used for debug logging. - // Need to store the handle in a persistant variable so it won't be freed. - private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; // Sometimes you just have to log everything. public Logging.LogWriter PhysicsLogging; @@ -194,15 +188,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters // Set default values for physics parameters plus any overrides from the ini file GetInitialParameterValues(config); - // For the moment, only one version of the interface - PE = new BSAPIUnman(); - - // Allocate more pinned memory. Do this early to try and get all pinned memory close together. - m_paramsHandle = GCHandle.Alloc(UnmanagedParams, GCHandleType.Pinned); - m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame]; - m_collisionArrayPinnedHandle = GCHandle.Alloc(m_collisionArray, GCHandleType.Pinned); - m_updateArray = new EntityProperties[m_maxUpdatesPerFrame]; - m_updateArrayPinnedHandle = GCHandle.Alloc(m_updateArray, GCHandleType.Pinned); + // Get the connection to the physics engine (could be native or one of many DLLs) + PE = SelectUnderlyingBulletEngine(BulletEngineName); // Enable very detailed logging. // By creating an empty logger when not logging, the log message invocation code @@ -217,22 +204,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters PhysicsLogging = new Logging.LogWriter(); } - // If Debug logging level, enable logging from the unmanaged code - m_DebugLogCallbackHandle = null; - if (m_log.IsDebugEnabled || PhysicsLogging.Enabled) - { - m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader); - if (PhysicsLogging.Enabled) - // The handle is saved in a variable to make sure it doesn't get freed after this call - m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLoggerPhysLog); - else - m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger); - } - - // Get the version of the DLL - // TODO: this doesn't work yet. Something wrong with marshaling the returned string. - // BulletSimVersion = BulletSimAPI.GetVersion(); - // m_log.WarnFormat("{0}: BulletSim.dll version='{1}'", LogHeader, BulletSimVersion); + // Allocate memory for returning of the updates and collisions from the physics engine + m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame]; + m_updateArray = new EntityProperties[m_maxUpdatesPerFrame]; // The bounding box for the simulated world. The origin is 0,0,0 unless we're // a child in a mega-region. @@ -240,11 +214,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters // area. It tracks active objects no matter where they are. Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); - // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader); - World = new BulletWorld(0, this, BulletSimAPI.Initialize2(worldExtent, m_paramsHandle.AddrOfPinnedObject(), - m_maxCollisionsPerFrame, m_collisionArrayPinnedHandle.AddrOfPinnedObject(), - m_maxUpdatesPerFrame, m_updateArrayPinnedHandle.AddrOfPinnedObject(), - m_DebugLogCallbackHandle)); + World = PE.Initialize(worldExtent, Params, m_maxCollisionsPerFrame, ref m_collisionArray, m_maxUpdatesPerFrame, ref m_updateArray); Constraints = new BSConstraintCollection(World); @@ -274,6 +244,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters { BSParam.SetParameterConfigurationValues(this, pConfig); + // There are two Bullet implementations to choose from + BulletEngineName = pConfig.GetString("BulletEngine", "BulletUnmanaged"); + // Very detailed logging for physics debugging // TODO: the boolean values can be moved to the normal parameter processing. m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false); @@ -315,16 +288,41 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters return ret; } - // Called directly from unmanaged code so don't do much - private void BulletLogger(string msg) + // Select the connection to the actual Bullet implementation. + // The main engine selection is the engineName up to the first hypen. + // So "Bullet-2.80-OpenCL-Intel" specifies the 'bullet' class here and the whole name + // is passed to the engine to do its special selection, etc. + private BSAPITemplate SelectUnderlyingBulletEngine(string engineName) { - m_log.Debug("[BULLETS UNMANAGED]:" + msg); - } + // For the moment, do a simple switch statement. + // Someday do fancyness with looking up the interfaces in the assembly. + BSAPITemplate ret = null; - // Called directly from unmanaged code so don't do much - private void BulletLoggerPhysLog(string msg) - { - DetailLog("[BULLETS UNMANAGED]:" + msg); + string selectionName = engineName.ToLower(); + int hyphenIndex = engineName.IndexOf("-"); + if (hyphenIndex > 0) + selectionName = engineName.ToLower().Substring(0, hyphenIndex - 1); + + switch (selectionName) + { + case "bulletunmanaged": + ret = new BSAPIUnman(engineName, this); + break; + case "bulletxna": + // ret = new BSAPIXNA(engineName, this); + break; + } + + if (ret == null) + { + m_log.ErrorFormat("{0) COULD NOT SELECT BULLET ENGINE: '[BulletSim]PhysicsEngine' must be either 'BulletUnmanaged-*' or 'BulletXNA-*'", LogHeader); + } + else + { + m_log.WarnFormat("{0} Selected bullet engine {1} -> {2}/{3}", LogHeader, engineName, ret.BulletEngineName, ret.BulletEngineVersion); + } + + return ret; } public override void Dispose() @@ -361,7 +359,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters } // Anything left in the unmanaged code should be cleaned out - BulletSimAPI.Shutdown2(World.ptr); + PE.Shutdown(World); // Not logging any more PhysicsLogging.Close(); @@ -474,9 +472,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters LastTimeStep = timeStep; int updatedEntityCount = 0; - IntPtr updatedEntitiesPtr; int collidersCount = 0; - IntPtr collidersPtr; int beforeTime = 0; int simTime = 0; @@ -492,6 +488,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters TriggerPreStepEvent(timeStep); // the prestep actions might have added taints + numTaints += _taintOperations.Count; ProcessTaints(); InTaintTime = false; // Only used for debugging so locking is not necessary. @@ -499,23 +496,25 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. // Only enable this in a limited test world with few objects. if (m_physicsPhysicalDumpEnabled) - BulletSimAPI.DumpAllInfo2(World.ptr); + PE.DumpAllInfo(World); // step the physical world one interval m_simulationStep++; int numSubSteps = 0; - try { - if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount(); + if (PhysicsLogging.Enabled) + beforeTime = Util.EnvironmentTickCount(); - numSubSteps = BulletSimAPI.PhysicsStep2(World.ptr, timeStep, m_maxSubSteps, m_fixedTimeStep, - out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr); + numSubSteps = PE.PhysicsStep(World, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out collidersCount); - if (PhysicsLogging.Enabled) simTime = Util.EnvironmentTickCountSubtract(beforeTime); - DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}, objWColl={7}", - DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps, - updatedEntityCount, collidersCount, ObjectsWithCollisions.Count); + if (PhysicsLogging.Enabled) + { + simTime = Util.EnvironmentTickCountSubtract(beforeTime); + DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}, objWColl={7}", + DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps, + updatedEntityCount, collidersCount, ObjectsWithCollisions.Count); + } } catch (Exception e) { @@ -527,8 +526,6 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters collidersCount = 0; } - // Don't have to use the pointers passed back since we know it is the same pinned memory we passed in. - // Get a value for 'now' so all the collision and update routines don't have to get their own. SimulationNowTime = Util.EnvironmentTickCount(); @@ -570,7 +567,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters // Objects that are done colliding are removed from the ObjectsWithCollisions list. // Not done above because it is inside an iteration of ObjectWithCollisions. // This complex collision processing is required to create an empty collision - // event call after all collisions have happened on an object. This enables + // event call after all real collisions have happened on an object. This enables // the simulator to generate the 'collision end' event. if (ObjectsWithNoMoreCollisions.Count > 0) { @@ -599,11 +596,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. // Only enable this in a limited test world with few objects. if (m_physicsPhysicalDumpEnabled) - BulletSimAPI.DumpAllInfo2(World.ptr); + PE.DumpAllInfo(World); // The physics engine returns the number of milliseconds it simulated this call. // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS. - // Multiply by 55 to give a nominal frame rate of 55. + // Multiply by a fixed nominal frame rate to give a rate similar to the simulator (usually 55). return (float)numSubSteps * m_fixedTimeStep * 1000f * NominalFrameRate; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index cc28344..0802b3a 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs @@ -44,7 +44,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys { static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]"; - BulletHeightMapInfo m_mapInfo = null; + BulletHMapInfo m_mapInfo = null; // Constructor to build a default, flat heightmap terrain. public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize) @@ -58,7 +58,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys { initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION; } - m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); + m_mapInfo = new BulletHMapInfo(id, initialMap, IntPtr.Zero); m_mapInfo.minCoords = minTerrainCoords; m_mapInfo.maxCoords = maxTerrainCoords; m_mapInfo.terrainRegionBase = TerrainBase; @@ -72,7 +72,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys Vector3 minCoords, Vector3 maxCoords) : base(physicsScene, regionBase, id) { - m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); + m_mapInfo = new BulletHMapInfo(id, initialMap, IntPtr.Zero); m_mapInfo.minCoords = minCoords; m_mapInfo.maxCoords = maxCoords; m_mapInfo.minZ = minCoords.Z; @@ -91,12 +91,12 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys // Using the information in m_mapInfo, create the physical representation of the heightmap. private void BuildHeightmapTerrain() { - m_mapInfo.Ptr = PhysicsScene.PE.CreateHeightMapInfo(PhysicsScene.World, m_mapInfo.ID, + m_mapInfo.ptr = PhysicsScene.PE.CreateHeightMapInfo(PhysicsScene.World, m_mapInfo.ID, m_mapInfo.minCoords, m_mapInfo.maxCoords, m_mapInfo.heightMap, BSParam.TerrainCollisionMargin); // Create the terrain shape from the mapInfo - m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape(m_mapInfo.Ptr); + m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape(m_mapInfo.ptr); // The terrain object initial position is at the center of the object Vector3 centerPos; @@ -138,7 +138,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_mapInfo.terrainBody); // Frees both the body and the shape. PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody); - PhysicsScene.PE.ReleaseHeightMapInfo(m_mapInfo.Ptr); + PhysicsScene.PE.ReleaseHeightMapInfo(m_mapInfo.ptr); } } m_mapInfo = null; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs index a040928..c8f4602 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs @@ -187,11 +187,11 @@ public class BulletConstraint // Made a class rather than a struct so there would be only one // instance of this and C# will pass around pointers rather // than making copies. -public class BulletHeightMapInfo +public class BulletHMapInfo { - public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) { + public BulletHMapInfo(uint id, float[] hm, IntPtr xx) { ID = id; - Ptr = xx; + ptr = xx; heightMap = hm; terrainRegionBase = OMV.Vector3.Zero; minCoords = new OMV.Vector3(100f, 100f, 25f); @@ -200,7 +200,7 @@ public class BulletHeightMapInfo sizeX = sizeY = 256f; } public uint ID; - public IntPtr Ptr; + public IntPtr ptr; public float[] heightMap; public OMV.Vector3 terrainRegionBase; public OMV.Vector3 minCoords; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 4cb8e6d..a8a4ff5 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -61,7 +61,8 @@ Incorporate inter-relationship of angular corrections. For instance, angularDefl BULLETSIM TODO LIST: ================================================= -Avatar density is WAY off. Compare and calibrate with what's in SL. +Implement an avatar mesh shape. The Bullet capsule is way too limited. + Consider just hand creating a vertex/index array in a new BSShapeAvatar. Revisit CollisionMargin. Builders notice the 0.04 spacing between prims. Duplicating a physical prim causes old prim to jump away Dup a phys prim and the original become unselected and thus interacts w/ selected prim. @@ -170,6 +171,9 @@ Avatar attachments have no mass? http://forums-archive.secondlife.com/54/f0/3179 INTERNAL IMPROVEMENT/CLEANUP ================================================= +Create the physical wrapper classes (BulletBody, BulletShape) by methods on + BSAPITemplate and make their actual implementation Bullet engine specific. + For the short term, just call the existing functions in ShapeCollection. Consider moving prim/character body and shape destruction in destroy() to postTimeTime rather than protecting all the potential sets that might have been queued up. @@ -204,6 +208,8 @@ Should taints check for existance or activeness of target? Possibly have and 'active' flag that is checked by the taint processor? Parameters for physics logging should be moved from BSScene to BSParam (at least boolean ones) Can some of the physical wrapper classes (BulletBody, BulletWorld, BulletShape) be 'sealed'? +There are TOO MANY interfaces from BulletSim core to Bullet itself + Think of something to eliminate one or more of the layers THREADING ================================================= @@ -262,3 +268,5 @@ llApplyImpulse() (Resolution: tested on SL and OS. AddForce scales the force for timestep) llSetBuoyancy() (DONE) (Resolution: Bullet resets object gravity when added to world. Moved set gravity) +Avatar density is WAY off. Compare and calibrate with what's in SL. (DONE) + (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; using System.IO; using System.Reflection; using Nini.Config; -using log4net; +using log4net; using OpenSim.Framework; namespace OpenSim.Region.Physics.Manager -- cgit v1.1 From 9396ccc078516023d63b5a86b3262ff97a1e97fb Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 31 Dec 2012 16:54:39 -0800 Subject: BulletSim: eliminate the use of the unmanaged HeightMapInfo structure. Remove all related calls from the unmanaged and BSAPITemplate interfaces. Update DLLs and SOs to include the version without HeightMapInfo structures. --- OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 26 +++++++++------------- .../Region/Physics/BulletSPlugin/BSApiTemplate.cs | 18 ++------------- .../Physics/BulletSPlugin/BSTerrainHeightmap.cs | 14 +++++------- .../Region/Physics/BulletSPlugin/BulletSimData.cs | 4 +--- 4 files changed, 20 insertions(+), 42 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs index 0355b94..cf37e56 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs @@ -108,10 +108,6 @@ private void BulletLoggerPhysLog(string msg) PhysicsScene.DetailLog("[BULLETS UNMANAGED]:" + msg); } - /* -public void SetHeightMap(BulletWorld world, float[] heightmap); - - */ public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, out int updatedEntityCount, out int collidersCount) { @@ -277,6 +273,7 @@ public override void DestroyObject(BulletWorld sim, BulletBody obj) // ===================================================================================== // Terrain creation and helper routines + /* public override IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords, float[] heightMap, float collisionMargin) { @@ -293,15 +290,18 @@ public override bool ReleaseHeightMapInfo(IntPtr heightMapInfo) { return BSAPICPP.ReleaseHeightMapInfo2(heightMapInfo); } + */ public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin) { return new BulletShape(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE); } -public override BulletShape CreateTerrainShape(IntPtr mapInfo) +public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, + float scaleFactor, float collisionMargin) { - return new BulletShape(BSAPICPP.CreateTerrainShape2(mapInfo), BSPhysicsShapeType.SHAPE_TERRAIN); + return new BulletShape(BSAPICPP.CreateTerrainShape2(id, size, minHeight, maxHeight, heightMap, scaleFactor, collisionMargin), + BSPhysicsShapeType.SHAPE_TERRAIN); } // ===================================================================================== @@ -977,11 +977,6 @@ public override void DumpCollisionShape(BulletWorld sim, BulletShape collisionSh BSAPICPP.DumpCollisionShape2(sim.ptr, collisionShape.ptr); } -public override void DumpMapInfo(BulletWorld sim, BulletHMapInfo mapInfo) -{ - BSAPICPP.DumpMapInfo2(sim.ptr, mapInfo.ptr); -} - public override void DumpConstraint(BulletWorld sim, BulletConstraint constrain) { BSAPICPP.DumpConstraint2(sim.ptr, constrain.ptr); @@ -1025,9 +1020,6 @@ public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms, DebugLogCallback logRoutine); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void SetHeightMap2(IntPtr world, float[] heightmap); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep, out int updatedEntityCount, out int collidersCount); @@ -1119,6 +1111,7 @@ public static extern void DestroyObject2(IntPtr sim, IntPtr obj); // ===================================================================================== // Terrain creation and helper routines + /* [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords, [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); @@ -1129,12 +1122,15 @@ public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo); + */ [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo); +public static extern IntPtr CreateTerrainShape2(uint id, Vector3 size, float minHeight, float maxHeight, + [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, + float scaleFactor, float collisionMargin); // ===================================================================================== // Constraint creation and helper routines diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs index 64a886b..a618a21 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs @@ -302,10 +302,6 @@ public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParamet int maxUpdates, ref EntityProperties[] updateArray ); - /* -public abstract void SetHeightMap(BulletWorld world, float[] heightmap); - - */ public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, out int updatedEntityCount, out int collidersCount); @@ -369,18 +365,10 @@ public abstract void ReleaseBodyInfo(IntPtr obj); public abstract void DestroyObject(BulletWorld sim, BulletBody obj); // ===================================================================================== -// Terrain creation and helper routines -public abstract IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords, - float[] heightMap, float collisionMargin); - -public abstract IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, - float[] heightMap, float collisionMargin); - -public abstract bool ReleaseHeightMapInfo(IntPtr heightMapInfo); - public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin); -public abstract BulletShape CreateTerrainShape(IntPtr mapInfo); +public abstract BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, + float scaleFactor, float collisionMargin); // ===================================================================================== // Constraint creation and helper routines @@ -667,8 +655,6 @@ public abstract void DumpRigidBody(BulletWorld sim, BulletBody collisionObject); public abstract void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape); -public abstract void DumpMapInfo(BulletWorld sim, BulletHMapInfo mapInfo); - public abstract void DumpConstraint(BulletWorld sim, BulletConstraint constrain); public abstract void DumpActivationInfo(BulletWorld sim); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index 0802b3a..114c0aa 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs @@ -58,7 +58,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys { initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION; } - m_mapInfo = new BulletHMapInfo(id, initialMap, IntPtr.Zero); + m_mapInfo = new BulletHMapInfo(id, initialMap); m_mapInfo.minCoords = minTerrainCoords; m_mapInfo.maxCoords = maxTerrainCoords; m_mapInfo.terrainRegionBase = TerrainBase; @@ -72,7 +72,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys Vector3 minCoords, Vector3 maxCoords) : base(physicsScene, regionBase, id) { - m_mapInfo = new BulletHMapInfo(id, initialMap, IntPtr.Zero); + m_mapInfo = new BulletHMapInfo(id, initialMap); m_mapInfo.minCoords = minCoords; m_mapInfo.maxCoords = maxCoords; m_mapInfo.minZ = minCoords.Z; @@ -91,12 +91,11 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys // Using the information in m_mapInfo, create the physical representation of the heightmap. private void BuildHeightmapTerrain() { - m_mapInfo.ptr = PhysicsScene.PE.CreateHeightMapInfo(PhysicsScene.World, m_mapInfo.ID, - m_mapInfo.minCoords, m_mapInfo.maxCoords, - m_mapInfo.heightMap, BSParam.TerrainCollisionMargin); - // Create the terrain shape from the mapInfo - m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape(m_mapInfo.ptr); + m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape( m_mapInfo.ID, + new Vector3(m_mapInfo.sizeX, m_mapInfo.sizeY, 0), m_mapInfo.minZ, m_mapInfo.maxZ, + m_mapInfo.heightMap, 1f, BSParam.TerrainCollisionMargin); + // The terrain object initial position is at the center of the object Vector3 centerPos; @@ -138,7 +137,6 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_mapInfo.terrainBody); // Frees both the body and the shape. PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody); - PhysicsScene.PE.ReleaseHeightMapInfo(m_mapInfo.ptr); } } m_mapInfo = null; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs index c8f4602..681d21e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs @@ -189,9 +189,8 @@ public class BulletConstraint // than making copies. public class BulletHMapInfo { - public BulletHMapInfo(uint id, float[] hm, IntPtr xx) { + public BulletHMapInfo(uint id, float[] hm) { ID = id; - ptr = xx; heightMap = hm; terrainRegionBase = OMV.Vector3.Zero; minCoords = new OMV.Vector3(100f, 100f, 25f); @@ -200,7 +199,6 @@ public class BulletHMapInfo sizeX = sizeY = 256f; } public uint ID; - public IntPtr ptr; public float[] heightMap; public OMV.Vector3 terrainRegionBase; public OMV.Vector3 minCoords; -- cgit v1.1 From 6988b5ceaf6387198f0d23769adefdf572757c4a Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 31 Dec 2012 17:06:47 -0800 Subject: BulletSim: remove rigid body contruction functions from BSAPITemplate that relied on prebuilt construction info structures. --- OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 56 ---------------------- .../Region/Physics/BulletSPlugin/BSApiTemplate.cs | 5 -- 2 files changed, 61 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs index cf37e56..a06f6d0 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs @@ -226,11 +226,6 @@ public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape return new BulletShape(BSAPICPP.DuplicateCollisionShape2(sim.ptr, srcShape.ptr, id), srcShape.type); } -public override BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo) -{ - return new BulletBody(id, BSAPICPP.CreateBodyFromShapeAndInfo2(sim.ptr, shape.ptr, id, constructionInfo)); -} - public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape) { return BSAPICPP.DeleteCollisionShape2(world.ptr, shape.ptr); @@ -256,16 +251,6 @@ public override BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape sha return new BulletBody(id, BSAPICPP.CreateGhostFromShape2(sim.ptr, shape.ptr, id, pos, rot)); } -public override IntPtr AllocateBodyInfo(BulletBody obj) -{ - return BSAPICPP.AllocateBodyInfo2(obj.ptr); -} - -public override void ReleaseBodyInfo(IntPtr obj) -{ - BSAPICPP.ReleaseBodyInfo2(obj); -} - public override void DestroyObject(BulletWorld sim, BulletBody obj) { BSAPICPP.DestroyObject2(sim.ptr, obj.ptr); @@ -273,25 +258,6 @@ public override void DestroyObject(BulletWorld sim, BulletBody obj) // ===================================================================================== // Terrain creation and helper routines - /* -public override IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords, - float[] heightMap, float collisionMargin) -{ - return BSAPICPP.CreateHeightMapInfo2(sim.ptr, id, minCoords, maxCoords, heightMap, collisionMargin); -} - -public override IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, - float[] heightMap, float collisionMargin) -{ - return BSAPICPP.FillHeightMapInfo2(sim.ptr, mapInfo, id, minCoords, maxCoords, heightMap, collisionMargin); -} - -public override bool ReleaseHeightMapInfo(IntPtr heightMapInfo) -{ - return BSAPICPP.ReleaseHeightMapInfo2(heightMapInfo); -} - */ - public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin) { return new BulletShape(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE); @@ -1083,9 +1049,6 @@ public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape); public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] @@ -1101,29 +1064,10 @@ public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr AllocateBodyInfo2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern void ReleaseBodyInfo2(IntPtr obj); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern void DestroyObject2(IntPtr sim, IntPtr obj); // ===================================================================================== // Terrain creation and helper routines - /* -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords, - [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords, - [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin); - -[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo); - */ - [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs index a618a21..6e67c7a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs @@ -346,7 +346,6 @@ public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape); public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id); -public abstract BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo); public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape); @@ -358,10 +357,6 @@ public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, u public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot); -public abstract IntPtr AllocateBodyInfo(BulletBody obj); - -public abstract void ReleaseBodyInfo(IntPtr obj); - public abstract void DestroyObject(BulletWorld sim, BulletBody obj); // ===================================================================================== -- cgit v1.1 From db3b6e892133c096f2c4244a0902b4f9f1a87371 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 31 Dec 2012 19:56:32 -0800 Subject: BulletSim: remove unused unmanaged memory reference functions from BSAPITemplate. --- OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 2 ++ OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs index a06f6d0..3975776 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs @@ -524,6 +524,7 @@ public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion BSAPICPP.SetTranslation2(obj.ptr, position, rotation); } + /* public override IntPtr GetBroadphaseHandle(BulletBody obj) { return BSAPICPP.GetBroadphaseHandle2(obj.ptr); @@ -533,6 +534,7 @@ public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle) { BSAPICPP.SetUserPointer2(obj.ptr, handle); } + */ public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel) { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs index 6e67c7a..699f055 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs @@ -475,9 +475,9 @@ public abstract Quaternion GetOrientation(BulletBody obj); public abstract void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation); -public abstract IntPtr GetBroadphaseHandle(BulletBody obj); +// public abstract IntPtr GetBroadphaseHandle(BulletBody obj); -public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle); +// public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle); public abstract void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel); -- cgit v1.1