diff options
Merge branch 'avination-current' of ssh://3dhosting.de/var/git/careminster into avination-current
Conflicts:
bin/Regions/Regions.ini.example
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs | 269 |
1 files changed, 269 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs new file mode 100755 index 0000000..8012d91 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs | |||
@@ -0,0 +1,269 @@ | |||
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 | // These classes are subclassed by the various physical implementations of | ||
37 | // objects. In particular, there is a version for physical instances in | ||
38 | // unmanaged memory ("unman") and one for in managed memory ("XNA"). | ||
39 | |||
40 | // Currently, the instances of these classes are a reference to a | ||
41 | // physical representation and this has no releationship to other | ||
42 | // instances. Someday, refarb the usage of these classes so each instance | ||
43 | // refers to a particular physical instance and this class controls reference | ||
44 | // counts and such. This should be done along with adding BSShapes. | ||
45 | |||
46 | public class BulletWorld | ||
47 | { | ||
48 | public BulletWorld(uint worldId, BSScene bss) | ||
49 | { | ||
50 | worldID = worldId; | ||
51 | physicsScene = bss; | ||
52 | } | ||
53 | public uint worldID; | ||
54 | // The scene is only in here so very low level routines have a handle to print debug/error messages | ||
55 | public BSScene physicsScene; | ||
56 | } | ||
57 | |||
58 | // An allocated Bullet btRigidBody | ||
59 | public class BulletBody | ||
60 | { | ||
61 | public BulletBody(uint id) | ||
62 | { | ||
63 | ID = id; | ||
64 | collisionType = CollisionType.Static; | ||
65 | } | ||
66 | public uint ID; | ||
67 | public CollisionType collisionType; | ||
68 | |||
69 | public virtual void Clear() { } | ||
70 | public virtual bool HasPhysicalBody { get { return false; } } | ||
71 | |||
72 | // Apply the specificed collision mask into the physical world | ||
73 | public virtual bool ApplyCollisionMask(BSScene physicsScene) | ||
74 | { | ||
75 | // Should assert the body has been added to the physical world. | ||
76 | // (The collision masks are stored in the collision proxy cache which only exists for | ||
77 | // a collision body that is in the world.) | ||
78 | return physicsScene.PE.SetCollisionGroupMask(this, | ||
79 | BulletSimData.CollisionTypeMasks[collisionType].group, | ||
80 | BulletSimData.CollisionTypeMasks[collisionType].mask); | ||
81 | } | ||
82 | |||
83 | // Used for log messages for a unique display of the memory/object allocated to this instance | ||
84 | public virtual string AddrString | ||
85 | { | ||
86 | get { return "unknown"; } | ||
87 | } | ||
88 | |||
89 | public override string ToString() | ||
90 | { | ||
91 | StringBuilder buff = new StringBuilder(); | ||
92 | buff.Append("<id="); | ||
93 | buff.Append(ID.ToString()); | ||
94 | buff.Append(",p="); | ||
95 | buff.Append(AddrString); | ||
96 | buff.Append(",c="); | ||
97 | buff.Append(collisionType); | ||
98 | buff.Append(">"); | ||
99 | return buff.ToString(); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | public class BulletShape | ||
104 | { | ||
105 | public BulletShape() | ||
106 | { | ||
107 | type = BSPhysicsShapeType.SHAPE_UNKNOWN; | ||
108 | shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE; | ||
109 | isNativeShape = false; | ||
110 | } | ||
111 | public BSPhysicsShapeType type; | ||
112 | public System.UInt64 shapeKey; | ||
113 | public bool isNativeShape; | ||
114 | |||
115 | public virtual void Clear() { } | ||
116 | public virtual bool HasPhysicalShape { get { return false; } } | ||
117 | |||
118 | // Make another reference to this physical object. | ||
119 | public virtual BulletShape Clone() { return new BulletShape(); } | ||
120 | |||
121 | // Return 'true' if this and other refer to the same physical object | ||
122 | public virtual bool ReferenceSame(BulletShape xx) { return false; } | ||
123 | |||
124 | // Used for log messages for a unique display of the memory/object allocated to this instance | ||
125 | public virtual string AddrString | ||
126 | { | ||
127 | get { return "unknown"; } | ||
128 | } | ||
129 | |||
130 | public override string ToString() | ||
131 | { | ||
132 | StringBuilder buff = new StringBuilder(); | ||
133 | buff.Append("<p="); | ||
134 | buff.Append(AddrString); | ||
135 | buff.Append(",s="); | ||
136 | buff.Append(type.ToString()); | ||
137 | buff.Append(",k="); | ||
138 | buff.Append(shapeKey.ToString("X")); | ||
139 | buff.Append(",n="); | ||
140 | buff.Append(isNativeShape.ToString()); | ||
141 | buff.Append(">"); | ||
142 | return buff.ToString(); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | // An allocated Bullet btConstraint | ||
147 | public class BulletConstraint | ||
148 | { | ||
149 | public BulletConstraint() | ||
150 | { | ||
151 | } | ||
152 | public virtual void Clear() { } | ||
153 | public virtual bool HasPhysicalConstraint { get { return false; } } | ||
154 | |||
155 | // Used for log messages for a unique display of the memory/object allocated to this instance | ||
156 | public virtual string AddrString | ||
157 | { | ||
158 | get { return "unknown"; } | ||
159 | } | ||
160 | } | ||
161 | |||
162 | // An allocated HeightMapThing which holds various heightmap info. | ||
163 | // Made a class rather than a struct so there would be only one | ||
164 | // instance of this and C# will pass around pointers rather | ||
165 | // than making copies. | ||
166 | public class BulletHMapInfo | ||
167 | { | ||
168 | public BulletHMapInfo(uint id, float[] hm) { | ||
169 | ID = id; | ||
170 | heightMap = hm; | ||
171 | terrainRegionBase = OMV.Vector3.Zero; | ||
172 | minCoords = new OMV.Vector3(100f, 100f, 25f); | ||
173 | maxCoords = new OMV.Vector3(101f, 101f, 26f); | ||
174 | minZ = maxZ = 0f; | ||
175 | sizeX = sizeY = 256f; | ||
176 | } | ||
177 | public uint ID; | ||
178 | public float[] heightMap; | ||
179 | public OMV.Vector3 terrainRegionBase; | ||
180 | public OMV.Vector3 minCoords; | ||
181 | public OMV.Vector3 maxCoords; | ||
182 | public float sizeX, sizeY; | ||
183 | public float minZ, maxZ; | ||
184 | public BulletShape terrainShape; | ||
185 | public BulletBody terrainBody; | ||
186 | } | ||
187 | |||
188 | // The general class of collsion object. | ||
189 | public enum CollisionType | ||
190 | { | ||
191 | Avatar, | ||
192 | Groundplane, | ||
193 | Terrain, | ||
194 | Static, | ||
195 | Dynamic, | ||
196 | VolumeDetect, | ||
197 | // Linkset, // A linkset should be either Static or Dynamic | ||
198 | LinksetChild, | ||
199 | Unknown | ||
200 | }; | ||
201 | |||
202 | // Hold specification of group and mask collision flags for a CollisionType | ||
203 | public struct CollisionTypeFilterGroup | ||
204 | { | ||
205 | public CollisionTypeFilterGroup(CollisionType t, uint g, uint m) | ||
206 | { | ||
207 | type = t; | ||
208 | group = g; | ||
209 | mask = m; | ||
210 | } | ||
211 | public CollisionType type; | ||
212 | public uint group; | ||
213 | public uint mask; | ||
214 | }; | ||
215 | |||
216 | public static class BulletSimData | ||
217 | { | ||
218 | |||
219 | // Map of collisionTypes to flags for collision groups and masks. | ||
220 | // An object's 'group' is the collison groups this object belongs to | ||
221 | // An object's 'filter' is the groups another object has to belong to in order to collide with me | ||
222 | // A collision happens if ((obj1.group & obj2.filter) != 0) || ((obj2.group & obj1.filter) != 0) | ||
223 | // | ||
224 | // As mentioned above, don't use the CollisionFilterGroups definitions directly in the code | ||
225 | // but, instead, use references to this dictionary. Finding and debugging | ||
226 | // collision flag problems will be made easier. | ||
227 | public static Dictionary<CollisionType, CollisionTypeFilterGroup> CollisionTypeMasks | ||
228 | = new Dictionary<CollisionType, CollisionTypeFilterGroup>() | ||
229 | { | ||
230 | { CollisionType.Avatar, | ||
231 | new CollisionTypeFilterGroup(CollisionType.Avatar, | ||
232 | (uint)CollisionFilterGroups.BCharacterGroup, | ||
233 | (uint)CollisionFilterGroups.BAllGroup) | ||
234 | }, | ||
235 | { CollisionType.Groundplane, | ||
236 | new CollisionTypeFilterGroup(CollisionType.Groundplane, | ||
237 | (uint)CollisionFilterGroups.BGroundPlaneGroup, | ||
238 | (uint)CollisionFilterGroups.BAllGroup) | ||
239 | }, | ||
240 | { CollisionType.Terrain, | ||
241 | new CollisionTypeFilterGroup(CollisionType.Terrain, | ||
242 | (uint)CollisionFilterGroups.BTerrainGroup, | ||
243 | (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup)) | ||
244 | }, | ||
245 | { CollisionType.Static, | ||
246 | new CollisionTypeFilterGroup(CollisionType.Static, | ||
247 | (uint)CollisionFilterGroups.BStaticGroup, | ||
248 | (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) | ||
249 | }, | ||
250 | { CollisionType.Dynamic, | ||
251 | new CollisionTypeFilterGroup(CollisionType.Dynamic, | ||
252 | (uint)CollisionFilterGroups.BSolidGroup, | ||
253 | (uint)(CollisionFilterGroups.BAllGroup)) | ||
254 | }, | ||
255 | { CollisionType.VolumeDetect, | ||
256 | new CollisionTypeFilterGroup(CollisionType.VolumeDetect, | ||
257 | (uint)CollisionFilterGroups.BSensorTrigger, | ||
258 | (uint)(~CollisionFilterGroups.BSensorTrigger)) | ||
259 | }, | ||
260 | { CollisionType.LinksetChild, | ||
261 | new CollisionTypeFilterGroup(CollisionType.LinksetChild, | ||
262 | (uint)CollisionFilterGroups.BLinksetChildGroup, | ||
263 | (uint)(CollisionFilterGroups.BNoneGroup)) | ||
264 | // (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) | ||
265 | }, | ||
266 | }; | ||
267 | |||
268 | } | ||
269 | } | ||