newton

Posted By: ventilator

newton - 02/21/07 18:53

i started to convert the newton header to make it usable with lite-c. this is what i have so far:

Code:
typedef float dFloat;



typedef struct NewtonBody{void* dummy;} NewtonBody;
typedef struct NewtonWorld{void* dummy;} NewtonWorld;
typedef struct NewtonJoint{void* dummy;} NewtonJoint;
typedef struct NewtonContact{void* dummy;} NewtonContact;
typedef struct NewtonMaterial{void* dummy;} NewtonMaterial;
typedef struct NewtonCollision{void* dummy;} NewtonCollision;

typedef struct NewtonRagDoll{void* dummy;} NewtonRagDoll;
typedef struct NewtonRagDollBone{void* dummy;} NewtonRagDollBone;

typedef struct NewtonUserMeshCollisionCollideDescTag
{
dFloat m_boxP0[4];
dFloat m_boxP1[4];
void* m_userData;
int m_faceCount;
dFloat* m_vertex;
int m_vertexStrideInBytes;
int* m_userAttribute;
int* m_faceIndexCount;
int* m_faceVertexIndex;
NewtonBody* m_objBody;
NewtonBody* m_polySoupBody;
} NewtonUserMeshCollisionCollideDesc;

typedef struct NewtonUserMeshCollisionRayHitDescTag
{
dFloat m_p0[4];
dFloat m_p1[4];
dFloat m_normalOut[4];
int m_userIdOut;
void* m_userData;
} NewtonUserMeshCollisionRayHitDesc;

typedef struct NewtonHingeSliderUpdateDescTag
{
dFloat m_accel;
dFloat m_minFriction;
dFloat m_maxFriction;
dFloat m_timestep;
} NewtonHingeSliderUpdateDesc;



// newton callback functions

/*
typedef void* (*NewtonAllocMemory) (int sizeInBytes);
typedef void (*NewtonFreeMemory) (void *ptr, int sizeInBytes);

typedef void (*NewtonSerialize) (void* serializeHandle, const void* buffer, size_t size);
typedef void (*NewtonDeserialize) (void* serializeHandle, void* buffer, size_t size);

typedef void (*NewtonUserMeshCollisionCollideCallback) (NewtonUserMeshCollisionCollideDesc* collideDescData);
typedef dFloat (*NewtonUserMeshCollisionRayHitCallback) (NewtonUserMeshCollisionRayHitDesc* lineDescData);
typedef void (*NewtonUserMeshCollisionDestroyCallback) (void* descData);
typedef void (*NewtonTreeCollisionCallback) (const NewtonBody* bodyWithTreeCollision, const NewtonBody* body,
const dFloat* vertex, int vertexstrideInBytes,
int indexCount, const int* indexArray);

typedef void (*NewtonBodyDestructor) (const NewtonBody* body);
typedef void (*NewtonApplyForceAndTorque) (const NewtonBody* body);
typedef void (*NewtonBodyActivationState) (const NewtonBody* body, unsigned state);
typedef void (*NewtonSetTransform) (const NewtonBody* body, const dFloat* matrix);
typedef void (*NewtonSetRagDollTransform) (const NewtonRagDollBone* bone);
typedef void (*NewtonGetBuoyancyPlane) (void *context, const dFloat* globalSpaceMatrix, dFloat* globalSpacePlane);

typedef void (*NewtonVehicleTireUpdate) (const NewtonJoint* vehicle);

typedef dFloat (*NewtonWorldRayFilterCallback)(const NewtonBody* body, const dFloat* hitNormal, int collisionID, void* userData, dFloat intersetParam);
typedef void (*NewtonBodyLeaveWorld) (const NewtonBody* body);

typedef int (*NewtonContactBegin) (const NewtonMaterial* material, const NewtonBody* body0, const NewtonBody* body1);
typedef int (*NewtonContactProcess) (const NewtonMaterial* material, const NewtonContact* contact);
typedef void (*NewtonContactEnd) (const NewtonMaterial* material);

typedef void (*NewtonBodyIterator) (const NewtonBody* body);
typedef void (*NewtonCollisionIterator) (const NewtonBody* body, int vertexCount, const dFloat* FaceArray, int faceId);

typedef void (*NewtonBallCallBack) (const NewtonJoint* ball);
typedef unsigned (*NewtonHingeCallBack) (const NewtonJoint* hinge, NewtonHingeSliderUpdateDesc* desc);
typedef unsigned (*NewtonSliderCallBack) (const NewtonJoint* slider, NewtonHingeSliderUpdateDesc* desc);
typedef unsigned (*NewtonUniversalCallBack) (const NewtonJoint* universal, NewtonHingeSliderUpdateDesc* desc);
typedef unsigned (*NewtonCorkscrewCallBack) (const NewtonJoint* corkscrew, NewtonHingeSliderUpdateDesc* desc);
typedef void (*NewtonUserBilateralCallBack) (const NewtonJoint* userJoint);

typedef void (*NewtonConstraintDestructor) (const NewtonJoint* me);
*/



// **********************************************************************************************
//
// world control functions
//
// **********************************************************************************************
NewtonWorld* NewtonCreate (void* malloc, void* mfree);
void NewtonDestroy (NewtonWorld* newtonWorld);
void NewtonDestroyAllBodies (NewtonWorld* newtonWorld);

void NewtonUpdate (NewtonWorld* newtonWorld, dFloat timestep);
void NewtonSetSolverModel (NewtonWorld* newtonWorld, int model);
void NewtonSetFrictionModel (NewtonWorld* newtonWorld, int model);
dFloat NewtonGetTimeStep (NewtonWorld* newtonWorld);
void NewtonSetMinimumFrameRate (NewtonWorld* newtonWorld, dFloat frameRate);
void NewtonSetBodyLeaveWorldEvent (NewtonWorld* newtonWorld, void* callback);
void NewtonSetWorldSize (NewtonWorld* newtonWorld, dFloat* minPoint, dFloat* maxPoint);

void NewtonWorldFreezeBody (NewtonWorld* newtonWorld, NewtonBody* body);
void NewtonWorldUnfreezeBody (NewtonWorld* newtonWorld, NewtonBody* body);

void NewtonWorldForEachBodyDo (NewtonWorld* newtonWorld, void* callback);

void NewtonWorldSetUserData (NewtonWorld* newtonWorld, void* userData);
void* NewtonWorldGetUserData (NewtonWorld* newtonWorld);
int NewtonWorldGetVersion (NewtonWorld* newtonWorld);

void NewtonWorldRayCast (NewtonWorld* newtonWorld, dFloat* p0, dFloat* p1, void* filter, void* userData);



// **********************************************************************************************
//
// physics material section
//
// **********************************************************************************************
int NewtonMaterialGetDefaultGroupID(NewtonWorld* newtonWorld);
int NewtonMaterialCreateGroupID(NewtonWorld* newtonWorld);
void NewtonMaterialDestroyAllGroupID(NewtonWorld* newtonWorld);

void NewtonMaterialSetDefaultSoftness (NewtonWorld* newtonWorld, int id0, int id1, dFloat value);
void NewtonMaterialSetDefaultElasticity (NewtonWorld* newtonWorld, int id0, int id1, dFloat elasticCoef);
void NewtonMaterialSetDefaultCollidable (NewtonWorld* newtonWorld, int id0, int id1, int state);
void NewtonMaterialSetContinuousCollisionMode (NewtonWorld* newtonWorld, int id0, int id1, int state);
void NewtonMaterialSetDefaultFriction (NewtonWorld* newtonWorld, int id0, int id1, dFloat staticFriction, dFloat kineticFriction);

void NewtonMaterialSetCollisionCallback (NewtonWorld* newtonWorld, int id0, int id1, void* userData, void* begin, void* process, void* end);

void* NewtonMaterialGetUserData (NewtonWorld* newtonWorld, int id0, int id1);



// **********************************************************************************************
//
// physics contact control functions
//
// **********************************************************************************************
void NewtonMaterialDisableContact (NewtonMaterial* material);
dFloat NewtonMaterialGetCurrentTimestep (NewtonMaterial* material);
void* NewtonMaterialGetMaterialPairUserData (NewtonMaterial* material);
int NewtonMaterialGetContactFaceAttribute (NewtonMaterial* material); // unsigned -> int?
int NewtonMaterialGetBodyCollisionID (NewtonMaterial* material, NewtonBody* body); // unsigned -> int?
dFloat NewtonMaterialGetContactNormalSpeed (NewtonMaterial* material, NewtonContact* contactlHandle);
void NewtonMaterialGetContactForce (NewtonMaterial* material, dFloat* force);
void NewtonMaterialGetContactPositionAndNormal (NewtonMaterial* material, dFloat* posit, dFloat* normal);
void NewtonMaterialGetContactTangentDirections (NewtonMaterial* material, dFloat* dir0, dFloat* dir);
dFloat NewtonMaterialGetContactTangentSpeed (NewtonMaterial* material, NewtonContact* contactlHandle, int index);

void NewtonMaterialSetContactSoftness (NewtonMaterial* material, dFloat softness);
void NewtonMaterialSetContactElasticity (NewtonMaterial* material, dFloat restitution);
void NewtonMaterialSetContactFrictionState (NewtonMaterial* material, int state, int index);
void NewtonMaterialSetContactStaticFrictionCoef (NewtonMaterial* material, dFloat coef, int index);
void NewtonMaterialSetContactKineticFrictionCoef (NewtonMaterial* material, dFloat coef, int index);

void NewtonMaterialSetContactNormalAcceleration (NewtonMaterial* material, dFloat accel);
void NewtonMaterialSetContactNormalDirection (NewtonMaterial* material, dFloat* directionVector);

void NewtonMaterialSetContactTangentAcceleration (NewtonMaterial* material, dFloat accel, int index);
void NewtonMaterialContactRotateTangentDirections (NewtonMaterial* material, dFloat* directionVector);



// **********************************************************************************************
//
// convex collision primitives creation functions
//
// **********************************************************************************************
NewtonCollision* NewtonCreateNull (NewtonWorld* newtonWorld);
NewtonCollision* NewtonCreateSphere (NewtonWorld* newtonWorld, dFloat radiusX, dFloat radiusY, dFloat radiusZ, dFloat *offsetMatrix);
NewtonCollision* NewtonCreateBox (NewtonWorld* newtonWorld, dFloat dx, dFloat dy, dFloat dz, dFloat *offsetMatrix);
NewtonCollision* NewtonCreateCone (NewtonWorld* newtonWorld, dFloat radius, dFloat height, dFloat *offsetMatrix);
NewtonCollision* NewtonCreateCapsule (NewtonWorld* newtonWorld, dFloat radius, dFloat height, dFloat *offsetMatrix);
NewtonCollision* NewtonCreateCylinder (NewtonWorld* newtonWorld, dFloat radius, dFloat height, dFloat *offsetMatrix);
NewtonCollision* NewtonCreateChamferCylinder (NewtonWorld* newtonWorld, dFloat radius, dFloat height, dFloat *offsetMatrix);
NewtonCollision* NewtonCreateConvexHull (NewtonWorld* newtonWorld, int count, dFloat* vertexCloud, int strideInBytes, dFloat *offsetMatrix);
NewtonCollision* NewtonCreateConvexHullModifier (NewtonWorld* newtonWorld, NewtonCollision* convexHullCollision);
void NewtonConvexHullModifierGetMatrix (NewtonCollision* convexHullCollision, dFloat* matrix);
void NewtonConvexHullModifierSetMatrix (NewtonCollision* convexHullCollision, dFloat* matrix);

void NewtonConvexCollisionSetUserID (NewtonCollision* convexCollision, int id); // unsigned -> int?
int NewtonConvexCollisionGetUserID (NewtonCollision* convexCollision); // unsigned -> int?

dFloat NewtonConvexCollisionCalculateVolume (NewtonCollision* convexCollision);
void NewtonConvexCollisionCalculateInertialMatrix (NewtonCollision* convexCollision, dFloat* inertia, dFloat* origin);

void NewtonReleaseCollision (NewtonWorld* newtonWorld, NewtonCollision* collision);

// **********************************************************************************************
//
// complex collision primitives creation functions
// note: can only be used with static bodies (bodies with infinite mass)
//
// **********************************************************************************************
NewtonCollision* NewtonCreateCompoundCollision (NewtonWorld* newtonWorld, int count,
NewtonCollision** collisionPrimitiveArray);

NewtonCollision* NewtonCreateUserMeshCollision (NewtonWorld* newtonWorld, dFloat *minBox,
dFloat *maxBox, void *userData, void* collideCallback, void* rayHitCallback, void* destroyCallback);

// **********************************************************************************************
//
// collisiontree utility functions
//
// **********************************************************************************************
NewtonCollision* NewtonCreateTreeCollision (NewtonWorld* newtonWorld, void* userCallback);
void NewtonTreeCollisionBeginBuild (NewtonCollision* treeCollision);
void NewtonTreeCollisionAddFace (NewtonCollision* treeCollision, int vertexCount, dFloat* vertexPtr,
int strideInBytes, int faceAttribute);
void NewtonTreeCollisionEndBuild (NewtonCollision* treeCollision, int optimize);

void NewtonTreeCollisionSerialize (NewtonCollision* treeCollision, void* serializeFunction, void* serializeHandle);
NewtonCollision* NewtonCreateTreeCollisionFromSerialization (NewtonWorld* newtonWorld,
void* userCallback, void* deserializeFunction, void* serializeHandle);

int NewtonTreeCollisionGetFaceAtribute (NewtonCollision* treeCollision, int* faceIndexArray);
void NewtonTreeCollisionSetFaceAtribute (NewtonCollision* treeCollision, int* faceIndexArray, int attribute);

// **********************************************************************************************
//
// general purpose collision library functions
//
// **********************************************************************************************
int NewtonCollisionPointDistance (NewtonWorld* newtonWorld, float *point,
NewtonCollision* collision, dFloat* matrix, dFloat* contact, dFloat* normal);

int NewtonCollisionClosestPoint (NewtonWorld* newtonWorld,
NewtonCollision* collisionA, dFloat* matrixA, NewtonCollision* collsionB, dFloat* matrixB,
dFloat* contactA, dFloat* contactB, dFloat* normalAB);

int NewtonCollisionCollide (NewtonWorld* newtonWorld, int maxSize,
NewtonCollision* collisionA, dFloat* matrixA, NewtonCollision* collsionB, dFloat* matrixB,
dFloat* contacts, dFloat* normals, dFloat* penetration);

int NewtonCollisionCollideContinue (NewtonWorld* newtonWorld, int maxSize, dFloat timestep,
NewtonCollision* collisionA, dFloat* matrixA, dFloat* velocA, dFloat* omegaA,
NewtonCollision* collisionB, dFloat* matrixB, dFloat* velocB, dFloat* omegaB,
dFloat* timeOfImpact, dFloat* contacts, dFloat* normals, dFloat* penetration);

dFloat NewtonCollisionRayCast (NewtonCollision* collision, dFloat* p0, dFloat* p1, dFloat* normals, int* attribute);
void NewtonCollisionCalculateAABB (NewtonCollision* collision, dFloat *matrix, dFloat* p0, dFloat* p1);



// **********************************************************************************************
//
// transform utility functions
//
// **********************************************************************************************
void NewtonGetEulerAngle (dFloat* matrix, dFloat* eulersAngles);
void NewtonSetEulerAngle (dFloat* eulersAngles, dFloat* matrix);



// **********************************************************************************************
//
// body manipulation functions
//
// **********************************************************************************************
NewtonBody* NewtonCreateBody (NewtonWorld* newtonWorld, NewtonCollision* collision);
void NewtonDestroyBody(NewtonWorld* newtonWorld, NewtonBody* body);

