
// Linear Math

interface btVector3 {
  void btVector3();
  void btVector3(float x, float y, float z);
  float length();
  float x();
  float y();
  float z();
  void setX(float x);
  void setY(float y);
  void setZ(float z);
  void setValue(float x, float y, float z);
  [Operator="*=", Ref] btVector3 op_mul(float x);
};

interface btVector4 {
  void btVector4();
  void btVector4(float x, float y, float z, float w);
  float w();
  void setValue(float x, float y, float z, float w);
};
btVector4 implements btVector3;

interface btQuadWord {
  float x();
  float y();
  float z();
  float w();
  void setX(float x);
  void setY(float y);
  void setZ(float z);
  void setW(float w);
};

interface btQuaternion {
  void btQuaternion(float x, float y, float z, float w);
  void setValue(float x, float y, float z, float w);
};
btQuaternion implements btQuadWord;

interface btMatrix3x3 {
  void setEulerZYX(float ex, float ey, float ez);
  void getRotation([Ref] btQuaternion q);
};

interface btTransform {
  void btTransform();
  void btTransform([Ref] btQuaternion q, [Ref] btVector3 v);

  void setIdentity();
  void setOrigin([Ref] btVector3 origin);
  void setRotation([Ref] btQuaternion rotation);
  [Ref] btVector3 getOrigin();
  [Value] btQuaternion getRotation();
  [Ref] btMatrix3x3 getBasis();
};

interface btMotionState {
  void getWorldTransform([Ref] btTransform worldTrans);
  void setWorldTransform([Ref] btTransform worldTrans);
};

interface btDefaultMotionState {
  void btDefaultMotionState([Ref] optional btTransform startTrans, [Ref] optional btTransform centerOfMassOffset);
  [Value] attribute btTransform m_graphicsWorldTrans;
};
btDefaultMotionState implements btMotionState;

// Collision

interface btCollisionObject {
  void setAnisotropicFriction([Const, Ref] btVector3 anisotropicFriction, long frictionMode);
  btCollisionShape getCollisionShape();
  void setContactProcessingThreshold(float contactProcessingThreshold);
  void setActivationState(long newState);  
  void forceActivationState(long newState);
  void activate(optional boolean forceActivation);
  boolean isActive();
  boolean isKinematicObject();
  void setRestitution(float rest);
  void setFriction(float frict);
  void setRollingFriction(float frict);
  [Ref] btTransform getWorldTransform();
  long getCollisionFlags();
  void setCollisionFlags(long flags);
  void setWorldTransform ([Const,Ref] btTransform worldTrans);
  void setCollisionShape (btCollisionShape collisionShape);
  void setCcdMotionThreshold (float ccdMotionThreshold);
  void setCcdSweptSphereRadius (float radius);
};

[NoDelete]
interface btCollisionObjectWrapper {
};

[Prefix="btCollisionWorld::"]
interface RayResultCallback {
  // abstract base class, no constructor
  boolean hasHit();
  attribute short m_collisionFilterGroup;
  attribute short m_collisionFilterMask;
  [Const] attribute btCollisionObject m_collisionObject;
};

[Prefix="btCollisionWorld::"]
interface ClosestRayResultCallback {
  void ClosestRayResultCallback([Const, Ref] btVector3 from, [Const, Ref] btVector3 to);

  [Value] attribute btVector3 m_rayFromWorld;
  [Value] attribute btVector3 m_rayToWorld;
  [Value] attribute btVector3 m_hitNormalWorld;
  [Value] attribute btVector3 m_hitPointWorld;
};
ClosestRayResultCallback implements RayResultCallback;

interface btManifoldPoint {
  [Const, Ref] btVector3 getPositionWorldOnA();
  [Const, Ref] btVector3 getPositionWorldOnB();
  [Const] double getDistance();
  [Value] attribute btVector3 m_localPointA;
  [Value] attribute btVector3 m_localPointB;
  [Value] attribute btVector3 m_positionWorldOnB;
  [Value] attribute btVector3 m_positionWorldOnA;
  [Value] attribute btVector3 m_normalWorldOnB;
};

