BulletSimAPI.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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. namespace OpenSim.Region.Physics.BulletSPlugin {
  33. // Classes to allow some type checking for the API
  34. // These hold pointers to allocated objects in the unmanaged space.
  35. // The physics engine controller class created at initialization
  36. public struct BulletSim
  37. {
  38. public BulletSim(uint worldId, BSScene bss, IntPtr xx)
  39. {
  40. ptr = xx;
  41. worldID = worldId;
  42. physicsScene = bss;
  43. }
  44. public IntPtr ptr;
  45. public uint worldID;
  46. // The scene is only in here so very low level routines have a handle to print debug/error messages
  47. public BSScene physicsScene;
  48. }
  49. // An allocated Bullet btRigidBody
  50. public struct BulletBody
  51. {
  52. public BulletBody(uint id, IntPtr xx)
  53. {
  54. ID = id;
  55. ptr = xx;
  56. collisionFilter = 0;
  57. collisionMask = 0;
  58. }
  59. public IntPtr ptr;
  60. public uint ID;
  61. public CollisionFilterGroups collisionFilter;
  62. public CollisionFilterGroups collisionMask;
  63. public override string ToString()
  64. {
  65. StringBuilder buff = new StringBuilder();
  66. buff.Append("<id=");
  67. buff.Append(ID.ToString());
  68. buff.Append(",p=");
  69. buff.Append(ptr.ToString("X"));
  70. if (collisionFilter != 0 || collisionMask != 0)
  71. {
  72. buff.Append(",f=");
  73. buff.Append(collisionFilter.ToString("X"));
  74. buff.Append(",m=");
  75. buff.Append(collisionMask.ToString("X"));
  76. }
  77. buff.Append(">");
  78. return buff.ToString();
  79. }
  80. }
  81. public struct BulletShape
  82. {
  83. public BulletShape(IntPtr xx)
  84. {
  85. ptr = xx;
  86. type=ShapeData.PhysicsShapeType.SHAPE_UNKNOWN;
  87. shapeKey = 0;
  88. isNativeShape = false;
  89. }
  90. public BulletShape(IntPtr xx, ShapeData.PhysicsShapeType typ)
  91. {
  92. ptr = xx;
  93. type = typ;
  94. shapeKey = 0;
  95. isNativeShape = false;
  96. }
  97. public IntPtr ptr;
  98. public ShapeData.PhysicsShapeType type;
  99. public System.UInt64 shapeKey;
  100. public bool isNativeShape;
  101. public override string ToString()
  102. {
  103. StringBuilder buff = new StringBuilder();
  104. buff.Append("<p=");
  105. buff.Append(ptr.ToString("X"));
  106. buff.Append(",s=");
  107. buff.Append(type.ToString());
  108. buff.Append(",k=");
  109. buff.Append(shapeKey.ToString("X"));
  110. buff.Append(",n=");
  111. buff.Append(isNativeShape.ToString());
  112. buff.Append(">");
  113. return buff.ToString();
  114. }
  115. }
  116. // Constraint type values as defined by Bullet
  117. public enum ConstraintType : int
  118. {
  119. POINT2POINT_CONSTRAINT_TYPE = 3,
  120. HINGE_CONSTRAINT_TYPE,
  121. CONETWIST_CONSTRAINT_TYPE,
  122. D6_CONSTRAINT_TYPE,
  123. SLIDER_CONSTRAINT_TYPE,
  124. CONTACT_CONSTRAINT_TYPE,
  125. D6_SPRING_CONSTRAINT_TYPE,
  126. MAX_CONSTRAINT_TYPE
  127. }
  128. // An allocated Bullet btConstraint
  129. public struct BulletConstraint
  130. {
  131. public BulletConstraint(IntPtr xx)
  132. {
  133. ptr = xx;
  134. }
  135. public IntPtr ptr;
  136. }
  137. // An allocated HeightMapThing which holds various heightmap info.
  138. // Made a class rather than a struct so there would be only one
  139. // instance of this and C# will pass around pointers rather
  140. // than making copies.
  141. public class BulletHeightMapInfo
  142. {
  143. public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) {
  144. ID = id;
  145. Ptr = xx;
  146. heightMap = hm;
  147. terrainRegionBase = new Vector2(0f, 0f);
  148. minCoords = new Vector3(100f, 100f, 25f);
  149. maxCoords = new Vector3(101f, 101f, 26f);
  150. minZ = maxZ = 0f;
  151. sizeX = sizeY = 256f;
  152. }
  153. public uint ID;
  154. public IntPtr Ptr;
  155. public float[] heightMap;
  156. public Vector2 terrainRegionBase;
  157. public Vector3 minCoords;
  158. public Vector3 maxCoords;
  159. public float sizeX, sizeY;
  160. public float minZ, maxZ;
  161. public BulletShape terrainShape;
  162. public BulletBody terrainBody;
  163. }
  164. // ===============================================================================
  165. [StructLayout(LayoutKind.Sequential)]
  166. public struct ConvexHull
  167. {
  168. Vector3 Offset;
  169. int VertexCount;
  170. Vector3[] Vertices;
  171. }
  172. [StructLayout(LayoutKind.Sequential)]
  173. public struct ShapeData
  174. {
  175. public enum PhysicsShapeType
  176. {
  177. SHAPE_UNKNOWN = 0,
  178. SHAPE_AVATAR = 1,
  179. SHAPE_BOX = 2,
  180. SHAPE_CONE = 3,
  181. SHAPE_CYLINDER = 4,
  182. SHAPE_SPHERE = 5,
  183. SHAPE_MESH = 6,
  184. SHAPE_HULL = 7,
  185. // following defined by BulletSim
  186. SHAPE_GROUNDPLANE = 20,
  187. SHAPE_TERRAIN = 21,
  188. };
  189. public uint ID;
  190. public PhysicsShapeType Type;
  191. public Vector3 Position;
  192. public Quaternion Rotation;
  193. public Vector3 Velocity;
  194. public Vector3 Scale;
  195. public float Mass;
  196. public float Buoyancy;
  197. public System.UInt64 HullKey;
  198. public System.UInt64 MeshKey;
  199. public float Friction;
  200. public float Restitution;
  201. public float Collidable; // true of things bump into this
  202. public float Static; // true if a static object. Otherwise gravity, etc.
  203. public float Solid; // true if object cannot be passed through
  204. public Vector3 Size;
  205. // note that bools are passed as floats since bool size changes by language and architecture
  206. public const float numericTrue = 1f;
  207. public const float numericFalse = 0f;
  208. // The native shapes have predefined shape hash keys
  209. public enum FixedShapeKey : ulong
  210. {
  211. KEY_BOX = 1,
  212. KEY_SPHERE = 2,
  213. KEY_CONE = 3,
  214. KEY_CYLINDER = 4,
  215. KEY_CAPSULE = 5,
  216. }
  217. }
  218. [StructLayout(LayoutKind.Sequential)]
  219. public struct SweepHit
  220. {
  221. public uint ID;
  222. public float Fraction;
  223. public Vector3 Normal;
  224. public Vector3 Point;
  225. }
  226. [StructLayout(LayoutKind.Sequential)]
  227. public struct RaycastHit
  228. {
  229. public uint ID;
  230. public float Fraction;
  231. public Vector3 Normal;
  232. }
  233. [StructLayout(LayoutKind.Sequential)]
  234. public struct CollisionDesc
  235. {
  236. public uint aID;
  237. public uint bID;
  238. public Vector3 point;
  239. public Vector3 normal;
  240. }
  241. [StructLayout(LayoutKind.Sequential)]
  242. public struct EntityProperties
  243. {
  244. public uint ID;
  245. public Vector3 Position;
  246. public Quaternion Rotation;
  247. public Vector3 Velocity;
  248. public Vector3 Acceleration;
  249. public Vector3 RotationalVelocity;
  250. }
  251. // Format of this structure must match the definition in the C++ code
  252. [StructLayout(LayoutKind.Sequential)]
  253. public struct ConfigurationParameters
  254. {
  255. public float defaultFriction;
  256. public float defaultDensity;
  257. public float defaultRestitution;
  258. public float collisionMargin;
  259. public float gravity;
  260. public float linearDamping;
  261. public float angularDamping;
  262. public float deactivationTime;
  263. public float linearSleepingThreshold;
  264. public float angularSleepingThreshold;
  265. public float ccdMotionThreshold;
  266. public float ccdSweptSphereRadius;
  267. public float contactProcessingThreshold;
  268. public float terrainFriction;
  269. public float terrainHitFraction;
  270. public float terrainRestitution;
  271. public float avatarFriction;
  272. public float avatarStandingFriction;
  273. public float avatarDensity;
  274. public float avatarRestitution;
  275. public float avatarCapsuleRadius;
  276. public float avatarCapsuleHeight;
  277. public float avatarContactProcessingThreshold;
  278. public float maxPersistantManifoldPoolSize;
  279. public float maxCollisionAlgorithmPoolSize;
  280. public float shouldDisableContactPoolDynamicAllocation;
  281. public float shouldForceUpdateAllAabbs;
  282. public float shouldRandomizeSolverOrder;
  283. public float shouldSplitSimulationIslands;
  284. public float shouldEnableFrictionCaching;
  285. public float numberOfSolverIterations;
  286. public float linkConstraintUseFrameOffset;
  287. public float linkConstraintEnableTransMotor;
  288. public float linkConstraintTransMotorMaxVel;
  289. public float linkConstraintTransMotorMaxForce;
  290. public float linkConstraintERP;
  291. public float linkConstraintCFM;
  292. public float linkConstraintSolverIterations;
  293. public float physicsLoggingFrames;
  294. public const float numericTrue = 1f;
  295. public const float numericFalse = 0f;
  296. }
  297. // The states a bullet collision object can have
  298. public enum ActivationState : uint
  299. {
  300. ACTIVE_TAG = 1,
  301. ISLAND_SLEEPING,
  302. WANTS_DEACTIVATION,
  303. DISABLE_DEACTIVATION,
  304. DISABLE_SIMULATION,
  305. }
  306. public enum CollisionObjectTypes : int
  307. {
  308. CO_COLLISION_OBJECT = 1 << 0,
  309. CO_RIGID_BODY = 1 << 1,
  310. CO_GHOST_OBJECT = 1 << 2,
  311. CO_SOFT_BODY = 1 << 3,
  312. CO_HF_FLUID = 1 << 4,
  313. CO_USER_TYPE = 1 << 5,
  314. }
  315. // Values used by Bullet and BulletSim to control object properties.
  316. // Bullet's "CollisionFlags" has more to do with operations on the
  317. // object (if collisions happen, if gravity effects it, ...).
  318. public enum CollisionFlags : uint
  319. {
  320. CF_STATIC_OBJECT = 1 << 0,
  321. CF_KINEMATIC_OBJECT = 1 << 1,
  322. CF_NO_CONTACT_RESPONSE = 1 << 2,
  323. CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3,
  324. CF_CHARACTER_OBJECT = 1 << 4,
  325. CF_DISABLE_VISUALIZE_OBJECT = 1 << 5,
  326. CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6,
  327. // Following used by BulletSim to control collisions
  328. BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10,
  329. BS_FLOATS_ON_WATER = 1 << 11,
  330. BS_NONE = 0,
  331. BS_ALL = 0xFFFFFFFF,
  332. // These are the collision flags switched depending on physical state.
  333. // The other flags are used for other things and should not be fooled with.
  334. BS_ACTIVE = CF_STATIC_OBJECT
  335. | CF_KINEMATIC_OBJECT
  336. | CF_NO_CONTACT_RESPONSE
  337. };
  338. // Values for collisions groups and masks
  339. public enum CollisionFilterGroups : uint
  340. {
  341. // Don't use the bit definitions!! Define the use in a
  342. // filter/mask definition below. This way collision interactions
  343. // are more easily debugged.
  344. BNoneFilter = 0,
  345. BDefaultFilter = 1 << 0,
  346. BStaticFilter = 1 << 1,
  347. BKinematicFilter = 1 << 2,
  348. BDebrisFilter = 1 << 3,
  349. BSensorTrigger = 1 << 4,
  350. BCharacterFilter = 1 << 5,
  351. BAllFilter = 0xFFFFFFFF,
  352. // Filter groups defined by BulletSim
  353. BGroundPlaneFilter = 1 << 10,
  354. BTerrainFilter = 1 << 11,
  355. BRaycastFilter = 1 << 12,
  356. BSolidFilter = 1 << 13,
  357. // The collsion filters and masked are defined in one place -- don't want them scattered
  358. AvatarFilter = BCharacterFilter,
  359. AvatarMask = BAllFilter,
  360. ObjectFilter = BSolidFilter,
  361. ObjectMask = BAllFilter,
  362. StaticObjectFilter = BStaticFilter,
  363. StaticObjectMask = BAllFilter,
  364. VolumeDetectFilter = BSensorTrigger,
  365. VolumeDetectMask = ~BSensorTrigger,
  366. TerrainFilter = BTerrainFilter,
  367. TerrainMask = BAllFilter & ~BStaticFilter,
  368. GroundPlaneFilter = BGroundPlaneFilter,
  369. GroundPlaneMask = BAllFilter
  370. };
  371. // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0
  372. // ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2.
  373. public enum ConstraintParams : int
  374. {
  375. BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730
  376. BT_CONSTRAINT_STOP_ERP,
  377. BT_CONSTRAINT_CFM,
  378. BT_CONSTRAINT_STOP_CFM,
  379. };
  380. public enum ConstraintParamAxis : int
  381. {
  382. AXIS_LINEAR_X = 0,
  383. AXIS_LINEAR_Y,
  384. AXIS_LINEAR_Z,
  385. AXIS_ANGULAR_X,
  386. AXIS_ANGULAR_Y,
  387. AXIS_ANGULAR_Z,
  388. AXIS_LINEAR_ALL = 20, // these last three added by BulletSim so we don't have to do zillions of calls
  389. AXIS_ANGULAR_ALL,
  390. AXIS_ALL
  391. };
  392. // ===============================================================================
  393. static class BulletSimAPI {
  394. // Link back to the managed code for outputting log messages
  395. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  396. public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
  397. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  398. [return: MarshalAs(UnmanagedType.LPStr)]
  399. public static extern string GetVersion();
  400. /* Remove the linkage to the old api methods
  401. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  402. public static extern uint Initialize(Vector3 maxPosition, IntPtr parms,
  403. int maxCollisions, IntPtr collisionArray,
  404. int maxUpdates, IntPtr updateArray,
  405. DebugLogCallback logRoutine);
  406. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  407. public static extern void CreateInitialGroundPlaneAndTerrain(uint worldID);
  408. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  409. public static extern void SetHeightmap(uint worldID, [MarshalAs(UnmanagedType.LPArray)] float[] heightMap);
  410. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  411. public static extern void Shutdown(uint worldID);
  412. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  413. public static extern bool UpdateParameter(uint worldID, uint localID,
  414. [MarshalAs(UnmanagedType.LPStr)]string paramCode, float value);
  415. // ===============================================================================
  416. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  417. public static extern int PhysicsStep(uint worldID, float timeStep, int maxSubSteps, float fixedTimeStep,
  418. out int updatedEntityCount,
  419. out IntPtr updatedEntitiesPtr,
  420. out int collidersCount,
  421. out IntPtr collidersPtr);
  422. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  423. public static extern bool CreateHull(uint worldID, System.UInt64 meshKey,
  424. int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls
  425. );
  426. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  427. public static extern bool CreateMesh(uint worldID, System.UInt64 meshKey,
  428. int indexCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
  429. int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices
  430. );
  431. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  432. public static extern bool DestroyHull(uint worldID, System.UInt64 meshKey);
  433. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  434. public static extern bool DestroyMesh(uint worldID, System.UInt64 meshKey);
  435. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  436. public static extern bool CreateObject(uint worldID, ShapeData shapeData);
  437. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  438. public static extern Vector3 GetObjectPosition(uint WorldID, uint id);
  439. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  440. public static extern Quaternion GetObjectOrientation(uint WorldID, uint id);
  441. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  442. public static extern bool SetObjectTranslation(uint worldID, uint id, Vector3 position, Quaternion rotation);
  443. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  444. public static extern bool SetObjectVelocity(uint worldID, uint id, Vector3 velocity);
  445. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  446. public static extern bool SetObjectAngularVelocity(uint worldID, uint id, Vector3 angularVelocity);
  447. // Set the current force acting on the object
  448. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  449. public static extern bool SetObjectForce(uint worldID, uint id, Vector3 force);
  450. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  451. public static extern bool SetObjectScaleMass(uint worldID, uint id, Vector3 scale, float mass, bool isDynamic);
  452. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  453. public static extern bool SetObjectCollidable(uint worldID, uint id, bool phantom);
  454. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  455. public static extern bool SetObjectDynamic(uint worldID, uint id, bool isDynamic, float mass);
  456. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  457. public static extern bool SetObjectGhost(uint worldID, uint id, bool ghostly);
  458. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  459. public static extern bool SetObjectProperties(uint worldID, uint id, bool isStatic, bool isSolid, bool genCollisions, float mass);
  460. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  461. public static extern bool SetObjectBuoyancy(uint worldID, uint id, float buoyancy);
  462. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  463. public static extern bool HasObject(uint worldID, uint id);
  464. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  465. public static extern bool DestroyObject(uint worldID, uint id);
  466. // ===============================================================================
  467. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  468. public static extern SweepHit ConvexSweepTest(uint worldID, uint id, Vector3 to, float extraMargin);
  469. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  470. public static extern RaycastHit RayTest(uint worldID, uint id, Vector3 from, Vector3 to);
  471. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  472. public static extern Vector3 RecoverFromPenetration(uint worldID, uint id);
  473. // ===============================================================================
  474. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  475. public static extern void DumpBulletStatistics();
  476. */
  477. // Log a debug message
  478. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  479. public static extern void SetDebugLogCallback(DebugLogCallback callback);
  480. // ===============================================================================
  481. // ===============================================================================
  482. // ===============================================================================
  483. // A new version of the API that enables moving all the logic out of the C++ code and into
  484. // the C# code. This will make modifications easier for the next person.
  485. // This interface passes the actual pointers to the objects in the unmanaged
  486. // address space. All the management (calls for creation/destruction/lookup)
  487. // is done in the C# code.
  488. // The names have a "2" tacked on. This will be removed as the C# code gets rebuilt
  489. // and the old code is removed.
  490. // Functions use while converting from API1 to API2. Can be removed when totally converted.
  491. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  492. public static extern IntPtr GetSimHandle2(uint worldID);
  493. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  494. public static extern IntPtr GetBodyHandleWorldID2(uint worldID, uint id);
  495. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  496. public static extern IntPtr GetBodyHandle2(IntPtr world, uint id);
  497. // ===============================================================================
  498. // Initialization and simulation
  499. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  500. public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
  501. int maxCollisions, IntPtr collisionArray,
  502. int maxUpdates, IntPtr updateArray,
  503. DebugLogCallback logRoutine);
  504. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  505. public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
  506. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  507. public static extern void SetHeightMap2(IntPtr world, float[] heightmap);
  508. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  509. public static extern void Shutdown2(IntPtr sim);
  510. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  511. public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
  512. out int updatedEntityCount,
  513. out IntPtr updatedEntitiesPtr,
  514. out int collidersCount,
  515. out IntPtr collidersPtr);
  516. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  517. public static extern bool PushUpdate2(IntPtr obj);
  518. // =====================================================================================
  519. // Mesh, hull, shape and body creation helper routines
  520. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  521. public static extern IntPtr CreateMeshShape2(IntPtr world,
  522. int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
  523. int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
  524. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  525. public static extern IntPtr CreateHullShape2(IntPtr world,
  526. int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls);
  527. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  528. public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape);
  529. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  530. public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData);
  531. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  532. public static extern bool IsNativeShape2(IntPtr shape);
  533. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  534. public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale);
  535. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  536. public static extern IntPtr CreateCompoundShape2(IntPtr sim);
  537. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  538. public static extern void AddChildToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot);
  539. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  540. public static extern void RemoveChildFromCompoundShape2(IntPtr cShape, IntPtr removeShape);
  541. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  542. public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id);
  543. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  544. public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo);
  545. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  546. public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape);
  547. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  548. public static extern int GetBodyType2(IntPtr obj);
  549. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  550. public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
  551. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  552. public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot);
  553. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  554. public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
  555. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  556. public static extern IntPtr AllocateBodyInfo2(IntPtr obj);
  557. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  558. public static extern void ReleaseBodyInfo2(IntPtr obj);
  559. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  560. public static extern void DestroyObject2(IntPtr sim, IntPtr obj);
  561. // =====================================================================================
  562. // Terrain creation and helper routines
  563. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  564. public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords,
  565. [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
  566. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  567. public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
  568. [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
  569. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  570. public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo);
  571. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  572. public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
  573. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  574. public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo);
  575. // =====================================================================================
  576. // Constraint creation and helper routines
  577. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  578. public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
  579. Vector3 frame1loc, Quaternion frame1rot,
  580. Vector3 frame2loc, Quaternion frame2rot,
  581. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  582. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  583. public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2,
  584. Vector3 joinPoint,
  585. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  586. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  587. public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
  588. Vector3 pivotinA, Vector3 pivotinB,
  589. Vector3 axisInA, Vector3 axisInB,
  590. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  591. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  592. public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse);
  593. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  594. public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations);
  595. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  596. public static extern bool SetFrames2(IntPtr constrain,
  597. Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
  598. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  599. public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
  600. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  601. public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
  602. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  603. public static extern bool UseFrameOffset2(IntPtr constrain, float enable);
  604. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  605. public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce);
  606. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  607. public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold);
  608. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  609. public static extern bool CalculateTransforms2(IntPtr constrain);
  610. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  611. public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
  612. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  613. public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain);
  614. // =====================================================================================
  615. // btCollisionWorld entries
  616. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  617. public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj);
  618. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  619. public static extern void UpdateAabbs2(IntPtr world);
  620. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  621. public static extern bool GetForceUpdateAllAabbs2(IntPtr world);
  622. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  623. public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force);
  624. // =====================================================================================
  625. // btDynamicsWorld entries
  626. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  627. public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj);
  628. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  629. public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj);
  630. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  631. public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects);
  632. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  633. public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain);
  634. // =====================================================================================
  635. // btCollisionObject entries
  636. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  637. public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain);
  638. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  639. public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict);
  640. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  641. public static extern bool HasAnisotripicFriction2(IntPtr constrain);
  642. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  643. public static extern void SetContactProcessingThreshold2(IntPtr obj, float val);
  644. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  645. public static extern float GetContactProcessingThreshold2(IntPtr obj);
  646. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  647. public static extern bool IsStaticObject2(IntPtr obj);
  648. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  649. public static extern bool IsKinematicObject2(IntPtr obj);
  650. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  651. public static extern bool IsStaticOrKinematicObject2(IntPtr obj);
  652. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  653. public static extern bool HasContactResponse2(IntPtr obj);
  654. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  655. public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape);
  656. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  657. public static extern IntPtr GetCollisionShape2(IntPtr obj);
  658. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  659. public static extern int GetActivationState2(IntPtr obj);
  660. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  661. public static extern void SetActivationState2(IntPtr obj, int state);
  662. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  663. public static extern void SetDeactivationTime2(IntPtr obj, float dtime);
  664. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  665. public static extern float GetDeactivationTime2(IntPtr obj);
  666. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  667. public static extern void ForceActivationState2(IntPtr obj, ActivationState state);
  668. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  669. public static extern void Activate2(IntPtr obj, bool forceActivation);
  670. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  671. public static extern bool IsActive2(IntPtr obj);
  672. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  673. public static extern void SetRestitution2(IntPtr obj, float val);
  674. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  675. public static extern float GetRestitution2(IntPtr obj);
  676. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  677. public static extern void SetFriction2(IntPtr obj, float val);
  678. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  679. public static extern float GetFriction2(IntPtr obj);
  680. /* Haven't defined the type 'Transform'
  681. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  682. public static extern Transform GetWorldTransform2(IntPtr obj);
  683. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  684. public static extern void setWorldTransform2(IntPtr obj, Transform trans);
  685. */
  686. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  687. public static extern Vector3 GetPosition2(IntPtr obj);
  688. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  689. public static extern Quaternion GetOrientation2(IntPtr obj);
  690. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  691. public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation);
  692. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  693. public static extern IntPtr GetBroadphaseHandle2(IntPtr obj);
  694. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  695. public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle);
  696. /*
  697. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  698. public static extern Transform GetInterpolationWorldTransform2(IntPtr obj);
  699. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  700. public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans);
  701. */
  702. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  703. public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel);
  704. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  705. public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel);
  706. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  707. public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel);
  708. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  709. public static extern float GetHitFraction2(IntPtr obj);
  710. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  711. public static extern void SetHitFraction2(IntPtr obj, float val);
  712. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  713. public static extern CollisionFlags GetCollisionFlags2(IntPtr obj);
  714. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  715. public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags);
  716. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  717. public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags);
  718. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  719. public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags);
  720. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  721. public static extern float GetCcdMotionThreshold2(IntPtr obj);
  722. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  723. public static extern void SetCcdMotionThreshold2(IntPtr obj, float val);
  724. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  725. public static extern float GetCcdSweepSphereRadius2(IntPtr obj);
  726. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  727. public static extern void SetCcdSweepSphereRadius2(IntPtr obj, float val);
  728. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  729. public static extern IntPtr GetUserPointer2(IntPtr obj);
  730. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  731. public static extern void SetUserPointer2(IntPtr obj, IntPtr val);
  732. // =====================================================================================
  733. // btRigidBody entries
  734. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  735. public static extern void ApplyGravity2(IntPtr obj);
  736. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  737. public static extern void SetGravity2(IntPtr obj, Vector3 val);
  738. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  739. public static extern Vector3 GetGravity2(IntPtr obj);
  740. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  741. public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping);
  742. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  743. public static extern float GetLinearDamping2(IntPtr obj);
  744. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  745. public static extern float GetAngularDamping2(IntPtr obj);
  746. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  747. public static extern float GetLinearSleepingThreshold2(IntPtr obj);
  748. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  749. public static extern float GetAngularSleepingThreshold2(IntPtr obj);
  750. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  751. public static extern void ApplyDamping2(IntPtr obj, float timeStep);
  752. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  753. public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia);
  754. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  755. public static extern Vector3 GetLinearFactor2(IntPtr obj);
  756. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  757. public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor);
  758. /*
  759. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  760. public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans);
  761. */
  762. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  763. public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot);
  764. // Add a force to the object as if its mass is one.
  765. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  766. public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force);
  767. // Set the force being applied to the object as if its mass is one.
  768. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  769. public static extern void SetObjectForce2(IntPtr obj, Vector3 force);
  770. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  771. public static extern Vector3 GetTotalForce2(IntPtr obj);
  772. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  773. public static extern Vector3 GetTotalTorque2(IntPtr obj);
  774. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  775. public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj);
  776. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  777. public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert);
  778. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  779. public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold);
  780. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  781. public static extern void ApplyTorque2(IntPtr obj, Vector3 torque);
  782. // Apply force at the given point. Will add torque to the object.
  783. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  784. public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos);
  785. // Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
  786. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  787. public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp);
  788. // Apply impulse to the object's torque. Force is scaled by object's mass.
  789. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  790. public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp);
  791. // Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
  792. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  793. public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos);
  794. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  795. public static extern void ClearForces2(IntPtr obj);
  796. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  797. public static extern void ClearAllForces2(IntPtr obj);
  798. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  799. public static extern void UpdateInertiaTensor2(IntPtr obj);
  800. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  801. public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj);
  802. /*
  803. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  804. public static extern Transform GetCenterOfMassTransform2(IntPtr obj);
  805. */
  806. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  807. public static extern Vector3 GetLinearVelocity2(IntPtr obj);
  808. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  809. public static extern Vector3 GetAngularVelocity2(IntPtr obj);
  810. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  811. public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val);
  812. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  813. public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity);
  814. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  815. public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos);
  816. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  817. public static extern void Translate2(IntPtr obj, Vector3 trans);
  818. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  819. public static extern void UpdateDeactivation2(IntPtr obj, float timeStep);
  820. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  821. public static extern bool WantsSleeping2(IntPtr obj);
  822. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  823. public static extern void SetAngularFactor2(IntPtr obj, float factor);
  824. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  825. public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor);
  826. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  827. public static extern Vector3 GetAngularFactor2(IntPtr obj);
  828. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  829. public static extern bool IsInWorld2(IntPtr obj);
  830. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  831. public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain);
  832. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  833. public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain);
  834. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  835. public static extern IntPtr GetConstraintRef2(IntPtr obj, int index);
  836. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  837. public static extern int GetNumConstraintRefs2(IntPtr obj);
  838. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  839. public static extern void SetCollisionFilterMask2(IntPtr body, uint filter, uint mask);
  840. // =====================================================================================
  841. // btCollisionShape entries
  842. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  843. public static extern float GetAngularMotionDisc2(IntPtr shape);
  844. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  845. public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor);
  846. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  847. public static extern bool IsPolyhedral2(IntPtr shape);
  848. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  849. public static extern bool IsConvex2d2(IntPtr shape);
  850. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  851. public static extern bool IsConvex2(IntPtr shape);
  852. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  853. public static extern bool IsNonMoving2(IntPtr shape);
  854. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  855. public static extern bool IsConcave2(IntPtr shape);
  856. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  857. public static extern bool IsCompound2(IntPtr shape);
  858. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  859. public static extern bool IsSoftBody2(IntPtr shape);
  860. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  861. public static extern bool IsInfinite2(IntPtr shape);
  862. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  863. public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale);
  864. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  865. public static extern Vector3 GetLocalScaling2(IntPtr shape);
  866. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  867. public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass);
  868. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  869. public static extern int GetShapeType2(IntPtr shape);
  870. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  871. public static extern void SetMargin2(IntPtr shape, float val);
  872. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  873. public static extern float GetMargin2(IntPtr shape);
  874. // =====================================================================================
  875. // Debugging
  876. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  877. public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject);
  878. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  879. public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape);
  880. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  881. public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain);
  882. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  883. public static extern void DumpAllInfo2(IntPtr sim);
  884. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  885. public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo);
  886. [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  887. public static extern void DumpPhysicsStatistics2(IntPtr sim);
  888. }
  889. }