void NewtonBodyAddForce (NewtonBody* body, dFloat* force);
void NewtonBodyAddTorque (NewtonBody* body, dFloat* torque);

void NewtonBodySetMatrix (NewtonBody* body, dFloat* matrix);
void NewtonBodySetMatrixRecursive (NewtonBody* body, dFloat* matrix);
void NewtonBodySetMassMatrix (NewtonBody* body, dFloat mass, dFloat Ixx, dFloat Iyy, dFloat Izz);
void NewtonBodySetMaterialGroupID (NewtonBody* body, int id);
void NewtonBodySetContinuousCollisionMode (NewtonBody* body, int state); // unsigned -> int
void NewtonBodySetJointRecursiveCollision (NewtonBody* body, int state); // unsigned -> int
void NewtonBodySetOmega (NewtonBody* body, dFloat* omega);
void NewtonBodySetVelocity (NewtonBody* body, dFloat* velocity);
void NewtonBodySetForce (NewtonBody* body, dFloat* force);
void NewtonBodySetTorque (NewtonBody* body, dFloat* torque);

void NewtonBodySetCentreOfMass (NewtonBody* body, dFloat* com);
void NewtonBodySetLinearDamping (NewtonBody* body, dFloat linearDamp);
void NewtonBodySetAngularDamping (NewtonBody* body, dFloat* angularDamp);
void NewtonBodySetUserData (NewtonBody* body, void* userData);
void NewtonBodyCoriolisForcesMode (NewtonBody* body, int mode);
void NewtonBodySetCollision (NewtonBody* body, NewtonCollision* collision);
void NewtonBodySetAutoFreeze (NewtonBody* body, int state);
void NewtonBodySetFreezeTreshold (NewtonBody* body, dFloat freezeSpeed2, dFloat freezeOmega2, int framesCount);

void NewtonBodySetTransformCallback (NewtonBody* body, void* callback);
void NewtonBodySetDestructorCallback (NewtonBody* body, void* callback);
void NewtonBodySetAutoactiveCallback (NewtonBody* body, void* callback);
void NewtonBodySetForceAndTorqueCallback (NewtonBody* body, void* callback);
void* NewtonBodyGetForceAndTorqueCallback (NewtonBody* body);

void* NewtonBodyGetUserData (NewtonBody* body);
NewtonWorld* NewtonBodyGetWorld (NewtonBody* body);
NewtonCollision* NewtonBodyGetCollision (NewtonBody* body);
int NewtonBodyGetMaterialGroupID (NewtonBody* body);
int NewtonBodyGetContinuousCollisionMode (NewtonBody* body);
int NewtonBodyGetJointRecursiveCollision (NewtonBody* body);

void NewtonBodyGetMatrix(NewtonBody* body, dFloat* matrix);
void NewtonBodyGetMassMatrix (NewtonBody* body, dFloat* mass, dFloat* Ixx, dFloat* Iyy, dFloat* Izz);
void NewtonBodyGetInvMass(NewtonBody* body, dFloat* invMass, dFloat* invIxx, dFloat* invIyy, dFloat* invIzz);
void NewtonBodyGetOmega(NewtonBody* body, dFloat* vector);
void NewtonBodyGetVelocity(NewtonBody* body, dFloat* vector);
void NewtonBodyGetForce(NewtonBody* body, dFloat* vector);
void NewtonBodyGetTorque(NewtonBody* body, dFloat* vector);
void NewtonBodyGetCentreOfMass (NewtonBody* body, dFloat* com);

int NewtonBodyGetSleepingState(NewtonBody* body);
int NewtonBodyGetAutoFreeze(NewtonBody* body);
dFloat NewtonBodyGetLinearDamping (NewtonBody* body);
void NewtonBodyGetAngularDamping (NewtonBody* body, dFloat* vector);
void NewtonBodyGetAABB (NewtonBody* body, dFloat* p0, dFloat* p1);
void NewtonBodyGetFreezeTreshold (NewtonBody* body, dFloat* freezeSpeed2, dFloat* freezeOmega2);


void NewtonBodyAddBuoyancyForce (NewtonBody* body, dFloat fluidDensity,
dFloat fluidLinearViscosity, dFloat fluidAngularViscosity,
dFloat* gravityVector, void* buoyancyPlane, void* context);

void NewtonBodyForEachPolygonDo (NewtonBody* body, void* callback);
void NewtonAddBodyImpulse (NewtonBody* body, dFloat* pointDeltaVeloc, dFloat* pointPosit);



// **********************************************************************************************
//
// common joint functions
//
// **********************************************************************************************
void* NewtonJointGetUserData (NewtonJoint* joint);
void NewtonJointSetUserData (NewtonJoint* joint, void* userData);

int NewtonJointGetCollisionState (NewtonJoint* joint);
void NewtonJointSetCollisionState (NewtonJoint* joint, int state);

dFloat NewtonJointGetStiffness (NewtonJoint* joint);
void NewtonJointSetStiffness (NewtonJoint* joint, dFloat state);

void NewtonDestroyJoint(NewtonWorld* newtonWorld, NewtonJoint* joint);
void NewtonJointSetDestructor (NewtonJoint* joint, void* destructor);



// **********************************************************************************************
//
// ball and socket joint functions
//
// **********************************************************************************************
NewtonJoint* NewtonConstraintCreateBall (NewtonWorld* newtonWorld,
dFloat* pivotPoint, NewtonBody* childBody, NewtonBody* parentBody);
void NewtonBallSetUserCallback (NewtonJoint* ball, void* callback);
void NewtonBallGetJointAngle (NewtonJoint* ball, dFloat* angle);
void NewtonBallGetJointOmega (NewtonJoint* ball, dFloat* omega);
void NewtonBallGetJointForce (NewtonJoint* ball, dFloat* force);
void NewtonBallSetConeLimits (NewtonJoint* ball, dFloat* pin, dFloat maxConeAngle, dFloat maxTwistAngle);



// **********************************************************************************************
//
// hinge joint functions
//
// **********************************************************************************************
NewtonJoint* NewtonConstraintCreateHinge (NewtonWorld* newtonWorld,
dFloat* pivotPoint, dFloat* pinDir, NewtonBody* childBody, NewtonBody* parentBody);
void NewtonHingeSetUserCallback (NewtonJoint* hinge, void* callback);
dFloat NewtonHingeGetJointAngle (NewtonJoint* hinge);
dFloat NewtonHingeGetJointOmega (NewtonJoint* hinge);
void NewtonHingeGetJointForce (NewtonJoint* hinge, dFloat* force);
dFloat NewtonHingeCalculateStopAlpha (NewtonJoint* hinge, NewtonHingeSliderUpdateDesc* desc, dFloat angle);



// **********************************************************************************************
//
// slider joint functions
//
// **********************************************************************************************
NewtonJoint* NewtonConstraintCreateSlider (NewtonWorld* newtonWorld,
dFloat* pivotPoint, dFloat* pinDir, NewtonBody* childBody, NewtonBody* parentBody);
void NewtonSliderSetUserCallback (NewtonJoint* slider, void* callback);
dFloat NewtonSliderGetJointPosit (NewtonJoint* slider);
dFloat NewtonSliderGetJointVeloc (NewtonJoint* slider);
void NewtonSliderGetJointForce (NewtonJoint* slider, dFloat* force);
dFloat NewtonSliderCalculateStopAccel (NewtonJoint* slider, NewtonHingeSliderUpdateDesc* desc, dFloat position);



// **********************************************************************************************
//
// corkscrew joint functions
//
// **********************************************************************************************
NewtonJoint* NewtonConstraintCreateCorkscrew (NewtonWorld* newtonWorld,
dFloat* pivotPoint, dFloat* pinDir, NewtonBody* childBody, NewtonBody* parentBody);
void NewtonCorkscrewSetUserCallback (NewtonJoint* corkscrew, void* callback);
dFloat NewtonCorkscrewGetJointPosit (NewtonJoint* corkscrew);
dFloat NewtonCorkscrewGetJointAngle (NewtonJoint* corkscrew);
dFloat NewtonCorkscrewGetJointVeloc (NewtonJoint* corkscrew);
dFloat NewtonCorkscrewGetJointOmega (NewtonJoint* corkscrew);
void NewtonCorkscrewGetJointForce (NewtonJoint* corkscrew, dFloat* force);
dFloat NewtonCorkscrewCalculateStopAlpha (NewtonJoint* corkscrew, NewtonHingeSliderUpdateDesc* desc, dFloat angle);
dFloat NewtonCorkscrewCalculateStopAccel (NewtonJoint* corkscrew, NewtonHingeSliderUpdateDesc* desc, dFloat position);



// **********************************************************************************************
//
// universal joint functions
//
// **********************************************************************************************
NewtonJoint* NewtonConstraintCreateUniversal (NewtonWorld* newtonWorld,
dFloat* pivotPoint, dFloat* pinDir0, dFloat* pinDir1, NewtonBody* childBody, NewtonBody* parentBody);
void NewtonUniversalSetUserCallback (NewtonJoint* universal, void* callback);
dFloat NewtonUniversalGetJointAngle0 (NewtonJoint* universal);
dFloat NewtonUniversalGetJointAngle1 (NewtonJoint* universal);
dFloat NewtonUniversalGetJointOmega0 (NewtonJoint* universal);
dFloat NewtonUniversalGetJointOmega1 (NewtonJoint* universal);
void NewtonUniversalGetJointForce (NewtonJoint* universal, dFloat* force);
dFloat NewtonUniversalCalculateStopAlpha0 (NewtonJoint* universal, NewtonHingeSliderUpdateDesc* desc, dFloat angle);
dFloat NewtonUniversalCalculateStopAlpha1 (NewtonJoint* universal, NewtonHingeSliderUpdateDesc* desc, dFloat angle);



// **********************************************************************************************
//
// up vector joint functions
//
// **********************************************************************************************
NewtonJoint* NewtonConstraintCreateUpVector (NewtonWorld* newtonWorld, dFloat* pinDir, NewtonBody* body);
void NewtonUpVectorGetPin (NewtonJoint* upVector, dFloat *pin);
void NewtonUpVectorSetPin (NewtonJoint* upVector, dFloat *pin);



// **********************************************************************************************
//
// user defined bilateral joint
//
// **********************************************************************************************
NewtonJoint* NewtonConstraintCreateUserJoint (NewtonWorld* newtonWorld,
int maxDOF, void* callback, NewtonBody* childBody, NewtonBody* parentBody);
void NewtonUserJointAddLinearRow (NewtonJoint* joint, dFloat *pivot0, dFloat *pivot1, dFloat *dir);
void NewtonUserJointAddAngularRow (NewtonJoint* joint, dFloat relativeAngle, dFloat *dir);
void NewtonUserJointSetRowMinimumFriction (NewtonJoint* joint, dFloat friction);
void NewtonUserJointSetRowMaximumFriction (NewtonJoint* joint, dFloat friction);
void NewtonUserJointSetRowAcceleration (NewtonJoint* joint, dFloat acceleration);
void NewtonUserJointSetRowSpringDamperAcceleration (NewtonJoint* joint, dFloat springK, dFloat springD);
void NewtonUserJointSetRowStiffness (NewtonJoint* joint, dFloat stiffness);
dFloat NewtonUserJointGetRowForce (NewtonJoint* joint, int row);



// **********************************************************************************************
//
// rag doll joint container functions
//
// **********************************************************************************************
NewtonRagDoll* NewtonCreateRagDoll (NewtonWorld* newtonWorld);
void NewtonDestroyRagDoll (NewtonWorld* newtonWorld, NewtonRagDoll* ragDoll);

void NewtonRagDollBegin (NewtonRagDoll* ragDoll);
void NewtonRagDollEnd (NewtonRagDoll* ragDoll);

// void NewtonRagDollSetFriction (NewtonRagDoll* ragDoll, dFloat friction);

NewtonRagDollBone* NewtonRagDollFindBone (NewtonRagDoll* ragDoll, int id);
// NewtonRagDollBone* NewtonRagDollGetRootBone (NewtonRagDoll* ragDoll);

void NewtonRagDollSetForceAndTorqueCallback (NewtonRagDoll* ragDoll, void* callback);
void NewtonRagDollSetTransformCallback (NewtonRagDoll* ragDoll, void* callback);
NewtonRagDollBone* NewtonRagDollAddBone (NewtonRagDoll* ragDoll, NewtonRagDollBone* parent,
void *userData, dFloat mass, dFloat* matrix, NewtonCollision* boneCollision, dFloat* size);

void* NewtonRagDollBoneGetUserData (NewtonRagDollBone* bone);
NewtonBody* NewtonRagDollBoneGetBody (NewtonRagDollBone* bone);
void NewtonRagDollBoneSetID (NewtonRagDollBone* bone, int id);

void NewtonRagDollBoneSetLimits (NewtonRagDollBone* bone,
dFloat* coneDir, dFloat minConeAngle, dFloat maxConeAngle, dFloat maxTwistAngle,
dFloat* bilateralConeDir, dFloat negativeBilateralConeAngle, dFloat positiveBilateralConeAngle);

// NewtonRagDollBone* NewtonRagDollBoneGetChild (NewtonRagDollBone* bone);
// NewtonRagDollBone* NewtonRagDollBoneGetSibling (NewtonRagDollBone* bone);
// NewtonRagDollBone* NewtonRagDollBoneGetParent (NewtonRagDollBone* bone);
// void NewtonRagDollBoneSetLocalMatrix (NewtonRagDollBone* bone, dFloat* matrix);
// void NewtonRagDollBoneSetGlobalMatrix (NewtonRagDollBone* bone, dFloat* matrix);

void NewtonRagDollBoneGetLocalMatrix (NewtonRagDollBone* bone, dFloat* matrix);
void NewtonRagDollBoneGetGlobalMatrix (NewtonRagDollBone* bone, dFloat* matrix);



// **********************************************************************************************
//
// vehicle joint functions
//
// **********************************************************************************************
NewtonJoint* NewtonConstraintCreateVehicle (NewtonWorld* newtonWorld, dFloat* upDir, NewtonBody* body);
void NewtonVehicleReset (NewtonJoint* vehicle);
void NewtonVehicleSetTireCallback (NewtonJoint* vehicle, void* update);
int NewtonVehicleAddTire (NewtonJoint* vehicle, dFloat* localMatrix, dFloat* pin, dFloat mass, dFloat width, dFloat radius,
dFloat suspensionShock, dFloat suspensionSpring, dFloat suspensionLength, void* userData, int collisionID);
void NewtonVehicleRemoveTire (NewtonJoint* vehicle, int tireIndex);

int NewtonVehicleGetFirstTireID (NewtonJoint* vehicle);
int NewtonVehicleGetNextTireID (NewtonJoint* vehicle, int tireId);

int NewtonVehicleTireIsAirBorne (NewtonJoint* vehicle, int tireId);
int NewtonVehicleTireLostSideGrip (NewtonJoint* vehicle, int tireId);
int NewtonVehicleTireLostTraction (NewtonJoint* vehicle, int tireId);

void* NewtonVehicleGetTireUserData (NewtonJoint* vehicle, int tireId);
dFloat NewtonVehicleGetTireOmega (NewtonJoint* vehicle, int tireId);
dFloat NewtonVehicleGetTireNormalLoad (NewtonJoint* vehicle, int tireId);
dFloat NewtonVehicleGetTireSteerAngle (NewtonJoint* vehicle, int tireId);
dFloat NewtonVehicleGetTireLateralSpeed (NewtonJoint* vehicle, int tireId);
dFloat NewtonVehicleGetTireLongitudinalSpeed (NewtonJoint* vehicle, int tireId);
void NewtonVehicleGetTireMatrix (NewtonJoint* vehicle, int tireId, dFloat* matrix);

