#use "Newton.lib"
#define NEWTON_H__736495_6495_076__INCLUDED_
#define _NEWTON_USE_LIB
#typedef dFloat double

#define _BOX_PRIMITIVE 0
#define _CONE_PRIMITIVE 1
#define _SPHERE_PRIMITIVE 2
#define _CYLINDER_PRIMITIVE 3
#define _CAPSULE_PRIMITIVE 4
#define _CHAMFER_CYLINDER_PRIMITIVE 5
#define _RANDOM_COMVEX_HULL_PRIMITIVE 6

#typedef ShortInt byte
#typedef SmallInt word
#typedef LongInt int
#typedef sInt64 int64

#typedef NewtonBody int
#typedef NewtonWorld int
#typedef NewtonJoint int
#typedef NewtonContact int
#typedef NewtonMaterial int
#typedef NewtonCollision int
#typedef NewtonRagDoll int
#typedef NewtonRagDollBone int

#typedef PNewtonBody POINTER
#typedef PNewtonWorld POINTER
#typedef PNewtonJoint POINTER
#typedef PNewtonContact POINTER
#typedef PNewtonMaterial POINTER
#typedef PNewtonCollision POINTER
#typedef PNewtonRagDoll POINTER
#typedef PNewtonRagDollBone POINTER

struct NewtonUserMeshCollisionCollideDescTag
	{
		dFloat m_boxP0[4];						// lower bounding box of intersection query in local space
		dFloat m_boxP1[4];						// upper bounding box of intersection query in local space
		void* m_userData;                       // user data passed to the collision geometry at creation time
		int	  m_faceCount;                      // the application should set here how many polygons intersect the query box
		dFloat* m_vertex;                       // the application should the pointer to the vertex array. 
		int m_vertexStrideInBytes;              // the application should set here the size of each vertex
	 	int* m_userAttribute;                   // the application should set here the pointer to the user data, one for each face
		int* m_faceIndexCount;                  // the application should set here the pointer to the vertex count of each face.
		int* m_faceVertexIndex;                 // the application should set here the pointer index array for each vertex on a face.
		NewtonBody* m_objBody;                  // pointer to the colliding body
		NewtonBody* m_polySoupBody;             // pointer to the rigid body owner of this collision tree 
	};

struct NewtonUserMeshCollisionRayHitDescTag
	{
		dFloat m_p0[4];							// ray origin in collision local space
		dFloat m_p1[4];                         // ray destination in collision local space   
		dFloat m_normalOut[4];					// copy here the normal at the rat intersection
		int m_userIdOut;                        // copy here a user defined id for further feedback  
		void* m_userData;                       // user data passed to the collision geometry at creation time
	};

struct NewtonHingeSliderUpdateDescTag
	{
		dFloat m_accel;
		dFloat m_minFriction;
		dFloat m_maxFriction;
		dFloat m_timestep;
	};

//Call Back Routines
declare *NewtonAllocMemory(int sizeInBytes),pointer;
declare *NewtonFreeMemory(void *ptr, int sizeInBytes);

declare *NewtonSerialize(void *serializeHandle,void *buffer, size_t size);
declare *NewtonDeserialize(void *serializeHandle, void *buffer, size_t size);
	
declare *NewtonUserMeshCollisionCollideCallback(NewtonUserMeshCollisionCollideDesc *collideDescData);
declare *NewtonUserMeshCollisionRayHitCallback(NewtonUserMeshCollisionRayHitDesc *lineDescData),dFloat;
declare *NewtonUserMeshCollisionDestroyCallback(void *descData);
declare *NewtonTreeCollisionCallback(NewtonBody *bodyWithTreeCollision,NewtonBody *body,dFloat *vertex, int vertexstrideInBytes,	int indexCount,int *indexArray);

declare *NewtonBodyDestructor(NewtonBody *body);
declare *NewtonApplyForceAndTorque(NewtonBody *body);
declare *NewtonBodyActivationState(NewtonBody *body, void pstate);
declare *NewtonSetTransform(NewtonBody *body,dFloat *matrix);
declare *NewtonSetRagDollTransform(NewtonRagDollBone *bone);
declare *NewtonGetBuoyancyPlane(int collisionID, void *context,dFloat *globalSpaceMatrix, dFloat *globalSpacePlane),int;

declare *NewtonVehicleTireUpdate(NewtonJoint *vehicle);
	
declare *NewtonWorldRayPrefilterCallback(NewtonBody *body,NewtonCollision *collision, void *userData),void;
declare *NewtonWorldRayFilterCallback(NewtonBody *body,dFloat *hitNormal, int collisionID, void *userData, dFloat intersetParam),dFloat;
declare *NewtonBodyLeaveWorld(NewtonBody *body);