[Prefix="btCollisionWorld::"]
interface ContactResultCallback {
  float addSingleResult([Ref] btManifoldPoint cp, [Const] btCollisionObjectWrapper colObj0Wrap, long partId0, long index0, [Const] btCollisionObjectWrapper colObj1Wrap, long partId1, long index1);
};

[JSImplementation="ContactResultCallback"]
interface ConcreteContactResultCallback {
  void ConcreteContactResultCallback();
  float addSingleResult([Ref] btManifoldPoint cp, [Const] btCollisionObjectWrapper colObj0Wrap, long partId0, long index0, [Const] btCollisionObjectWrapper colObj1Wrap, long partId1, long index1);
};

[Prefix="btCollisionWorld::"]
interface LocalShapeInfo {
    attribute long m_shapePart;
    attribute long m_triangleIndex;
 };

[Prefix="btCollisionWorld::"]
interface LocalConvexResult  {
  void LocalConvexResult([Const] btCollisionObject hitCollisionObject, LocalShapeInfo localShapeInfo, [Const, Ref] btVector3 hitNormalLocal, [Const, Ref] btVector3 hitPointLocal, float hitFraction);
  [Const] attribute btCollisionObject m_hitCollisionObject;
  attribute LocalShapeInfo m_localShapeInfo;
  [Value] attribute btVector3 m_hitNormalLocal;
  [Value] attribute btVector3 m_hitPointLocal;
  attribute float m_hitFraction;
};

[Prefix="btCollisionWorld::"]
interface ConvexResultCallback {
  // abstract base class, no constructor
  boolean hasHit();
  attribute short m_collisionFilterGroup;
  attribute short m_collisionFilterMask;
  attribute float m_closestHitFraction;
};

[Prefix="btCollisionWorld::"]
interface ClosestConvexResultCallback {
  void ClosestConvexResultCallback([Const, Ref] btVector3 convexFromWorld, [Const, Ref] btVector3 convexToWorld);
    
  [Value] attribute btVector3 m_convexFromWorld;
  [Value] attribute btVector3 m_convexToWorld;
  [Value] attribute btVector3 m_hitNormalWorld;
  [Value] attribute btVector3 m_hitPointWorld;
};
ClosestConvexResultCallback implements ConvexResultCallback;

interface btCollisionShape {
  void setLocalScaling([Const, Ref] btVector3 scaling);
  void calculateLocalInertia(float mass, [Ref] btVector3 inertia);
};

interface btConvexShape {
};
btConvexShape implements btCollisionShape;

interface btConvexTriangleMeshShape {
  void btConvexTriangleMeshShape(btStridingMeshInterface meshInterface, optional boolean calcAabb);
};
btConvexTriangleMeshShape implements btConvexShape;

interface btBoxShape {
  void btBoxShape([Ref] btVector3 boxHalfExtents);
};
btBoxShape implements btCollisionShape;

interface btCapsuleShape {
  void btCapsuleShape(float radius, float height);
};
btCapsuleShape implements btCollisionShape;

interface btCapsuleShapeX {
  void btCapsuleShapeX(float radius, float height);
};
btCapsuleShapeX implements btCapsuleShape;

interface btCapsuleShapeZ {
  void btCapsuleShapeZ(float radius, float height);
};
btCapsuleShapeZ implements btCapsuleShape;

interface btCylinderShape {
  void btCylinderShape([Ref] btVector3 halfExtents);
};
btCylinderShape implements btCollisionShape;

interface btCylinderShapeX {
  void btCylinderShapeX([Ref] btVector3 halfExtents);
};
btCylinderShapeX implements btCylinderShape;

interface btCylinderShapeZ {
  void btCylinderShapeZ([Ref] btVector3 halfExtents);
};
btCylinderShapeZ implements btCylinderShape;

interface btSphereShape {
  void btSphereShape(float radius);
};
btSphereShape implements btCollisionShape;

interface btConeShape {
  void btConeShape(float radius, float height);
};
btConeShape implements btCollisionShape;

interface btConvexHullShape {
  void btConvexHullShape();
  void addPoint([Const, Ref] btVector3 point, optional boolean recalculateLocalAABB);
};
btConvexHullShape implements btCollisionShape;

interface btConeShapeX {
  void btConeShapeX(float radius, float height);
};
btConeShapeX implements btConeShape;