void NewtonVehicleSetTireTorque (NewtonJoint* vehicle, int tireId, dFloat torque);
void NewtonVehicleSetTireSteerAngle (NewtonJoint* vehicle, int tireId, dFloat angle);

void NewtonVehicleSetTireMaxSideSleepSpeed (NewtonJoint* vehicle, int tireId, dFloat speed);
void NewtonVehicleSetTireSideSleepCoeficient (NewtonJoint* vehicle, int tireId, dFloat coefficient);
void NewtonVehicleSetTireMaxLongitudinalSlideSpeed (NewtonJoint* vehicle, int tireId, dFloat speed);
void NewtonVehicleSetTireLongitudinalSlideCoeficient (NewtonJoint* vehicle, int tireId, dFloat coefficient);

dFloat NewtonVehicleTireCalculateMaxBrakeAcceleration (NewtonJoint* vehicle, int tireId);
void NewtonVehicleTireSetBrakeAcceleration (NewtonJoint* vehicle, int tireId, dFloat acceleration, dFloat torqueLimit);










// **********************************************************************************************
//
//
//
// **********************************************************************************************
void newton_startup()
{
long dll = LoadLibrary("newton");



//------------------------------------------------------------
NewtonCreate = GetProcAddress(dll, "NewtonCreate");
NewtonDestroy = GetProcAddress(dll, "NewtonDestroy");
NewtonDestroyAllBodies = GetProcAddress(dll, "NewtonDestroyAllBodies");

NewtonUpdate = GetProcAddress(dll, "NewtonUpdate");
NewtonSetSolverModel = GetProcAddress(dll, "NewtonSetSolverModel");
NewtonSetFrictionModel = GetProcAddress(dll, "NewtonSetFrictionModel");
NewtonGetTimeStep = GetProcAddress(dll, "NewtonGetTimeStep");
NewtonSetMinimumFrameRate = GetProcAddress(dll, "NewtonSetMinimumFrameRate");
NewtonSetBodyLeaveWorldEvent = GetProcAddress(dll, "NewtonSetBodyLeaveWorldEvent");
NewtonSetWorldSize = GetProcAddress(dll, "NewtonSetWorldSize");

NewtonWorldFreezeBody = GetProcAddress(dll, "NewtonWorldFreezeBody");
NewtonWorldUnfreezeBody = GetProcAddress(dll, "NewtonWorldUnfreezeBody");

NewtonWorldForEachBodyDo = GetProcAddress(dll, "NewtonWorldForEachBodyDo");

NewtonWorldSetUserData = GetProcAddress(dll, "NewtonWorldSetUserData");
NewtonWorldGetUserData = GetProcAddress(dll, "NewtonWorldGetUserData");
NewtonWorldGetVersion = GetProcAddress(dll, "NewtonWorldGetVersion");
NewtonWorldRayCast = GetProcAddress(dll, "NewtonDestroyAllBodies");



//------------------------------------------------------------
NewtonMaterialGetDefaultGroupID = GetProcAddress(dll, "NewtonMaterialGetDefaultGroupID");
NewtonMaterialCreateGroupID = GetProcAddress(dll, "NewtonMaterialCreateGroupID");
NewtonMaterialDestroyAllGroupID = GetProcAddress(dll, "NewtonMaterialDestroyAllGroupID");

NewtonMaterialSetDefaultSoftness = GetProcAddress(dll, "NewtonMaterialSetDefaultSoftness");
NewtonMaterialSetDefaultElasticity = GetProcAddress(dll, "NewtonMaterialSetDefaultElasticity");
NewtonMaterialSetDefaultCollidable = GetProcAddress(dll, "NewtonMaterialSetDefaultCollidable");
NewtonMaterialSetContinuousCollisionMode = GetProcAddress(dll, "NewtonMaterialSetContinuousCollisionMode");
NewtonMaterialSetDefaultFriction = GetProcAddress(dll, "NewtonMaterialSetDefaultFriction");

NewtonMaterialSetCollisionCallback = GetProcAddress(dll, "NewtonMaterialSetCollisionCallback");

NewtonMaterialGetUserData = GetProcAddress(dll, "NewtonMaterialGetUserData");



//------------------------------------------------------------
NewtonMaterialDisableContact = GetProcAddress(dll, "NewtonMaterialDisableContact");
NewtonMaterialGetCurrentTimestep = GetProcAddress(dll, "NewtonMaterialGetCurrentTimestep");
NewtonMaterialGetMaterialPairUserData = GetProcAddress(dll, "NewtonMaterialGetMaterialPairUserData");
NewtonMaterialGetContactFaceAttribute = GetProcAddress(dll, "NewtonMaterialGetContactFaceAttribute");
NewtonMaterialGetBodyCollisionID = GetProcAddress(dll, "NewtonMaterialGetBodyCollisionID");
NewtonMaterialGetContactNormalSpeed = GetProcAddress(dll, "NewtonMaterialGetContactNormalSpeed");
NewtonMaterialGetContactForce = GetProcAddress(dll, "NewtonMaterialGetContactForce");
NewtonMaterialGetContactPositionAndNormal = GetProcAddress(dll, "NewtonMaterialGetContactPositionAndNormal");
NewtonMaterialGetContactTangentDirections = GetProcAddress(dll, "NewtonMaterialGetContactTangentDirections");
NewtonMaterialGetContactTangentSpeed = GetProcAddress(dll, "NewtonCreate");

NewtonMaterialSetContactSoftness = GetProcAddress(dll, "NewtonMaterialSetContactSoftness");
NewtonMaterialSetContactElasticity = GetProcAddress(dll, "NewtonMaterialSetContactElasticity");
NewtonMaterialSetContactFrictionState = GetProcAddress(dll, "NewtonMaterialSetContactFrictionState");
NewtonMaterialSetContactStaticFrictionCoef = GetProcAddress(dll, "NewtonMaterialSetContactStaticFrictionCoef");
NewtonMaterialSetContactKineticFrictionCoef = GetProcAddress(dll, "NewtonMaterialSetContactKineticFrictionCoef");

NewtonMaterialSetContactNormalAcceleration = GetProcAddress(dll, "NewtonMaterialSetContactNormalAcceleration");
NewtonMaterialSetContactNormalDirection = GetProcAddress(dll, "NewtonMaterialSetContactNormalDirection");

NewtonMaterialSetContactTangentAcceleration = GetProcAddress(dll, "NewtonMaterialSetContactTangentAcceleration");
NewtonMaterialContactRotateTangentDirections = GetProcAddress(dll, "NewtonMaterialContactRotateTangentDirections");



//------------------------------------------------------------
NewtonCreateNull = GetProcAddress(dll, "NewtonCreateNull");
NewtonCreateSphere = GetProcAddress(dll, "NewtonCreateSphere");
NewtonCreateBox = GetProcAddress(dll, "NewtonCreateBox");
NewtonCreateCone = GetProcAddress(dll, "NewtonCreateCone");
NewtonCreateCapsule = GetProcAddress(dll, "NewtonCreateCapsule");
NewtonCreateCylinder = GetProcAddress(dll, "NewtonCreateCylinder");
NewtonCreateChamferCylinder = GetProcAddress(dll, "NewtonCreateChamferCylinder");
NewtonCreateConvexHull = GetProcAddress(dll, "NewtonCreateConvexHull");
NewtonCreateConvexHullModifier = GetProcAddress(dll, "NewtonCreateConvexHullModifier");
NewtonConvexHullModifierGetMatrix = GetProcAddress(dll, "NewtonConvexHullModifierGetMatrix");
NewtonConvexHullModifierSetMatrix = GetProcAddress(dll, "NewtonConvexHullModifierSetMatrix");

NewtonConvexCollisionSetUserID = GetProcAddress(dll, "NewtonConvexCollisionSetUserID");
NewtonConvexCollisionGetUserID = GetProcAddress(dll, "NewtonConvexCollisionGetUserID");

NewtonConvexCollisionCalculateVolume = GetProcAddress(dll, "NewtonConvexCollisionCalculateVolume");
NewtonConvexCollisionCalculateInertialMatrix = GetProcAddress(dll, "NewtonConvexCollisionCalculateInertialMatrix");

NewtonReleaseCollision = GetProcAddress(dll, "NewtonReleaseCollision");



//------------------------------------------------------------
NewtonCreateCompoundCollision = GetProcAddress(dll, "NewtonCreateCompoundCollision");
NewtonCreateUserMeshCollision = GetProcAddress(dll, "NewtonCreateUserMeshCollision");



//------------------------------------------------------------
NewtonCreateTreeCollision = GetProcAddress(dll, "NewtonCreateTreeCollision");
NewtonTreeCollisionBeginBuild = GetProcAddress(dll, "NewtonTreeCollisionBeginBuild");
NewtonTreeCollisionAddFace = GetProcAddress(dll, "NewtonTreeCollisionAddFace");
NewtonTreeCollisionEndBuild = GetProcAddress(dll, "NewtonTreeCollisionEndBuild");

NewtonTreeCollisionSerialize = GetProcAddress(dll, "NewtonTreeCollisionSerialize");
NewtonCreateTreeCollisionFromSerialization = GetProcAddress(dll, "NewtonCreateTreeCollisionFromSerialization");

NewtonTreeCollisionGetFaceAtribute = GetProcAddress(dll, "NewtonTreeCollisionGetFaceAtribute");
NewtonTreeCollisionSetFaceAtribute = GetProcAddress(dll, "NewtonTreeCollisionSetFaceAtribute");



//------------------------------------------------------------
NewtonCollisionPointDistance = GetProcAddress(dll, "NewtonCollisionPointDistance");
NewtonCollisionClosestPoint = GetProcAddress(dll, "NewtonCollisionClosestPoint");
NewtonCollisionCollide = GetProcAddress(dll, "NewtonCollisionCollide");
NewtonCollisionCollideContinue = GetProcAddress(dll, "NewtonCollisionCollideContinue");
NewtonCollisionRayCast = GetProcAddress(dll, "NewtonCollisionRayCast");
NewtonCollisionCalculateAABB = GetProcAddress(dll, "NewtonCollisionCalculateAABB");



//------------------------------------------------------------
NewtonGetEulerAngle = GetProcAddress(dll, "NewtonGetEulerAngle");
NewtonSetEulerAngle = GetProcAddress(dll, "NewtonSetEulerAngle");



//------------------------------------------------------------
NewtonCreateBody = GetProcAddress(dll, "NewtonCreateBody");
NewtonDestroyBody = GetProcAddress(dll, "NewtonDestroyBody");

NewtonBodyAddForce = GetProcAddress(dll, "NewtonBodyAddForce");
NewtonBodyAddTorque = GetProcAddress(dll, "NewtonBodyAddTorque");

NewtonBodySetMatrix = GetProcAddress(dll, "NewtonBodySetMatrix");
NewtonBodySetMatrixRecursive = GetProcAddress(dll, "NewtonBodySetMatrixRecursive");
NewtonBodySetMassMatrix = GetProcAddress(dll, "NewtonBodySetMassMatrix");
NewtonBodySetMaterialGroupID = GetProcAddress(dll, "NewtonBodySetMaterialGroupID");
NewtonBodySetContinuousCollisionMode = GetProcAddress(dll, "NewtonBodySetContinuousCollisionMode");
NewtonBodySetJointRecursiveCollision = GetProcAddress(dll, "NewtonBodySetJointRecursiveCollision");
NewtonBodySetOmega = GetProcAddress(dll, "NewtonBodySetOmega");
NewtonBodySetVelocity = GetProcAddress(dll, "NewtonBodySetVelocity");
NewtonBodySetForce = GetProcAddress(dll, "NewtonBodySetForce");
NewtonBodySetTorque = GetProcAddress(dll, "NewtonBodySetTorque");

NewtonBodySetCentreOfMass = GetProcAddress(dll, "NewtonBodySetCentreOfMass");
NewtonBodySetLinearDamping = GetProcAddress(dll, "NewtonBodySetLinearDamping");
NewtonBodySetAngularDamping = GetProcAddress(dll, "NewtonBodySetAngularDamping");
NewtonBodySetUserData = GetProcAddress(dll, "NewtonBodySetUserData");
NewtonBodyCoriolisForcesMode = GetProcAddress(dll, "NewtonBodyCoriolisForcesMode");
NewtonBodySetCollision = GetProcAddress(dll, "NewtonBodySetCollision");
NewtonBodySetAutoFreeze = GetProcAddress(dll, "NewtonBodySetAutoFreeze");
NewtonBodySetFreezeTreshold = GetProcAddress(dll, "NewtonBodySetFreezeTreshold");

NewtonBodySetTransformCallback = GetProcAddress(dll, "NewtonBodySetTransformCallback");
NewtonBodySetDestructorCallback = GetProcAddress(dll, "NewtonBodySetDestructorCallback");
NewtonBodySetAutoactiveCallback = GetProcAddress(dll, "NewtonBodySetAutoactiveCallback");
NewtonBodySetForceAndTorqueCallback = GetProcAddress(dll, "NewtonBodySetForceAndTorqueCallback");
NewtonBodyGetForceAndTorqueCallback = GetProcAddress(dll, "NewtonBodyGetForceAndTorqueCallback");

NewtonBodyGetUserData = GetProcAddress(dll, "NewtonBodyGetUserData");
NewtonBodyGetWorld = GetProcAddress(dll, "NewtonBodyGetWorld");
NewtonBodyGetCollision = GetProcAddress(dll, "NewtonBodyGetCollision");
NewtonBodyGetMaterialGroupID = GetProcAddress(dll, "NewtonBodyGetMaterialGroupID");
NewtonBodyGetContinuousCollisionMode = GetProcAddress(dll, "NewtonBodyGetContinuousCollisionMode");
NewtonBodyGetJointRecursiveCollision = GetProcAddress(dll, "NewtonBodyGetJointRecursiveCollision");

NewtonBodyGetMatrix = GetProcAddress(dll, "NewtonBodyGetMatrix");
NewtonBodyGetMassMatrix = GetProcAddress(dll, "NewtonBodyGetMassMatrix");
NewtonBodyGetInvMass = GetProcAddress(dll, "NewtonBodyGetInvMass");
NewtonBodyGetOmega = GetProcAddress(dll, "NewtonBodyGetOmega");
NewtonBodyGetVelocity = GetProcAddress(dll, "NewtonBodyGetVelocity");
NewtonBodyGetForce = GetProcAddress(dll, "NewtonBodyGetForce");
NewtonBodyGetTorque = GetProcAddress(dll, "NewtonBodyGetTorque");
NewtonBodyGetCentreOfMass = GetProcAddress(dll, "NewtonBodyGetCentreOfMass");

NewtonBodyGetSleepingState = GetProcAddress(dll, "NewtonBodyGetSleepingState");
NewtonBodyGetAutoFreeze = GetProcAddress(dll, "NewtonBodyGetAutoFreeze");
NewtonBodyGetLinearDamping = GetProcAddress(dll, "NewtonBodyGetLinearDamping");
NewtonBodyGetAngularDamping = GetProcAddress(dll, "NewtonBodyGetAngularDamping");
NewtonBodyGetAABB = GetProcAddress(dll, "NewtonBodyGetAABB");
NewtonBodyGetFreezeTreshold = GetProcAddress(dll, "NewtonBodyGetFreezeTreshold");

NewtonBodyAddBuoyancyForce = GetProcAddress(dll, "NewtonBodyAddBuoyancyForce");

NewtonBodyForEachPolygonDo = GetProcAddress(dll, "NewtonBodyForEachPolygonDo");
NewtonAddBodyImpulse = GetProcAddress(dll, "NewtonAddBodyImpulse");



//------------------------------------------------------------
NewtonJointGetUserData = GetProcAddress(dll, "NewtonJointGetUserData");
NewtonJointSetUserData = GetProcAddress(dll, "NewtonJointSetUserData");

NewtonJointGetCollisionState = GetProcAddress(dll, "NewtonJointGetCollisionState");
NewtonJointSetCollisionState = GetProcAddress(dll, "NewtonJointSetCollisionState");

NewtonJointGetStiffness = GetProcAddress(dll, "NewtonJointGetStiffness");
NewtonJointSetStiffness = GetProcAddress(dll, "NewtonJointSetStiffness");

NewtonDestroyJoint = GetProcAddress(dll, "NewtonDestroyJoint");
NewtonJointSetDestructor = GetProcAddress(dll, "NewtonJointSetDestructor");



//------------------------------------------------------------
NewtonConstraintCreateBall = GetProcAddress(dll, "NewtonConstraintCreateBall");
NewtonBallSetUserCallback = GetProcAddress(dll, "NewtonBallSetUserCallback");
NewtonBallGetJointAngle = GetProcAddress(dll, "NewtonBallGetJointAngle");
NewtonBallGetJointOmega = GetProcAddress(dll, "NewtonBallGetJointOmega");
NewtonBallGetJointForce = GetProcAddress(dll, "NewtonBallGetJointForce");
NewtonBallSetConeLimits = GetProcAddress(dll, "NewtonBallSetConeLimits");



//------------------------------------------------------------
NewtonConstraintCreateHinge = GetProcAddress(dll, "NewtonConstraintCreateHinge");
NewtonHingeSetUserCallback = GetProcAddress(dll, "NewtonHingeSetUserCallback");
NewtonHingeGetJointAngle = GetProcAddress(dll, "NewtonHingeGetJointAngle");
NewtonHingeGetJointOmega = GetProcAddress(dll, "NewtonHingeGetJointOmega");
NewtonHingeGetJointForce = GetProcAddress(dll, "NewtonHingeGetJointForce");
NewtonHingeCalculateStopAlpha = GetProcAddress(dll, "NewtonHingeCalculateStopAlpha");



//------------------------------------------------------------
NewtonConstraintCreateSlider = GetProcAddress(dll, "NewtonConstraintCreateSlider");
NewtonSliderSetUserCallback = GetProcAddress(dll, "NewtonSliderSetUserCallback");
NewtonSliderGetJointPosit = GetProcAddress(dll, "NewtonSliderGetJointPosit");
NewtonSliderGetJointVeloc = GetProcAddress(dll, "NewtonSliderGetJointVeloc");
NewtonSliderGetJointForce = GetProcAddress(dll, "NewtonSliderGetJointForce");
NewtonSliderCalculateStopAccel = GetProcAddress(dll, "NewtonSliderCalculateStopAccel");



//------------------------------------------------------------
NewtonConstraintCreateCorkscrew = GetProcAddress(dll, "NewtonConstraintCreateCorkscrew");
NewtonCorkscrewSetUserCallback = GetProcAddress(dll, "NewtonCorkscrewSetUserCallback");
NewtonCorkscrewGetJointPosit = GetProcAddress(dll, "NewtonCorkscrewGetJointPosit");
NewtonCorkscrewGetJointAngle = GetProcAddress(dll, "NewtonCorkscrewGetJointAngle");
NewtonCorkscrewGetJointVeloc = GetProcAddress(dll, "NewtonCorkscrewGetJointVeloc");
NewtonCorkscrewGetJointOmega = GetProcAddress(dll, "NewtonCorkscrewGetJointOmega");
NewtonCorkscrewGetJointForce = GetProcAddress(dll, "NewtonCorkscrewGetJointForce");
NewtonCorkscrewCalculateStopAlpha = GetProcAddress(dll, "NewtonCorkscrewCalculateStopAlpha");
NewtonCorkscrewCalculateStopAccel = GetProcAddress(dll, "NewtonCorkscrewCalculateStopAccel");



//------------------------------------------------------------
NewtonConstraintCreateUniversal = GetProcAddress(dll, "NewtonConstraintCreateUniversal");
NewtonUniversalSetUserCallback = GetProcAddress(dll, "NewtonUniversalSetUserCallback");
NewtonUniversalGetJointAngle0 = GetProcAddress(dll, "NewtonUniversalGetJointAngle0");
NewtonUniversalGetJointAngle1 = GetProcAddress(dll, "NewtonUniversalGetJointAngle1");
NewtonUniversalGetJointOmega0 = GetProcAddress(dll, "NewtonUniversalGetJointOmega0");
NewtonUniversalGetJointOmega1 = GetProcAddress(dll, "NewtonUniversalGetJointOmega1");
NewtonUniversalGetJointForce = GetProcAddress(dll, "NewtonUniversalGetJointForce");
NewtonUniversalCalculateStopAlpha0 = GetProcAddress(dll, "NewtonUniversalCalculateStopAlpha0");
NewtonUniversalCalculateStopAlpha1 = GetProcAddress(dll, "NewtonUniversalCalculateStopAlpha1");



//------------------------------------------------------------
NewtonConstraintCreateUpVector = GetProcAddress(dll, "NewtonConstraintCreateUpVector");
NewtonUpVectorGetPin = GetProcAddress(dll, "NewtonUpVectorGetPin");
NewtonUpVectorSetPin = GetProcAddress(dll, "NewtonUpVectorSetPin");



//------------------------------------------------------------
NewtonConstraintCreateUserJoint = GetProcAddress(dll, "NewtonConstraintCreateUserJoint");
NewtonUserJointAddLinearRow = GetProcAddress(dll, "NewtonUserJointAddLinearRow");
NewtonUserJointAddAngularRow = GetProcAddress(dll, "NewtonUserJointAddAngularRow");
NewtonUserJointSetRowMinimumFriction = GetProcAddress(dll, "NewtonUserJointSetRowMinimumFriction");
NewtonUserJointSetRowMaximumFriction = GetProcAddress(dll, "NewtonUserJointSetRowMaximumFriction");
NewtonUserJointSetRowAcceleration = GetProcAddress(dll, "NewtonUserJointSetRowAcceleration");
NewtonUserJointSetRowSpringDamperAcceleration = GetProcAddress(dll, "NewtonUserJointSetRowSpringDamperAcceleration");
NewtonUserJointSetRowStiffness = GetProcAddress(dll, "NewtonUserJointSetRowStiffness");
NewtonUserJointGetRowForce = GetProcAddress(dll, "NewtonUserJointGetRowForce");



//------------------------------------------------------------
NewtonCreateRagDoll = GetProcAddress(dll, "NewtonCreateRagDoll");
NewtonDestroyRagDoll = GetProcAddress(dll, "NewtonDestroyRagDoll");

NewtonRagDollBegin = GetProcAddress(dll, "NewtonRagDollBegin");
NewtonRagDollEnd = GetProcAddress(dll, "NewtonRagDollEnd");

NewtonRagDollFindBone = GetProcAddress(dll, "NewtonRagDollFindBone");

NewtonRagDollSetForceAndTorqueCallback = GetProcAddress(dll, "NewtonRagDollSetForceAndTorqueCallback");
NewtonRagDollSetTransformCallback = GetProcAddress(dll, "NewtonRagDollSetTransformCallback");
NewtonRagDollAddBone = GetProcAddress(dll, "NewtonRagDollAddBone");

NewtonRagDollBoneGetUserData = GetProcAddress(dll, "NewtonRagDollBoneGetUserData");
NewtonRagDollBoneGetBody = GetProcAddress(dll, "NewtonRagDollBoneGetBody");
NewtonRagDollBoneSetID = GetProcAddress(dll, "NewtonRagDollBoneSetID");

NewtonRagDollBoneSetLimits = GetProcAddress(dll, "NewtonRagDollBoneSetLimits ");

NewtonRagDollBoneGetLocalMatrix = GetProcAddress(dll, "NewtonRagDollBoneGetLocalMatrix");
NewtonRagDollBoneGetGlobalMatrix = GetProcAddress(dll, "NewtonRagDollBoneGetGlobalMatrix");



//------------------------------------------------------------
NewtonConstraintCreateVehicle = GetProcAddress(dll, "NewtonConstraintCreateVehicle");
NewtonVehicleReset = GetProcAddress(dll, "NewtonVehicleReset");
NewtonVehicleSetTireCallback = GetProcAddress(dll, "NewtonVehicleSetTireCallback");
NewtonVehicleAddTire = GetProcAddress(dll, "NewtonVehicleAddTire");
NewtonVehicleRemoveTire = GetProcAddress(dll, "NewtonVehicleRemoveTire");

NewtonVehicleGetFirstTireID = GetProcAddress(dll, "NewtonVehicleGetFirstTireID");
NewtonVehicleGetNextTireID = GetProcAddress(dll, "NewtonVehicleGetNextTireID");

NewtonVehicleTireIsAirBorne = GetProcAddress(dll, "NewtonVehicleTireIsAirBorne");
NewtonVehicleTireLostSideGrip = GetProcAddress(dll, "NewtonVehicleTireLostSideGrip");
NewtonVehicleTireLostTraction = GetProcAddress(dll, "NewtonVehicleTireLostTraction");

NewtonVehicleGetTireUserData = GetProcAddress(dll, "NewtonVehicleGetTireUserData");
NewtonVehicleGetTireOmega = GetProcAddress(dll, "NewtonVehicleGetTireOmega");
NewtonVehicleGetTireNormalLoad = GetProcAddress(dll, "NewtonVehicleGetTireNormalLoad");
NewtonVehicleGetTireSteerAngle = GetProcAddress(dll, "NewtonVehicleGetTireSteerAngle");
NewtonVehicleGetTireLateralSpeed = GetProcAddress(dll, "NewtonVehicleGetTireLateralSpeed");
NewtonVehicleGetTireLongitudinalSpeed = GetProcAddress(dll, "NewtonVehicleGetTireLongitudinalSpeed");
NewtonVehicleGetTireMatrix = GetProcAddress(dll, "NewtonVehicleGetTireMatrix");

NewtonVehicleSetTireTorque = GetProcAddress(dll, "NewtonVehicleSetTireTorque");
NewtonVehicleSetTireSteerAngle = GetProcAddress(dll, "NewtonVehicleSetTireSteerAngle");

NewtonVehicleSetTireMaxSideSleepSpeed = GetProcAddress(dll, "NewtonVehicleSetTireMaxSideSleepSpeed");
NewtonVehicleSetTireSideSleepCoeficient = GetProcAddress(dll, "NewtonVehicleSetTireSideSleepCoeficient");
NewtonVehicleSetTireMaxLongitudinalSlideSpeed = GetProcAddress(dll, "NewtonVehicleSetTireMaxLongitudinalSlideSpeed");
NewtonVehicleSetTireLongitudinalSlideCoeficient = GetProcAddress(dll, "NewtonVehicleSetTireLongitudinalSlideCoeficient");

NewtonVehicleTireCalculateMaxBrakeAcceleration = GetProcAddress(dll, "NewtonVehicleTireCalculateMaxBrakeAcceleration");
NewtonVehicleTireSetBrakeAcceleration = GetProcAddress(dll, "NewtonVehicleTireSetBrakeAcceleration");
}