declare *NewtonContactBegin(NewtonMaterial *material,NewtonBody *body0,NewtonBody *body1),int;
declare *NewtonContactProcess(NewtonMaterial *material,NewtonContact *contact),int;
declare *NewtonContactEnd(NewtonMaterial *material);

declare *NewtonBodyIterator(NewtonBody *body);
declare *NewtonCollisionIterator(NewtonBody *body, int vertexCount, dFloat *FaceArray, int faceId);

declare *NewtonBallCallBack(NewtonJoint *ball);
declare *NewtonHingeCallBack(NewtonJoint *hinge, NewtonHingeSliderUpdateDesc *desc),void;
declare *NewtonSliderCallBack(NewtonJoint *slider, NewtonHingeSliderUpdateDesc *desc),void;
declare *NewtonUniversalCallBack(NewtonJoint *universal, NewtonHingeSliderUpdateDesc *desc),void;
declare *NewtonCorkscrewCallBack(NewtonJoint *corkscrew, NewtonHingeSliderUpdateDesc *desc),void;
declare *NewtonUserBilateralCallBack(NewtonJoint *userJoint);

declare *NewtonConstraintDestructor(NewtonJoint *me);

//World interface
declare cdecl import, NewtonCreate(opt NewtonAllocMemory *malloc,opt NewtonFreeMemory *mfree),int;
declare cdecl import, NewtonDestroy(NewtonWorld newtonWorld);
declare cdecl import, NewtonDestroyAllBodies(NewtonWorld newtonWorld);

declare cdecl import, NewtonUpdate(NewtonWorld newtonWorld, dFloat timestep);
declare cdecl import, NewtonSetPlatformArchitecture(NewtonWorld newtonWorld, int mode);
declare cdecl import, NewtonSetSolverModel(NewtonWorld newtonWorld, int model);
declare cdecl import, NewtonSetFrictionModel(NewtonWorld newtonWorld, int model);
declare cdecl import, NewtonGetTimeStep(NewtonWorld newtonWorld),dFloat;
declare cdecl import, NewtonSetMinimumFrameRate(NewtonWorld newtonWorld, dFloat frameRate);
declare cdecl import, NewtonSetBodyLeaveWorldEvent(NewtonWorld newtonWorld, NewtonBodyLeaveWorld *callback); 
declare cdecl import, NewtonSetWorldSize(NewtonWorld newtonWorld, dFloat minPoint,dFloat maxPoint); 
	
declare cdecl import, NewtonWorldFreezeBody(NewtonWorld newtonWorld,NewtonBody body);
declare cdecl import, NewtonWorldUnfreezeBody(NewtonWorld newtonWorld,NewtonBody body);

declare cdecl import, NewtonWorldForEachBodyDo(NewtonWorld newtonWorld, NewtonBodyIterator *callback);
declare cdecl import, NewtonWorldForEachBodyInAABBDo(NewtonWorld newtonWorld,dFloat p0,dFloat p1, NewtonBodyIterator *callback);

declare cdecl import, NewtonWorldSetUserData(NewtonWorld newtonWorld, void *userData);
declare cdecl import, NewtonWorldGetUserData(NewtonWorld newtonWorld),void *;
declare cdecl import, NewtonWorldGetVersion(NewtonWorld newtonWorld),int;

declare cdecl import, NewtonWorldRayCast(NewtonWorld newtonWorld,dFloat p0, dFloat p1,NewtonWorldRayFilterCallback filter, void *userData, NewtonWorldRayPrefilterCallback prefilter);

// **********************************************************************************************
//
// Physics Material Section
//
// **********************************************************************************************
declare cdecl import, NewtonMaterialGetDefaultGroupID(NewtonWorld newtonWorld),int;
declare cdecl import, NewtonMaterialCreateGroupID(NewtonWorld newtonWorld),int;
declare cdecl import, NewtonMaterialDestroyAllGroupID(NewtonWorld newtonWorld);
	
declare cdecl import, NewtonMaterialSetDefaultSoftness(NewtonWorld newtonWorld, int id0, int id1, dFloat value);
declare cdecl import, NewtonMaterialSetDefaultElasticity(NewtonWorld newtonWorld, int id0, int id1, dFloat elasticCoef);
declare cdecl import, NewtonMaterialSetDefaultCollidable(NewtonWorld newtonWorld, int id0, int id1, int state);
declare cdecl import, NewtonMaterialSetContinuousCollisionMode(NewtonWorld newtonWorld, int id0, int id1, int state);
declare cdecl import, NewtonMaterialSetDefaultFriction(NewtonWorld newtonWorld, int id0, int id1, dFloat staticFriction, dFloat kineticFriction);

declare cdecl import, NewtonMaterialSetCollisionCallback(NewtonWorld newtonWorld, int id0, int id1, void* userData,	NewtonContactBegin *begin, NewtonContactProcess *process, NewtonContactEnd *end);
declare cdecl import, NewtonMaterialGetUserData(NewtonWorld newtonWorld, int id0, int id1),void *;