interface btConeShapeZ {
  void btConeShapeZ(float radius, float height);
};
btConeShapeZ implements btConeShape;

interface btCompoundShape {
  void btCompoundShape(optional boolean enableDynamicAabbTree);
  void addChildShape([Const, Ref] btTransform localTransform, btCollisionShape shape);
};
btCompoundShape implements btCollisionShape;

interface btStridingMeshInterface {
};

interface btTriangleMesh {
  void btTriangleMesh(optional boolean use32bitIndices, optional boolean use4componentVertices);
  void addTriangle([Const, Ref] btVector3 vertex0, [Const, Ref] btVector3 vertex1, [Const, Ref] btVector3 vertex2, optional boolean removeDuplicateVertices);
};
btTriangleMesh implements btStridingMeshInterface;

interface btConcaveShape {
};
btConcaveShape implements btCollisionShape;

interface btStaticPlaneShape {
  void btStaticPlaneShape([Const, Ref] btVector3 planeNormal, float planeConstant); 
};
btStaticPlaneShape implements btConcaveShape;

interface btTriangleMeshShape {
};
btTriangleMeshShape implements btConcaveShape;

interface btBvhTriangleMeshShape {
  void btBvhTriangleMeshShape(btStridingMeshInterface meshInterface, boolean useQuantizedAabbCompression, optional boolean buildBvh);
};
btBvhTriangleMeshShape implements btTriangleMeshShape;

interface btDefaultCollisionConstructionInfo {
  void btDefaultCollisionConstructionInfo();
};

interface btDefaultCollisionConfiguration {
  void btDefaultCollisionConfiguration([Ref] optional btDefaultCollisionConstructionInfo info);
};

interface btPersistentManifold {
  void btPersistentManifold();
  [Const] btCollisionObject getBody0();
  [Const] btCollisionObject getBody1();
  long getNumContacts();
  [Ref] btManifoldPoint getContactPoint(long index);  
};

interface btDispatcher {
  long getNumManifolds();
  btPersistentManifold getManifoldByIndexInternal(long index);
};

interface btCollisionDispatcher {
  void btCollisionDispatcher(btDefaultCollisionConfiguration conf);
};
btCollisionDispatcher implements btDispatcher;

interface btOverlappingPairCallback {
};

interface btOverlappingPairCache {
  void setInternalGhostPairCallback(btOverlappingPairCallback ghostPairCallback);
};

interface btAxisSweep3 {
  void btAxisSweep3([Ref] btVector3 worldAabbMin, [Ref] btVector3 worldAabbMax, optional long maxHandles, optional btOverlappingPairCache pairCache, optional boolean disableRaycastAccelerator);
};

interface btBroadphaseInterface {
};

interface btCollisionConfiguration {
};

interface btDbvtBroadphase {
  void btDbvtBroadphase();
};


// Dynamics

[Prefix="btRigidBody::"]
interface btRigidBodyConstructionInfo {
  void btRigidBodyConstructionInfo(float mass, btMotionState motionState, btCollisionShape collisionShape, [Ref] optional btVector3 localInertia);
  attribute float m_linearDamping;
  attribute float m_angularDamping;
  attribute float m_friction;
  attribute float m_rollingFriction;
  attribute float m_restitution;
  attribute float m_linearSleepingThreshold;
  attribute float m_angularSleepingThreshold;
  attribute boolean m_additionalDamping;
  attribute float m_additionalDampingFactor;
  attribute float m_additionalLinearDampingThresholdSqr;
  attribute float m_additionalAngularDampingThresholdSqr;
  attribute float m_additionalAngularDampingFactor;
};

interface btRigidBody {
  void btRigidBody([Const, Ref] btRigidBodyConstructionInfo constructionInfo);
  
