BSApiTemplate.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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 copyright
  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.Collections.Generic;
  29. using System.Runtime.InteropServices;
  30. using System.Security;
  31. using System.Text;
  32. using OpenMetaverse;
  33. namespace OpenSim.Region.Physics.BulletSPlugin {
  34. // Constraint type values as defined by Bullet
  35. public enum ConstraintType : int
  36. {
  37. POINT2POINT_CONSTRAINT_TYPE = 3,
  38. HINGE_CONSTRAINT_TYPE,
  39. CONETWIST_CONSTRAINT_TYPE,
  40. D6_CONSTRAINT_TYPE,
  41. SLIDER_CONSTRAINT_TYPE,
  42. CONTACT_CONSTRAINT_TYPE,
  43. D6_SPRING_CONSTRAINT_TYPE,
  44. MAX_CONSTRAINT_TYPE, // last type defined by Bullet
  45. //
  46. FIXED_CONSTRAINT_TYPE = 1234 // BulletSim constraint that is fixed and unmoving
  47. }
  48. // ===============================================================================
  49. [StructLayout(LayoutKind.Sequential)]
  50. public struct ConvexHull
  51. {
  52. Vector3 Offset;
  53. int VertexCount;
  54. Vector3[] Vertices;
  55. }
  56. public enum BSPhysicsShapeType
  57. {
  58. SHAPE_UNKNOWN = 0,
  59. SHAPE_CAPSULE = 1,
  60. SHAPE_BOX = 2,
  61. SHAPE_CONE = 3,
  62. SHAPE_CYLINDER = 4,
  63. SHAPE_SPHERE = 5,
  64. SHAPE_MESH = 6,
  65. SHAPE_HULL = 7,
  66. // following defined by BulletSim
  67. SHAPE_GROUNDPLANE = 20,
  68. SHAPE_TERRAIN = 21,
  69. SHAPE_COMPOUND = 22,
  70. SHAPE_HEIGHTMAP = 23,
  71. SHAPE_AVATAR = 24,
  72. SHAPE_CONVEXHULL= 25,
  73. SHAPE_GIMPACT = 26,
  74. };
  75. // The native shapes have predefined shape hash keys
  76. public enum FixedShapeKey : ulong
  77. {
  78. KEY_NONE = 0,
  79. KEY_BOX = 1,
  80. KEY_SPHERE = 2,
  81. KEY_CONE = 3,
  82. KEY_CYLINDER = 4,
  83. KEY_CAPSULE = 5,
  84. KEY_AVATAR = 6,
  85. }
  86. [StructLayout(LayoutKind.Sequential)]
  87. public struct ShapeData
  88. {
  89. public UInt32 ID;
  90. public BSPhysicsShapeType Type;
  91. public Vector3 Position;
  92. public Quaternion Rotation;
  93. public Vector3 Velocity;
  94. public Vector3 Scale;
  95. public float Mass;
  96. public float Buoyancy;
  97. public System.UInt64 HullKey;
  98. public System.UInt64 MeshKey;
  99. public float Friction;
  100. public float Restitution;
  101. public float Collidable; // true of things bump into this
  102. public float Static; // true if a static object. Otherwise gravity, etc.
  103. public float Solid; // true if object cannot be passed through
  104. public Vector3 Size;
  105. // note that bools are passed as floats since bool size changes by language and architecture
  106. public const float numericTrue = 1f;
  107. public const float numericFalse = 0f;
  108. }
  109. [StructLayout(LayoutKind.Sequential)]
  110. public struct SweepHit
  111. {
  112. public UInt32 ID;
  113. public float Fraction;
  114. public Vector3 Normal;
  115. public Vector3 Point;
  116. }
  117. [StructLayout(LayoutKind.Sequential)]
  118. public struct RaycastHit
  119. {
  120. public UInt32 ID;
  121. public float Fraction;
  122. public Vector3 Normal;
  123. }
  124. [StructLayout(LayoutKind.Sequential)]
  125. public struct CollisionDesc
  126. {
  127. public UInt32 aID;
  128. public UInt32 bID;
  129. public Vector3 point;
  130. public Vector3 normal;
  131. public float penetration;
  132. }
  133. [StructLayout(LayoutKind.Sequential)]
  134. public struct EntityProperties
  135. {
  136. public UInt32 ID;
  137. public Vector3 Position;
  138. public Quaternion Rotation;
  139. public Vector3 Velocity;
  140. public Vector3 Acceleration;
  141. public Vector3 RotationalVelocity;
  142. public override string ToString()
  143. {
  144. StringBuilder buff = new StringBuilder();
  145. buff.Append("<i=");
  146. buff.Append(ID.ToString());
  147. buff.Append(",p=");
  148. buff.Append(Position.ToString());
  149. buff.Append(",r=");
  150. buff.Append(Rotation.ToString());
  151. buff.Append(",v=");
  152. buff.Append(Velocity.ToString());
  153. buff.Append(",a=");
  154. buff.Append(Acceleration.ToString());
  155. buff.Append(",rv=");
  156. buff.Append(RotationalVelocity.ToString());
  157. buff.Append(">");
  158. return buff.ToString();
  159. }
  160. }
  161. // Format of this structure must match the definition in the C++ code
  162. // NOTE: adding the X causes compile breaks if used. These are unused symbols
  163. // that can be removed from both here and the unmanaged definition of this structure.
  164. [StructLayout(LayoutKind.Sequential)]
  165. public struct ConfigurationParameters
  166. {
  167. public float defaultFriction;
  168. public float defaultDensity;
  169. public float defaultRestitution;
  170. public float collisionMargin;
  171. public float gravity;
  172. public float maxPersistantManifoldPoolSize;
  173. public float maxCollisionAlgorithmPoolSize;
  174. public float shouldDisableContactPoolDynamicAllocation;
  175. public float shouldForceUpdateAllAabbs;
  176. public float shouldRandomizeSolverOrder;
  177. public float shouldSplitSimulationIslands;
  178. public float shouldEnableFrictionCaching;
  179. public float numberOfSolverIterations;
  180. public float useSingleSidedMeshes;
  181. public float globalContactBreakingThreshold;
  182. public float physicsLoggingFrames;
  183. public const float numericTrue = 1f;
  184. public const float numericFalse = 0f;
  185. }
  186. // Parameters passed for the conversion of a mesh to a hull using Bullet's HACD library.
  187. [StructLayout(LayoutKind.Sequential)]
  188. public struct HACDParams
  189. {
  190. // usual default values
  191. public float maxVerticesPerHull; // 100
  192. public float minClusters; // 2
  193. public float compacityWeight; // 0.1
  194. public float volumeWeight; // 0.0
  195. public float concavity; // 100
  196. public float addExtraDistPoints; // false
  197. public float addNeighboursDistPoints; // false
  198. public float addFacesPoints; // false
  199. public float shouldAdjustCollisionMargin; // false
  200. }
  201. // The states a bullet collision object can have
  202. public enum ActivationState : uint
  203. {
  204. ACTIVE_TAG = 1,
  205. ISLAND_SLEEPING,
  206. WANTS_DEACTIVATION,
  207. DISABLE_DEACTIVATION,
  208. DISABLE_SIMULATION,
  209. }
  210. public enum CollisionObjectTypes : int
  211. {
  212. CO_COLLISION_OBJECT = 1 << 0,
  213. CO_RIGID_BODY = 1 << 1,
  214. CO_GHOST_OBJECT = 1 << 2,
  215. CO_SOFT_BODY = 1 << 3,
  216. CO_HF_FLUID = 1 << 4,
  217. CO_USER_TYPE = 1 << 5,
  218. }
  219. // Values used by Bullet and BulletSim to control object properties.
  220. // Bullet's "CollisionFlags" has more to do with operations on the
  221. // object (if collisions happen, if gravity effects it, ...).
  222. public enum CollisionFlags : uint
  223. {
  224. CF_STATIC_OBJECT = 1 << 0,
  225. CF_KINEMATIC_OBJECT = 1 << 1,
  226. CF_NO_CONTACT_RESPONSE = 1 << 2,
  227. CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3,
  228. CF_CHARACTER_OBJECT = 1 << 4,
  229. CF_DISABLE_VISUALIZE_OBJECT = 1 << 5,
  230. CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6,
  231. // Following used by BulletSim to control collisions and updates
  232. BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10, // return collision events from unmanaged to managed
  233. BS_FLOATS_ON_WATER = 1 << 11, // the object should float at water level
  234. BS_VEHICLE_COLLISIONS = 1 << 12, // return collisions for vehicle ground checking
  235. BS_RETURN_ROOT_COMPOUND_SHAPE = 1 << 13, // return the pos/rot of the root shape in a compound shape
  236. BS_NONE = 0,
  237. BS_ALL = 0x7FFF // collision flags are a signed short
  238. };
  239. // Values f collisions groups and masks
  240. public enum CollisionFilterGroups : uint
  241. {
  242. // Don't use the bit definitions!! Define the use in a
  243. // filter/mask definition below. This way collision interactions
  244. // are more easily found and debugged.
  245. BNoneGroup = 0,
  246. BDefaultGroup = 1 << 0, // 0001
  247. BStaticGroup = 1 << 1, // 0002
  248. BKinematicGroup = 1 << 2, // 0004
  249. BDebrisGroup = 1 << 3, // 0008
  250. BSensorTrigger = 1 << 4, // 0010
  251. BCharacterGroup = 1 << 5, // 0020
  252. BAllGroup = 0x0007FFF, // collision flags are a signed short
  253. // Filter groups defined by BulletSim
  254. BGroundPlaneGroup = 1 << 8, // 0400
  255. BTerrainGroup = 1 << 9, // 0800
  256. BRaycastGroup = 1 << 10, // 1000
  257. BSolidGroup = 1 << 11, // 2000
  258. // BLinksetGroup = xx // a linkset proper is either static or dynamic
  259. BLinksetChildGroup = 1 << 12, // 4000
  260. };
  261. // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0
  262. // ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2.
  263. public enum ConstraintParams : int
  264. {
  265. BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730
  266. BT_CONSTRAINT_STOP_ERP,
  267. BT_CONSTRAINT_CFM,
  268. BT_CONSTRAINT_STOP_CFM,
  269. };
  270. public enum ConstraintParamAxis : int
  271. {
  272. AXIS_LINEAR_X = 0,
  273. AXIS_LINEAR_Y,
  274. AXIS_LINEAR_Z,
  275. AXIS_ANGULAR_X,
  276. AXIS_ANGULAR_Y,
  277. AXIS_ANGULAR_Z,
  278. AXIS_LINEAR_ALL = 20, // added by BulletSim so we don't have to do zillions of calls
  279. AXIS_ANGULAR_ALL,
  280. AXIS_ALL
  281. };
  282. public abstract class BSAPITemplate
  283. {
  284. // Returns the name of the underlying Bullet engine
  285. public abstract string BulletEngineName { get; }
  286. public abstract string BulletEngineVersion { get; protected set;}
  287. // Initialization and simulation
  288. public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms,
  289. int maxCollisions, ref CollisionDesc[] collisionArray,
  290. int maxUpdates, ref EntityProperties[] updateArray
  291. );
  292. public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
  293. out int updatedEntityCount, out int collidersCount);
  294. public abstract bool UpdateParameter(BulletWorld world, UInt32 localID, String parm, float value);
  295. public abstract void Shutdown(BulletWorld sim);
  296. public abstract bool PushUpdate(BulletBody obj);
  297. // =====================================================================================
  298. // Mesh, hull, shape and body creation helper routines
  299. public abstract BulletShape CreateMeshShape(BulletWorld world,
  300. int indicesCount, int[] indices,
  301. int verticesCount, float[] vertices );
  302. public abstract BulletShape CreateGImpactShape(BulletWorld world,
  303. int indicesCount, int[] indices,
  304. int verticesCount, float[] vertices );
  305. public abstract BulletShape CreateHullShape(BulletWorld world,
  306. int hullCount, float[] hulls);
  307. public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms);
  308. public abstract BulletShape BuildConvexHullShapeFromMesh(BulletWorld world, BulletShape meshShape);
  309. public abstract BulletShape CreateConvexHullShape(BulletWorld world,
  310. int indicesCount, int[] indices,
  311. int verticesCount, float[] vertices );
  312. public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData);
  313. public abstract bool IsNativeShape(BulletShape shape);
  314. public abstract void SetShapeCollisionMargin(BulletShape shape, float margin);
  315. public abstract BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale);
  316. public abstract BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree);
  317. public abstract int GetNumberOfCompoundChildren(BulletShape cShape);
  318. public abstract void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot);
  319. public abstract BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
  320. public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
  321. public abstract void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape);
  322. public abstract void UpdateChildTransform(BulletShape pShape, int childIndex, Vector3 pos, Quaternion rot, bool shouldRecalculateLocalAabb);
  323. public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape);
  324. public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, UInt32 id);
  325. public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape);
  326. public abstract CollisionObjectTypes GetBodyType(BulletBody obj);
  327. public abstract BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot);
  328. public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot);
  329. public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot);
  330. public abstract void DestroyObject(BulletWorld sim, BulletBody obj);
  331. // =====================================================================================
  332. public abstract BulletShape CreateGroundPlaneShape(UInt32 id, float height, float collisionMargin);
  333. public abstract BulletShape CreateTerrainShape(UInt32 id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
  334. float scaleFactor, float collisionMargin);
  335. // =====================================================================================
  336. // Constraint creation and helper routines
  337. public abstract BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  338. Vector3 frame1loc, Quaternion frame1rot,
  339. Vector3 frame2loc, Quaternion frame2rot,
  340. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  341. public abstract BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  342. Vector3 joinPoint,
  343. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  344. public abstract BulletConstraint Create6DofConstraintFixed(BulletWorld world, BulletBody obj1,
  345. Vector3 frameInBloc, Quaternion frameInBrot,
  346. bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies);
  347. public abstract BulletConstraint Create6DofSpringConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  348. Vector3 frame1loc, Quaternion frame1rot,
  349. Vector3 frame2loc, Quaternion frame2rot,
  350. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  351. public abstract BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  352. Vector3 pivotinA, Vector3 pivotinB,
  353. Vector3 axisInA, Vector3 axisInB,
  354. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  355. public abstract BulletConstraint CreateSliderConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  356. Vector3 frameInAloc, Quaternion frameInArot,
  357. Vector3 frameInBloc, Quaternion frameInBrot,
  358. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
  359. public abstract BulletConstraint CreateConeTwistConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  360. Vector3 frameInAloc, Quaternion frameInArot,
  361. Vector3 frameInBloc, Quaternion frameInBrot,
  362. bool disableCollisionsBetweenLinkedBodies);
  363. public abstract BulletConstraint CreateGearConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  364. Vector3 axisInA, Vector3 axisInB,
  365. float ratio, bool disableCollisionsBetweenLinkedBodies);
  366. public abstract BulletConstraint CreatePoint2PointConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
  367. Vector3 pivotInA, Vector3 pivotInB,
  368. bool disableCollisionsBetweenLinkedBodies);
  369. public abstract void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse);
  370. public abstract void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations);
  371. public abstract bool SetFrames(BulletConstraint constrain,
  372. Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
  373. public abstract bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
  374. public abstract bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
  375. public abstract bool UseFrameOffset(BulletConstraint constrain, float enable);
  376. public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce);
  377. public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold);
  378. public const int HINGE_NOT_SPECIFIED = -1;
  379. public abstract bool HingeSetLimits(BulletConstraint constrain, float low, float high, float softness, float bias, float relaxation);
  380. public abstract bool SpringEnable(BulletConstraint constrain, int index, float numericTrueFalse);
  381. public const int SPRING_NOT_SPECIFIED = -1;
  382. public abstract bool SpringSetEquilibriumPoint(BulletConstraint constrain, int index, float equilibriumPoint);
  383. public abstract bool SpringSetStiffness(BulletConstraint constrain, int index, float stiffnesss);
  384. public abstract bool SpringSetDamping(BulletConstraint constrain, int index, float damping);
  385. public const int SLIDER_LOWER_LIMIT = 0;
  386. public const int SLIDER_UPPER_LIMIT = 1;
  387. public const int SLIDER_LINEAR = 2;
  388. public const int SLIDER_ANGULAR = 3;
  389. public abstract bool SliderSetLimits(BulletConstraint constrain, int lowerUpper, int linAng, float val);
  390. public const int SLIDER_SET_SOFTNESS = 4;
  391. public const int SLIDER_SET_RESTITUTION = 5;
  392. public const int SLIDER_SET_DAMPING = 6;
  393. public const int SLIDER_SET_DIRECTION = 7;
  394. public const int SLIDER_SET_LIMIT = 8;
  395. public const int SLIDER_SET_ORTHO = 9;
  396. public abstract bool SliderSet(BulletConstraint constrain, int softRestDamp, int dirLimOrtho, int linAng, float val);
  397. public abstract bool SliderMotorEnable(BulletConstraint constrain, int linAng, float numericTrueFalse);
  398. public const int SLIDER_MOTOR_VELOCITY = 10;
  399. public const int SLIDER_MAX_MOTOR_FORCE = 11;
  400. public abstract bool SliderMotor(BulletConstraint constrain, int forceVel, int linAng, float val);
  401. public abstract bool CalculateTransforms(BulletConstraint constrain);
  402. public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
  403. public abstract bool DestroyConstraint(BulletWorld world, BulletConstraint constrain);
  404. // =====================================================================================
  405. // btCollisionWorld entries
  406. public abstract void UpdateSingleAabb(BulletWorld world, BulletBody obj);
  407. public abstract void UpdateAabbs(BulletWorld world);
  408. public abstract bool GetForceUpdateAllAabbs(BulletWorld world);
  409. public abstract void SetForceUpdateAllAabbs(BulletWorld world, bool force);
  410. // =====================================================================================
  411. // btDynamicsWorld entries
  412. // public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj, Vector3 pos, Quaternion rot);
  413. public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj);
  414. public abstract bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj);
  415. public abstract bool ClearCollisionProxyCache(BulletWorld world, BulletBody obj);
  416. public abstract bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects);
  417. public abstract bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain);
  418. // =====================================================================================
  419. // btCollisionObject entries
  420. public abstract Vector3 GetAnisotripicFriction(BulletConstraint constrain);
  421. public abstract Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict);
  422. public abstract bool HasAnisotripicFriction(BulletConstraint constrain);
  423. public abstract void SetContactProcessingThreshold(BulletBody obj, float val);
  424. public abstract float GetContactProcessingThreshold(BulletBody obj);
  425. public abstract bool IsStaticObject(BulletBody obj);
  426. public abstract bool IsKinematicObject(BulletBody obj);
  427. public abstract bool IsStaticOrKinematicObject(BulletBody obj);
  428. public abstract bool HasContactResponse(BulletBody obj);
  429. public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape);
  430. public abstract BulletShape GetCollisionShape(BulletBody obj);
  431. public abstract int GetActivationState(BulletBody obj);
  432. public abstract void SetActivationState(BulletBody obj, int state);
  433. public abstract void SetDeactivationTime(BulletBody obj, float dtime);
  434. public abstract float GetDeactivationTime(BulletBody obj);
  435. public abstract void ForceActivationState(BulletBody obj, ActivationState state);
  436. public abstract void Activate(BulletBody obj, bool forceActivation);
  437. public abstract bool IsActive(BulletBody obj);
  438. public abstract void SetRestitution(BulletBody obj, float val);
  439. public abstract float GetRestitution(BulletBody obj);
  440. public abstract void SetFriction(BulletBody obj, float val);
  441. public abstract float GetFriction(BulletBody obj);
  442. public abstract Vector3 GetPosition(BulletBody obj);
  443. public abstract Quaternion GetOrientation(BulletBody obj);
  444. public abstract void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation);
  445. // public abstract IntPtr GetBroadphaseHandle(BulletBody obj);
  446. // public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle);
  447. public abstract void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel);
  448. public abstract void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel);
  449. public abstract void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel);
  450. public abstract float GetHitFraction(BulletBody obj);
  451. public abstract void SetHitFraction(BulletBody obj, float val);
  452. public abstract CollisionFlags GetCollisionFlags(BulletBody obj);
  453. public abstract CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags);
  454. public abstract CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags);
  455. public abstract CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags);
  456. public abstract float GetCcdMotionThreshold(BulletBody obj);
  457. public abstract void SetCcdMotionThreshold(BulletBody obj, float val);
  458. public abstract float GetCcdSweptSphereRadius(BulletBody obj);
  459. public abstract void SetCcdSweptSphereRadius(BulletBody obj, float val);
  460. public abstract IntPtr GetUserPointer(BulletBody obj);
  461. public abstract void SetUserPointer(BulletBody obj, IntPtr val);
  462. // =====================================================================================
  463. // btRigidBody entries
  464. public abstract void ApplyGravity(BulletBody obj);
  465. public abstract void SetGravity(BulletBody obj, Vector3 val);
  466. public abstract Vector3 GetGravity(BulletBody obj);
  467. public abstract void SetDamping(BulletBody obj, float lin_damping, float ang_damping);
  468. public abstract void SetLinearDamping(BulletBody obj, float lin_damping);
  469. public abstract void SetAngularDamping(BulletBody obj, float ang_damping);
  470. public abstract float GetLinearDamping(BulletBody obj);
  471. public abstract float GetAngularDamping(BulletBody obj);
  472. public abstract float GetLinearSleepingThreshold(BulletBody obj);
  473. public abstract void ApplyDamping(BulletBody obj, float timeStep);
  474. public abstract void SetMassProps(BulletBody obj, float mass, Vector3 inertia);
  475. public abstract Vector3 GetLinearFactor(BulletBody obj);
  476. public abstract void SetLinearFactor(BulletBody obj, Vector3 factor);
  477. public abstract void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot);
  478. // Add a force to the object as if its mass is one.
  479. public abstract void ApplyCentralForce(BulletBody obj, Vector3 force);
  480. // Set the force being applied to the object as if its mass is one.
  481. public abstract void SetObjectForce(BulletBody obj, Vector3 force);
  482. public abstract Vector3 GetTotalForce(BulletBody obj);
  483. public abstract Vector3 GetTotalTorque(BulletBody obj);
  484. public abstract Vector3 GetInvInertiaDiagLocal(BulletBody obj);
  485. public abstract void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert);
  486. public abstract void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold);
  487. public abstract void ApplyTorque(BulletBody obj, Vector3 torque);
  488. // Apply force at the given point. Will add torque to the object.
  489. public abstract void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos);
  490. // Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
  491. public abstract void ApplyCentralImpulse(BulletBody obj, Vector3 imp);
  492. // Apply impulse to the object's torque. Force is scaled by object's mass.
  493. public abstract void ApplyTorqueImpulse(BulletBody obj, Vector3 imp);
  494. // Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
  495. public abstract void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos);
  496. public abstract void ClearForces(BulletBody obj);
  497. public abstract void ClearAllForces(BulletBody obj);
  498. public abstract void UpdateInertiaTensor(BulletBody obj);
  499. public abstract Vector3 GetLinearVelocity(BulletBody obj);
  500. public abstract Vector3 GetAngularVelocity(BulletBody obj);
  501. public abstract void SetLinearVelocity(BulletBody obj, Vector3 val);
  502. public abstract void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity);
  503. public abstract Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos);
  504. public abstract void Translate(BulletBody obj, Vector3 trans);
  505. public abstract void UpdateDeactivation(BulletBody obj, float timeStep);
  506. public abstract bool WantsSleeping(BulletBody obj);
  507. public abstract void SetAngularFactor(BulletBody obj, float factor);
  508. public abstract void SetAngularFactorV(BulletBody obj, Vector3 factor);
  509. public abstract Vector3 GetAngularFactor(BulletBody obj);
  510. public abstract bool IsInWorld(BulletWorld world, BulletBody obj);
  511. public abstract void AddConstraintRef(BulletBody obj, BulletConstraint constrain);
  512. public abstract void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain);
  513. public abstract BulletConstraint GetConstraintRef(BulletBody obj, int index);
  514. public abstract int GetNumConstraintRefs(BulletBody obj);
  515. public abstract bool SetCollisionGroupMask(BulletBody body, UInt32 filter, UInt32 mask);
  516. // =====================================================================================
  517. // btCollisionShape entries
  518. public abstract float GetAngularMotionDisc(BulletShape shape);
  519. public abstract float GetContactBreakingThreshold(BulletShape shape, float defaultFactor);
  520. public abstract bool IsPolyhedral(BulletShape shape);
  521. public abstract bool IsConvex2d(BulletShape shape);
  522. public abstract bool IsConvex(BulletShape shape);
  523. public abstract bool IsNonMoving(BulletShape shape);
  524. public abstract bool IsConcave(BulletShape shape);
  525. public abstract bool IsCompound(BulletShape shape);
  526. public abstract bool IsSoftBody(BulletShape shape);
  527. public abstract bool IsInfinite(BulletShape shape);
  528. public abstract void SetLocalScaling(BulletShape shape, Vector3 scale);
  529. public abstract Vector3 GetLocalScaling(BulletShape shape);
  530. public abstract Vector3 CalculateLocalInertia(BulletShape shape, float mass);
  531. public abstract int GetShapeType(BulletShape shape);
  532. public abstract void SetMargin(BulletShape shape, float val);
  533. public abstract float GetMargin(BulletShape shape);
  534. // =====================================================================================
  535. // Debugging
  536. public virtual void DumpRigidBody(BulletWorld sim, BulletBody collisionObject) { }
  537. public virtual void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape) { }
  538. public virtual void DumpConstraint(BulletWorld sim, BulletConstraint constrain) { }
  539. public virtual void DumpActivationInfo(BulletWorld sim) { }
  540. public virtual void DumpAllInfo(BulletWorld sim) { }
  541. public virtual void DumpPhysicsStatistics(BulletWorld sim) { }
  542. public virtual void ResetBroadphasePool(BulletWorld sim) { }
  543. public virtual void ResetConstraintSolver(BulletWorld sim) { }
  544. };
  545. }