// **********************************************************************************************
//
// Physics Contact control functions
//
// **********************************************************************************************
declare cdecl import,NewtonMaterialDisableContact(NewtonMaterial material);
declare cdecl import,NewtonMaterialGetCurrentTimestep(NewtonMaterial material),dFloat;
declare cdecl import,NewtonMaterialGetMaterialPairUserData(NewtonMaterial material),void *;
declare cdecl import,NewtonMaterialGetContactFaceAttribute(NewtonMaterial material),void;
declare cdecl import,NewtonMaterialGetBodyCollisionID(NewtonMaterial material, NewtonBody* body),void;
declare cdecl import,NewtonMaterialGetContactNormalSpeed(NewtonMaterial material, NewtonContact contactlHandle),dFloat;
declare cdecl import,NewtonMaterialGetContactForce(NewtonMaterial material, dFloat force);
declare cdecl import,NewtonMaterialGetContactPositionAndNormal(NewtonMaterial material, dFloat posit, dFloat normal);
declare cdecl import,NewtonMaterialGetContactTangentDirections(NewtonMaterial material, dFloat dir0, dFloat dir);
declare cdecl import,NewtonMaterialGetContactTangentSpeed(NewtonMaterial material, NewtonContact contactlHandle, int index),dFloat;

declare cdecl import,NewtonMaterialSetContactSoftness(NewtonMaterial material, dFloat softness);
declare cdecl import,NewtonMaterialSetContactElasticity(NewtonMaterial material, dFloat restitution);
declare cdecl import,NewtonMaterialSetContactFrictionState(NewtonMaterial material, int state, int index);
declare cdecl import,NewtonMaterialSetContactStaticFrictionCoef(NewtonMaterial material, dFloat coef, int index);
declare cdecl import,NewtonMaterialSetContactKineticFrictionCoef(NewtonMaterial material, dFloat coef, int index);
	
declare cdecl import,NewtonMaterialSetContactNormalAcceleration(NewtonMaterial material, dFloat accel);
declare cdecl import,NewtonMaterialSetContactNormalDirection(NewtonMaterial material, dFloat directionVector);

declare cdecl import,NewtonMaterialSetContactTangentAcceleration(NewtonMaterial material, dFloat accel, int index);
declare cdecl import,NewtonMaterialContactRotateTangentDirections(NewtonMaterial material, dFloat directionVector);


// **********************************************************************************************
//
// convex collision primitives creation functions
//
// **********************************************************************************************
declare cdecl import, NewtonCreateNull(NewtonWorld newtonWorld),NewtonCollision;
declare cdecl import, NewtonCreateSphere(NewtonWorld newtonWorld, dFloat radiusX, dFloat radiusY, dFloat radiusZ, opt dFloat offsetMatrix),NewtonCollision;
declare cdecl import, NewtonCreateBox(NewtonWorld newtonWorld, dFloat dx, dFloat dy, dFloat dz, opt dFloat offsetMatrix),NewtonCollision;

declare cdecl import, NewtonCreateCone(NewtonWorld newtonWorld, dFloat radius, dFloat height, opt dFloat offsetMatrix),NewtonCollision;
declare cdecl import, NewtonCreateCapsule(NewtonWorld newtonWorld, dFloat radius, dFloat height, opt dFloat offsetMatrix),NewtonCollision;
declare cdecl import, NewtonCreateCylinder(NewtonWorld newtonWorld, dFloat radius, dFloat height, opt dFloat offsetMatrix),NewtonCollision;
declare cdecl import, NewtonCreateChamferCylinder(NewtonWorld newtonWorld, dFloat radius, dFloat height, opt dFloat offsetMatrix),NewtonCollision;
declare cdecl import, NewtonCreateConvexHull(NewtonWorld newtonWorld, int count, dFloat vertexCloud, int strideInBytes, opt dFloat offsetMatrix),NewtonCollision;
declare cdecl import, NewtonCreateConvexHullModifier(NewtonWorld newtonWorld, NewtonCollision convexHullCollision),NewtonCollision;
declare cdecl import, NewtonConvexHullModifierGetMatrix(NewtonCollision convexHullCollision, dFloat matrix);
declare cdecl import, NewtonConvexHullModifierSetMatrix(NewtonCollision convexHullCollision, dFloat matrix);

declare cdecl import, NewtonConvexCollisionSetUserID(NewtonCollision convexCollision, void id);
declare cdecl import, NewtonConvexCollisionGetUserID(NewtonCollision convexCollision),void;

declare cdecl import, NewtonConvexCollisionCalculateVolume(NewtonCollision convexCollision),dFloat;
declare cdecl import, NewtonConvexCollisionCalculateInertialMatrix(NewtonCollision convexCollision, dFloat inertia, dFloat origin);	

