diff options
author | Robert Adams | 2012-12-13 12:42:25 -0800 |
---|---|---|
committer | Robert Adams | 2012-12-13 16:32:06 -0800 |
commit | 3b2b785a461eba34c26a45be246c2baef2820e39 (patch) | |
tree | 10f25858b084edcd6e58af0fb220b893260ddf5d /OpenSim/Region/Physics | |
parent | BulletSim: remove extra linkset rebuilds. (diff) | |
download | opensim-SC_OLD-3b2b785a461eba34c26a45be246c2baef2820e39.zip opensim-SC_OLD-3b2b785a461eba34c26a45be246c2baef2820e39.tar.gz opensim-SC_OLD-3b2b785a461eba34c26a45be246c2baef2820e39.tar.bz2 opensim-SC_OLD-3b2b785a461eba34c26a45be246c2baef2820e39.tar.xz |
BulletSim: Add 'BulletSimData' which separates structures created
for the operation of BulletSim and those defintiions/structures defined
so they can be used in the unmanaged world.
Consolidate setting of collision flags so implementation is not scattered.
Diffstat (limited to 'OpenSim/Region/Physics')
7 files changed, 308 insertions, 205 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index c8aad8d..0defb24 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -167,9 +167,8 @@ public sealed class BSCharacter : BSPhysObject | |||
167 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); | 167 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); |
168 | 168 | ||
169 | // Do this after the object has been added to the world | 169 | // Do this after the object has been added to the world |
170 | BulletSimAPI.SetCollisionGroupMask2(PhysBody.ptr, | 170 | PhysBody.collisionType = CollisionType.Avatar; |
171 | (uint)CollisionFilterGroups.AvatarGroup, | 171 | PhysBody.ApplyCollisionMask(); |
172 | (uint)CollisionFilterGroups.AvatarMask); | ||
173 | } | 172 | } |
174 | 173 | ||
175 | public override void RequestPhysicsterseUpdate() | 174 | public override void RequestPhysicsterseUpdate() |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 19c29cc..c9c9c2c 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -661,14 +661,7 @@ public sealed class BSPrim : BSPhysObject | |||
661 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); | 661 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); |
662 | 662 | ||
663 | // Collision filter can be set only when the object is in the world | 663 | // Collision filter can be set only when the object is in the world |
664 | if (PhysBody.collisionGroup != 0 || PhysBody.collisionMask != 0) | 664 | PhysBody.ApplyCollisionMask(); |
665 | { | ||
666 | if (!BulletSimAPI.SetCollisionGroupMask2(PhysBody.ptr, (uint)PhysBody.collisionGroup, (uint)PhysBody.collisionMask)) | ||
667 | { | ||
668 | PhysicsScene.Logger.ErrorFormat("{0} Failure setting prim collision mask. localID={1}, grp={2:X}, mask={3:X}", | ||
669 | LogHeader, LocalID, PhysBody.collisionGroup, PhysBody.collisionMask); | ||
670 | } | ||
671 | } | ||
672 | 665 | ||
673 | // Recompute any linkset parameters. | 666 | // Recompute any linkset parameters. |
674 | // When going from non-physical to physical, this re-enables the constraints that | 667 | // When going from non-physical to physical, this re-enables the constraints that |
@@ -713,11 +706,11 @@ public sealed class BSPrim : BSPhysObject | |||
713 | // Start it out sleeping and physical actions could wake it up. | 706 | // Start it out sleeping and physical actions could wake it up. |
714 | BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ISLAND_SLEEPING); | 707 | BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ISLAND_SLEEPING); |
715 | 708 | ||
709 | // This collides like a static object | ||
710 | PhysBody.collisionType = CollisionType.Static; | ||
711 | |||
716 | // There can be special things needed for implementing linksets | 712 | // There can be special things needed for implementing linksets |
717 | Linkset.MakeStatic(this); | 713 | Linkset.MakeStatic(this); |
718 | |||
719 | PhysBody.collisionGroup = CollisionFilterGroups.StaticObjectGroup; | ||
720 | PhysBody.collisionMask = CollisionFilterGroups.StaticObjectMask; | ||
721 | } | 714 | } |
722 | else | 715 | else |
723 | { | 716 | { |
@@ -755,16 +748,15 @@ public sealed class BSPrim : BSPhysObject | |||
755 | BulletSimAPI.SetSleepingThresholds2(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); | 748 | BulletSimAPI.SetSleepingThresholds2(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); |
756 | BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, PhysicsScene.Params.contactProcessingThreshold); | 749 | BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, PhysicsScene.Params.contactProcessingThreshold); |
757 | 750 | ||
758 | // There might be special things needed for implementing linksets. | 751 | // This collides like an object. |
759 | Linkset.MakeDynamic(this); | 752 | PhysBody.collisionType = CollisionType.Dynamic; |
760 | 753 | ||
761 | // Force activation of the object so Bullet will act on it. | 754 | // Force activation of the object so Bullet will act on it. |
762 | // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects. | 755 | // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects. |
763 | BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ACTIVE_TAG); | 756 | BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ACTIVE_TAG); |
764 | // BulletSimAPI.Activate2(BSBody.ptr, true); | ||
765 | 757 | ||
766 | PhysBody.collisionGroup = CollisionFilterGroups.ObjectGroup; | 758 | // There might be special things needed for implementing linksets. |
767 | PhysBody.collisionMask = CollisionFilterGroups.ObjectMask; | 759 | Linkset.MakeDynamic(this); |
768 | } | 760 | } |
769 | } | 761 | } |
770 | 762 | ||
@@ -791,8 +783,9 @@ public sealed class BSPrim : BSPhysObject | |||
791 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); | 783 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); |
792 | } | 784 | } |
793 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); | 785 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); |
794 | PhysBody.collisionGroup = CollisionFilterGroups.VolumeDetectGroup; | 786 | |
795 | PhysBody.collisionMask = CollisionFilterGroups.VolumeDetectMask; | 787 | // Change collision info from a static object to a ghosty collision object |
788 | PhysBody.collisionType = CollisionType.VolumeDetect; | ||
796 | } | 789 | } |
797 | } | 790 | } |
798 | 791 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index 2d379bb..2b120d6 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs | |||
@@ -121,9 +121,8 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
121 | // redo its bounding box now that it is in the world | 121 | // redo its bounding box now that it is in the world |
122 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); | 122 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); |
123 | 123 | ||
124 | BulletSimAPI.SetCollisionGroupMask2(m_mapInfo.terrainBody.ptr, | 124 | m_mapInfo.terrainBody.collisionType = CollisionType.Terrain; |
125 | (uint)CollisionFilterGroups.TerrainGroup, | 125 | m_mapInfo.terrainBody.ApplyCollisionMask(); |
126 | (uint)CollisionFilterGroups.TerrainMask); | ||
127 | 126 | ||
128 | // Make it so the terrain will not move or be considered for movement. | 127 | // Make it so the terrain will not move or be considered for movement. |
129 | BulletSimAPI.ForceActivationState2(m_mapInfo.terrainBody.ptr, ActivationState.DISABLE_SIMULATION); | 128 | BulletSimAPI.ForceActivationState2(m_mapInfo.terrainBody.ptr, ActivationState.DISABLE_SIMULATION); |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index c28d69d..5dbd8ce 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs | |||
@@ -140,8 +140,8 @@ public sealed class BSTerrainManager | |||
140 | // Ground plane does not move | 140 | // Ground plane does not move |
141 | BulletSimAPI.ForceActivationState2(m_groundPlane.ptr, ActivationState.DISABLE_SIMULATION); | 141 | BulletSimAPI.ForceActivationState2(m_groundPlane.ptr, ActivationState.DISABLE_SIMULATION); |
142 | // Everything collides with the ground plane. | 142 | // Everything collides with the ground plane. |
143 | BulletSimAPI.SetCollisionGroupMask2(m_groundPlane.ptr, | 143 | m_groundPlane.collisionType = CollisionType.Groundplane; |
144 | (uint)CollisionFilterGroups.GroundPlaneGroup, (uint)CollisionFilterGroups.GroundPlaneMask); | 144 | m_groundPlane.ApplyCollisionMask(); |
145 | 145 | ||
146 | // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain. | 146 | // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain. |
147 | BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize); | 147 | 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 3473006..6dc0d92 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs | |||
@@ -130,9 +130,8 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
130 | // Redo its bounding box now that it is in the world | 130 | // Redo its bounding box now that it is in the world |
131 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_terrainBody.ptr); | 131 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_terrainBody.ptr); |
132 | 132 | ||
133 | BulletSimAPI.SetCollisionGroupMask2(m_terrainBody.ptr, | 133 | m_terrainBody.collisionType = CollisionType.Terrain; |
134 | (uint)CollisionFilterGroups.TerrainGroup, | 134 | m_terrainBody.ApplyCollisionMask(); |
135 | (uint)CollisionFilterGroups.TerrainMask); | ||
136 | 135 | ||
137 | // Make it so the terrain will not move or be considered for movement. | 136 | // Make it so the terrain will not move or be considered for movement. |
138 | BulletSimAPI.ForceActivationState2(m_terrainBody.ptr, ActivationState.DISABLE_SIMULATION); | 137 | BulletSimAPI.ForceActivationState2(m_terrainBody.ptr, ActivationState.DISABLE_SIMULATION); |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index 1559025..962b540 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | |||
@@ -25,6 +25,7 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | ||
28 | using System.Runtime.InteropServices; | 29 | using System.Runtime.InteropServices; |
29 | using System.Security; | 30 | using System.Security; |
30 | using System.Text; | 31 | using System.Text; |
@@ -32,110 +33,6 @@ using OpenMetaverse; | |||
32 | 33 | ||
33 | namespace OpenSim.Region.Physics.BulletSPlugin { | 34 | namespace OpenSim.Region.Physics.BulletSPlugin { |
34 | 35 | ||
35 | // Classes to allow some type checking for the API | ||
36 | // These hold pointers to allocated objects in the unmanaged space. | ||
37 | |||
38 | // The physics engine controller class created at initialization | ||
39 | public struct BulletSim | ||
40 | { | ||
41 | public BulletSim(uint worldId, BSScene bss, IntPtr xx) | ||
42 | { | ||
43 | ptr = xx; | ||
44 | worldID = worldId; | ||
45 | physicsScene = bss; | ||
46 | } | ||
47 | public IntPtr ptr; | ||
48 | public uint worldID; | ||
49 | // The scene is only in here so very low level routines have a handle to print debug/error messages | ||
50 | public BSScene physicsScene; | ||
51 | } | ||
52 | |||
53 | // An allocated Bullet btRigidBody | ||
54 | public struct BulletBody | ||
55 | { | ||
56 | public BulletBody(uint id) : this(id, IntPtr.Zero) | ||
57 | { | ||
58 | } | ||
59 | public BulletBody(uint id, IntPtr xx) | ||
60 | { | ||
61 | ID = id; | ||
62 | ptr = xx; | ||
63 | collisionGroup = 0; | ||
64 | collisionMask = 0; | ||
65 | } | ||
66 | public IntPtr ptr; | ||
67 | public uint ID; | ||
68 | public CollisionFilterGroups collisionGroup; | ||
69 | public CollisionFilterGroups collisionMask; | ||
70 | |||
71 | public void Clear() | ||
72 | { | ||
73 | ptr = IntPtr.Zero; | ||
74 | } | ||
75 | public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } } | ||
76 | |||
77 | public override string ToString() | ||
78 | { | ||
79 | StringBuilder buff = new StringBuilder(); | ||
80 | buff.Append("<id="); | ||
81 | buff.Append(ID.ToString()); | ||
82 | buff.Append(",p="); | ||
83 | buff.Append(ptr.ToString("X")); | ||
84 | if (collisionGroup != 0 || collisionMask != 0) | ||
85 | { | ||
86 | buff.Append(",g="); | ||
87 | buff.Append(collisionGroup.ToString("X")); | ||
88 | buff.Append(",m="); | ||
89 | buff.Append(collisionMask.ToString("X")); | ||
90 | } | ||
91 | buff.Append(">"); | ||
92 | return buff.ToString(); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | public struct BulletShape | ||
97 | { | ||
98 | public BulletShape(IntPtr xx) | ||
99 | { | ||
100 | ptr = xx; | ||
101 | type=BSPhysicsShapeType.SHAPE_UNKNOWN; | ||
102 | shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; | ||
103 | isNativeShape = false; | ||
104 | } | ||
105 | public BulletShape(IntPtr xx, BSPhysicsShapeType typ) | ||
106 | { | ||
107 | ptr = xx; | ||
108 | type = typ; | ||
109 | shapeKey = 0; | ||
110 | isNativeShape = false; | ||
111 | } | ||
112 | public IntPtr ptr; | ||
113 | public BSPhysicsShapeType type; | ||
114 | public System.UInt64 shapeKey; | ||
115 | public bool isNativeShape; | ||
116 | |||
117 | public void Clear() | ||
118 | { | ||
119 | ptr = IntPtr.Zero; | ||
120 | } | ||
121 | public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } } | ||
122 | |||
123 | public override string ToString() | ||
124 | { | ||
125 | StringBuilder buff = new StringBuilder(); | ||
126 | buff.Append("<p="); | ||
127 | buff.Append(ptr.ToString("X")); | ||
128 | buff.Append(",s="); | ||
129 | buff.Append(type.ToString()); | ||
130 | buff.Append(",k="); | ||
131 | buff.Append(shapeKey.ToString("X")); | ||
132 | buff.Append(",n="); | ||
133 | buff.Append(isNativeShape.ToString()); | ||
134 | buff.Append(">"); | ||
135 | return buff.ToString(); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | // Constraint type values as defined by Bullet | 36 | // Constraint type values as defined by Bullet |
140 | public enum ConstraintType : int | 37 | public enum ConstraintType : int |
141 | { | 38 | { |
@@ -149,50 +46,6 @@ public enum ConstraintType : int | |||
149 | MAX_CONSTRAINT_TYPE | 46 | MAX_CONSTRAINT_TYPE |
150 | } | 47 | } |
151 | 48 | ||
152 | // An allocated Bullet btConstraint | ||
153 | public struct BulletConstraint | ||
154 | { | ||
155 | public BulletConstraint(IntPtr xx) | ||
156 | { | ||
157 | ptr = xx; | ||
158 | } | ||
159 | public IntPtr ptr; | ||
160 | |||
161 | public void Clear() | ||
162 | { | ||
163 | ptr = IntPtr.Zero; | ||
164 | } | ||
165 | public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } } | ||
166 | } | ||
167 | |||
168 | // An allocated HeightMapThing which holds various heightmap info. | ||
169 | // Made a class rather than a struct so there would be only one | ||
170 | // instance of this and C# will pass around pointers rather | ||
171 | // than making copies. | ||
172 | public class BulletHeightMapInfo | ||
173 | { | ||
174 | public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) { | ||
175 | ID = id; | ||
176 | Ptr = xx; | ||
177 | heightMap = hm; | ||
178 | terrainRegionBase = Vector3.Zero; | ||
179 | minCoords = new Vector3(100f, 100f, 25f); | ||
180 | maxCoords = new Vector3(101f, 101f, 26f); | ||
181 | minZ = maxZ = 0f; | ||
182 | sizeX = sizeY = 256f; | ||
183 | } | ||
184 | public uint ID; | ||
185 | public IntPtr Ptr; | ||
186 | public float[] heightMap; | ||
187 | public Vector3 terrainRegionBase; | ||
188 | public Vector3 minCoords; | ||
189 | public Vector3 maxCoords; | ||
190 | public float sizeX, sizeY; | ||
191 | public float minZ, maxZ; | ||
192 | public BulletShape terrainShape; | ||
193 | public BulletBody terrainBody; | ||
194 | } | ||
195 | |||
196 | // =============================================================================== | 49 | // =============================================================================== |
197 | [StructLayout(LayoutKind.Sequential)] | 50 | [StructLayout(LayoutKind.Sequential)] |
198 | public struct ConvexHull | 51 | public struct ConvexHull |
@@ -385,21 +238,15 @@ public enum CollisionFlags : uint | |||
385 | BS_FLOATS_ON_WATER = 1 << 11, | 238 | BS_FLOATS_ON_WATER = 1 << 11, |
386 | BS_VEHICLE_COLLISIONS = 1 << 12, | 239 | BS_VEHICLE_COLLISIONS = 1 << 12, |
387 | BS_NONE = 0, | 240 | BS_NONE = 0, |
388 | BS_ALL = 0xFFFFFFFF, | 241 | BS_ALL = 0xFFFFFFFF |
389 | |||
390 | // These are the collision flags switched depending on physical state. | ||
391 | // The other flags are used for other things and should not be fooled with. | ||
392 | BS_ACTIVE = CF_STATIC_OBJECT | ||
393 | | CF_KINEMATIC_OBJECT | ||
394 | | CF_NO_CONTACT_RESPONSE | ||
395 | }; | 242 | }; |
396 | 243 | ||
397 | // Values for collisions groups and masks | 244 | // Values f collisions groups and masks |
398 | public enum CollisionFilterGroups : uint | 245 | public enum CollisionFilterGroups : uint |
399 | { | 246 | { |
400 | // Don't use the bit definitions!! Define the use in a | 247 | // Don't use the bit definitions!! Define the use in a |
401 | // filter/mask definition below. This way collision interactions | 248 | // filter/mask definition below. This way collision interactions |
402 | // are more easily debugged. | 249 | // are more easily found and debugged. |
403 | BNoneGroup = 0, | 250 | BNoneGroup = 0, |
404 | BDefaultGroup = 1 << 0, | 251 | BDefaultGroup = 1 << 0, |
405 | BStaticGroup = 1 << 1, | 252 | BStaticGroup = 1 << 1, |
@@ -413,24 +260,8 @@ public enum CollisionFilterGroups : uint | |||
413 | BTerrainGroup = 1 << 11, | 260 | BTerrainGroup = 1 << 11, |
414 | BRaycastGroup = 1 << 12, | 261 | BRaycastGroup = 1 << 12, |
415 | BSolidGroup = 1 << 13, | 262 | BSolidGroup = 1 << 13, |
416 | BLinksetGroup = 1 << 14, | 263 | // BLinksetGroup = xx // a linkset proper is either static or dynamic |
417 | 264 | BLinksetChildGroup = 1 << 14, | |
418 | // The collsion filters and masked are defined in one place -- don't want them scattered | ||
419 | AvatarGroup = BCharacterGroup, | ||
420 | AvatarMask = BAllGroup, | ||
421 | ObjectGroup = BSolidGroup, | ||
422 | ObjectMask = BAllGroup, | ||
423 | StaticObjectGroup = BStaticGroup, | ||
424 | StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much | ||
425 | LinksetGroup = BLinksetGroup, | ||
426 | LinksetMask = BAllGroup & ~BLinksetGroup, // linkset objects don't collide with each other | ||
427 | VolumeDetectGroup = BSensorTrigger, | ||
428 | VolumeDetectMask = ~BSensorTrigger, | ||
429 | TerrainGroup = BTerrainGroup, | ||
430 | TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide | ||
431 | GroundPlaneGroup = BGroundPlaneGroup, | ||
432 | GroundPlaneMask = BAllGroup | ||
433 | |||
434 | }; | 265 | }; |
435 | 266 | ||
436 | // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 | 267 | // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 |
@@ -457,7 +288,7 @@ public enum ConstraintParamAxis : int | |||
457 | 288 | ||
458 | // =============================================================================== | 289 | // =============================================================================== |
459 | static class BulletSimAPI { | 290 | static class BulletSimAPI { |
460 | 291 | // =============================================================================== | |
461 | // Link back to the managed code for outputting log messages | 292 | // Link back to the managed code for outputting log messages |
462 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] | 293 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
463 | public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); | 294 | public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs new file mode 100755 index 0000000..e5c4777 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs | |||
@@ -0,0 +1,282 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using OMV = OpenMetaverse; | ||
31 | |||
32 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
33 | { | ||
34 | // Classes to allow some type checking for the API | ||
35 | // These hold pointers to allocated objects in the unmanaged space. | ||
36 | |||
37 | // The physics engine controller class created at initialization | ||
38 | public struct BulletSim | ||
39 | { | ||
40 | public BulletSim(uint worldId, BSScene bss, IntPtr xx) | ||
41 | { | ||
42 | ptr = xx; | ||
43 | worldID = worldId; | ||
44 | physicsScene = bss; | ||
45 | } | ||
46 | public IntPtr ptr; | ||
47 | public uint worldID; | ||
48 | // The scene is only in here so very low level routines have a handle to print debug/error messages | ||
49 | public BSScene physicsScene; | ||
50 | } | ||
51 | |||
52 | // An allocated Bullet btRigidBody | ||
53 | public struct BulletBody | ||
54 | { | ||
55 | public BulletBody(uint id) : this(id, IntPtr.Zero) | ||
56 | { | ||
57 | } | ||
58 | public BulletBody(uint id, IntPtr xx) | ||
59 | { | ||
60 | ID = id; | ||
61 | ptr = xx; | ||
62 | collisionType = CollisionType.Static; | ||
63 | } | ||
64 | public IntPtr ptr; | ||
65 | public uint ID; | ||
66 | public CollisionType collisionType; | ||
67 | |||
68 | public void Clear() | ||
69 | { | ||
70 | ptr = IntPtr.Zero; | ||
71 | } | ||
72 | public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } } | ||
73 | |||
74 | // Apply the specificed collision mask into the physical world | ||
75 | public void ApplyCollisionMask() | ||
76 | { | ||
77 | // Should assert the body has been added to the physical world. | ||
78 | // (The collision masks are stored in the collision proxy cache which only exists for | ||
79 | // a collision body that is in the world.) | ||
80 | BulletSimAPI.SetCollisionGroupMask2(ptr, | ||
81 | BulletSimData.CollisionTypeMasks[collisionType].group, | ||
82 | BulletSimData.CollisionTypeMasks[collisionType].mask); | ||
83 | } | ||
84 | |||
85 | public override string ToString() | ||
86 | { | ||
87 | StringBuilder buff = new StringBuilder(); | ||
88 | buff.Append("<id="); | ||
89 | buff.Append(ID.ToString()); | ||
90 | buff.Append(",p="); | ||
91 | buff.Append(ptr.ToString("X")); | ||
92 | buff.Append(",c="); | ||
93 | buff.Append(collisionType); | ||
94 | buff.Append(">"); | ||
95 | return buff.ToString(); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | public struct BulletShape | ||
100 | { | ||
101 | public BulletShape(IntPtr xx) | ||
102 | { | ||
103 | ptr = xx; | ||
104 | type=BSPhysicsShapeType.SHAPE_UNKNOWN; | ||
105 | shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; | ||
106 | isNativeShape = false; | ||
107 | } | ||
108 | public BulletShape(IntPtr xx, BSPhysicsShapeType typ) | ||
109 | { | ||
110 | ptr = xx; | ||
111 | type = typ; | ||
112 | shapeKey = 0; | ||
113 | isNativeShape = false; | ||
114 | } | ||
115 | public IntPtr ptr; | ||
116 | public BSPhysicsShapeType type; | ||
117 | public System.UInt64 shapeKey; | ||
118 | public bool isNativeShape; | ||
119 | |||
120 | public void Clear() | ||
121 | { | ||
122 | ptr = IntPtr.Zero; | ||
123 | } | ||
124 | public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } } | ||
125 | |||
126 | public override string ToString() | ||
127 | { | ||
128 | StringBuilder buff = new StringBuilder(); | ||
129 | buff.Append("<p="); | ||
130 | buff.Append(ptr.ToString("X")); | ||
131 | buff.Append(",s="); | ||
132 | buff.Append(type.ToString()); | ||
133 | buff.Append(",k="); | ||
134 | buff.Append(shapeKey.ToString("X")); | ||
135 | buff.Append(",n="); | ||
136 | buff.Append(isNativeShape.ToString()); | ||
137 | buff.Append(">"); | ||
138 | return buff.ToString(); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | // An allocated Bullet btConstraint | ||
143 | public struct BulletConstraint | ||
144 | { | ||
145 | public BulletConstraint(IntPtr xx) | ||
146 | { | ||
147 | ptr = xx; | ||
148 | } | ||
149 | public IntPtr ptr; | ||
150 | |||
151 | public void Clear() | ||
152 | { | ||
153 | ptr = IntPtr.Zero; | ||
154 | } | ||
155 | public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } } | ||
156 | } | ||
157 | |||
158 | // An allocated HeightMapThing which holds various heightmap info. | ||
159 | // Made a class rather than a struct so there would be only one | ||
160 | // instance of this and C# will pass around pointers rather | ||
161 | // than making copies. | ||
162 | public class BulletHeightMapInfo | ||
163 | { | ||
164 | public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) { | ||
165 | ID = id; | ||
166 | Ptr = xx; | ||
167 | heightMap = hm; | ||
168 | terrainRegionBase = OMV.Vector3.Zero; | ||
169 | minCoords = new OMV.Vector3(100f, 100f, 25f); | ||
170 | maxCoords = new OMV.Vector3(101f, 101f, 26f); | ||
171 | minZ = maxZ = 0f; | ||
172 | sizeX = sizeY = 256f; | ||
173 | } | ||
174 | public uint ID; | ||
175 | public IntPtr Ptr; | ||
176 | public float[] heightMap; | ||
177 | public OMV.Vector3 terrainRegionBase; | ||
178 | public OMV.Vector3 minCoords; | ||
179 | public OMV.Vector3 maxCoords; | ||
180 | public float sizeX, sizeY; | ||
181 | public float minZ, maxZ; | ||
182 | public BulletShape terrainShape; | ||
183 | public BulletBody terrainBody; | ||
184 | } | ||
185 | |||
186 | // The general class of collsion object. | ||
187 | public enum CollisionType | ||
188 | { | ||
189 | Avatar, | ||
190 | Groundplane, | ||
191 | Terrain, | ||
192 | Static, | ||
193 | Dynamic, | ||
194 | VolumeDetect, | ||
195 | // Linkset, // A linkset proper should be either Static or Dynamic | ||
196 | LinksetChild, | ||
197 | Unknown | ||
198 | }; | ||
199 | |||
200 | // Hold specification of group and mask collision flags for a CollisionType | ||
201 | public struct CollisionTypeFilterGroup | ||
202 | { | ||
203 | public CollisionTypeFilterGroup(CollisionType t, uint g, uint m) | ||
204 | { | ||
205 | type = t; | ||
206 | group = g; | ||
207 | mask = m; | ||
208 | } | ||
209 | public CollisionType type; | ||
210 | public uint group; | ||
211 | public uint mask; | ||
212 | }; | ||
213 | |||
214 | /* | ||
215 | // The collsion filters and masked are defined in one place -- don't want them scattered | ||
216 | AvatarGroup = BCharacterGroup, | ||
217 | AvatarMask = BAllGroup, | ||
218 | ObjectGroup = BSolidGroup, | ||
219 | ObjectMask = BAllGroup, | ||
220 | StaticObjectGroup = BStaticGroup, | ||
221 | StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much | ||
222 | LinksetGroup = BLinksetGroup, | ||
223 | LinksetMask = BAllGroup, | ||
224 | LinksetChildGroup = BLinksetChildGroup, | ||
225 | LinksetChildMask = BNoneGroup, // Linkset children disappear from the world | ||
226 | VolumeDetectGroup = BSensorTrigger, | ||
227 | VolumeDetectMask = ~BSensorTrigger, | ||
228 | TerrainGroup = BTerrainGroup, | ||
229 | TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide | ||
230 | GroundPlaneGroup = BGroundPlaneGroup, | ||
231 | GroundPlaneMask = BAllGroup | ||
232 | */ | ||
233 | |||
234 | public static class BulletSimData | ||
235 | { | ||
236 | |||
237 | // Map of collisionTypes to flags for collision groups and masks. | ||
238 | // As mentioned above, don't use the CollisionFilterGroups definitions directly in the code | ||
239 | // but, instead, user references to this dictionary. This makes finding and debugging | ||
240 | // collision flag usage easier. | ||
241 | public static Dictionary<CollisionType, CollisionTypeFilterGroup> CollisionTypeMasks | ||
242 | = new Dictionary<CollisionType, CollisionTypeFilterGroup>() | ||
243 | { | ||
244 | { CollisionType.Avatar, | ||
245 | new CollisionTypeFilterGroup(CollisionType.Avatar, | ||
246 | (uint)CollisionFilterGroups.BCharacterGroup, | ||
247 | (uint)CollisionFilterGroups.BAllGroup) | ||
248 | }, | ||
249 | { CollisionType.Groundplane, | ||
250 | new CollisionTypeFilterGroup(CollisionType.Groundplane, | ||
251 | (uint)CollisionFilterGroups.BGroundPlaneGroup, | ||
252 | (uint)CollisionFilterGroups.BAllGroup) | ||
253 | }, | ||
254 | { CollisionType.Terrain, | ||
255 | new CollisionTypeFilterGroup(CollisionType.Terrain, | ||
256 | (uint)CollisionFilterGroups.BTerrainGroup, | ||
257 | (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup)) | ||
258 | }, | ||
259 | { CollisionType.Static, | ||
260 | new CollisionTypeFilterGroup(CollisionType.Static, | ||
261 | (uint)CollisionFilterGroups.BStaticGroup, | ||
262 | (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) | ||
263 | }, | ||
264 | { CollisionType.Dynamic, | ||
265 | new CollisionTypeFilterGroup(CollisionType.Dynamic, | ||
266 | (uint)CollisionFilterGroups.BSolidGroup, | ||
267 | (uint)(CollisionFilterGroups.BAllGroup)) | ||
268 | }, | ||
269 | { CollisionType.VolumeDetect, | ||
270 | new CollisionTypeFilterGroup(CollisionType.VolumeDetect, | ||
271 | (uint)CollisionFilterGroups.BSensorTrigger, | ||
272 | (uint)(~CollisionFilterGroups.BSensorTrigger)) | ||
273 | }, | ||
274 | { CollisionType.LinksetChild, | ||
275 | new CollisionTypeFilterGroup(CollisionType.LinksetChild, | ||
276 | (uint)CollisionFilterGroups.BTerrainGroup, | ||
277 | (uint)(CollisionFilterGroups.BNoneGroup)) | ||
278 | }, | ||
279 | }; | ||
280 | |||
281 | } | ||
282 | } | ||