create an empty file "ngd.c" and copy the above into it. copy the newton.dll to your directory and then you can test it like that:

Code:

#include "ngd.c"

void main()
{
wait(3);
level_load("empty.wmb");
wait(1);



NewtonWorld* world;
world = NewtonCreate(0, 0);

int version;
version = NewtonWorldGetVersion(world);

printf("version: %d", version);

NewtonDestroy(world);
}



still a lot to do.
Posted By: Carloos

Re: newton - 02/21/07 18:57

Fantastic, Ventilator !

What newton Version is planned to use ? Will it be able to collide with model only levels ?
Posted By: ventilator

Re: newton - 02/21/07 19:03

i will use the latest newton version and collisions with model only levels will work.

i could use some help with that though. it would be great if someone with direct3d experience could provide a code snippet of how to use ent_mesh and read the needed information from the vertex and index buffers (i think i only need the vertex positions of every triangle). i haven't done that before...
Posted By: ulf

Re: newton - 02/21/07 19:31

wow ventilator great to see you doing this, unfortunately iam unable to help you with it. all i can do is encourage you to continue!
Posted By: Orange Brat

Re: newton - 02/21/07 20:20

Quote:

i will use the newest newton version and collisions with model only levels will work.




This is good news. Do you still have plans to update the c-script version using the newest Newton?
Posted By: D3D

Re: newton - 02/22/07 02:54

Great news I almost gave up on Newton as I no longer use blocks
Posted By: Nowherebrain

Re: newton - 03/02/07 03:19

Blocks are for girls!
Posted By: ulf

Re: newton - 03/25/07 08:42

hi, just wondering if you or anybody found a solution for? in case you are still working on this...
Quote:


provide a code snippet of how to use ent_mesh and read the needed information from the vertex and index buffers (i think i only need the vertex positions of every triangle)



Posted By: ventilator

Re: newton - 04/01/07 12:36

sorry, the time i can spend on this is somewhat sparse at the moment but i started with the next necessary step now. i am not sure when i will get it to work though.
Posted By: ventilator

Re: newton - 04/04/07 21:36

good news: i got access to model geometry working now. so everything (the header and the access to geometry) to really start using newton would be there now. bad news: not sure when i will have the time and notion to continue with it.
Posted By: xXxGuitar511

Re: newton - 04/04/07 21:44

Nice, can't wait for more info.

If I knew c++, I'd offer to help
Posted By: ulf

Re: newton - 04/05/07 06:58

very nice news ventilator!
Posted By: ventilator

Re: newton - 04/29/07 19:04

static collision geometry can be loaded from models and spheres can roll around:



still a lot to do but this is much more fun in lite-c than doing a plugin for c-script.
Posted By: xXxGuitar511

Re: newton - 05/02/07 05:11

Ventilator: I think I love you... lol. This is great news. Can't wait till it gets near completion!
Posted By: ulf

Re: newton - 05/02/07 07:17

very nice already, keep on going
Posted By: bstudio

Re: newton - 05/02/07 11:17

Hehe, this makes me more interested in lite-c then i was. Keep up the nice development
Posted By: andy_1984

Re: newton - 05/09/07 09:05

can lite c be used with 3dgs or is it a totaly diffrent and can only be used standalone ?
Posted By: ulf

Re: newton - 05/16/07 10:29

litec will be part of the new gamestudio release a7 as its scripting language. but you can also grab the free version of litec right now + the free med tool modelling for non commercial projects/applications without the world editor wed.
look at the top links of this forum to get more information about this.
Posted By: ventilator

Re: newton - 05/16/07 15:56

another small step:

