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