declare cdecl import, NewtonCollisionMakeUnique(NewtonWorld newtonWorld, NewtonCollision collision);
declare cdecl import, NewtonReleaseCollision(NewtonWorld newtonWorld, NewtonCollision collision);


// **********************************************************************************************
//
// complex collision primitives creation functions
// note: can only be used with static bodies (bodies with infinite mass)
//
// **********************************************************************************************
declare cdecl import, NewtonCreateCompoundCollision(NewtonWorld newtonWorld, int count, NewtonCollision collisionPrimitiveArray[]),NewtonCollision;
declare cdecl import, NewtonCreateUserMeshCollision(NewtonWorld newtonWorld, dFloat minBox, dFloat maxBox, void *userData, NewtonUserMeshCollisionCollideCallback collideCallback,NewtonUserMeshCollisionRayHitCallback rayHitCallback, NewtonUserMeshCollisionDestroyCallback destroyCallback),NewtonCollision;


// **********************************************************************************************
//
// CollisionTree Utility functions
//
// **********************************************************************************************
declare cdecl import, NewtonCreateTreeCollision(NewtonWorld newtonWorld, NewtonTreeCollisionCallback userCallback),NewtonCollision;
declare cdecl import, NewtonTreeCollisionBeginBuild(NewtonCollision treeCollision);
declare cdecl import, NewtonTreeCollisionAddFace(NewtonCollision treeCollision, int vertexCount, dFloat vertexPtr, int strideInBytes, int faceAttribute);
declare cdecl import, NewtonTreeCollisionEndBuild(NewtonCollision treeCollision, int optimize);
declare cdecl import, NewtonTreeCollisionSerialize(NewtonCollision treeCollision, NewtonSerialize serializeFunction, void *serializeHandle);
declare cdecl import, NewtonCreateTreeCollisionFromSerialization(NewtonWorld newtonWorld, NewtonTreeCollisionCallback userCallback, NewtonDeserialize deserializeFunction, void *serializeHandle),NewtonCollision;
declare cdecl import, NewtonTreeCollisionGetFaceAtribute(NewtonCollision treeCollision, int faceIndexArray),int; 
declare cdecl import, NewtonTreeCollisionSetFaceAtribute(NewtonCollision treeCollision, int faceIndexArray, int attribute); 
		
// **********************************************************************************************
//
// General purpose collision library functions
//
// **********************************************************************************************
declare cdecl import, NewtonCollisionPointDistance(NewtonWorld newtonWorld, dFloat *point,
	 NewtonCollision collsion,  dFloat matrix, dFloat contact, dFloat normal),int;

declare cdecl import, NewtonCollisionClosestPoint(NewtonWorld newtonWorld, 
	 NewtonCollision collsionA,  dFloat matrixA,  NewtonCollision collsionB,  dFloat matrixB,
	dFloat contactA, dFloat contactB, dFloat normalAB),int;
	
declare cdecl import, NewtonCollisionCollide(NewtonWorld newtonWorld, int maxSize,
	 NewtonCollision collsionA,  dFloat matrixA,  NewtonCollision collsionB,  dFloat matrixB,
	dFloat contacts, dFloat normals, dFloat penetration),int;

declare cdecl import, NewtonCollisionCollideContinue(NewtonWorld newtonWorld, int maxSize,  dFloat timestap, 
	 NewtonCollision collsionA,  dFloat matrixA,  dFloat velocA,  dFloat omegaA, 
	 NewtonCollision collsionB,  dFloat matrixB,  dFloat velocB,  dFloat omegaB, 
	dFloat timeOfImpact, dFloat contacts, dFloat normals, dFloat penetration),int;

declare cdecl import, NewtonCollisionRayCast(NewtonCollision collision,  dFloat p0,  dFloat p1, dFloat normals, int attribute),dFloat;
declare cdecl import, NewtonCollisionCalculateAABB(NewtonCollision collision,  dFloat *matrix, dFloat p0, dFloat p1);
	

// **********************************************************************************************
//
// transforms utility functions
//
// **********************************************************************************************
declare cdecl import, NewtonGetEulerAngle(dFloat matrix, dFloat eulersAngles);
declare cdecl import, NewtonSetEulerAngle(dFloat eulersAngles, dFloat matrix);


// **********************************************************************************************
//
// body manipulation functions
//
// **********************************************************************************************
declare cdecl import, NewtonCreateBody(NewtonWorld newtonWorld,  NewtonCollision collision),NewtonBody;
declare cdecl import, NewtonDestroyBody( NewtonWorld newtonWorld,  NewtonBody* body);

declare cdecl import, NewtonBodyAddForce(NewtonBody body,  dFloat force);
declare cdecl import, NewtonBodyAddTorque(NewtonBody body,  dFloat torque);

