void CCTDebugData::addAABB(const NxBounds3& bounds, NxU32 color, bool renderFrame) { // Reuse OBB code... NxVec3 center; bounds.getCenter(center); NxVec3 extents; bounds.getExtents(extents); NxMat33 id; id.id(); addOBB(NxBox(center, extents, id), color, renderFrame); }
//----------------------------------------------------------------------------- // CalcBBox //----------------------------------------------------------------------------- NxBox CPhysicModelSimple::CalcBBox (void) const { NxBounds3 bounds; for (int i = 0; i < (int)m_ActorDesc.shapes.size(); i++) { NxShapeDesc* pShapeDesc = m_ActorDesc.shapes[i]; switch (pShapeDesc->getType()) { case NX_SHAPE_BOX: { NxBoxShapeDesc* pBoxShape = (NxBoxShapeDesc*) pShapeDesc; NxBox shapeBBox (pBoxShape->localPose.t, pBoxShape->dimensions, pBoxShape->localPose.M); NxBounds3 shapeBounds; shapeBounds.boundsOfOBB( shapeBBox.rot, shapeBBox.center, shapeBBox.extents ); bounds.combine (shapeBounds); } break; case NX_SHAPE_SPHERE: { NxSphereShapeDesc* pSphereShape = (NxSphereShapeDesc*) pShapeDesc; NxBox shapeBBox (pSphereShape->localPose.t, NxVec3(pSphereShape->radius), pSphereShape->localPose.M); NxBounds3 shapeBounds; shapeBounds.boundsOfOBB( shapeBBox.rot, shapeBBox.center, shapeBBox.extents ); bounds.combine (shapeBounds); } break; default: // Caso no soportado assert(0); break; } } NxBox result; bounds.getCenter (result.center); bounds.getExtents (result.extents); return result; }
// ----------------------------------------------------------------------- void MyCloth::draw(bool shadows) { static NxU32 numVertices = mNumVertices; NxU32 numElements = mNumIndices; numVertices = mNumVertices; // Disable pressure if tearing occurs if (mTeared && (mCloth->getFlags() & NX_CLF_PRESSURE)) { // Disable Pressure mCloth->setFlags(mCloth->getFlags() & ~NX_CLF_PRESSURE); mCloth->setPressure(0); // Reduce tearing factor NxReal oldTearing = mCloth->getTearFactor(); oldTearing = (oldTearing - 1) / 3 + 1; mCloth->setTearFactor(oldTearing); // Reduce bending stiffness if (mCloth->getBendingStiffness() > 0.9f) mCloth->setBendingStiffness(0.2f); // Apply explosion in the middle of the cloth NxBounds3 bounds; mCloth->getWorldBounds(bounds); NxVec3 center; bounds.getCenter(center); NxReal radius = bounds.min.distance(bounds.max); mCloth->addForceAtPos(center, 7 * NxMath::pow(radius,3), radius, NX_IMPULSE); printf("Pressure disabled\n"); } if (mTexId > 0) { updateTextureCoordinates(); } glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(RenderBufferVertexElement), numVertices, &(mVertexRenderBuffer[0].position.x)); glNormalPointer(GL_FLOAT, sizeof(RenderBufferVertexElement), numVertices, &(mVertexRenderBuffer[0].normal.x)); if (mTexId) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(RenderBufferVertexElement), numVertices, &(mVertexRenderBuffer[0].texCoord[0])); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, mTexId); glColor4f(1.0f, 1.0f, 1.0f,1.0f); } #ifdef __CELLOS_LV2__ glDrawRangeElements(GL_TRIANGLES, 0, numVertices-1, numElements, GL_UNSIGNED_INT, mIndexRenderBuffer); #else glDrawElements(GL_TRIANGLES, numElements, GL_UNSIGNED_INT, mIndexRenderBuffer); #endif if (mTexId) { glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D); } if (shadows) { const static float ShadowMat[]={ 1,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,1 }; glPushMatrix(); glMultMatrixf(ShadowMat); glDisable(GL_LIGHTING); glColor4f(0.05f, 0.1f, 0.15f,1.0f); #ifdef __CELLOS_LV2__ glDrawRangeElements(GL_TRIANGLES, 0, numVertices-1, numElements, GL_UNSIGNED_INT, mIndexRenderBuffer); #else glDrawElements(GL_TRIANGLES, numElements, GL_UNSIGNED_INT, mIndexRenderBuffer); #endif glColor4f(1.0f, 1.0f, 1.0f,1.0f); glEnable(GL_LIGHTING); glPopMatrix(); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); }