Help with onCollision, collision meshes, where its stored,...
by Luke Jones · in Torque Game Engine · 05/04/2004 (1:20 am) · 7 replies
Im trying to get Newton Game Dynamics integrated and need a litlle help with some things.
First off, I need to grab the collision meshes from torque, including player, shapebase, interior and terrain and dump them in Newton.
It should be relativly easy to convert the torque objects collision mesh into newton, but i dont know how to get that info and read it.
Second, Newton works using callbacks, if an item were to collide with something in the newtonworld, it will callback a function to update torque. Not too sure how to do that either.
Newton Game Dynamics
Engines reference is in the SDK download.
All I've got so far, is an initial link+compile and world setup, not much of an idea on how to go about doing the rest, but Im getting there, slowly, with a bit of help.
...ding....
First off, I need to grab the collision meshes from torque, including player, shapebase, interior and terrain and dump them in Newton.
It should be relativly easy to convert the torque objects collision mesh into newton, but i dont know how to get that info and read it.
Second, Newton works using callbacks, if an item were to collide with something in the newtonworld, it will callback a function to update torque. Not too sure how to do that either.
Newton Game Dynamics
Engines reference is in the SDK download.
All I've got so far, is an initial link+compile and world setup, not much of an idea on how to go about doing the rest, but Im getting there, slowly, with a bit of help.
...ding....
About the author
Core developer using Rust lang at Sphere Identity.
#2
But how would I update an object in Torque using a callback?
From the Newton doc:
Im just really not sure how to go about doing something like that in TGE.
Newton Tutorial to help explain a few things.
05/04/2004 (1:52 am)
I've been digging through shapeBase and am figuring it out and learning what I can.But how would I update an object in Torque using a callback?
From the Newton doc:
void NewtonMaterialSetCollisionCallback( const NewtonWorld* newtonWorld, int id0, int id1, void *userData, NewtonContactBegin beginCallback, NewtonContactProcess processCallback, NewtonContactEnd endCallback)
const NewtonWorld *newtonWorld - is the pointer to the Newton world int id0 - group id0 int id1 - group id1 void *userData - user data value NewtonContactBegin beginCallback - address of the event function called before contact calculation for collision. This parameter can be NULL. NewtonContactProcess processCallback - address of the event function called for every contact resulting from contact calculation. This parameter can be NULL. NewtonContactEnd endCallback - address of the event function called after all contacts are processed. This parameter can be NULL.Example from Irricht+Newton demo:
int CGame::ProcesContact (const NewtonMaterial* material, const NewtonContact* contact)
{
float normalSpeed;
// if this contact is stronger than the previus one ....
normalSpeed = NewtonMaterialGetContactNormalSpeed (material, contact);
if (normalSpeed > g_currectEffect->m_contactSpeed) {
// save the position of the contact (for 3d sound of particles effects)
vector3df normal;
g_currectEffect->m_contactSpeed = normalSpeed;
NewtonMaterialGetContactPositionAndNormal (material, &g_currectEffect->m_contactPoistion.X, &normal.X);
}Im just really not sure how to go about doing something like that in TGE.
Newton Tutorial to help explain a few things.
#4
Anyways, suppose that the form of the processCallBack is like the CGame::ProcesContact, you have to write something like:
when you intialize the newtown engine
So when the newton engine need to call the ProcessContact, it calls your function that you have named ProcContactCallBack
I hope you can understand me :)
05/04/2004 (6:48 am)
I've taken a look at the link you supply, but since I don't know Irricht I can't understan where it starts and where the newtown's code begins :)Anyways, suppose that the form of the processCallBack is like the CGame::ProcesContact, you have to write something like:
static int ProcContactCallBack((const NewtonMaterial* material, const NewtonContact* contact)
{
blah
blah
}when you intialize the newtown engine
void NewtonMaterialSetCollisionCallback(newtonWorld,id0,id1,NULL, NULL, ProcContactCallBack,NULL);
So when the newton engine need to call the ProcessContact, it calls your function that you have named ProcContactCallBack
I hope you can understand me :)
#5
Davide, I understood what I needed to do and how the function works, but not how I can implement something like the body of the callback in the example(irrlicht).
Actually, those examples of bigin/processContact look like they are just for special effects. the ones i need are:
NewtonBodySetTransformCallback.
NewtonBodySetForceAndTorqueCallback.
Some code from a tutorial.
05/04/2004 (1:20 pm)
Thanks Matthew, I've already looked at that.Davide, I understood what I needed to do and how the function works, but not how I can implement something like the body of the callback in the example(irrlicht).
Actually, those examples of bigin/processContact look like they are just for special effects. the ones i need are:
NewtonBodySetTransformCallback.
NewtonBodySetForceAndTorqueCallback.
Some code from a tutorial.
// set the tranformation of a rigid body
void _cdecl PhysicsApplyForceAndTorque (const NewtonBody* body)
{
float mass;
float Ixx;
float Iyy;
float Izz;
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
dVector force (0.0f, -mass * 9.8f, 0.0f);
NewtonBodySetForce (body, &force.m_x);
}
// add force and torque to rigid body
void _cdecl PhysicsSetTransform (const NewtonBody* body, const float* matrix)
{
RenderPrimitive* primitive;
// get the graphic object form the rigid body
primitive = (RenderPrimitive*) NewtonBodyGetUserData (body);
// set the transformation matrix for this rigid body
dMatrix& mat = *((dMatrix*)matrix);
primitive->SetMatrix (mat);
}Can someone explain how those callbacks work?
#6
I'm thinking that you are loosing yourselft in a glass of water :) but since you don't know well Torque nor Newtown it's easy that this happen.
Anyways, really I don't know how to help you, here I see only NewtonXXXX variables, but somewhere you need to have your game objects, Do they need to be stored in the Newton's pointers?
I suppose yes, since there is a function like
primitive = (RenderPrimitive*) NewtonBodyGetUserData (body);
And I suppose that "primitive" is a type of the game engine, in torque you should cast to a SimObjectPtr or whatelse you have sent to the user data in the NewtonBody struct.
Ok, try to go on, and try to ask very detailed questions, otherwise I really don't know how to help you
05/05/2004 (2:33 am)
Hi,I'm thinking that you are loosing yourselft in a glass of water :) but since you don't know well Torque nor Newtown it's easy that this happen.
Anyways, really I don't know how to help you, here I see only NewtonXXXX variables, but somewhere you need to have your game objects, Do they need to be stored in the Newton's pointers?
I suppose yes, since there is a function like
primitive = (RenderPrimitive*) NewtonBodyGetUserData (body);
And I suppose that "primitive" is a type of the game engine, in torque you should cast to a SimObjectPtr or whatelse you have sent to the user data in the NewtonBody struct.
Ok, try to go on, and try to ask very detailed questions, otherwise I really don't know how to help you
#7
All Im tring to do at the moment, is get as much info as I can to further my understanding of Torque, constantly having the TGE & NGD references and docs open helps alot when going through code.
Right now, I probably know 5x more than I did yesterday about both TGE and NGD.
Thanks for the little bit of help anyway.
05/05/2004 (3:38 am)
DOnt worry Davide, Im only getting started, and Im learning fast.All Im tring to do at the moment, is get as much info as I can to further my understanding of Torque, constantly having the TGE & NGD references and docs open helps alot when going through code.
Right now, I probably know 5x more than I did yesterday about both TGE and NGD.
Thanks for the little bit of help anyway.
Torque Owner Davide Archetti
Default Studio Name
About callback, remember that there is the Sim::findObject function that can give you the pointer to every object in the game just passing to it the object's name or its Id.