opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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 shapeType = BSPhysicsShapeType.SHAPE_UNKNOWN;
108 shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE;
109 isNativeShape = false;
110 }
111 public BSPhysicsShapeType shapeType;
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(shapeType.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, float pSizeX, float pSizeY) {
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 = pSizeX;
176 sizeY = pSizeY;
177 }
178 public uint ID;
179 public float[] heightMap;
180 public OMV.Vector3 terrainRegionBase;
181 public OMV.Vector3 minCoords;
182 public OMV.Vector3 maxCoords;
183 public float sizeX, sizeY;
184 public float minZ, maxZ;
185 public BulletShape terrainShape;
186 public BulletBody terrainBody;
187 }
188  
189 // The general class of collsion object.
190 public enum CollisionType
191 {
192 Avatar,
193 Groundplane,
194 Terrain,
195 Static,
196 Dynamic,
197 VolumeDetect,
198 // Linkset, // A linkset should be either Static or Dynamic
199 LinksetChild,
200 Unknown
201 };
202  
203 // Hold specification of group and mask collision flags for a CollisionType
204 public struct CollisionTypeFilterGroup
205 {
206 public CollisionTypeFilterGroup(CollisionType t, uint g, uint m)
207 {
208 type = t;
209 group = g;
210 mask = m;
211 }
212 public CollisionType type;
213 public uint group;
214 public uint mask;
215 };
216  
217 public static class BulletSimData
218 {
219  
220 // Map of collisionTypes to flags for collision groups and masks.
221 // An object's 'group' is the collison groups this object belongs to
222 // An object's 'filter' is the groups another object has to belong to in order to collide with me
223 // A collision happens if ((obj1.group & obj2.filter) != 0) || ((obj2.group & obj1.filter) != 0)
224 //
225 // As mentioned above, don't use the CollisionFilterGroups definitions directly in the code
226 // but, instead, use references to this dictionary. Finding and debugging
227 // collision flag problems will be made easier.
228 public static Dictionary<CollisionType, CollisionTypeFilterGroup> CollisionTypeMasks
229 = new Dictionary<CollisionType, CollisionTypeFilterGroup>()
230 {
231 { CollisionType.Avatar,
232 new CollisionTypeFilterGroup(CollisionType.Avatar,
233 (uint)CollisionFilterGroups.BCharacterGroup,
234 (uint)CollisionFilterGroups.BAllGroup)
235 },
236 { CollisionType.Groundplane,
237 new CollisionTypeFilterGroup(CollisionType.Groundplane,
238 (uint)CollisionFilterGroups.BGroundPlaneGroup,
239 // (uint)CollisionFilterGroups.BAllGroup)
240 (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup))
241 },
242 { CollisionType.Terrain,
243 new CollisionTypeFilterGroup(CollisionType.Terrain,
244 (uint)CollisionFilterGroups.BTerrainGroup,
245 (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup))
246 },
247 { CollisionType.Static,
248 new CollisionTypeFilterGroup(CollisionType.Static,
249 (uint)CollisionFilterGroups.BStaticGroup,
250 (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup))
251 },
252 { CollisionType.Dynamic,
253 new CollisionTypeFilterGroup(CollisionType.Dynamic,
254 (uint)CollisionFilterGroups.BSolidGroup,
255 (uint)(CollisionFilterGroups.BAllGroup))
256 },
257 { CollisionType.VolumeDetect,
258 new CollisionTypeFilterGroup(CollisionType.VolumeDetect,
259 (uint)CollisionFilterGroups.BSensorTrigger,
260 (uint)(~CollisionFilterGroups.BSensorTrigger))
261 },
262 { CollisionType.LinksetChild,
263 new CollisionTypeFilterGroup(CollisionType.LinksetChild,
264 (uint)CollisionFilterGroups.BLinksetChildGroup,
265 (uint)(CollisionFilterGroups.BNoneGroup))
266 // (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup))
267 },
268 };
269  
270 }
271 }