aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs564
1 files changed, 282 insertions, 282 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
index e5c4777..524a1d0 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
@@ -1,282 +1,282 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyrightD 9 * * Redistributions in binary form must reproduce the above copyrightD
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the 12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Text; 29using System.Text;
30using OMV = OpenMetaverse; 30using OMV = OpenMetaverse;
31 31
32namespace OpenSim.Region.Physics.BulletSPlugin 32namespace OpenSim.Region.Physics.BulletSPlugin
33{ 33{
34// Classes to allow some type checking for the API 34// Classes to allow some type checking for the API
35// These hold pointers to allocated objects in the unmanaged space. 35// These hold pointers to allocated objects in the unmanaged space.
36 36
37// The physics engine controller class created at initialization 37// The physics engine controller class created at initialization
38public struct BulletSim 38public struct BulletSim
39{ 39{
40 public BulletSim(uint worldId, BSScene bss, IntPtr xx) 40 public BulletSim(uint worldId, BSScene bss, IntPtr xx)
41 { 41 {
42 ptr = xx; 42 ptr = xx;
43 worldID = worldId; 43 worldID = worldId;
44 physicsScene = bss; 44 physicsScene = bss;
45 } 45 }
46 public IntPtr ptr; 46 public IntPtr ptr;
47 public uint worldID; 47 public uint worldID;
48 // The scene is only in here so very low level routines have a handle to print debug/error messages 48 // The scene is only in here so very low level routines have a handle to print debug/error messages
49 public BSScene physicsScene; 49 public BSScene physicsScene;
50} 50}
51 51
52// An allocated Bullet btRigidBody 52// An allocated Bullet btRigidBody
53public struct BulletBody 53public struct BulletBody
54{ 54{
55 public BulletBody(uint id) : this(id, IntPtr.Zero) 55 public BulletBody(uint id) : this(id, IntPtr.Zero)
56 { 56 {
57 } 57 }
58 public BulletBody(uint id, IntPtr xx) 58 public BulletBody(uint id, IntPtr xx)
59 { 59 {
60 ID = id; 60 ID = id;
61 ptr = xx; 61 ptr = xx;
62 collisionType = CollisionType.Static; 62 collisionType = CollisionType.Static;
63 } 63 }
64 public IntPtr ptr; 64 public IntPtr ptr;
65 public uint ID; 65 public uint ID;
66 public CollisionType collisionType; 66 public CollisionType collisionType;
67 67
68 public void Clear() 68 public void Clear()
69 { 69 {
70 ptr = IntPtr.Zero; 70 ptr = IntPtr.Zero;
71 } 71 }
72 public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } } 72 public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } }
73 73
74 // Apply the specificed collision mask into the physical world 74 // Apply the specificed collision mask into the physical world
75 public void ApplyCollisionMask() 75 public void ApplyCollisionMask()
76 { 76 {
77 // Should assert the body has been added to the physical world. 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 78 // (The collision masks are stored in the collision proxy cache which only exists for
79 // a collision body that is in the world.) 79 // a collision body that is in the world.)
80 BulletSimAPI.SetCollisionGroupMask2(ptr, 80 BulletSimAPI.SetCollisionGroupMask2(ptr,
81 BulletSimData.CollisionTypeMasks[collisionType].group, 81 BulletSimData.CollisionTypeMasks[collisionType].group,
82 BulletSimData.CollisionTypeMasks[collisionType].mask); 82 BulletSimData.CollisionTypeMasks[collisionType].mask);
83 } 83 }
84 84
85 public override string ToString() 85 public override string ToString()
86 { 86 {
87 StringBuilder buff = new StringBuilder(); 87 StringBuilder buff = new StringBuilder();
88 buff.Append("<id="); 88 buff.Append("<id=");
89 buff.Append(ID.ToString()); 89 buff.Append(ID.ToString());
90 buff.Append(",p="); 90 buff.Append(",p=");
91 buff.Append(ptr.ToString("X")); 91 buff.Append(ptr.ToString("X"));
92 buff.Append(",c="); 92 buff.Append(",c=");
93 buff.Append(collisionType); 93 buff.Append(collisionType);
94 buff.Append(">"); 94 buff.Append(">");
95 return buff.ToString(); 95 return buff.ToString();
96 } 96 }
97} 97}
98 98
99public struct BulletShape 99public struct BulletShape
100{ 100{
101 public BulletShape(IntPtr xx) 101 public BulletShape(IntPtr xx)
102 { 102 {
103 ptr = xx; 103 ptr = xx;
104 type=BSPhysicsShapeType.SHAPE_UNKNOWN; 104 type=BSPhysicsShapeType.SHAPE_UNKNOWN;
105 shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; 105 shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE;
106 isNativeShape = false; 106 isNativeShape = false;
107 } 107 }
108 public BulletShape(IntPtr xx, BSPhysicsShapeType typ) 108 public BulletShape(IntPtr xx, BSPhysicsShapeType typ)
109 { 109 {
110 ptr = xx; 110 ptr = xx;
111 type = typ; 111 type = typ;
112 shapeKey = 0; 112 shapeKey = 0;
113 isNativeShape = false; 113 isNativeShape = false;
114 } 114 }
115 public IntPtr ptr; 115 public IntPtr ptr;
116 public BSPhysicsShapeType type; 116 public BSPhysicsShapeType type;
117 public System.UInt64 shapeKey; 117 public System.UInt64 shapeKey;
118 public bool isNativeShape; 118 public bool isNativeShape;
119 119
120 public void Clear() 120 public void Clear()
121 { 121 {
122 ptr = IntPtr.Zero; 122 ptr = IntPtr.Zero;
123 } 123 }
124 public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } } 124 public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } }
125 125
126 public override string ToString() 126 public override string ToString()
127 { 127 {
128 StringBuilder buff = new StringBuilder(); 128 StringBuilder buff = new StringBuilder();
129 buff.Append("<p="); 129 buff.Append("<p=");
130 buff.Append(ptr.ToString("X")); 130 buff.Append(ptr.ToString("X"));
131 buff.Append(",s="); 131 buff.Append(",s=");
132 buff.Append(type.ToString()); 132 buff.Append(type.ToString());
133 buff.Append(",k="); 133 buff.Append(",k=");
134 buff.Append(shapeKey.ToString("X")); 134 buff.Append(shapeKey.ToString("X"));
135 buff.Append(",n="); 135 buff.Append(",n=");
136 buff.Append(isNativeShape.ToString()); 136 buff.Append(isNativeShape.ToString());
137 buff.Append(">"); 137 buff.Append(">");
138 return buff.ToString(); 138 return buff.ToString();
139 } 139 }
140} 140}
141 141
142// An allocated Bullet btConstraint 142// An allocated Bullet btConstraint
143public struct BulletConstraint 143public struct BulletConstraint
144{ 144{
145 public BulletConstraint(IntPtr xx) 145 public BulletConstraint(IntPtr xx)
146 { 146 {
147 ptr = xx; 147 ptr = xx;
148 } 148 }
149 public IntPtr ptr; 149 public IntPtr ptr;
150 150
151 public void Clear() 151 public void Clear()
152 { 152 {
153 ptr = IntPtr.Zero; 153 ptr = IntPtr.Zero;
154 } 154 }
155 public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } } 155 public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } }
156} 156}
157 157
158// An allocated HeightMapThing which holds various heightmap info. 158// An allocated HeightMapThing which holds various heightmap info.
159// Made a class rather than a struct so there would be only one 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 160// instance of this and C# will pass around pointers rather
161// than making copies. 161// than making copies.
162public class BulletHeightMapInfo 162public class BulletHeightMapInfo
163{ 163{
164 public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) { 164 public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) {
165 ID = id; 165 ID = id;
166 Ptr = xx; 166 Ptr = xx;
167 heightMap = hm; 167 heightMap = hm;
168 terrainRegionBase = OMV.Vector3.Zero; 168 terrainRegionBase = OMV.Vector3.Zero;
169 minCoords = new OMV.Vector3(100f, 100f, 25f); 169 minCoords = new OMV.Vector3(100f, 100f, 25f);
170 maxCoords = new OMV.Vector3(101f, 101f, 26f); 170 maxCoords = new OMV.Vector3(101f, 101f, 26f);
171 minZ = maxZ = 0f; 171 minZ = maxZ = 0f;
172 sizeX = sizeY = 256f; 172 sizeX = sizeY = 256f;
173 } 173 }
174 public uint ID; 174 public uint ID;
175 public IntPtr Ptr; 175 public IntPtr Ptr;
176 public float[] heightMap; 176 public float[] heightMap;
177 public OMV.Vector3 terrainRegionBase; 177 public OMV.Vector3 terrainRegionBase;
178 public OMV.Vector3 minCoords; 178 public OMV.Vector3 minCoords;
179 public OMV.Vector3 maxCoords; 179 public OMV.Vector3 maxCoords;
180 public float sizeX, sizeY; 180 public float sizeX, sizeY;
181 public float minZ, maxZ; 181 public float minZ, maxZ;
182 public BulletShape terrainShape; 182 public BulletShape terrainShape;
183 public BulletBody terrainBody; 183 public BulletBody terrainBody;
184} 184}
185 185
186// The general class of collsion object. 186// The general class of collsion object.
187public enum CollisionType 187public enum CollisionType
188{ 188{
189 Avatar, 189 Avatar,
190 Groundplane, 190 Groundplane,
191 Terrain, 191 Terrain,
192 Static, 192 Static,
193 Dynamic, 193 Dynamic,
194 VolumeDetect, 194 VolumeDetect,
195 // Linkset, // A linkset proper should be either Static or Dynamic 195 // Linkset, // A linkset proper should be either Static or Dynamic
196 LinksetChild, 196 LinksetChild,
197 Unknown 197 Unknown
198}; 198};
199 199
200// Hold specification of group and mask collision flags for a CollisionType 200// Hold specification of group and mask collision flags for a CollisionType
201public struct CollisionTypeFilterGroup 201public struct CollisionTypeFilterGroup
202{ 202{
203 public CollisionTypeFilterGroup(CollisionType t, uint g, uint m) 203 public CollisionTypeFilterGroup(CollisionType t, uint g, uint m)
204 { 204 {
205 type = t; 205 type = t;
206 group = g; 206 group = g;
207 mask = m; 207 mask = m;
208 } 208 }
209 public CollisionType type; 209 public CollisionType type;
210 public uint group; 210 public uint group;
211 public uint mask; 211 public uint mask;
212}; 212};
213 213
214 /* 214 /*
215 // The collsion filters and masked are defined in one place -- don't want them scattered 215 // The collsion filters and masked are defined in one place -- don't want them scattered
216 AvatarGroup = BCharacterGroup, 216 AvatarGroup = BCharacterGroup,
217 AvatarMask = BAllGroup, 217 AvatarMask = BAllGroup,
218 ObjectGroup = BSolidGroup, 218 ObjectGroup = BSolidGroup,
219 ObjectMask = BAllGroup, 219 ObjectMask = BAllGroup,
220 StaticObjectGroup = BStaticGroup, 220 StaticObjectGroup = BStaticGroup,
221 StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much 221 StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much
222 LinksetGroup = BLinksetGroup, 222 LinksetGroup = BLinksetGroup,
223 LinksetMask = BAllGroup, 223 LinksetMask = BAllGroup,
224 LinksetChildGroup = BLinksetChildGroup, 224 LinksetChildGroup = BLinksetChildGroup,
225 LinksetChildMask = BNoneGroup, // Linkset children disappear from the world 225 LinksetChildMask = BNoneGroup, // Linkset children disappear from the world
226 VolumeDetectGroup = BSensorTrigger, 226 VolumeDetectGroup = BSensorTrigger,
227 VolumeDetectMask = ~BSensorTrigger, 227 VolumeDetectMask = ~BSensorTrigger,
228 TerrainGroup = BTerrainGroup, 228 TerrainGroup = BTerrainGroup,
229 TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide 229 TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide
230 GroundPlaneGroup = BGroundPlaneGroup, 230 GroundPlaneGroup = BGroundPlaneGroup,
231 GroundPlaneMask = BAllGroup 231 GroundPlaneMask = BAllGroup
232 */ 232 */
233 233
234public static class BulletSimData 234public static class BulletSimData
235{ 235{
236 236
237// Map of collisionTypes to flags for collision groups and masks. 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 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 239// but, instead, use references to this dictionary. Finding and debugging
240// collision flag usage easier. 240// collision flag problems will be made easier.
241public static Dictionary<CollisionType, CollisionTypeFilterGroup> CollisionTypeMasks 241public static Dictionary<CollisionType, CollisionTypeFilterGroup> CollisionTypeMasks
242 = new Dictionary<CollisionType, CollisionTypeFilterGroup>() 242 = new Dictionary<CollisionType, CollisionTypeFilterGroup>()
243{ 243{
244 { CollisionType.Avatar, 244 { CollisionType.Avatar,
245 new CollisionTypeFilterGroup(CollisionType.Avatar, 245 new CollisionTypeFilterGroup(CollisionType.Avatar,
246 (uint)CollisionFilterGroups.BCharacterGroup, 246 (uint)CollisionFilterGroups.BCharacterGroup,
247 (uint)CollisionFilterGroups.BAllGroup) 247 (uint)CollisionFilterGroups.BAllGroup)
248 }, 248 },
249 { CollisionType.Groundplane, 249 { CollisionType.Groundplane,
250 new CollisionTypeFilterGroup(CollisionType.Groundplane, 250 new CollisionTypeFilterGroup(CollisionType.Groundplane,
251 (uint)CollisionFilterGroups.BGroundPlaneGroup, 251 (uint)CollisionFilterGroups.BGroundPlaneGroup,
252 (uint)CollisionFilterGroups.BAllGroup) 252 (uint)CollisionFilterGroups.BAllGroup)
253 }, 253 },
254 { CollisionType.Terrain, 254 { CollisionType.Terrain,
255 new CollisionTypeFilterGroup(CollisionType.Terrain, 255 new CollisionTypeFilterGroup(CollisionType.Terrain,
256 (uint)CollisionFilterGroups.BTerrainGroup, 256 (uint)CollisionFilterGroups.BTerrainGroup,
257 (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup)) 257 (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup))
258 }, 258 },
259 { CollisionType.Static, 259 { CollisionType.Static,
260 new CollisionTypeFilterGroup(CollisionType.Static, 260 new CollisionTypeFilterGroup(CollisionType.Static,
261 (uint)CollisionFilterGroups.BStaticGroup, 261 (uint)CollisionFilterGroups.BStaticGroup,
262 (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) 262 (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup))
263 }, 263 },
264 { CollisionType.Dynamic, 264 { CollisionType.Dynamic,
265 new CollisionTypeFilterGroup(CollisionType.Dynamic, 265 new CollisionTypeFilterGroup(CollisionType.Dynamic,
266 (uint)CollisionFilterGroups.BSolidGroup, 266 (uint)CollisionFilterGroups.BSolidGroup,
267 (uint)(CollisionFilterGroups.BAllGroup)) 267 (uint)(CollisionFilterGroups.BAllGroup))
268 }, 268 },
269 { CollisionType.VolumeDetect, 269 { CollisionType.VolumeDetect,
270 new CollisionTypeFilterGroup(CollisionType.VolumeDetect, 270 new CollisionTypeFilterGroup(CollisionType.VolumeDetect,
271 (uint)CollisionFilterGroups.BSensorTrigger, 271 (uint)CollisionFilterGroups.BSensorTrigger,
272 (uint)(~CollisionFilterGroups.BSensorTrigger)) 272 (uint)(~CollisionFilterGroups.BSensorTrigger))
273 }, 273 },
274 { CollisionType.LinksetChild, 274 { CollisionType.LinksetChild,
275 new CollisionTypeFilterGroup(CollisionType.LinksetChild, 275 new CollisionTypeFilterGroup(CollisionType.LinksetChild,
276 (uint)CollisionFilterGroups.BTerrainGroup, 276 (uint)CollisionFilterGroups.BTerrainGroup,
277 (uint)(CollisionFilterGroups.BNoneGroup)) 277 (uint)(CollisionFilterGroups.BNoneGroup))
278 }, 278 },
279}; 279};
280 280
281} 281}
282} 282}