declare cdecl import, NewtonBodySetMatrix(NewtonBody body,  dFloat matrix);
declare cdecl import, NewtonBodySetMatrixRecursive(NewtonBody body,  dFloat matrix);
declare cdecl import, NewtonBodySetMassMatrix(NewtonBody body, dFloat mass, dFloat Ixx, dFloat Iyy, dFloat Izz);
declare cdecl import, NewtonBodySetMaterialGroupID(NewtonBody body, int id);
declare cdecl import, NewtonBodySetContinuousCollisionMode(NewtonBody body, void state);
declare cdecl import, NewtonBodySetJointRecursiveCollision(NewtonBody body, void state);
declare cdecl import, NewtonBodySetOmega(NewtonBody body,  dFloat omega);
declare cdecl import, NewtonBodySetVelocity(NewtonBody body,  dFloat velocity);
declare cdecl import, NewtonBodySetForce(NewtonBody body,  dFloat force);
declare cdecl import, NewtonBodySetTorque(NewtonBody body,  dFloat torque);

declare cdecl import, NewtonBodySetCentreOfMass (NewtonBody body,  dFloat com);
declare cdecl import, NewtonBodySetLinearDamping(NewtonBody body, dFloat linearDamp);
declare cdecl import, NewtonBodySetAngularDamping(NewtonBody body,  dFloat angularDamp);
declare cdecl import, NewtonBodySetUserData(NewtonBody body, void *userData);
declare cdecl import, NewtonBodyCoriolisForcesMode(NewtonBody body, int mode);
declare cdecl import, NewtonBodySetCollision(NewtonBody body,  NewtonCollision collision);
declare cdecl import, NewtonBodySetAutoFreeze(NewtonBody body, int state);
declare cdecl import, NewtonBodySetFreezeTreshold(NewtonBody body, dFloat freezeSpeed2, dFloat freezeOmega2, int framesCount);
	
declare cdecl import, NewtonBodySetTransformCallback(NewtonBody body, NewtonSetTransform callback);
declare cdecl import, NewtonBodySetDestructorCallback(NewtonBody body, NewtonBodyDestructor callback);
declare cdecl import, NewtonBodySetAutoactiveCallback(NewtonBody body, NewtonBodyActivationState callback);
declare cdecl import, NewtonBodySetForceAndTorqueCallback(NewtonBody body, NewtonApplyForceAndTorque callback);

declare cdecl import, NewtonBodyGetForceAndTorqueCallback(NewtonBody body),NewtonApplyForceAndTorque;
	
declare cdecl import, NewtonBodyGetUserData(NewtonBody body),void *;
declare cdecl import, NewtonBodyGetWorld(NewtonBody body),NewtonWorld;
declare cdecl import, NewtonBodyGetCollision(NewtonBody body),NewtonCollision;
declare cdecl import, NewtonBodyGetMaterialGroupID(NewtonBody body),int;
declare cdecl import, NewtonBodyGetContinuousCollisionMode(NewtonBody body),int;
declare cdecl import, NewtonBodyGetJointRecursiveCollision(NewtonBody body),int;

declare cdecl import,  NewtonBodyGetMatrix( NewtonBody body, dFloat matrix);
declare cdecl import,  NewtonBodyGetMassMatrix(NewtonBody body, dFloat mass, dFloat Ixx, dFloat Iyy, dFloat Izz);
declare cdecl import,  NewtonBodyGetInvMass( NewtonBody body, dFloat invMass, dFloat invIxx, dFloat invIyy, dFloat invIzz);
declare cdecl import,  NewtonBodyGetOmega( NewtonBody body, dFloat vector);
declare cdecl import,  NewtonBodyGetVelocity( NewtonBody body, dFloat vector);
declare cdecl import,  NewtonBodyGetForce( NewtonBody body, dFloat vector);
declare cdecl import,  NewtonBodyGetTorque( NewtonBody body, dFloat vector);
declare cdecl import,  NewtonBodyGetCentreOfMass(NewtonBody body, dFloat com);

declare cdecl import, NewtonBodyGetSleepingState( NewtonBody body),int;
declare cdecl import, NewtonBodyGetAutoFreeze( NewtonBody body),int;
declare cdecl import, NewtonBodyGetLinearDamping(NewtonBody body),dFloat;
declare cdecl import,  NewtonBodyGetAngularDamping(NewtonBody body, dFloat vector);
declare cdecl import,  NewtonBodyGetAABB(NewtonBody body, dFloat p0, dFloat p1);	
declare cdecl import,  NewtonBodyGetFreezeTreshold(NewtonBody body, dFloat freezeSpeed2, dFloat freezeOmega2);

	
declare cdecl import,  NewtonBodyAddBuoyancyForce(NewtonBody body, dFloat fluidDensity, 
	dFloat fluidLinearViscosity, dFloat fluidAngularViscosity, 
	 dFloat gravityVector, NewtonGetBuoyancyPlane buoyancyPlane, void *context);

