aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
diff options
context:
space:
mode:
authorRobert Adams2012-12-13 12:42:25 -0800
committerRobert Adams2012-12-13 16:32:06 -0800
commit3b2b785a461eba34c26a45be246c2baef2820e39 (patch)
tree10f25858b084edcd6e58af0fb220b893260ddf5d /OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
parentBulletSim: remove extra linkset rebuilds. (diff)
downloadopensim-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/BulletSPlugin/BulletSimAPI.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs183
1 files changed, 7 insertions, 176 deletions
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 */
27using System; 27using System;
28using System.Collections.Generic;
28using System.Runtime.InteropServices; 29using System.Runtime.InteropServices;
29using System.Security; 30using System.Security;
30using System.Text; 31using System.Text;
@@ -32,110 +33,6 @@ using OpenMetaverse;
32 33
33namespace OpenSim.Region.Physics.BulletSPlugin { 34namespace 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
39public 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
54public 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
96public 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
140public enum ConstraintType : int 37public 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
153public 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.
172public 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)]
198public struct ConvexHull 51public 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
398public enum CollisionFilterGroups : uint 245public 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// ===============================================================================
459static class BulletSimAPI { 290static 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)]
463public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); 294public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);