BSApiTemplate.cs 27 KB

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