aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs234
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 */
27using System;
28using System.Runtime.InteropServices;
29using System.Security;
30using System.Text;
31using OpenMetaverse;
32
33namespace OpenSim.Region.Physics.BulletSPlugin {
34
35[StructLayout(LayoutKind.Sequential)]
36public struct ConvexHull
37{
38 Vector3 Offset;
39 int VertexCount;
40 Vector3[] Vertices;
41}
42[StructLayout(LayoutKind.Sequential)]
43public 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)]
72public struct SweepHit
73{
74 public uint ID;
75 public float Fraction;
76 public Vector3 Normal;
77 public Vector3 Point;
78}
79[StructLayout(LayoutKind.Sequential)]
80public struct RaycastHit
81{
82 public uint ID;
83 public float Fraction;
84 public Vector3 Normal;
85}
86[StructLayout(LayoutKind.Sequential)]
87public struct CollisionDesc
88{
89 public uint aID;
90 public uint bID;
91 public Vector3 point;
92 public Vector3 normal;
93}
94[StructLayout(LayoutKind.Sequential)]
95public 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)]
107public 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
133static class BulletSimAPI {
134
135[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
136public 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]
141public static extern void SetHeightmap(uint worldID, [MarshalAs(UnmanagedType.LPArray)] float[] heightMap);
142
143[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
144public static extern void Shutdown(uint worldID);
145
146
147[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
148public 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]
155public 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]
160public static extern bool DestroyHull(uint worldID, System.UInt64 meshKey);
161
162[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
163public static extern bool CreateObject(uint worldID, ShapeData shapeData);
164
165[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
166public static extern void CreateLinkset(uint worldID, int objectCount, ShapeData[] shapeDatas);
167
168[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
169public 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]
175public static extern bool RemoveConstraintByID(uint worldID, uint id1);
176
177[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
178public static extern bool RemoveConstraint(uint worldID, uint id1, uint id2);
179
180[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
181public static extern Vector3 GetObjectPosition(uint WorldID, uint id);
182
183[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
184public static extern bool SetObjectTranslation(uint worldID, uint id, Vector3 position, Quaternion rotation);
185
186[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
187public static extern bool SetObjectVelocity(uint worldID, uint id, Vector3 velocity);
188
189[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
190public static extern bool SetObjectAngularVelocity(uint worldID, uint id, Vector3 angularVelocity);
191
192[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
193public static extern bool SetObjectForce(uint worldID, uint id, Vector3 force);
194
195[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
196public static extern bool SetObjectScaleMass(uint worldID, uint id, Vector3 scale, float mass, bool isDynamic);
197
198[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
199public static extern bool SetObjectCollidable(uint worldID, uint id, bool phantom);
200
201[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
202public static extern bool SetObjectDynamic(uint worldID, uint id, bool isDynamic, float mass);
203
204[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
205public static extern bool SetObjectGhost(uint worldID, uint id, bool ghostly);
206
207[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
208public static extern bool SetObjectProperties(uint worldID, uint id, bool isStatic, bool isSolid, bool genCollisions, float mass);
209
210[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
211public static extern bool SetObjectBuoyancy(uint worldID, uint id, float buoyancy);
212
213[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
214public static extern bool HasObject(uint worldID, uint id);
215
216[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
217public static extern bool DestroyObject(uint worldID, uint id);
218
219[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
220public static extern SweepHit ConvexSweepTest(uint worldID, uint id, Vector3 to, float extraMargin);
221
222[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
223public static extern RaycastHit RayTest(uint worldID, uint id, Vector3 from, Vector3 to);
224
225[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
226public static extern Vector3 RecoverFromPenetration(uint worldID, uint id);
227
228// Log a debug message
229[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
230public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
231[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
232public static extern void SetDebugLogCallback(DebugLogCallback callback);
233}
234}