Code:
//----------------------------------------------------------------------------- ent_getmatrix_rb
// return transformation matrix of entity (without scale -> for rigid bodies)
//-----------------------------------------------------------------------------
void ent_getmatrix_rb(ENTITY *entity, D3DXMATRIX *mout)
{
// ignores entity scale -> not needed for rigid bodies -> collision shape size gets defined by bounding box

D3DXMATRIX mpan;
D3DXMatrixRotationZ(&mpan, entity->pan * DEG2RAD);

D3DXMATRIX mtilt;
D3DXMatrixRotationY(&mtilt, -entity->tilt * DEG2RAD); // -tilt?

D3DXMATRIX mroll;
D3DXMatrixRotationX(&mroll, entity->roll * DEG2RAD);

D3DXMATRIX mtranslation;
D3DXMatrixTranslation(&mtranslation,
entity->x * QUANTTOMETER,
entity->y * QUANTTOMETER,
entity->z * QUANTTOMETER);

D3DXMATRIX mtemp1;
D3DXMATRIX mtemp2;

D3DXMatrixMultiply(&mtemp1, &mroll, &mtilt);
D3DXMatrixMultiply(&mtemp2, &mtemp1, &mpan);
D3DXMatrixMultiply(mout, &mtemp2, &mtranslation);
}

//----------------------------------------------------------------------------- ent_getmatrix_rb
// return transformation matrix of entity (without scale -> for rigid bodies)
// (same as above but done in a different way)
//-----------------------------------------------------------------------------
//void ent_getmatrix_rb(ENTITY *entity, float *mout)
//{
// VECTOR xaxis; vec_set(&xaxis, vector(1, 0, 0));
// VECTOR yaxis; vec_set(&yaxis, vector(0, 1, 0));
// VECTOR zaxis; vec_set(&zaxis, vector(0, 0, 1));
//
// // ignores entity scale -> not needed for rigid bodies -> collision shape size gets defined by bounding box
//
// vec_rotate(&xaxis, &entity->pan);
// vec_rotate(&yaxis, &entity->pan);
// vec_rotate(&zaxis, &entity->pan);
//
// mout[0] = xaxis.x; mout[1] = xaxis.y; mout[2] = xaxis.z; mout[3] = 0;
// mout[4] = yaxis.x; mout[5] = yaxis.y; mout[6] = yaxis.z; mout[7] = 0;
// mout[8] = zaxis.x; mout[9] = zaxis.y; mout[10] = zaxis.z; mout[11] = 0;
// mout[12] = entity->x * QUANTTOMETER;
// mout[13] = entity->y * QUANTTOMETER;
// mout[14] = entity->z * QUANTTOMETER;
// mout[15] = 1;
//}

//----------------------------------------------------------------------------- ent_setmatrix_rb
//
// i think a 3dgs rotation matrix gets constructed like that:
//
// pan matrix (rotation about z-axis)
// | cos(p) -sin(p) 0 |
// | sin(p) cos(p) 0 |
// | 0 0 1 |
//
// tilt matrix (rotation about y-axis)
// | cos(t) 0 sin(t) |
// | 0 1 0 |
// | -sin(t) 0 cos(t) |
//
// roll matrix (rotation about x-axis)
// | 1 0 0 |
// | 0 cos(r) -sin(r) |
// | 0 sin(r) cos(r) |
//
// roll * tilt * pan =
//
// | cos(t)*cos(p) cos(t)*-sin(p) sin(t) |
// | -sin(r)*-sin(t)*cos(p) + cos(r)*sin(p) -sin(r)*-sin(t)*-sin(p) + cos(r)*cos(p) -sin(r)*cos(t) |
// | cos(r)*-sin(t)*cos(p) + sin(r)*sin(p) cos(r)*-sin(t)*-sin(p) + sin(r)*cos(p) cos(r)*cos(t) |
//
// in case of gimbal lock (cos(t) = 0, sin(r) = 0, cos(r) = 1):
//
// | 0 0 sin(t) |
// | sin(p) cos(p) 0 |
// | -sin(t)*cos(p) -sin(t)*-sin(p) 0 |

void ent_setmatrix_rb(ENTITY *entity, float *m)
{
float pan, tilt, roll;

if(fabs(m[2]) > 0.9999) // looking straight up or down -> gimbal lock
{
draw_text("gimbal lock", 10, 10, vector(255,255,255));
pan = atan2f(-m[4], m[5]); // -m[4]?
tilt = 1.570796 * sign(m[2]);
roll = 0;
}
else
{
pan = atan2f(m[1], m[0]); // swap?
tilt = asinf(m[2]);
roll = atan2f(m[6], m[10]);
}

entity->pan = pan * RAD2DEG;
entity->tilt = tilt * RAD2DEG;
entity->roll = roll * RAD2DEG;

entity->x = m[12] * METERTOQUANT;
entity->y = m[13] * METERTOQUANT;
entity->z = m[14] * METERTOQUANT;
}



the conversion from 3dgs eulers to matrices (needed by newton) and back again. previously i had some problems with this which caused wrong orientation and jitters occasionally. now it seems to work flawlessly.

there isn't much missing now for posting the first simple working example.
Posted By: ventilator

Re: newton - 05/19/07 10:28

newton_lite-c_example.exe ~3.5mb


Posted By: Dyc

Re: newton - 05/19/07 16:18

Says "Archive is not supported"
Posted By: ventilator

Re: newton - 05/19/07 16:47

it's supposed to be a self extracting 7zip archive. please try to download it again. maybe you downloaded it while i was uploading.
Posted By: Dyc

Re: newton - 05/19/07 19:04

Downloaded again, no luck. This is what I get after double clicking newton_lite-c_example.exe


Did you try to download it yourself?
Posted By: sheefo

Re: newton - 05/19/07 19:32

I get the same error message, the previous one worked though.
Posted By: ventilator

Re: newton - 05/19/07 19:44

i think something went wrong with the upload. it wasn't complete. now it should work! the server sometimes isn't very reliable...
Posted By: ventilator

Re: newton - 05/20/07 11:24

newton_lite-c_example.exe ~3.5mb

i have uploaded it to a different server. the other one seems to be down half of the time.
Posted By: D3D

Re: newton - 05/20/07 20:30

Thanks for posting the sample i'm having fun already! When finished will become another awesome contribution

To save some bandwidth i'll mirror the sample here -> newton_lite-c_example.exe
Posted By: Andreas C

Re: newton - 06/13/07 19:48

Wow ... what a cool example ... I just spent 40 minutes "playing" ...

Thanks Ventilator !

Cheers,
Andreas
Posted By: BigM

Re: newton - 06/23/07 06:19

First of all, thank you so much for creating this possibility to fully use newton.dll with lite-C!

I have a question regarding time slicing:

To set a time slice of TIME_SLICE seconds, I changed your NewtonUpdate call loop, in newton.c, to read:

Code:
	while(newton_running) // newton has to update every frame
{
NewtonUpdate(nworld, TIME_SLICE);
wait(-TIME_SLICE);
}



(In my case TIME_SLICE was 1/180 s)
The rationale is that the simulation should advance 1/180 seconds at a time, every 1/180 seconds.

Is this approach correct? For me, this resulted in increasingly slow movements, as I reduced TIME_SLICE. The fps, however, stayed the same.

Why does the increase in the sampling frequency of the newton physics simulation seem to interfer with the game speed?

What can i do to correctly implement time slicing?

I'm also having a problem of projectiles crossing walls, even with newton refresh rates of 1/256 s-1.i The only workaround to problems like this is to decrease to further TIME_SLICE, right?

Thank you for your effort!
Posted By: Andreas C

Re: newton - 06/23/07 13:10


Just a general question for my understanding...

From everything I've seen so far, collision (using Newton) works only on models, not on "level geometry" ? Is that correct ?

So I can (have to) create MDLs for everything. Compiled map entities would NOT work, correct ?

Sorry if the answer is obvious, but I'm a bit unsure about my comprehension.

Cheers,
Andreas
Posted By: ventilator

Re: newton - 06/23/07 13:39

no, increasing the number of newton updates isn't the only way to prevent tunneling (fast/small bodies missing collisions). newton supports a continuous collision mode which can be enabled for bodies! you can read about it in the newton documentation.

currently the example doesn't use time slicing and it also isn't really necessary. it works correctly as it is. time slicing can be used if you would like to have the physics updates more balanced and more independent of the frame rate for some reason. there are examples of how to do time slicing correctly on the newton forum.



ent_getmesh() works for level geometry too with a7. just pass NULL instead of an entity pointer and loop through all level meshes. but this only works for ABT levels and not for old BSP levels.

another way which also would work with BSP levels is to export the level geometry as mdl from WED and load that model just for using it as collision geometry.
Posted By: Andreas C

Re: newton - 06/23/07 19:19

Quote:


ent_getmesh() works for level geometry too with a7. just pass NULL instead of an entity pointer and loop through all level meshes. but this only works for ABT levels and not for old BSP levels.

another way which also would work with BSP levels is to export the level geometry as mdl from WED and load that model just for using it as collision geometry.




Thanks for the help ! Going the MDL route worked like a charm ... I'll try the ent_getmesh() later ... right now, I'm having too much fun

As far as I know, Newton does not support any fluid dynamics, correct ? Has anyone tried mixing Newton physics with fluid physics from A7 ?

Cheers,
Andreas
Posted By: ventilator

Re: newton - 06/23/07 19:34

newton supports buoyancy. you can define a water volume and entities will behave correctly if they fall into it (swim or sink) but there won't be any water effects like waves. you have to care for that yourself.

a7 "fluid dynamics" just jiggles the vertices of a plane a little to make it look like waves. it shouldn't be a problem to mix that with newton.

...
the newton author currently works on multi-core support and looks into nvidia cuda so i could imagine that future newton versions will support stuff like physics enabled particles, cloth, water effects,...
Posted By: BigM

Re: newton - 07/03/07 11:36

Hi again, ventilator!

I'm experiencing some problems using small entities:
I'm using the meter-to-quant conversions you set in your example. I'm simulating a sphere falling down on a surface (treecollision). According to the conversion, the sphere is about 3.7cm in diameter (~1.2 quants). I want the sizes to be as close as possible to the real world, so that the newton simulation is as realistic as possible.

The problem is that, falling from only 20cm high the sphere will pass through the surface. If I time slice it so that newton is updated at least ~45 times per second the sphere will stand on the surface, but fall through when it rolls across an edge of a treecollision polygon. In addition, spheres will not collide with each other nor with other physics entities, even with an absurdly high frequency of update (1024 Hz, which is the maximum my laptop will handle...).

However:

If I set METERTOQUANT and QUANTTOMETER both to 1 I will get the expected result (except for size related differences, such as the need to increase gravitational acceleration). On the other hand, If I maintain the 32 quant per meter ratio, but increase the size of the models, I will get the expected results (same size related differences as above). If I increase model size, but also increase QUANTTOMETER accordingly, the passthroughs will happen again.

Is this a known problem or do you believe it is a bug in my implementation? Maybe centimeter scale simulation is not accurate enough... In that case is it valid to use larger models/acceleration constants/forces... or will it result in unrealistic behaviour?

Thank you!
Posted By: ventilator

Re: newton - 07/03/07 11:59

i don't think it's a problem with newton but you could ask at the newton forum if there is something special to know about small objects in the centimeter range.

you could also try to use the double precision dll instead of the single precision dll. it is included in the newton sdk.

can you post an example for experimenting?

btw. newton clamps updates to the 60..600hz range. if you update with less than 60hz then newton will do sub steps.
Posted By: BigM

Re: newton - 07/04/07 01:29

Hi!

Thanks for the reply.
I tried to use the double precision DLL but it crashed on loading... Are you able to use it? I am using your implementation, with minor changes to newton.c

But,
I checked if the newton.dll you included with the sample was the same as the SDK 1.53 and they differ. Did you use an older one? Anyway, using the new dll solved the problem! (Any clues on why the double precision dll failed?)

Another issue: I'm having a little bit of a problem trying to detect collision between a rotating object (a bat) and a relatively static one (a ball). I am using NewtonBodySetContinuousCollisionMode, as you pointed out earlier (dumb me for not RTFM). However, this function only works with translations, right? So I guess this time I will really have to push the time slices up a notch...

Thank you very much!
Posted By: ventilator

Re: newton - 07/04/07 02:15

i don't know why the double precision dll failed. i guess it has something to do with lite-c since it works with c++. i didn't try it with lite-c yet.

so your problems with small objects are solved now? great! it is very possible that my zip accidentally contains an older (beta?) dll. ...chaos on my hard drive...

Quote:

However, this function only works with translations, right?


i am not sure. you would have to ask on the newton forum.
Posted By: Shadow969

Re: newton - 07/09/07 07:41

ventilator, your script is awesome! Sorry for a silly question, but does it already have support for hinges and joints? If yes, can you please make a small example? i want to move my ragdoll from wdl to lite-c. Thanks for your contribution again!
Posted By: ventilator

Re: newton - 07/09/07 08:11

of course you can add hinges and other joints. there just aren't any examples yet but i will add some once i find time. you could have a look at the official newton tutorials in the meantime.

newton has a special ragdoll joint but i think ragdolls are one of the more complicated things to do.
Posted By: Shadow969

Re: newton - 08/08/07 11:51

cool, i've managed to understand all this coordinate conversion stuff, and succeeded in making joints i'm going to post a simple demo later
Posted By: msl_manni

Re: newton - 08/18/07 04:36

The contribution doesn't works with the latest upgrade of A7 7.05. Please look into it.
Posted By: ventilator

Re: newton - 08/19/07 09:58

the engine uses a different vertex struct now so you have to change

Code:

typedef struct
{
float x, y, z;
float nx, ny, nz;
float tu1, tv1;
float tu2, tv2;
float tu3, tv3, tw3;
} VERTEX;



to

Code:

typedef struct
{
float x, y, z;
float nx, ny, nz;
float tu1, tv1;
float tu2, tv2;
float tx3, ty3, tz3, tw3;
} VERTEX;



to get the loading of collision geometry working.
Posted By: msl_manni

Re: newton - 08/19/07 11:42

Thanks for the speedy solution .
Posted By: ventilator

Re: newton - 10/15/07 13:22

i just wanted to post the new link: http://www.coniserver.net/coni_users/web_users/pirvu/au/demo/zips/litecnewton.zip

...
something about the double precision dll came to my mind. i guess you have to change the dFloat typedef to double in the newton header. probably that's why it crashed.

and here is an interesting article about time slicing: http://www.gaffer.org/game-physics/fix-your-timestep/
(but you don't really need this with the current newton solver since unlike most other physics engines newton doesn't need a fixed timestep to be stable. maybe it could have some slight performance advantages though and reduce small inaccuracies at extreme frame rates. i am not sure.)
Posted By: VeT

Re: newton - 10/17/07 13:17

Quote:


ent_getmesh() works for level geometry too with a7. just pass NULL instead of an entity pointer and loop through all level meshes. but this only works for ABT levels and not for old BSP levels.





Could you give some details at this?
Posted By: ventilator

Re: newton - 10/17/07 13:27

kind of like that (not tested):
Code:
int i = 0;
LPD3DXMESH pmesh = (LPD3DXMESH)ent_getmesh(NULL, i, 0);
while(pmesh)
{

// add the triangles of the mesh to newton here

i++;
pmesh = (LPD3DXMESH)ent_getmesh(NULL, i, 0);
}


Posted By: VeT

Re: newton - 10/18/07 07:48

okay, thanks, i'd try this one...
Posted By: VeT

Re: newton - 10/18/07 13:01

i think that converting blocks to models, registrating them at Newton and deleting after registration is quite faster and easier ;-)
Posted By: ventilator

Re: newton - 10/18/07 13:13

didn't you get it to work? i think it doesn't work with BSP-blocks, only with the new mesh based ABT-levels.

yes, you can use the "export model from WED" method too.
Posted By: VeT

Re: newton - 10/18/07 19:03

now i'm learning "Tutorial 7 Character Controller" official Newton tutorial and trying to make moveable character on lite-c...
if i'd finish that, i think that it could be helpfull ;-)
Posted By: VeT

