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); }
void cPhysicsBodyNewton::RenderDebugGeometry(iLowLevelGraphics *apLowLevel,const cColor &aColor) { NewtonCollision *pCollision = NewtonBodyGetCollision(mpNewtonBody); float matrix[4][4]; NewtonBodyGetMatrix(mpNewtonBody, &matrix[0][0]); gpLowLevelGraphics = apLowLevel; gDebugColor = aColor; NewtonCollisionForEachPolygonDo(pCollision, &matrix[0][0], RenderDebugPolygon, (void*)NULL); }
void dNewtonCollision::DebugRender(OnDrawFaceCallback callback, const dVector eyePoint) { DebugCallBack callbackInfo; callbackInfo.m_eyePoint = eyePoint; callbackInfo.m_callback = callback; dMatrix matrix(dGetIdentityMatrix()); NewtonCollisionForEachPolygonDo(m_shape, &matrix[0][0], DebugRenderCallback, &callbackInfo); }
NewtonMesh* CreateCollisionTreeDoubleFaces (NewtonWorld* world, NewtonCollision* optimizedDoubelFacesTree) { NewtonMesh* mesh = NewtonMeshCreate(world); dMatrix matrix (dGetIdentityMatrix()); NewtonMeshBeginFace(mesh); NewtonCollisionForEachPolygonDo (optimizedDoubelFacesTree, &matrix[0][0], ExtrudeFaces, mesh); NewtonMeshEndFace(mesh); return mesh; }
void cPhysicsBodyNewton::RenderDebugGeometry(iLowLevelGraphics *a_pLowLevel, const cColor &a_Color) { //cPhysicsWorldNewton *pPhysicsWorld = static_cast<cPhysicsWorldNewton*>(NewtonWorldGetUserData(m_pNewtonWorld)); //pPhysicsWorld->GetWorld3D()->gets NewtonCollision *pCollision = NewtonBodyGetCollision(m_pNewtonBody); float matrix[4][4]; NewtonBodyGetMatrix(m_pNewtonBody, &matrix[0][0]); g_pLowLevelGraphics = a_pLowLevel; g_DebugColor = a_Color; NewtonCollision *pNewtonCollision = NewtonBodyGetCollision(m_pNewtonBody); NewtonCollisionForEachPolygonDo(pNewtonCollision, m_mtxLocalTransform.GetTranspose().m[0], RenderDebugPolygon, this); }
void Collider3D::ForEachPolygon(const std::function<void(const Vector3f* vertices, std::size_t vertexCount)>& callback) const { auto newtCallback = [](void* const userData, int vertexCount, const dFloat* const faceArray, int /*faceId*/) { static_assert(sizeof(Vector3f) == 3 * sizeof(float), "Vector3 is expected to contain 3 floats without padding"); const auto& cb = *static_cast<std::add_pointer_t<decltype(callback)>>(userData); cb(reinterpret_cast<const Vector3f*>(faceArray), vertexCount); }; // Check for existing collision handles, and create a temporary one if none is available if (m_handles.empty()) { PhysWorld3D world; NewtonCollision* collision = CreateHandle(&world); { NewtonCollisionForEachPolygonDo(collision, Nz::Matrix4f::Identity(), newtCallback, const_cast<void*>(static_cast<const void*>(&callback))); //< This isn't that bad; pointer will not be used for writing } NewtonDestroyCollision(collision); } else NewtonCollisionForEachPolygonDo(m_handles.begin()->second, Nz::Matrix4f::Identity(), newtCallback, const_cast<void*>(static_cast<const void*>(&callback))); //< This isn't that bad; pointer will not be used for writing }
void DebugDrawCollision (const NewtonCollision* const collision, const dMatrix& matrix, DEBUG_DRAW_MODE mode) { // glBegin(GL_LINES); NewtonCollisionForEachPolygonDo (collision, &matrix[0][0], DebugShowGeometryCollision, (void*)mode); // glEnd(); }