  [Const, Ref] btTransform getCenterOfMassTransform();
  void setCenterOfMassTransform([Const, Ref] btTransform xform);
  void setSleepingThresholds(float linear, float angular);
  void setDamping(float lin_damping, float ang_damping);
  void setMassProps(float mass, [Const, Ref] btVector3 inertia);
  void setLinearFactor([Const, Ref] btVector3 linearFactor);
  void applyTorque([Const, Ref] btVector3 torque);
  void applyForce([Const, Ref] btVector3 force, [Const, Ref] btVector3 rel_pos);
  void applyCentralForce([Const, Ref] btVector3 force);
  void applyTorqueImpulse([Const, Ref] btVector3 torque);
  void applyImpulse([Const, Ref] btVector3 impulse, [Const, Ref] btVector3 rel_pos);
  void applyCentralImpulse([Const, Ref] btVector3 impulse);
  void updateInertiaTensor();
  [Const, Ref] btVector3 getLinearVelocity();
  [Const, Ref] btVector3 getAngularVelocity();
  void setLinearVelocity([Const, Ref] btVector3 lin_vel);
  void setAngularVelocity([Const, Ref] btVector3 ang_vel);
  btMotionState getMotionState();
  void setAngularFactor([Const, Ref] btVector3 angularFactor);
  btRigidBody upcast([Const] btCollisionObject colObj);
};
btRigidBody implements btCollisionObject;

interface btConstraintSetting {
  void btConstraintSetting();
  attribute float m_tau;
  attribute float m_damping;
  attribute float m_impulseClamp;
};

interface btTypedConstraint {
  void enableFeedback(boolean needsFeedback);
  [Const] float getBreakingImpulseThreshold();
  void setBreakingImpulseThreshold([Const] float threshold);
};

interface btPoint2PointConstraint {
  void btPoint2PointConstraint([Ref] btRigidBody rbA, [Ref] btRigidBody rbB, [Ref] btVector3 pivotInA, [Ref] btVector3 pivotInB);
  void btPoint2PointConstraint([Ref] btRigidBody rbA, [Ref] btVector3 pivotInA);
  void setPivotA([Const, Ref] btVector3 pivotA);
  void setPivotB([Const, Ref] btVector3 pivotB);
  [Const, Ref] btVector3 getPivotInA();
  [Const, Ref] btVector3 getPivotInB();

  [Value] attribute btConstraintSetting m_setting;
};
btPoint2PointConstraint implements btTypedConstraint;

interface btGeneric6DofConstraint {
  void btGeneric6DofConstraint([Ref] btRigidBody rbA, [Ref] btRigidBody rbB, [Ref] btTransform frameInA, [Ref] btTransform frameInB, boolean useLinearFrameReferenceFrameA);
  void btGeneric6DofConstraint([Ref] btRigidBody rbB, [Ref] btTransform frameInB, boolean useLinearFrameReferenceFrameB);
  void setLinearLowerLimit([Const, Ref] btVector3 linearLower);
  void setLinearUpperLimit([Const, Ref] btVector3 linearUpper);
  void setAngularLowerLimit([Const, Ref] btVector3 angularLower);
  void setAngularUpperLimit([Const, Ref] btVector3 angularUpper);  
};
btGeneric6DofConstraint implements btTypedConstraint;

interface btGeneric6DofSpringConstraint {
  void btGeneric6DofSpringConstraint([Ref] btRigidBody rbA, [Ref] btRigidBody rbB, [Ref] btTransform frameInA, [Ref] btTransform frameInB, boolean useLinearFrameReferenceFrameA);
  void btGeneric6DofSpringConstraint([Ref] btRigidBody rbB, [Ref] btTransform frameInB, boolean useLinearFrameReferenceFrameB);
  void enableSpring(long index, boolean onOff);
  void setStiffness(long index, float stiffness);
  void setDamping(long index, float damping);
};
btGeneric6DofSpringConstraint implements btGeneric6DofConstraint;

interface btSequentialImpulseConstraintSolver {
  void btSequentialImpulseConstraintSolver();
};

interface btConeTwistConstraint {
  void btConeTwistConstraint([Ref] btRigidBody rbA, [Ref] btRigidBody rbB, [Ref] btTransform rbAFrame, [Ref] btTransform rbBFrame);
  void btConeTwistConstraint([Ref] btRigidBody rbA, [Ref] btTransform rbAFrame);

  void setLimit(long limitIndex, float limitValue);
  void setAngularOnly(boolean angularOnly);
  void setDamping(float damping);
  void enableMotor(boolean b);
  void setMaxMotorImpulse(float maxMotorImpulse);
  void setMaxMotorImpulseNormalized(float maxMotorImpulse);
  void setMotorTarget([Const,Ref] btQuaternion q);
  void setMotorTargetInConstraintSpace([Const,Ref] btQuaternion q);
};
btConeTwistConstraint implements btTypedConstraint;

