1
0

BSApiTemplate.cs 31 KB

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