static dFloat RayCastFilter (const NewtonBody* const body, const NewtonCollision* const collisionHit, const dFloat* const contact, const dFloat* const normal, dLong collisionID, void* const userData, dFloat intersetParam) { dFloat mass; dFloat Ixx; dFloat Iyy; dFloat Izz; // check if we are hitting a sub shape const NewtonCollision* const parent = NewtonCollisionGetParentInstance(collisionHit); if (parent) { // you can use this to filter sub collision shapes. dAssert (NewtonCollisionGetSubCollisionHandle (collisionHit)); } dMousePickClass* const data = (dMousePickClass*) userData; NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz); if ((mass > 0.0f) || (NewtonBodyGetType(body) == NEWTON_KINEMATIC_BODY)) { data->m_body = body; } if (intersetParam < data->m_param) { data->m_param = intersetParam; data->m_normal = dVector (normal[0], normal[1], normal[2]); } return intersetParam; }
static void DebugShowBodyCollision (const NewtonBody* const body, DEBUG_DRAW_MODE mode) { switch (NewtonBodyGetType(body)) { case NEWTON_DYNAMIC_BODY: { 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); } break; } case NEWTON_KINEMATIC_BODY: glColor3f(1.0f, 1.0f, 0.0f); break; case NEWTON_DEFORMABLE_BODY: glColor3f (0.0f, 1.0f, 1.0f); break; } dMatrix matrix; NewtonBodyGetMatrix(body, &matrix[0][0]); NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(body), &matrix[0][0], DebugShowGeometryCollision, (void*) mode); }
// implement a ray cast pre-filter static unsigned RayCastPrefilter (const NewtonBody* body, const NewtonCollision* const collision, void* const userData) { // ray cannot pick trigger volumes //return NewtonCollisionIsTriggerVolume(collision) ? 0 : 1; const NewtonCollision* const parent = NewtonCollisionGetParentInstance(collision); if (parent) { // you can use this to filter sub collision shapes. dAssert (NewtonCollisionGetSubCollisionHandle (collision)); } return (NewtonBodyGetType(body) == NEWTON_DYNAMIC_BODY) ? 1 : 0; }