Moderators: Sascha Willems, walaber
Julio Jerez wrote:has you imp[lemnet debug display, to see if the collision ares in place?
void GetContactOnBody (NewtonBody* const body)
{
for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint (body); joint; joint = NewtonBodyGetNextContactJoint (body, joint)) {
for (void* contact = NewtonContactJointGetFirstContact (joint); contact; contact = NewtonContactJointGetNextContact (joint, contact)) {
NewtonBody* const body0 = NewtonJointGetBody0(joint);
NewtonBody* const body1 = NewtonJointGetBody1(joint);
_ASSERTE (body0 == body);
if (body1 != crasftBody) {
// do whatever you want with the force
NewtonMaterial* material = NewtonContactGetMaterial (contact);
NewtonMaterialGetContactPositionAndNormal (material, body1, &point.m_x, &normal.m_x);
}
}
}
}
Julio Jerez wrote:bascially you make a compoind collsion and add the collsion of teh ship as shapes. then you add teh extra collsion also as sushapenm bu you kabe this shaope not collidable.
now the body will carry all the shapes with it, then you call colldion collide to get the contacts genertaed form the trigger subshape.
I thonk this will be the most effiecient way.
NewtonBody* CreateLevelMeshBody (NewtonWorld* const world, DemoEntity* const ent, bool optimization)
{
// measure the time to build a collision tree
unsigned64 timer0 = dGetTimeInMicrosenconds();
// create the collision tree geometry
NewtonCollision* const collision = NewtonCreateTreeCollision(world, 0);
// set the application level callback
#ifdef USE_STATIC_MESHES_DEBUG_COLLISION
NewtonStaticCollisionSetDebugCallback (collision, ShowMeshCollidingFaces);
#endif
...
void ShowMeshCollidingFaces (const NewtonBody* const staticCollisionBody, const NewtonBody* const body, int faceID, int vertexCount, const dFloat* const vertex, int vertexstrideInBytes)
{
#ifdef USE_STATIC_MESHES_DEBUG_COLLISION
if (debugMode) {
if ((debugDisplayCount + vertexCount * 2) < int (sizeof (debugDisplayCallback) / sizeof(debugDisplayCallback[0]))) {
// we are coping data to and array of memory, another call back may be doing the same thing
// here fore we need to avoid race conditions
NewtonWorldCriticalSectionLock (NewtonBodyGetWorld (staticCollisionBody), 0);
int stride = vertexstrideInBytes / sizeof (dFloat);
dVector l0 (vertex[(vertexCount-1) * stride + 0], vertex[(vertexCount-1) * stride + 1], vertex[(vertexCount-1) * stride + 2], 0.0f);
for (int j = 0; j < vertexCount; j ++) {
dVector l1 (vertex[j * stride + 0], vertex[j * stride + 1] , vertex[j * stride + 2], 0.0f);
debugDisplayCallback[debugDisplayCount + 0] = l0;
debugDisplayCallback[debugDisplayCount + 1] = l1;
debugDisplayCount += 2;
l0 = l1;
}
// unlock the critical section
NewtonWorldCriticalSectionUnlock (NewtonBodyGetWorld (staticCollisionBody));
}
}
#endif
}
static void DebugShowBodyCollision (const NewtonBody* const body, DEBUG_DRAW_MODE mode)
{
dFloat mass;
dFloat Ixx;
dFloat Iyy;
dFloat Izz;
if (mode == m_lines) {
glBegin(GL_LINES);
} else {
glBegin(GL_TRIANGLES);
}
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
if (mass > 0.0f) {
int sleepState = NewtonBodyGetSleepState(body);
if (sleepState == 1) {
// indicate when body is sleeping
glColor3f(0.42f, 0.73f, 0.98f);
} else {
// body is active
glColor3f(1.0f, 1.0f, 1.0f);
}
dMatrix matrix;
NewtonBodyGetMatrix(body, &matrix[0][0]);
NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(body), &matrix[0][0], DebugShowGeometryCollision, (void*) mode);
} else if (NewtonBodyGetType(body) == NEWTON_KINEMATIC_BODY) {
// } else {
dMatrix matrix;
glColor3f(1.0f, 1.0f, 0.0f);
NewtonBodyGetMatrix(body, &matrix[0][0]);
NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(body), &matrix[0][0], DebugShowGeometryCollision, (void*) mode);
}
glEnd();
}
Users browsing this forum: No registered users and 1 guest