diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | 257 |
1 files changed, 257 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs new file mode 100644 index 0000000..a610c8d --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | |||
@@ -0,0 +1,257 @@ | |||
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.Runtime.InteropServices; | ||
29 | using System.Security; | ||
30 | using System.Text; | ||
31 | using OpenMetaverse; | ||
32 | |||
33 | namespace OpenSim.Region.Physics.BulletSPlugin { | ||
34 | |||
35 | [StructLayout(LayoutKind.Sequential)] | ||
36 | public struct ConvexHull | ||
37 | { | ||
38 | Vector3 Offset; | ||
39 | int VertexCount; | ||
40 | Vector3[] Vertices; | ||
41 | } | ||
42 | [StructLayout(LayoutKind.Sequential)] | ||
43 | public struct ShapeData | ||
44 | { | ||
45 | public enum PhysicsShapeType | ||
46 | { | ||
47 | SHAPE_AVATAR = 0, | ||
48 | SHAPE_BOX = 1, | ||
49 | SHAPE_CONE = 2, | ||
50 | SHAPE_CYLINDER = 3, | ||
51 | SHAPE_SPHERE = 4, | ||
52 | SHAPE_MESH = 5, | ||
53 | SHAPE_HULL = 6 | ||
54 | }; | ||
55 | public uint ID; | ||
56 | public PhysicsShapeType Type; | ||
57 | public Vector3 Position; | ||
58 | public Quaternion Rotation; | ||
59 | public Vector3 Velocity; | ||
60 | public Vector3 Scale; | ||
61 | public float Mass; | ||
62 | public float Buoyancy; | ||
63 | public System.UInt64 HullKey; | ||
64 | public System.UInt64 MeshKey; | ||
65 | public float Friction; | ||
66 | public float Restitution; | ||
67 | public int Collidable; | ||
68 | public int Static; // true if a static object. Otherwise gravity, etc. | ||
69 | |||
70 | // note that bools are passed as ints since bool size changes by language and architecture | ||
71 | public const int numericTrue = 1; | ||
72 | public const int numericFalse = 0; | ||
73 | } | ||
74 | [StructLayout(LayoutKind.Sequential)] | ||
75 | public struct SweepHit | ||
76 | { | ||
77 | public uint ID; | ||
78 | public float Fraction; | ||
79 | public Vector3 Normal; | ||
80 | public Vector3 Point; | ||
81 | } | ||
82 | [StructLayout(LayoutKind.Sequential)] | ||
83 | public struct RaycastHit | ||
84 | { | ||
85 | public uint ID; | ||
86 | public float Fraction; | ||
87 | public Vector3 Normal; | ||
88 | } | ||
89 | [StructLayout(LayoutKind.Sequential)] | ||
90 | public struct CollisionDesc | ||
91 | { | ||
92 | public uint aID; | ||
93 | public uint bID; | ||
94 | public Vector3 point; | ||
95 | public Vector3 normal; | ||
96 | } | ||
97 | [StructLayout(LayoutKind.Sequential)] | ||
98 | public struct EntityProperties | ||
99 | { | ||
100 | public uint ID; | ||
101 | public Vector3 Position; | ||
102 | public Quaternion Rotation; | ||
103 | public Vector3 Velocity; | ||
104 | public Vector3 Acceleration; | ||
105 | public Vector3 RotationalVelocity; | ||
106 | } | ||
107 | |||
108 | // Format of this structure must match the definition in the C++ code | ||
109 | [StructLayout(LayoutKind.Sequential)] | ||
110 | public struct ConfigurationParameters | ||
111 | { | ||
112 | public float defaultFriction; | ||
113 | public float defaultDensity; | ||
114 | public float defaultRestitution; | ||
115 | public float collisionMargin; | ||
116 | public float gravity; | ||
117 | |||
118 | public float linearDamping; | ||
119 | public float angularDamping; | ||
120 | public float deactivationTime; | ||
121 | public float linearSleepingThreshold; | ||
122 | public float angularSleepingThreshold; | ||
123 | public float ccdMotionThreshold; | ||
124 | public float ccdSweptSphereRadius; | ||
125 | |||
126 | public float terrainFriction; | ||
127 | public float terrainHitFraction; | ||
128 | public float terrainRestitution; | ||
129 | public float avatarFriction; | ||
130 | public float avatarDensity; | ||
131 | public float avatarRestitution; | ||
132 | public float avatarCapsuleRadius; | ||
133 | public float avatarCapsuleHeight; | ||
134 | |||
135 | public const float numericTrue = 1f; | ||
136 | public const float numericFalse = 0f; | ||
137 | } | ||
138 | |||
139 | static class BulletSimAPI { | ||
140 | |||
141 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
142 | [return: MarshalAs(UnmanagedType.LPStr)] | ||
143 | public static extern string GetVersion(); | ||
144 | |||
145 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
146 | public static extern uint Initialize(Vector3 maxPosition, IntPtr parms, | ||
147 | int maxCollisions, IntPtr collisionArray, | ||
148 | int maxUpdates, IntPtr updateArray); | ||
149 | |||
150 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
151 | public static extern bool UpdateParameter(uint worldID, uint localID, | ||
152 | [MarshalAs(UnmanagedType.LPStr)]string paramCode, float value); | ||
153 | |||
154 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
155 | public static extern void SetHeightmap(uint worldID, [MarshalAs(UnmanagedType.LPArray)] float[] heightMap); | ||
156 | |||
157 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
158 | public static extern void Shutdown(uint worldID); | ||
159 | |||
160 | |||
161 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
162 | public static extern int PhysicsStep(uint worldID, float timeStep, int maxSubSteps, float fixedTimeStep, | ||
163 | out int updatedEntityCount, | ||
164 | out IntPtr updatedEntitiesPtr, | ||
165 | out int collidersCount, | ||
166 | out IntPtr collidersPtr); | ||
167 | |||
168 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
169 | public static extern bool CreateHull(uint worldID, System.UInt64 meshKey, | ||
170 | int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls | ||
171 | ); | ||
172 | |||
173 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
174 | public static extern bool CreateMesh(uint worldID, System.UInt64 meshKey, | ||
175 | int indexCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices, | ||
176 | int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices | ||
177 | ); | ||
178 | |||
179 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
180 | public static extern bool DestroyHull(uint worldID, System.UInt64 meshKey); | ||
181 | |||
182 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
183 | public static extern bool DestroyMesh(uint worldID, System.UInt64 meshKey); | ||
184 | |||
185 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
186 | public static extern bool CreateObject(uint worldID, ShapeData shapeData); | ||
187 | |||
188 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
189 | public static extern void CreateLinkset(uint worldID, int objectCount, ShapeData[] shapeDatas); | ||
190 | |||
191 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
192 | public static extern void AddConstraint(uint worldID, uint id1, uint id2, | ||
193 | Vector3 frame1, Quaternion frame1rot, | ||
194 | Vector3 frame2, Quaternion frame2rot, | ||
195 | Vector3 lowLinear, Vector3 hiLinear, Vector3 lowAngular, Vector3 hiAngular); | ||
196 | |||
197 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
198 | public static extern bool RemoveConstraintByID(uint worldID, uint id1); | ||
199 | |||
200 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
201 | public static extern bool RemoveConstraint(uint worldID, uint id1, uint id2); | ||
202 | |||
203 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
204 | public static extern Vector3 GetObjectPosition(uint WorldID, uint id); | ||
205 | |||
206 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
207 | public static extern bool SetObjectTranslation(uint worldID, uint id, Vector3 position, Quaternion rotation); | ||
208 | |||
209 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
210 | public static extern bool SetObjectVelocity(uint worldID, uint id, Vector3 velocity); | ||
211 | |||
212 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
213 | public static extern bool SetObjectAngularVelocity(uint worldID, uint id, Vector3 angularVelocity); | ||
214 | |||
215 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
216 | public static extern bool SetObjectForce(uint worldID, uint id, Vector3 force); | ||
217 | |||
218 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
219 | public static extern bool SetObjectScaleMass(uint worldID, uint id, Vector3 scale, float mass, bool isDynamic); | ||
220 | |||
221 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
222 | public static extern bool SetObjectCollidable(uint worldID, uint id, bool phantom); | ||
223 | |||
224 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
225 | public static extern bool SetObjectDynamic(uint worldID, uint id, bool isDynamic, float mass); | ||
226 | |||
227 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
228 | public static extern bool SetObjectGhost(uint worldID, uint id, bool ghostly); | ||
229 | |||
230 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
231 | public static extern bool SetObjectProperties(uint worldID, uint id, bool isStatic, bool isSolid, bool genCollisions, float mass); | ||
232 | |||
233 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
234 | public static extern bool SetObjectBuoyancy(uint worldID, uint id, float buoyancy); | ||
235 | |||
236 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
237 | public static extern bool HasObject(uint worldID, uint id); | ||
238 | |||
239 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
240 | public static extern bool DestroyObject(uint worldID, uint id); | ||
241 | |||
242 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
243 | public static extern SweepHit ConvexSweepTest(uint worldID, uint id, Vector3 to, float extraMargin); | ||
244 | |||
245 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
246 | public static extern RaycastHit RayTest(uint worldID, uint id, Vector3 from, Vector3 to); | ||
247 | |||
248 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
249 | public static extern Vector3 RecoverFromPenetration(uint worldID, uint id); | ||
250 | |||
251 | // Log a debug message | ||
252 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
253 | public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); | ||
254 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
255 | public static extern void SetDebugLogCallback(DebugLogCallback callback); | ||
256 | } | ||
257 | } | ||