Re: newton - 10/18/07 21:47

heh...

it write
"Open the file and find the function AddCharacter this function creates a rigid body with a compound collision geometry."

..but there is no any uncommented functions AddCharacter nowhere... looking like unlucky day...
Posted By: VeT

Re: newton - 10/19/07 13:07

can you give the general idea of the "character movement"?
because, as i see, there are a lot of differences between tutorial document and example
Posted By: ventilator

Re: newton - 10/19/07 13:08

you could search the newton forum a bit. i think there are lots of tips about character movement.
Posted By: VeT

Re: newton - 10/19/07 18:03

if enybody would have ideas, wellcome:
http://newtondynamics.com/forum/viewtopic.php?p=27198
Posted By: VeT

Re: newton - 10/21/07 21:03

function player_move()
{
MH.moveFB = (key_pressed(17) - key_pressed(31))*5;
MH.moveLR = (key_pressed(30) - key_pressed(32))*3;
MH.mouseLR = mouse_force.x * 5 * time_step;
MH.mouseUD = mouse_force.y * 5 * time_step;

NewtonBodySetVelocity(MH.NewtonChar, vectorf(vector(MH.moveFB, MH.moveLR, -1)));

****


first time entity bounces, second time it falls down through floor... what happend?
Posted By: ventilator

Re: newton - 10/21/07 21:14

i think if you use setvelocity every frame then you can "press" physics entities through static geometry. better apply forces instead.

setvelocity should only be used for one frame. if you want to shoot an entity in a certain direction for example.
Posted By: Stelynn

Re: newton - 10/21/07 23:29

I downloaded the newton example and tried to run the Lite_c main script but it fails to run because of a error in line 257 of Newton.c file. I changed the typedef struct as was stated in the post for Vertex but it still comes back as a syntax error on 257. I downloaded and am using the latest version of Lite_c. Can you tell me what i am doing wrong. The newton application that is compiled runs fine.
Posted By: VeT

Re: newton - 10/22/07 10:45

and what is the better way of using forces?
simple NewtonBodyAddForce dont works...
Posted By: ventilator

Re: newton - 10/22/07 10:51

stelynn, i think you use the old version of the scripts.
this demo comes with newer scripts and they should work:
http://www.coniserver.net/coni_users/web_users/pirvu/au/demo/zips/litecnewton.zip

NewtonBodyAddForce() only should be used in the forceandtorque callback.
Posted By: Sam_Be

Re: newton - 10/23/07 06:39

hi cold somebody please write here the final code please?? thx
Posted By: VeT

Re: newton - 10/23/07 13:46

look at ventilator's sign

http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/730904/page/0/fpart/3/vc/1
Posted By: VeT

Re: newton - 10/23/07 16:16

okay, looking like working... :-)
now, question about upVector

when i add
Code:
  
NewtonJoint* m_upVector;
m_upVector = NewtonConstraintCreateUpVector (nworld, vector(0,1,0), MH.NewtonChar);


, model falls down through floor...
Posted By: Shadow969

Re: newton - 10/23/07 19:48

hey VeT
looks like you've defined a hinge wrong, if i remember correct you have to convert vector somehow. You may check my hinges example
Posted By: VeT

Re: newton - 10/24/07 07:17

greetings :-D
okay, i'd look to your example
Posted By: ventilator

Re: newton - 10/29/07 17:33

sometimes the question comes up how to do phent_addforceglobal()/phent_addforcelocal() with newton.

here is a short (untested) code snippet:
Code:
newton_bodyaddforceglobal(NewtonBody *body, VECTOR *force, VECTOR *point) // add force at point in global coordinate system
{
ENTITY *entity = (ENTITY*)NewtonBodyGetUserData(body);
VECTOR r, torque;
vec_diff(r, point, entity->x);
vec_cross(torque, r, force);
NewtonBodyAddForce(body, force);
NewtonBodyAddTorque(body, torque);
}

newton_bodyaddforcelocal(NewtonBody *body, VECTOR *force, VECTOR *point) // add force at point in entity coordinate system
{
ENTITY *entity = (ENTITY*)NewtonBodyGetUserData(body);
VECTOR globalforce, globalpoint;
vec_set(globalforce, force);
vec_set(globalpoint, point);
vec_rotate(globalforce, entity->pan);
vec_rotate(globalpoint, entity->pan);
vec_add(globalpoint, entity->x);
newton_bodyaddforceglobal(globalforce, globalpoint);
}



i think lite-c still doesn't come with a vec_cross() function so you have to do one yourself.

(...and i guess you also should apply QUANTTOMETER in those functions.)
Posted By: Stelynn

Re: newton - 10/29/07 19:48

Has anyone tried to set up a Material system and implement a water block.
Posted By: Shadow969

Re: newton - 10/29/07 20:06

i tried materials way back, but some newton function crashed all the time. maybe i'll try again later
Posted By: VeT

Re: newton - 10/31/07 19:08

and what about NewtonBodyGetVelocity?
in debug panel, there are always zeros... so i tried

NewtonBodyGetVelocity(MH.NewtonChar,vectorf(temp_vec2.x,temp_vec2.y,temp_vec2.z));
NewtonBodySetVelocity(MH.NewtonChar,vectorf(temp_vec2.x,temp_vec2.y,temp_vec2.z));

primary, this code mustnd do anything... but in real this works like
NewtonBodySetVelocity(MH.NewtonChar,vectorf(nullvector));

so, how can i get the speed of entity?
Posted By: ventilator

Re: newton - 10/31/07 19:15

vectorf() doesn't make sense for getvelocity since it just returns a temporary pointer which you can't really access afterwards.

try this:

float velocity[3];
NewtonBodyGetVelocity(MH.NewtonChar, velocity);
temp_vec2.x = velocity[0];
temp_vec2.y = velocity[1];
temp_vec2.z = velocity[2];
Posted By: VeT

Re: newton - 10/31/07 19:26

yeah, thanks, that's it :-)
Posted By: VeT

Re: newton - 11/01/07 20:15

what is the better way to clamp two objects, so they couldnt move?
may i use joints, compound collision, or just simple positions?

for example, i need to mount car carcass from two parts: down, that is more heavier, and top, wich is lighter

or the better way is to make one entity and use NewtonBodySetMassMatrix?
Posted By: ventilator

Re: newton - 11/01/07 20:50

if you are only interested in the center of mass then you can just offset the center of mass. if you would also like to have more accurate (concave) collision geometry for your car then you can use a compound collision object.
Posted By: VeT

Re: newton - 11/03/07 21:43

okay... i get

MH.keyX = (key_pressed(17) - key_pressed(31));
MH.keyY = (key_pressed(30) - key_pressed(32));
if (MH.keyX!=0 && MH.keyY!=0) { MH.keyX*=.5; MH.keyY*=.5;}

and

vec_set(temp_vec,vector(MH.keyX*100, MH.keyY*100,-mass*5));
vec_rotate(temp_vec,MH.model.pan);
NewtonBodySetForce(MH.NewtonChar,vectorf(temp_vec.x,temp_vec.y,temp_vec.z));

// damping
NewtonBodySetLinearDamping (MH.NewtonChar, 0.9);

// rotating
NewtonBodySetOmega(MH.NewtonChar, vectorf(0,0,-MH.mouseX*5));
Posted By: VeT

Re: newton - 11/03/07 21:44

okay... i get

MH.keyX = (key_pressed(17) - key_pressed(31));
MH.keyY = (key_pressed(30) - key_pressed(32));
if (MH.keyX!=0 && MH.keyY!=0) { MH.keyX*=.5; MH.keyY*=.5;}

and

vec_set(temp_vec,vector(MH.keyX*100, MH.keyY*100,-mass*5));
vec_rotate(temp_vec,MH.model.pan);
NewtonBodySetForce(MH.NewtonChar,vectorf(temp_vec.x,temp_vec.y,temp_vec.z));

// damping
NewtonBodySetLinearDamping (MH.NewtonChar, 0.9);

// rotating
NewtonBodySetOmega(MH.NewtonChar, vectorf(0,0,-MH.mouseX*5));



when i'm pressing W, body is going strait ahead... when i'm pressing W and A, body moves ahead-left... when i'm pressing A, body still move somwhere ahead, not left

what it could be?
Posted By: BigM

Re: newton - 11/04/07 01:46

Hi all,

some small issues:

1- with A7.05 I know the coordinate set 3 in the D3DVERTEX struct should have 4 coordinates. However, adding the 4th coordinate completely messes up the treecollision generation. Without the 4th coordinate, all is well (I can even use the 'old' newton.c script by modifying only 'VERTEX' to '_VERTEX_'). Any clues on why this occurs?

2- I tried using the double precision newton.dll but it failed with a 'crash in main' error, even though I typedefined dFloat as double in the newton header. Should other float variables in the script be changed to double as well? Despite the crash, defining dFloat as a double did have an effect: some entities loaded only after newton_start() became visible, whereas a crash would occur earlier if dFloat was typedefined as a float.

Thanks ventilator for your effort on this!
Posted By: BigM

Re: newton - 11/04/07 03:42

Hi again ventilator,

Another small question: I'd like to implement a sphere with rolling friction, using a DryRollingFriction joint, which is a custom joint that 'ships' with the Newton SDK. Is there a straightforward way to import it to GS? I tried, unsuccessfully, to include "CustomDryRollingFriction.cpp" but ran into many more include dependencies and gave up.

I though you'd be the right person to ask this since you made that great pool game with rolling friction.

Thanks
Posted By: ventilator

Re: newton - 11/04/07 16:16

1. the vertex struct changed with 7.05.1. are you sure your engine version isn't older? i don't have any other explanation.

2. i haven't tried the double precision dll with lite-c myself yet. i would have to experiment with this. but since the double precision dll works with other compilers it must be some issue on the lite-c side. i think lite-c automatically casts floats to double when needed but i am not sure. you could try to directly use doubles for everything.

3. my pool game uses the old gamestudio plugin and there julio jerez added the dryrollingfriction for me. for lite-c you have to adapt the custom joint example.

@vet: i am not sure what you want to achieve.
Posted By: VeT

Re: newton - 11/04/07 17:20

i mean, does somebody tried to move character in way, like my

for example, maybe i need to set forces at 0 every frame, or change damping...
Posted By: ventilator

Re: newton - 11/04/07 17:25

i don't have that much experience with moving characters around with a physics engine since my projects most of the time don't contain any characters. but i would look on the newton forum. i think there are many threads about doing character movement or you could start a new one.
Posted By: VeT

Re: newton - 11/04/07 17:44

here's very simple one... but i dont understand, why body dont moves to left...
Posted By: ventilator

Re: newton - 11/04/07 17:51

omega is the angular velocity. i wouldn't set that. i would try to apply a torque. but i don't really see what's wrong with your example. maybe you can show a simple demo.
Posted By: VeT

Re: newton - 11/04/07 17:55

Quote:

with moving characters



i can say, l'm just moving simple objects, called character ;-)))
Posted By: VeT

Re: newton - 11/04/07 18:17

okay, here it is

Code:
 void MHonforceandtorque(NewtonBody* body)
{
float mass, ixx, iyy, izz;
NewtonBodyGetMassMatrix(body, &mass, &ixx, &iyy, &izz);
NewtonBodySetAutoFreeze (MH.NewtonChar, 0);

vec_set(temp_vec,vector(MH.keyX*100, MH.keyY*100,-mass*5));
vec_rotate(temp_vec,MH.model.pan);
NewtonBodySetForce(MH.NewtonChar,vectorf(temp_vec.x,temp_vec.y,temp_vec.z));

// damping
NewtonBodySetLinearDamping (MH.NewtonChar, 0.9);

// rotating
NewtonBodySetOmega(MH.NewtonChar, vectorf(0,0,-MH.mouseX*5));

// // speed limit
NewtonBodyGetVelocity(MH.NewtonChar, velocity);
temp_vec2.x = velocity[0];
temp_vec2.y = velocity[1];
temp_vec2.z = velocity[2];
// NewtonBodySetVelocity(MH.NewtonChar,vectorf(temp_vec2.x,temp_vec2.y,temp_vec2.z));

}

function player_init()
{
// MH.model = me;
MH.handler = handle(MH.model);
MH.NewtonChar = newton_addentity(MH.model, 10, NEWTON_SPHERE, MHonforceandtorque);

NewtonBodySetMassMatrix (MH.NewtonChar, 10.0, 10.0, 10.0, 10.0);

NewtonBodySetAngularDamping (MH.NewtonChar, vector(100,100,100));
}






PS:i use omega to move entity exactly as mouse moves ;-)
Posted By: ventilator

Re: newton - 11/04/07 18:36

some things i noticed:
- the mass matrix already gets set in newton_addentity().
- be careful with vector()/vectorf(). newton doesn't work with vars.
- i think if your "character" is a rolling sphere then it doesn't really make sense to rotate your steering force like that. or does setomega block all rotation?

it's hard to say... maybe someone else has ideas.
Posted By: VeT

Re: newton - 11/04/07 18:49

thanks!

1) i played with matrix, because i need to make low center of mass
2) i'd look, where sphere points, but i dont think that this is the main problem

i set angular velocity just for normal reaction at mouse... if i'd use angular force, entity would rotate for too large angle
Posted By: VeT

Re: newton - 11/04/07 19:40

debug shows that sphere looks in right position...
red line is looking straight ahead, so problem isnt here

so, i'd try to explain problem more exactly:
- i press W, body moves forward...
- if i allow body to stop, and then press A, body strafes normal
- BUT if i dont allow it(for example, press W, press A, unperss W), body moves forvard-left... it's looks like forward force still working, but
Code:

vec_set(temp_vec,vector(MH.keyX*100, MH.keyY*100,-mass*5));


and MH.keyX = (key_pressed(17) - key_pressed(31));

so, force =0, if W isnt pushed...
thats main trouble :-(

anyway, ventilator, thank you very much for help... i'd add you to credits :-D
Posted By: VeT

Re: newton - 11/06/07 16:44

new trouble :-(
F11 shows 100-110 FPS, but entity moves looking like there are only 5-10 FPS... does everyone have the same problem?
Posted By: ventilator

Re: newton - 11/06/07 18:50

no, i don't have the "looks like 10fps" problem. i am out of ideas. maybe someone can help if you give a clear description of what you want to achieve and provide a small test level so that we see the problem and can experiment.
Posted By: VeT

Re: newton - 11/06/07 20:05

i found that i get this bug only at my machine... plus i get idea, what to do with "W+A"
Posted By: VeT

Re: newton - 11/17/07 18:56

okay, i deal with almost all problems... but still dont have and ideas about upvector

can somebody give a working example of this: my always falls down through the floor
Posted By: VeT

Re: newton - 11/18/07 13:04

i dont know, what it was, but now it's working


NewtonJoint* upVector;
upVector = NewtonConstraintCreateUpVector (nworld, vectorf(0,0,QUANTTOMETER) , MH.NewtonChar);


what about rotating upvector in litec?
how can i get and set point?
NewtonUpVectorGetPin(FF.upVector,temp_vec2); always returns error
any ideas?
Posted By: BigM

Re: newton - 11/20/07 18:35

Hey, look what I found out!
http://www.coniserver.net/ubbthreads/showflat.php?Cat=0&Board=AUM&Number=791033

Way to go ventilator!

Cheers!
Posted By: sheefo

Re: newton - 11/27/07 17:38

Has anyone used 'NewtonAddBodyImpulse' yet?

Can someone show me how to use it?
Posted By: VeT

Re: newton - 11/27/07 22:38

i asked that on official forum... waiting for answer)

http://newtondynamics.com/forum/viewtopic.php?t=4069&sid=d74df381977a31527182ae0f31855df2
Posted By: Slin

Re: newton - 12/22/07 15:20

Thank you very much for the efforts to get Newton working with Lite-C, ventilator . It is just awsome.

I have some problems with the collision and you wrote that it should help to turn the continious collision on. But I canīt find something like that?
So, how to do that?

Thanks a lot!


Edit: I found out how to do it but it doesnīt help with my problems...
I have a problem with an Object pushing an other through a wall.
Any Ideas on how to solve that?
Posted By: ventilator

Re: newton - 12/29/07 14:45

how does the object get pushed through the wall? maybe you wrongly build up extreme forces (for example by setting the velocity each frame)?

...
did you get NewtonAddBodyImpulse() working now?

...
btw. i think the new newton version isn't that far away anymore. it will be great. it will be much faster (stacking hundreds of bodies won't be a problem anymore) and there will be new stuff like an easier to use vehicle joint and character controller.
Posted By: Slin