interface btHingeConstraint {
  void btHingeConstraint ([Ref] btRigidBody rbA, [Ref] btRigidBody rbB, [Ref] btVector3 pivotInA, [Ref] btVector3 pivotInB, [Ref] btVector3 axisInA, [Ref] btVector3 axisInB, optional boolean useReferenceFrameA);
  //void btHingeConstraint ([Ref] btRigidBody rbA, [Ref] btVector3 pivotInA, [Ref] btVector3 axisInA, optional boolean useReferenceFrameA);
  void btHingeConstraint ([Ref] btRigidBody rbA, [Ref] btRigidBody rbB, [Ref] btTransform rbAFrame, [Ref] btTransform rbBFrame, optional boolean useReferenceFrameA);
  void btHingeConstraint ([Ref] btRigidBody rbA, [Ref] btTransform rbAFrame, optional boolean useReferenceFrameA);

  void setLimit(float low, float high, float softness, float biasFactor, optional float relaxationFactor);
  void enableAngularMotor(boolean enableMotor, float targetVelocity, float maxMotorImpulse);
};
btHingeConstraint implements btTypedConstraint;

interface btSliderConstraint {
  void btSliderConstraint([Ref] btRigidBody rbA, [Ref] btRigidBody rbB, [Const,Ref] btTransform frameInA, [Const,Ref] btTransform frameInB, boolean useLinearReferenceFrameA);
  void btSliderConstraint([Ref] btRigidBody rbB, [Const,Ref] btTransform frameInB, boolean uesLinearReferenceFrameA);
  void setLowerLinLimit(float lowerLimit);
  void setUpperLinLimit(float upperLimit);
  void setLowerAngLimit(float lowerAngLimit);
  void setUpperAngLimit(float upperAngLimit);
};
btSliderConstraint implements btTypedConstraint;

interface btConstraintSolver {
};

interface btDispatcherInfo {
  attribute float m_timeStep;
  attribute long m_stepCount;
  attribute long m_dispatchFunc;
  attribute float m_timeOfImpact;
  attribute boolean m_useContinuous; 
  attribute boolean m_enableSatConvex;
  attribute boolean m_enableSPU;
  attribute boolean m_useEpa;
  attribute float m_allowedCcdPenetration;
  attribute boolean m_useConvexConservativeDistanceUtil;
  attribute float m_convexConservativeDistanceThreshold;
};

interface btCollisionWorld {
  btDispatcher getDispatcher();
  void rayTest([Const, Ref] btVector3 rayFromWorld, [Const, Ref] btVector3 rayToWorld, [Ref] RayResultCallback resultCallback);
  btOverlappingPairCache getPairCache(); 
  [Ref] btDispatcherInfo getDispatchInfo();
  void addCollisionObject(btCollisionObject collisionObject, optional short collisionFilterGroup, optional short collisionFilterMask);
  [Const] btBroadphaseInterface getBroadphase ();
  void convexSweepTest([Const] btConvexShape castShape, [Const, Ref] btTransform from, [Const, Ref] btTransform to, [Ref] ConvexResultCallback resultCallback, float allowedCcdPenetration); 
  void contactPairTest([Const] btCollisionObject colObjA, [Const] btCollisionObject colObjB, [Ref] ContactResultCallback resultCallback);  
};

interface btContactSolverInfo {
  attribute boolean m_splitImpulse;
  attribute long m_splitImpulsePenetrationThreshold;  
};

interface btDynamicsWorld {
  void addAction(btActionInterface action);
  [Value] btContactSolverInfo getSolverInfo();
};
btDynamicsWorld implements btCollisionWorld;

interface btDiscreteDynamicsWorld {
  void btDiscreteDynamicsWorld(btDispatcher dispatcher, btBroadphaseInterface pairCache, btConstraintSolver constraintSolver, btCollisionConfiguration collisionConfiguration);

  void setGravity([Ref] btVector3 gravity);
  [Value] btVector3 getGravity();

  void addRigidBody(btRigidBody body);
  void addRigidBody(btRigidBody body, short group, short mask);
  void removeRigidBody(btRigidBody body);

