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