Re: newton - 12/29/07 15:29

Quote:

how does the object get pushed through the wall? maybe you wrongly build up extreme forces (for example by setting the velocity each frame)?




If I throw an object on the book or on the plate, they get pushed through the table.
This is the function for throwing:
Code:

void DebugThrow(char* FileName)
{
NewtonBody *body;
ENTITY* Temp_ent = 0;

while(1)
{
while(!mouse_left){wait(1);}

if(Temp_ent)
{
NewtonDestroyBody(nworld, body);
ent_remove(Temp_ent);
Temp_ent = NULL;
}

Temp_ent = ent_create(FileName,camera.x,NULL);
vec_scale(Temp_ent.scale_x,0.3);
body = newton_addentity(Temp_ent, 3, NEWTON_BOX, onforceandtorque);
VECTOR v;
vec_set(v, vector(20, 0, 0));
vec_rotate(v,camera.pan);
NewtonBodySetVelocity(body, vectorf(v.x,v.y,v.z));

while(mouse_left){wait(1);}
wait(1);
}
}


onforceandtorque is the same function you used in your example.

This is he scene where I use newton:


Quote:


btw. i think the new newton version isn't that far away anymore. it will be great. it will be much faster (stacking hundreds of bodies won't be a problem anymore) and there will be new stuff like an easier to use vehicle joint and character controller.



That sounds awsome! That should be a good reason to visit their webpage a bit more often The clips I remember were great

Thanks for your time and help
Posted By: VeT

Re: newton - 01/26/08 16:45

no, i still dont get Impulse to work

could you give me exapmle?
Posted By: ello

Re: newton - 01/30/08 21:05

hi here..
i just tried to get newton involved, but of course i failed. i tried to adapth the code from the litecnewton demo but the engine crashes as soon as i try to create a physics entity

this is how i start the code
Code:

#include <acknex.h>
#include <default.c>
#include <d3d9.h>

// newton works with meters!
// 1 meter = 32 quants
float QUANTTOMETER = 0.03125;
float METERTOQUANT = 32;

#include "newton.h"
#include "matrix.c"
#include "newton_main.c"
#include "newton_debug.c"

void onforceandtorque(NewtonBody* body)
{
float mass, ixx, iyy, izz;
NewtonBodyGetMassMatrix(body, &mass, &ixx, &iyy, &izz);
NewtonBodySetForce(body, vectorf(0, 0, -9.8 * mass));
}



this is the code for the entity to be created:
Code:

void erdbeere()
{
my.pan = random(360);
my.tilt = random(60)-30;
my.roll = random(60)-30;
c_updatehull(me,0);
set(my,POLYGON|FLAG2);
while(my.z>-50)
{
wait(1);
}
ent_remove(me);
}



this is how i create the entity:
Code:

you = ent_create("erdbeere.mdl",vector(my.x,my.y,900),kugel);
NewtonBody *body = newton_addentity(you, 10, "convex hull", onforceandtorque); // register entity as physics entity
NewtonBodySetVelocity(body, vectorf(0,0,-100));



and in the main function i have this, which creates a grid of floorparts and starts newton.
Code:

var i,j;
for (i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
you = ent_create("ground_box.mdl",vector(128*(i-5)+64,128*(j-5)+64,0),checkField);
you->flags |= FLAG8;
}
}

newton_start();
on_close = quit;



as soon as i call the entity creating function the engine crashes. any ideas whats my fault here?
Posted By: ventilator

Re: newton - 01/30/08 21:13

i think it happens because you pass a string as collision type. the function needs an integer (use the NEWTON_CONVEXHULL define).

it's a bit annoying that lite-c doesn't give more useful error messages in such cases.



Quote:

no, i still dont get Impulse to work

could you give me exapmle?




Code:
void create_sphere()
{
you = ent_create("ball.mdl", vector(100, 100, 200), NULL);
NewtonBody *body = newton_addentity(you, 10, NEWTON_SPHERE, 0);
NewtonAddBodyImpulse(body, vectorf(0, 0, 10), vectorf(you.x * QUANTTOMETER, you.y * QUANTTOMETER, you.z * QUANTTOMETER));
}

void create_sphere_startup()
{
on_p = create_sphere;
}

this works for me. maybe you forgot to add the QUANTTOMETER conversion (i first forgot this when i wrote this example)?

the first vector is the wanted change in velocity, the second vector is the point in global space where the impulse should be applied.
Posted By: ello

Re: newton - 01/31/08 18:41

thank you so much!! now it works... great

i am so happy that i have polygon collisions now. thats absolutely great!
Posted By: ello

Re: newton - 01/31/08 18:52

i have one question left (maybe not the last) but when i remove the entity, i guess i have to remove it from newton, too?? how do i do this?
Posted By: ventilator

Re: newton - 01/31/08 19:03

NewtonDestroyBody()

you additionally could use NewtonBodySetDestructorCallback() to set a function which gets called when you use NewtonDestroyBody(). in the callback you could do the ent_remove() and other cleanup things if necessary.
Posted By: ello

Re: newton - 01/31/08 19:12

now my function looks like this:
Code:

void erdbeere()
{
NewtonBody *body;
c_updatehull(me,0);
set(my,POLYGON|FLAG2);
while(my.z>-50)
{
wait(1);
}
NewtonDestroyBody(nworld, body);
// ent_remove(me);
}



this however leads to an engine crash with no further explanation

btw, how do i setup such a Callback? Never did this before
Posted By: ventilator

Re: newton - 01/31/08 19:31

hm... in your function you don't create the body? newtondestroybody() will crash if you don't pass a valid body.



you know how callbacks work from ent_create() for example.

function mycallback()
{
}

ent_create("model.mdl", nullvector, mycallback);

it's just a normal function. the pointer of this function gets passed to ent_create() and ent_create() will call that function then.

many newton features also work with callbacks.
Posted By: ello

Re: newton - 01/31/08 19:39

oh, thanks.. i now use this function and it works:
Code:

void erdbeere()
{
NewtonBody *body = newton_addentity(me, 10, NEWTON_CONVEXHULL, onforceandtorque);
NewtonBodySetVelocity(body, vectorf(0,0,-5));
c_updatehull(me,0);
set(my,POLYGON|FLAG2);
while(my.z>20)
{
wait(1);
}
NewtonDestroyBody(nworld, body);
ent_remove(me);
}



thanks again for your help
Posted By: ello

Re: newton - 01/31/08 20:06

me again...

now i want to add a random force or torque to the entity and was using this:


NewtonBodyAddForce(body, vectorf(random(100)-50,random(100)-50,random(100)-50));

or

NewtonBodyAddTorque(body, vectorf(random(100)-50,random(100)-50,random(100)-50));

but nothing changes. also i dont get the idea about how to have the entity with a certain start rotation

ok, now i used NewtonBodySetOmega and that works. Guess i'll search for a general newton manual now
Posted By: VeT

Re: newton - 02/01/08 12:35

yes, thanks very much ))
i really forgot about QUANTTOMETER
Posted By: VeT

Re: newton - 02/02/08 21:00

that works just great!!!

Code:
 
if (c_trace(camera.x, temp_vec.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_PASSENTS) > 0)
{
if (you.skill99!=0)
{
vec_for_vertex(temp_vec.x,you,hitvertex);
body_temp=you.skill99;
NewtonAddBodyImpulse(body_temp, vectorf(-normal.x,-normal.y,-normal.z) , vectorf(temp_vec.x * QUANTTOMETER, temp_vec.y * QUANTTOMETER, temp_vec.z * QUANTTOMETER) );
}



but box is rotating only in right side... i dont think that its famous error, but maybe you get this before?
Posted By: ventilator

Re: newton - 02/02/08 21:21

please explain what you want to achieve in more detail.
Posted By: VeT

Re: newton - 02/02/08 23:12

i'd try to explain as understandable as possible

i have box (top view)
++++
++++
++++
++++


when i shoot near left corner, box is moving by clock
->
++++
++++
++++
^+++


but when i shoot near right corner, box may move in another side, but he is still moving by clock
->
++++
++++
++++
+++^

maybe, this is trouble with mass matrix or someting like that?
Posted By: ventilator

Re: newton - 02/02/08 23:30

try to use the trace direction instead of vectorf(-normal.x,-normal.y,-normal.z).

(and the origin of the model should be in the center of the cube.)
Posted By: VeT

Re: newton - 02/03/08 10:52

i had tried that
Code:
 
vec_diff(temp_vec2.x,temp_vec.x,camera.x); // temp_vec2 from camera to target
vec_normalize(temp_vec2.x,1); // lenth of temp_vec2 = 1
NewtonAddBodyImpulse(body_temp, vectorf(temp_vec2.x,temp_vec2.y,temp_vec2.z),
vectorf(temp_vec.x * QUANTTOMETER, temp_vec.y * QUANTTOMETER, temp_vec.z * QUANTTOMETER) );



but the effect is similar

and the origin of model if exactly in the center(just because its your model crate.mdl )
Posted By: VeT

Re: newton - 02/03/08 18:42

i have idea....

for example, i have box:
[++++++++++++++++++++^++++++++]

so i may count distance from "^" to "]"... and add to vertex not all force, just a part of it... but, on the other hand, its not too important...
Posted By: VeT

Re: newton - 02/05/08 21:26

okay, that's really not too important:)
thanks)))
Posted By: VeT

Re: newton - 02/05/08 21:58

okay, going to materials...

so i have bullet
Code:
 
you = ent_create(bullet_mdl,my.x,0);
you.scale_x=.5; you.scale_y=.25; you.scale_z=.25;
vec_set(you.pan,my.pan);
you.skill99 = newton_addentity(you, 1, NEWTON_SPHERE, Bulletforceandtorque);
NewtonBodySetMaterialGroupID(you.skill99,bullet_nmat);



and box

Code:
 
action box_weapon_test()
{
c_setminmax(me);
my.skill99 = newton_addentity(me, 15, NEWTON_BOX, onforceandtorque);
NewtonBodySetMaterialGroupID(my.skill99,box_nmat);
}



and collision

Code:
 
NewtonMaterialSetCollisionCallback(nworld, bullet_nmat, box_nmat, 0, collided_ground, collided_ground2, collided_ground3);
NewtonMaterialSetDefaultCollidable(nworld, bullet_nmat, box_nmat, 1);



collided_ground - just beeps 1,2 and 3 times



so, bullet collides with box and nothing changes and beeps...
Posted By: ventilator

Re: newton - 02/05/08 22:03

i don't understand. when does it beep and when doesn't it beep? can you also show your callbacks?
Posted By: VeT

Re: newton - 02/05/08 22:57

hm... some materials are beeping, other - are not... i'd try to search solution in practical way and i'd write here, as i will get interesting results...

Quote:

when does it beep and when doesn't it beep?



it may beep all time, but sometimes(using different pairs of materials) i have no sound at all
Posted By: VeT

Re: newton - 02/05/08 23:23

i find!

Code:
 my.skill99 = newton_addentity(me, 15, NEWTON_BOX, onforceandtorque);
NewtonBodySetMaterialGroupID(my.skill99,box_nmat);



this is bad one...


Code:
 
NewtonBodySetMaterialGroupID(newton_addentity(you, 1, NEWTON_SPHERE, Bulletforceandtorque),bullet_nmat);


this wokrs
Posted By: ventilator

Re: newton - 02/05/08 23:31

hm... probably it's some lite-c quirk with how the pointer gets converted to the var skill. you could try to cast the pointer somehow. or use your method that works.
Posted By: VeT

Re: newton - 02/06/08 16:20

i decide to stop at this variant:

Code:
 
NewtonBody* body_temp;

*****

body_temp=newton_addentity(my, 15, NEWTON_SPHERE, MHforceandtorque);
NewtonConstraintCreateUpVector (nworld, vectorf(0,0,QUANTTOMETER), body_temp);
NewtonBodySetMaterialGroupID(body_temp, player_nmat);


Posted By: SilentDemon

Re: newton - 02/25/08 07:14

hi
any body can tell me where i can find DOWNLOAD link for this Dll ?
there is a link in forum ... but seems it demolished(ow)

so . if anyone can get it for me please hurry( )
thnx
Posted By: VeT

Re: newton - 02/26/08 20:30

here it is
http://www.coniserver.net/coni_users/web_users/pirvu/au/demo/zips/litecnewton.zip
Posted By: VeT

Re: newton - 02/27/08 11:03

ventilator, why did you wrote
Code:
 NewtonTreeCollisionEndBuild(treecollision, 0); 


not the
Code:
  NewtonTreeCollisionEndBuild(treecollision, 1); 


Posted By: VeT

Re: newton - 02/27/08 11:25

so i changed your newton_addstaticcollisiongeometry() to

Code:
 
void newton_addstaticcollisiongeometry()
{
NewtonCollision* treecollision = NewtonCreateTreeCollision(nworld, 0);
NewtonTreeCollisionBeginBuild(treecollision);

you = ent_next(0);
while(you != 0)
{
if(you.flags & FLAG8)
{
newton_treecollisionaddentity(treecollision, you);
}
you = ent_next(you);
}

int i = 0;
LPD3DXMESH pmesh = (LPD3DXMESH)ent_getmesh(NULL, i, 0);
while(pmesh)
{
// add the triangles of the mesh to newton here
int numvertices = pmesh->GetNumVertices();
int numfaces = pmesh->GetNumFaces();

_VERTEX_ *pvertices; pmesh->LockVertexBuffer(0, (void**)&pvertices);
short *pindices; pmesh->LockIndexBuffer(0, (void**)&pindices);
int *pattributes; pmesh->LockAttributeBuffer(0, &pattributes);

D3DXVECTOR4 *ptransformedvertices = (D3DXVECTOR4*)malloc(sizeof(D3DXVECTOR4) * numvertices);
D3DXMATRIX m; ent_getmatrix(pmesh, &m);
D3DXVECTOR3 tempvector;
int i;
for(i = 0; i < numvertices; i++)
{
tempvector.x = pvertices[i].x;
tempvector.y = pvertices[i].z;
tempvector.z = pvertices[i].y;
D3DXVec3Transform(&ptransformedvertices[i], &tempvector, &m);
}

for(i = 0; i < numfaces; i++)
{
float v[9];
v[0] = ptransformedvertices[pindices[(i*3)+2]].x * QUANTTOMETER;
v[1] = ptransformedvertices[pindices[(i*3)+2]].y * QUANTTOMETER;
v[2] = ptransformedvertices[pindices[(i*3)+2]].z * QUANTTOMETER;
v[3] = ptransformedvertices[pindices[(i*3)+1]].x * QUANTTOMETER;
v[4] = ptransformedvertices[pindices[(i*3)+1]].y * QUANTTOMETER;
v[5] = ptransformedvertices[pindices[(i*3)+1]].z * QUANTTOMETER;
v[6] = ptransformedvertices[pindices[(i*3)+0]].x * QUANTTOMETER;
v[7] = ptransformedvertices[pindices[(i*3)+0]].y * QUANTTOMETER;
v[8] = ptransformedvertices[pindices[(i*3)+0]].z * QUANTTOMETER;
NewtonTreeCollisionAddFace(treecollision, 3, v, 12, pattributes[i]);
}


free(ptransformedvertices);

pmesh->UnlockVertexBuffer();
pmesh->UnlockIndexBuffer();
pmesh->UnlockAttributeBuffer();

i++;
pmesh = (LPD3DXMESH)ent_getmesh(NULL, i, 0);
}


NewtonTreeCollisionEndBuild(treecollision, 0);
NewtonBody* level = NewtonCreateBody(nworld, treecollision);
NewtonReleaseCollision(nworld, treecollision);

NewtonSetWorldSize(nworld, vectorf(-1000, -1000, -1000), vectorf(1000, 1000, 1000)); // todo: make size dependent on tree collision bounding box
}