declare cdecl import, NewtonBodyForEachPolygonDo(NewtonBody body, NewtonCollisionIterator callback);
declare cdecl import, NewtonAddBodyImpulse(NewtonBody body,  dFloat pointDeltaVeloc,  dFloat pointPosit);

// **********************************************************************************************
//
// Common joint functions
//
// **********************************************************************************************
declare cdecl import, NewtonJointGetUserData(NewtonJoint joint),void *;
declare cdecl import, NewtonJointSetUserData(NewtonJoint joint, void *userData);
declare cdecl import, NewtonJointGetCollisionState(NewtonJoint joint),int;
declare cdecl import, NewtonJointSetCollisionState(NewtonJoint joint, int state);

declare cdecl import, NewtonJointGetStiffness(NewtonJoint joint),dFloat;
declare cdecl import, NewtonJointSetStiffness(NewtonJoint joint, dFloat state);

declare cdecl import, NewtonDestroyJoint( NewtonWorld newtonWorld,  NewtonJoint joint);
declare cdecl import, NewtonJointSetDestructor(NewtonJoint joint, NewtonraintDestructor destructor);


// **********************************************************************************************
//
// Ball and Socket joint functions
//
// **********************************************************************************************
declare cdecl import, NewtonraintCreateBall(NewtonWorld newtonWorld,  dFloat pivotPoint, 
	 NewtonBody childBody,  NewtonBody parentBody),NewtonJoint;
declare cdecl import, NewtonBallSetUserCallback(NewtonJoint ball, NewtonBallCallBack callback);
declare cdecl import, NewtonBallGetJointAngle(NewtonJoint ball, dFloat angle);
declare cdecl import, NewtonBallGetJointOmega(NewtonJoint ball, dFloat omega);
declare cdecl import, NewtonBallGetJointForce(NewtonJoint ball, dFloat force);
declare cdecl import, NewtonBallSetConeLimits(NewtonJoint ball,  dFloat pin, dFloat maxConeAngle, dFloat maxTwistAngle);

// **********************************************************************************************
//
// Hinge joint functions
//
// **********************************************************************************************
declare cdecl import, NewtonraintCreateHinge(NewtonWorld newtonWorld, 
	 dFloat pivotPoint,  dFloat pinDir, 
	 NewtonBody childBody,  NewtonBody parentBody),NewtonJoint;
declare cdecl import, NewtonHingeSetUserCallback(NewtonJoint hinge, NewtonHingeCallBack callback);
declare cdecl import, NewtonHingeGetJointAngle(NewtonJoint hinge),dFloat;
declare cdecl import, NewtonHingeGetJointOmega(NewtonJoint hinge),dFloat;
declare cdecl import, NewtonHingeGetJointForce(NewtonJoint hinge, dFloat force);
declare cdecl import, NewtonHingeCalculateStopAlpha(NewtonJoint hinge,  NewtonHingeSliderUpdateDesc* desc, dFloat angle),dFloat;

// **********************************************************************************************
//
// Slider joint functions
//
// **********************************************************************************************
declare cdecl import, NewtonraintCreateSlider(NewtonWorld newtonWorld, 
	 dFloat pivotPoint,  dFloat pinDir, 
	 NewtonBody childBody,  NewtonBody parentBody),NewtonJoint;
declare cdecl import, NewtonSliderSetUserCallback(NewtonJoint slider, NewtonSliderCallBack callback);
declare cdecl import, NewtonSliderGetJointPosit(NewtonJoint slider),dFloat;
declare cdecl import, NewtonSliderGetJointVeloc(NewtonJoint slider),dFloat;
declare cdecl import, NewtonSliderGetJointForce(NewtonJoint slider, dFloat force);
declare cdecl import, NewtonSliderCalculateStopAccel(NewtonJoint slider,  NewtonHingeSliderUpdateDesc *desc, dFloat position),dFloat;


// **********************************************************************************************
//
// Corkscrew joint functions
//
// **********************************************************************************************
declare cdecl import, NewtonraintCreateCorkscrew(NewtonWorld newtonWorld, 
	 dFloat pivotPoint,  dFloat pinDir, 
	 NewtonBody childBody,  NewtonBody parentBody),NewtonJoint;
