aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs186
1 files changed, 186 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..b2bc0d7
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
@@ -0,0 +1,186 @@
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
35public struct ConvexHull
36{
37 Vector3 Offset;
38 int VertexCount;
39 Vector3[] Vertices;
40}
41public struct ShapeData
42{
43 public enum PhysicsShapeType
44 {
45 SHAPE_AVATAR = 0,
46 SHAPE_BOX = 1,
47 SHAPE_CONE = 2,
48 SHAPE_CYLINDER = 3,
49 SHAPE_SPHERE = 4,
50 SHAPE_HULL = 5
51 };
52 public const int numericTrue = 1;
53 public const int numericFalse = 0;
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 int Collidable;
64 public float Friction;
65 public int Static; // true if a static object. Otherwise gravity, etc.
66 // note that bools are passed as ints since bool size changes by language
67}
68public struct SweepHit
69{
70 public uint ID;
71 public float Fraction;
72 public Vector3 Normal;
73 public Vector3 Point;
74}
75public struct RaycastHit
76{
77 public uint ID;
78 public float Fraction;
79 public Vector3 Normal;
80}
81
82public struct EntityProperties
83{
84 public uint ID;
85 public Vector3 Position;
86 public Quaternion Rotation;
87 public Vector3 Velocity;
88 public Vector3 Acceleration;
89 public Vector3 AngularVelocity;
90}
91
92static class BulletSimAPI {
93
94[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
95public static extern uint Initialize(Vector3 maxPosition);
96
97[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
98public static extern void SetHeightmap(uint worldID, [MarshalAs(UnmanagedType.LPArray)] float[] heightMap);
99
100[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
101public static extern void Shutdown(uint worldID);
102
103
104[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
105public static extern int PhysicsStep(uint worldID, float timeStep, int maxSubSteps, float fixedTimeStep,
106 out int updatedEntityCount,
107 out IntPtr updatedEntitiesPtr,
108 out int collidersCount,
109 out IntPtr collidersPtr);
110
111[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
112public static extern bool CreateHull(uint worldID, System.UInt64 meshKey, int hullCount,
113 [MarshalAs(UnmanagedType.LPArray)] float[] hulls
114 );
115
116[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
117public static extern bool DestroyHull(uint worldID, System.UInt64 meshKey);
118
119[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
120public static extern bool CreateObject(uint worldID, ShapeData shapeData);
121
122[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
123public static extern void CreateLinkset(uint worldID, int objectCount, ShapeData[] shapeDatas);
124
125[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
126public static extern void AddConstraint(uint worldID, uint id1, uint id2,
127 Vector3 frame1, Vector3 frame2, Vector3 lowLinear, Vector3 hiLinear, Vector3 lowAngular, Vector3 hiAngular);
128
129[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
130public static extern bool RemoveConstraint(uint worldID, uint id1, uint id2);
131
132[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
133public static extern Vector3 GetObjectPosition(uint WorldID, uint id);
134
135[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
136public static extern bool SetObjectTranslation(uint worldID, uint id, Vector3 position, Quaternion rotation);
137
138[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
139public static extern bool SetObjectVelocity(uint worldID, uint id, Vector3 velocity);
140
141[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
142public static extern bool SetObjectAngularVelocity(uint worldID, uint id, Vector3 angularVelocity);
143
144[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
145public static extern bool SetObjectForce(uint worldID, uint id, Vector3 force);
146
147[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
148public static extern bool SetObjectScaleMass(uint worldID, uint id, Vector3 scale, float mass, bool isDynamic);
149
150[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
151public static extern bool SetObjectCollidable(uint worldID, uint id, bool phantom);
152
153[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
154public static extern bool SetObjectDynamic(uint worldID, uint id, bool isDynamic, float mass);
155
156[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
157public static extern bool SetObjectGhost(uint worldID, uint id, bool ghostly);
158
159[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
160public static extern bool SetObjectProperties(uint worldID, uint id, bool isStatic, bool isSolid, bool genCollisions, float mass);
161
162[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
163public static extern bool SetObjectBuoyancy(uint worldID, uint id, float buoyancy);
164
165[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
166public static extern bool HasObject(uint worldID, uint id);
167
168[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
169public static extern bool DestroyObject(uint worldID, uint id);
170
171[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
172public static extern SweepHit ConvexSweepTest(uint worldID, uint id, Vector3 to, float extraMargin);
173
174[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
175public static extern RaycastHit RayTest(uint worldID, uint id, Vector3 from, Vector3 to);
176
177[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
178public static extern Vector3 RecoverFromPenetration(uint worldID, uint id);
179
180// Log a debug message
181[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
182public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
183[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
184public static extern void SetDebugLogCallback(DebugLogCallback callback);
185}
186}