  void addConstraint(btTypedConstraint constraint, optional boolean disableCollisionsBetweenLinkedBodies);
  void removeConstraint(btTypedConstraint constraint);

  long stepSimulation(float timeStep, optional long maxSubSteps, optional float fixedTimeStep);
};
btDiscreteDynamicsWorld implements btDynamicsWorld;

[Prefix="btRaycastVehicle::", NoDelete]
interface btVehicleTuning {
  void btVehicleTuning();
  attribute float m_suspensionStiffness;
  attribute float m_suspensionCompression;
  attribute float m_suspensionDamping;
  attribute float m_maxSuspensionTravelCm;
  attribute float m_frictionSlip;
  attribute float m_maxSuspensionForce; 
};

interface btVehicleRaycaster {
};

interface btDefaultVehicleRaycaster {
  void btDefaultVehicleRaycaster(btDynamicsWorld world);
};
btDefaultVehicleRaycaster implements btVehicleRaycaster;

interface btWheelInfo {
  attribute float m_suspensionStiffness;
  attribute float m_frictionSlip;
  attribute float m_rollInfluence;
  attribute float m_suspensionRestLength1;
  attribute float m_wheelsRadius;
  attribute float m_wheelsDampingCompression;
  attribute float m_wheelsDampingRelaxation;
  attribute float m_steering;
  attribute float m_maxSuspensionForce;
  attribute float m_maxSuspensionTravelCm;
  attribute float m_wheelsSuspensionForce;
  attribute boolean m_bIsFrontWheel;
  [Value] attribute btVector3 m_chassisConnectionPointCS;
};

interface btActionInterface {
};

interface btKinematicCharacterController {
  void btKinematicCharacterController(btPairCachingGhostObject ghostObject, btConvexShape convexShape, float stepHeight, optional long upAxis);

  void setUpAxis (long axis);
  void setWalkDirection ([Const,Ref] btVector3 walkDirection);
  void setVelocityForTimeInterval ([Const,Ref] btVector3 velocity, float timeInterval);
  //void reset ();
  void warp ([Const, Ref]btVector3 origin);
  void preStep (btCollisionWorld collisionWorld);
  void playerStep (btCollisionWorld collisionWorld, float dt);
  void setFallSpeed (float fallSpeed);
  void setJumpSpeed (float jumpSpeed);
  void setMaxJumpHeight (float maxJumpHeight);
  boolean canJump ();
  void jump ();
  void setGravity (float gravity);
  float getGravity ();
  void setMaxSlope (float slopeRadians);
  float getMaxSlope ();
  btPairCachingGhostObject getGhostObject ();
  void setUseGhostSweepTest (boolean useGhostObjectSweepTest);
  boolean onGround ();
};
btKinematicCharacterController implements btActionInterface;

interface btRaycastVehicle {
  void btRaycastVehicle([Const, Ref] btVehicleTuning tuning, btRigidBody chassis, btVehicleRaycaster raycaster);
  void applyEngineForce(float force, long wheel);
  void setSteeringValue(float steering, long wheel);
  [Const, Ref] btTransform getWheelTransformWS(long wheelIndex);
  void updateWheelTransform(long wheelIndex, boolean interpolatedTransform);
  [Ref] btWheelInfo addWheel([Const, Ref] btVector3 connectionPointCS0, [Const, Ref] btVector3 wheelDirectionCS0, [Const, Ref] btVector3 wheelAxleCS, float suspensionRestLength, float wheelRadius, [Const, Ref] btVehicleTuning tuning, boolean isFrontWheel);
  long getNumWheels();
  btRigidBody getRigidBody();
  [Ref] btWheelInfo getWheelInfo(long index);
  void setBrake(float brake, long wheelIndex);
  void setCoordinateSystem(long rightIndex, long upIndex, long forwardIndex);
};
btRaycastVehicle implements btActionInterface;

interface btGhostObject {
  void btGhostObject();
  long getNumOverlappingObjects();
  btCollisionObject getOverlappingObject(long index);
};
btGhostObject implements btCollisionObject;

interface btPairCachingGhostObject {
  void btPairCachingGhostObject();
};
btPairCachingGhostObject implements btGhostObject;

interface btGhostPairCallback {
  void btGhostPairCallback();
};