declare cdecl import, NewtonCorkscrewSetUserCallback(NewtonJoint corkscrew, NewtonCorkscrewCallBack callback);
declare cdecl import, NewtonCorkscrewGetJointPosit(NewtonJoint corkscrew),dFloat;
declare cdecl import, NewtonCorkscrewGetJointAngle(NewtonJoint corkscrew),dFloat;
declare cdecl import, NewtonCorkscrewGetJointVeloc(NewtonJoint corkscrew),dFloat;
declare cdecl import, NewtonCorkscrewGetJointOmega(NewtonJoint corkscrew),dFloat;
declare cdecl import, NewtonCorkscrewGetJointForce(NewtonJoint corkscrew, dFloat force);
declare cdecl import, NewtonCorkscrewCalculateStopAlpha(NewtonJoint corkscrew,  NewtonHingeSliderUpdateDesc *desc, dFloat angle),dFloat;
declare cdecl import, NewtonCorkscrewCalculateStopAccel(NewtonJoint corkscrew,  NewtonHingeSliderUpdateDesc *desc, dFloat position),dFloat;


// **********************************************************************************************
//
// Universal joint functions
//
// **********************************************************************************************
declare cdecl import, NewtonraintCreateUniversal(NewtonWorld newtonWorld, 
	 dFloat pivotPoint,  dFloat pinDir0,  dFloat pinDir1, 
	 NewtonBody childBody,  NewtonBody parentBody),NewtonJoint;
declare cdecl import, NewtonUniversalSetUserCallback(NewtonJoint universal, NewtonUniversalCallBack callback);
declare cdecl import, NewtonUniversalGetJointAngle0(NewtonJoint universal),dFloat;
declare cdecl import, NewtonUniversalGetJointAngle1(NewtonJoint universal),dFloat;
declare cdecl import, NewtonUniversalGetJointOmega0(NewtonJoint universal),dFloat;
declare cdecl import, NewtonUniversalGetJointOmega1(NewtonJoint universal),dFloat;
declare cdecl import, NewtonUniversalGetJointForce(NewtonJoint universal, dFloat force);
declare cdecl import, NewtonUniversalCalculateStopAlpha0(NewtonJoint universal,  NewtonHingeSliderUpdateDesc *desc, dFloat angle),dFloat;
declare cdecl import, NewtonUniversalCalculateStopAlpha1(NewtonJoint universal,  NewtonHingeSliderUpdateDesc *desc, dFloat angle),dFloat;


// **********************************************************************************************
//
// Up vector joint functions
//
// **********************************************************************************************
declare cdecl import, NewtonraintCreateUpVector(NewtonWorld newtonWorld,  dFloat pinDir,  NewtonBody body),NewtonJoint; 
declare cdecl import, NewtonUpVectorGetPin(NewtonJoint upVector, dFloat *pin);
declare cdecl import, NewtonUpVectorSetPin(NewtonJoint upVector,  dFloat *pin);


// **********************************************************************************************
//
// User defined bilateral Joint
//
// **********************************************************************************************
declare cdecl import, NewtonraintCreateUserJoint(NewtonWorld newtonWorld, int maxDOF, NewtonUserBilateralCallBack callback,
										  NewtonBody childBody,  NewtonBody parentBody),NewtonJoint; 
declare cdecl import, NewtonUserJointAddLinearRow(NewtonJoint joint,  dFloat *pivot0,  dFloat *pivot1,  dFloat *dir);
declare cdecl import, NewtonUserJointAddAngularRow(NewtonJoint joint, dFloat relativeAngle,  dFloat *dir);
declare cdecl import, NewtonUserJointAddGeneralRow(NewtonJoint joint,  dFloat *jacobian0,  dFloat *jacobian1);
declare cdecl import, NewtonUserJointSetRowMinimumFriction(NewtonJoint joint, dFloat friction);
declare cdecl import, NewtonUserJointSetRowMaximumFriction(NewtonJoint joint, dFloat friction);
declare cdecl import, NewtonUserJointSetRowAcceleration(NewtonJoint joint, dFloat acceleration);
declare cdecl import, NewtonUserJointSetRowSpringDamperAcceleration(NewtonJoint joint, dFloat springK, dFloat springD);
declare cdecl import, NewtonUserJointSetRowStiffness(NewtonJoint joint, dFloat stiffness);
declare cdecl import, NewtonUserJointGetRowForce(NewtonJoint joint, int row),dFloat;
	

// **********************************************************************************************
//
// Rag doll joint container functions
//
// **********************************************************************************************
declare cdecl import, NewtonCreateRagDoll(NewtonWorld newtonWorld),NewtonRagDoll;
declare cdecl import, NewtonDestroyRagDoll(NewtonWorld newtonWorld,  NewtonRagDoll *ragDoll);
declare cdecl import, NewtonRagDollBegin(NewtonRagDoll *ragDoll);
declare cdecl import, NewtonRagDollEnd(NewtonRagDoll *ragDoll);

declare cdecl import, NewtonRagDollFindBone(NewtonRagDoll *ragDoll, int id),NewtonRagDollBone;