but blocks are still ignored... maybe i forget something?...
Posted By: ventilator

Re: newton - 02/27/08 19:24

http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/813785/an/0/page/1#Post813785
Posted By: VeT

Re: newton - 02/28/08 22:34

thats it
Posted By: VeT

Re: newton - 03/16/08 14:07

ventilator, do you have good-working level with newton and blocks?
Posted By: ventilator

Re: newton - 03/16/08 15:05

no, i didn't use level geometry so far because the map compiler and light mapper didn't work properly for meshes anyway so i just kept using models. once the map compiler works and does nice light maps i will try it.
Posted By: VeT

Re: newton - 03/16/08 17:58

but what are you thinking about Gamestudio's "optimising": when you not looking at entity(but still looking at the shadow), its dissappears with its shadow?
Posted By: ventilator

Re: newton - 03/16/08 19:10

do you mean stencil shadows?
Posted By: VeT

Re: newton - 03/17/08 20:06

aha

looking like this




Posted By: VeT

Re: newton - 03/28/08 17:25

so, what about shadows(read: about models VS blocks)?
Posted By: ventilator

Re: newton - 03/28/08 17:35

i am not sure what i see there on the screenshots? do you mean that if a model gets out of the view frustum its stencil shadows disappear even if they still are supposed to be visible?

i don't use stencil shadows. they have other problems too not only that one. for static shadows on models i use my plugin and in the future i will use realtime shadow mapping. (i already have a working pssm implementation. it just needs some improvements like filtering.)
Posted By: croman

Re: newton - 05/09/08 16:10

does this newton lite-c code supports vehicle physics?
Posted By: ventilator

Re: newton - 05/09/08 17:23

yes, there is no vehicle example but the vehicle joint is there. you could look into the offical newton tutorials to figure out how it works.
Posted By: croman

Re: newton - 05/09/08 17:35

oh great. i worked with vehicles with old a6 newton plugin and before couple of months i started using lite-c so...thanks

and BTW, what are you planning to do more on this newton lite-c?

??? QUESTION...when i tried to put two newton vehicles back on a6 (before) they didn't collided with each other. do you know maybe why?
Posted By: croman

Re: newton - 05/09/08 22:20

i don't know what to put under upDir...???
NewtonConstraintCreateVehicle (const NewtonWorld* newtonWorld, const dFloat* upDir, const NewtonBody* body);


my code goes...
...
car = ent_create("car.mdl", camera.x, NULL);
NewtonBody *car_body = newton_addentity(car, 10, NEWTON_CONVEXHULL, onforceandtorque);
car_body = NewtonConstraintCreateVehicle (n_world, ""0"", car);
...

can someone please help? with what should i replace ""0"" part of my code???
Posted By: VeT

Re: newton - 05/09/08 23:07

you may ask at official forum - man from there primary makes racing-games, so they can help you
Posted By: croman

Re: newton - 05/11/08 10:19

no,no...that ""0"" must be replaced with "const dFloat* upDir".

NEWTON_API NewtonJoint* NewtonConstraintCreateVehicle (const NewtonWorld* newtonWorld, const dFloat* upDir, const NewtonBody* body);

that says in newton.c from ventilator. now i don't understand what type is const dFloat* updir,..what's that?
Posted By: ventilator

Re: newton - 05/11/08 10:59

it's an array/vector of 3 floats like that:
float updir[3] = {0.0, 0.0, 1.0};
Posted By: croman

Re: newton - 05/11/08 11:07

nope, still not working. engine shuts down every time...

here's my code:::

// add world geometry
n_world = ent_create("newton_playground.mdl", nullvector, NULL);
n_world->flags |= FLAG8; // flag8 -> will be added to world collision geometry

newton_start();
on_close = quit;
on_space = drop_it;

const float updir[3] = {0.0, 0.0, 9.8};

car = ent_create("car.mdl", vector(100,200,500), NULL);
NewtonBody *car_body = newton_addentity(car, 80, NEWTON_CONVEXHULL, onforceandtorque);
car_joint = NewtonConstraintCreateVehicle (n_world, &updir[0], car_body);
Posted By: croman

Re: newton - 05/13/08 13:54

anyone?
Posted By: ventilator

Re: newton - 05/13/08 14:42

the updir is supposed to be a unit vector (0,0,1) but it's unlikely that that would cause a crash.

did you look at the official newton examples for creating vehicles and try to do it similarly?

can you post you whole vehicle code (also the tires)?
Posted By: croman

Re: newton - 05/13/08 14:56

that's the problem. i didn't get so far. currently i'm trying to make my model be vehicle joint

[code]
#include <acknex.h>
#include <default.c>
#include <d3d9.h>

// newton works with meters!
// 1 meter = 32 quants
float QUANTTOMETER = 0.03125;
float METERTOQUANT = 32;

#include "newton.h"
#include "matrix.c"
#include "newton_main.c"
#include "newton_debug.c"


ENTITY* n_world;
//ENTITY* car_body;
ENTITY* car;
ENTITY* cam_ctrl;
//ENTITY* car_joint;

//--------------------------------------------------------------------------------------- onforceandtorque()
// callback which applies gravity to active physics entities
//---------------------------------------------------------------------------------------
void onforceandtorque(NewtonBody* body)
{
float mass, ixx, iyy, izz;
NewtonBodyGetMassMatrix(body, &mass, &ixx, &iyy, &izz);
NewtonBodySetForce(body, vectorf(0, 0, -9.8 * mass));
}

//--------------------------------------------------------------------------------------- quit()
// gets called when the engine closes
//---------------------------------------------------------------------------------------
void quit(){newton_stop();}
function camera_upd();

function drop_it()
{
you = ent_create("car.mdl", camera.x, NULL);
you->pan += camera->pan;
NewtonBody *body = newton_addentity(you, 10, NEWTON_CONVEXHULL, onforceandtorque);
}

function main()
{
fps_max = 120;
video_mode = 8;
//video_screen = 1;

wait(3);
level_load(""); // use an empty level
wait(3);

vec_set(&sun_angle, vector(300, 30, 0));
vec_set(&camera->x, vector(0, 0, 500)); // camera start position
camera_upd();

// add world geometry
n_world = ent_create("newton_playground.mdl", nullvector, NULL);
n_world->flags |= FLAG8; // flag8 -> will be added to world collision geometry

newton_start();
on_close = quit;
on_space = drop_it;

const float updir[3] = {0.0, 0.0, 9.8};

car = ent_create("car.mdl", vector(100,200,500), NULL);
NewtonBody *car_body = newton_addentity(car, 80, NEWTON_CONVEXHULL, onforceandtorque);
NewtonJoint *car_joint = NewtonConstraintCreateVehicle (n_world, &updir[0], car_body);
}


function camera_upd()
{
VECTOR cam_move;
cam_ctrl = ent_create("ball.mdl", vector(0,0,300), NULL);
set(cam_ctrl, INVISIBLE | PASSABLE);

while(1){
cam_move.x = (key_w - key_s) * 40 * time_step;
cam_move.y = (key_a - key_d) * 30 * time_step;

c_move(cam_ctrl, cam_move, nullvector, NULL);

cam_ctrl.tilt += mouse_force.y * 15 * time_step;
cam_ctrl.pan -= mouse_force.x * 15 * time_step;

vec_set(camera.x, cam_ctrl.x);
camera.tilt = cam_ctrl.tilt;
camera.pan = cam_ctrl.pan;

wait(1);
}
}
[code/]
Posted By: VeT

Re: newton - 05/13/08 19:54

body_temp=newton_addentity(my, -35, NEWTON_BOT, MHforceandtorque);
NewtonConstraintCreateUpVector (nworld, vectorf(0,0,QUANTTOMETER), body_temp);


maybe this could help you
Posted By: ventilator

Re: newton - 05/13/08 20:05

Code:
void create_vehicle()
{
	ENTITY* car = ent_create("crate.mdl", vector(0, 0, 500), NULL);
	NewtonBody *car_body = newton_addentity(car, 80, NEWTON_CONVEXHULL, onforceandtorque);
	NewtonJoint *car_joint = NewtonConstraintCreateVehicle (nworld, vectorf(0, 0, 1), car_body);
}


this doesn't crash for me. my guess is that your n_world pointer is wrong.
Posted By: VeT

Re: newton - 05/14/08 08:30

i got upvector unworking wile used
//float updir[3] = {0.0, 0.0, 1.0};

but
//float updir[3] = {0.0, 0.0, QUANTTOMETER};
it work fine
Posted By: croman

Re: newton - 05/14/08 12:32

no, still not working. my world creation code is this:

n_world = ent_create("newton_playground.mdl", nullvector, NULL);
n_world->flags |= FLAG8; // flag8 -> will be added to world collision geometry


if you made it work can you post that code please?
Posted By: ventilator

Re: newton - 05/14/08 16:49

nworld has to be the newton world and not a gamestudio entity. that's why it crashes.

just copy my function into the newton lite-c demo source code and call it from somewhere. it doesn't crash. then you can go on from there and try to add tires.
Posted By: croman

Re: newton - 05/14/08 17:40

aah, finally. thanks ventilator for your patience.

do you still intend to create a small car example with Newton?
Posted By: ventilator

Re: newton - 05/14/08 19:02

yes, but probably i will wait for a final newton 2.0.
Posted By: HoopyDerFrood

Re: newton - 06/11/08 21:46

Hello I've some problems with playing sounds on collisions.

I have some cans/tins in my world and can shoot them around.
Now I want them to play a sound when they collide with each other or falling on the ground or hitting a wall.

So i wrote in the CollisionEndCallback a command playing a sound.
But now they make this noise all the time they are touching each other or when they are rolling on the floor.

I've read in the Newton manual that it is possible to check in the CollisionProcessCallback how strong an Impact was to play sounds only at heavy impacts.

But I dont know how I can check the impactspeed in the CollisionCallback Function.

Can anyone help me with this problem or did anyone still realised realistic impact sounds?

Greetings RATsoft
Posted By: LaQroix

Re: newton - 07/09/08 16:48

Firstly thanx a lot for this great plug-in ventilator. It really works perfect. Also i wonder if someone succeeded to make a workin car physics. I tried doin somethng but thre is a problem about the tire pin. Also suspensions are like wood blocks. If someone knows how to fix these i will be real glad. Tnx..

Code:

action Newton_Car()
{
	while(!newton_running){wait(1);}
	wait(1);
	NewtonBody* car_body=newton_addentity(me, 200, 2, 2, onforceandtorque);
	
	D3DXMATRIX upside;
	D3DXMatrixTranslation(&upside, 0.0, 0.0, 1.0);
	NewtonJoint* car_joint = NewtonConstraintCreateVehicle(nworld, &upside, car_body);
	//NewtonVehicleSetTireCallback(car_joint, tireUpdate); 
	
	int tireMass;
	float wheelradius;
	tireMass =  20;
	wheelradius = 0.5; 
	
	D3DXMATRIX tire_offset;
	const float tirePin[3];
	tirePin[0]=0.0;
	tirePin[1]=0.0;
	tirePin[2]=1.0;

	//front left
	D3DXMatrixTranslation(&tire_offset, 40.0 * QUANTTOMETER,
				           -65.0 * QUANTTOMETER,
				           -50.0 * QUANTTOMETER);
	NewtonVehicleAddTire(car_joint, &tire_offset, tirePin, tireMass, wheelradius, wheelradius, 300,2000,1.5, NULL, 0);
	
	//front right
	D3DXMatrixTranslation(&tire_offset, -40.0 * QUANTTOMETER,
					    -65.0 * QUANTTOMETER, 
                                            -50.0 * QUANTTOMETER);
	NewtonVehicleAddTire(car_joint, &tire_offset, tirePin, tireMass, wheelradius, wheelradius, 300,2000,1.5, NULL, 1);
	
	//back left
	D3DXMatrixTranslation(&tire_offset, 40.0 * QUANTTOMETER,
				            65.0 * QUANTTOMETER,
					   -50.0 * QUANTTOMETER);
	NewtonVehicleAddTire(car_joint, &tire_offset, tirePin, tireMass, wheelradius, wheelradius, 300,2000,1.5, NULL, 2);
	
	//back right
	D3DXMatrixTranslation(&tire_offset, -40.0 * QUANTTOMETER,
				             65.0 * QUANTTOMETER,
					    -50.0 * QUANTTOMETER);
	NewtonVehicleAddTire(car_joint, &tire_offset, tirePin, tireMass, wheelradius, wheelradius, 3,20000,1.5, NULL, 3);
}



P.S: the 4th parameter at ventilators newton_addentity function defines the newton material for the entity, it aint no mistake
Posted By: croman

Re: newton - 07/23/08 13:06

hi,

can anyone help me please with this code?
i was wondering why this isn't working?

Code:
while(1)
{
   if(key_e)
   {
      NewtonBodySetVelocity((NewtonBody*)mouse_ent->skill99,vectorf(-200,200,200));
   }
   wait(1);
}


and this works:
Code:
while(1)
{
   if(key_e)
   {
      ent_remove(mouse_ent);
      NewtonDestroyBody(nworld,(NewtonBody*)mouse_ent->skill99);	
   }
   wait(1);
}	



under skill99 i have:

Code:
action blockAct()
{
    var panBlock;

    c_setminmax(me);
    set(my, PASSABLE | INVISIBLE);
    panBlock = my.pan;
    wait(3);
    
    you = ent_create("aim.mdl", vector(my.x, my.y, my.z), NULL);
    ent_remove(my);
    wait(3);
    my = you;
    c_setminmax(me);
    my.skill99 = handle(my);
    my.pan = panBlock;
    wait(3);
    NewtonBody *body = newton_addentity(my, 10, NEWTON_BOX, onforceandtorque);
}

Posted By: croman

Re: newton - 07/23/08 14:01

i think i found the problem. when newton entity stops moving it kinda disables herself, why? and after it stops moving i cant apply any force to it.

how can i solve that?
Posted By: croman

Re: newton - 07/23/08 14:29

i've found it. auto freezing and unfreeze functions. anyway thanks laugh
Posted By: hemahoney

Re: newton - 07/24/08 00:20

EDIT: SPAM
Posted By: croman

Re: newton - 07/24/08 08:05

this is definitely the WRONG FORUM for that kind of question.
Posted By: VeT

Re: newton - 07/29/08 18:04

i dont think that's a spam: some time ago i spent a lot of time because i also forget about freezing smile
© 2024 lite-C Forums