declare cdecl import, NewtonRagDollSetForceAndTorqueCallback(NewtonRagDoll *ragDoll, NewtonApplyForceAndTorque callback);
declare cdecl import, NewtonRagDollSetTransformCallback(NewtonRagDoll *ragDoll, NewtonSetRagDollTransform callback);
declare cdecl import, NewtonRagDollAddBone(NewtonRagDoll *ragDoll,  NewtonRagDollBone *parent, void *userData, dFloat mass, dFloat matrix, NewtonCollision boneCollision, dFloat size),NewtonRagDollBone;

declare cdecl import, NewtonRagDollBoneGetUserData(NewtonRagDollBone *bone),void *;
declare cdecl import, NewtonRagDollBoneGetBody(NewtonRagDollBone *bone),NewtonBody;
declare cdecl import, NewtonRagDollBoneSetID(NewtonRagDollBone *bone, int id);

declare cdecl import, NewtonRagDollBoneSetLimits(NewtonRagDollBone *bone, dFloat coneDir, dFloat minConeAngle, dFloat maxConeAngle, dFloat maxTwistAngle,dFloat bilateralConeDir, dFloat negativeBilateralConeAngle, dFloat positiveBilateralConeAngle);
declare cdecl import, NewtonRagDollBoneGetLocalMatrix(NewtonRagDollBone *bone, dFloat matrix);
declare cdecl import, NewtonRagDollBoneGetGlobalMatrix(NewtonRagDollBone *bone, dFloat matrix);

// **********************************************************************************************
//
// Vehicle joint functions
//
// **********************************************************************************************
declare cdecl import, NewtonraintCreateVehicle(NewtonWorld newtonWorld,  dFloat upDir,  NewtonBody body),NewtonJoint; 
declare cdecl import, NewtonVehicleReset(NewtonJoint vehicle); 
declare cdecl import, NewtonVehicleSetTireCallback(NewtonJoint vehicle, NewtonVehicleTireUpdate update);
declare cdecl import, NewtonVehicleAddTire(NewtonJoint vehicle,  dFloat localMatrix,  dFloat pin, dFloat mass, dFloat width, dFloat radius, 
	       dFloat suspesionShock, dFloat suspesionSpring, dFloat suspesionLength, void *userData, int collisionID),void *;
declare cdecl import, NewtonVehicleRemoveTire(NewtonJoint vehicle, void *tireId);
declare cdecl import, NewtonVehicleGetFirstTireID(NewtonJoint vehicle),void *;
declare cdecl import, NewtonVehicleGetNextTireID(NewtonJoint vehicle, void *tireId), void *;
declare cdecl import, NewtonVehicleTireIsAirBorne(NewtonJoint vehicle, void *tireId),int;
declare cdecl import, NewtonVehicleTireLostSideGrip(NewtonJoint vehicle, void *tireId),int;
declare cdecl import, NewtonVehicleTireLostTraction(NewtonJoint vehicle, void *tireId),int;
declare cdecl import, NewtonVehicleGetTireUserData(NewtonJoint vehicle, void *tireId),void *;
declare cdecl import, NewtonVehicleGetTireOmega(NewtonJoint vehicle, void *tireId),dFloat;
declare cdecl import, NewtonVehicleGetTireNormalLoad(NewtonJoint vehicle, void *tireId),dFloat;
declare cdecl import, NewtonVehicleGetTireSteerAngle(NewtonJoint vehicle, void *tireId),dFloat;
declare cdecl import, NewtonVehicleGetTireLateralSpeed(NewtonJoint vehicle, void *tireId),dFloat;
declare cdecl import, NewtonVehicleGetTireLongitudinalSpeed(NewtonJoint vehicle, void *tireId),dFloat;
declare cdecl import, NewtonVehicleGetTireMatrix(NewtonJoint vehicle, void *tireId, dFloat matrix);

declare cdecl import, NewtonVehicleSetTireTorque(NewtonJoint vehicle, void *tireId, dFloat torque);
declare cdecl import, NewtonVehicleSetTireSteerAngle(NewtonJoint vehicle, void *tireId, dFloat angle);
	
declare cdecl import, NewtonVehicleSetTireMaxSideSleepSpeed(NewtonJoint vehicle, void *tireId, dFloat speed);
declare cdecl import, NewtonVehicleSetTireSideSleepCoeficient(NewtonJoint vehicle, void *tireId, dFloat coeficient);
declare cdecl import, NewtonVehicleSetTireMaxLongitudinalSlideSpeed(NewtonJoint vehicle, void *tireId, dFloat speed);
declare cdecl import, NewtonVehicleSetTireLongitudinalSlideCoeficient(NewtonJoint vehicle, void *tireId, dFloat coeficient);

declare cdecl import, NewtonVehicleTireCalculateMaxBrakeAcceleration(NewtonJoint vehicle, void *tireId),dFloat;
declare cdecl import, NewtonVehicleTireSetBrakeAcceleration(NewtonJoint vehicle, void *tireId, dFloat accelaration, dFloat torqueLimit);
