void PendulumApplication::buildFlyingTrapeze() { /// Actu RagDoll * ragdoll = new RagDoll (m_dynamicsWorld, btVector3(0,12,0)); btRigidBody* right_hand = ragdoll->getBodyPart(ragdoll->BODYPART_RIGHT_LOWER_ARM); btRigidBody* left_hand = ragdoll->getBodyPart(ragdoll->BODYPART_LEFT_LOWER_ARM); btSoftBody * corde = btSoftBodyHelpers::CreateRope(m_softBodyWorldInfo, btVector3(2,17,0),right_hand->getWorldTransform().getOrigin(),7,1); btSoftBody * corde2 = btSoftBodyHelpers::CreateRope(m_softBodyWorldInfo, btVector3(-2,17,0),left_hand->getWorldTransform().getOrigin(),7,1); corde->appendAnchor(corde->m_nodes.size()-1,right_hand,btVector3(0,0.1,0),true,1); corde2->appendAnchor(corde2->m_nodes.size()-1,left_hand,btVector3(0,0.1,0),true,1); corde->setTotalMass(8.); this->getSoftDynamicsWorld()->addSoftBody(corde,1,1) ; corde2->setTotalMass(8.); this->getSoftDynamicsWorld()->addSoftBody(corde2,1,1) ; m_corde = corde; m_corde2 = corde2; /// fillet btVector3 c_00(-3,10,-3); btVector3 c_10(3,10,-3); btVector3 c_01(-3,10,3); btVector3 c_11(3,10,3); btSoftBody * fillet = btSoftBodyHelpers::CreatePatch(m_softBodyWorldInfo,c_00,c_10,c_01,c_11,20,20,15,true); //fillet->appendAnchor(fillet->m_nodes.size()-1,right_hand,false,1); fillet->setTotalMass(150.); getSoftDynamicsWorld()->addSoftBody(fillet,1,1) ; fillet->generateBendingConstraints(2,fillet->appendMaterial()); fillet->getCollisionShape()->setMargin (0.6) ; struct myFn :public btSoftBody::ImplicitFn { }; //myFn * ifn(); //fillet->refine(,2,true); // applyTorqueImpulse() /// camera btRigidBody* head = ragdoll->getBodyPart(ragdoll->BODYPART_HEAD); m_cameraTarget = head; m_ragdall = ragdoll; }
void PendulumApplication::exitPhysics() { //cleanup in the reverse order of creation/initialization //remove the rigid and soft bodies from the dynamics world and delete them if(m_ragdall == NULL) delete m_ragdall; for(int i=m_dynamicsWorld->getNumCollisionObjects()-1;i>=0;i--) { btCollisionObject* obj=m_dynamicsWorld->getCollisionObjectArray()[i]; btRigidBody* body=btRigidBody::upcast(obj); if(body&&body->getMotionState()) { delete body->getMotionState(); } //remove the constraint from the dynamics world and delete them while(m_dynamicsWorld->getNumConstraints()) { btTypedConstraint* pc=m_dynamicsWorld->getConstraint(0); m_dynamicsWorld->removeConstraint(pc); delete pc; } btSoftBody* softBody = btSoftBody::upcast(obj); if (softBody) { getSoftDynamicsWorld()->removeSoftBody(softBody); } else { btRigidBody* body = btRigidBody::upcast(obj); if (body) m_dynamicsWorld->removeRigidBody(body); else m_dynamicsWorld->removeCollisionObject(obj); } delete obj; } //delete collision shapes for (int j=0;j<m_collisionShapes.size();j++) { btCollisionShape* shape = m_collisionShapes[j]; delete shape; } m_collisionShapes.clear(); delete m_dynamicsWorld; delete m_solver; delete m_broadphase; delete m_dispatcher; delete m_collisionConfiguration; }
int mmdpiBullet::get_softbody_vertex( mmdpiVector3d *vertex, int id ) { btSoftBody* psb = getSoftDynamicsWorld()->getSoftBodyArray()[ id ]; int face_num = psb->m_faces.size(); int vertex_num = face_num * 3; if( vertex ) for( int i = 0; i < vertex_num; i ++ ) { const btVector3& position = psb->m_faces[ i / 3 ].m_n[ i % 3 ]->m_x; vertex[ i ].x = position.x(); vertex[ i ].y = position.y(); vertex[ i ].z = position.z(); } return face_num; }
void PendulumApplication::renderme() { glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); m_dynamicsWorld->debugDrawWorld(); btSoftRigidDynamicsWorld* softWorld = getSoftDynamicsWorld(); for ( int i=0; i<softWorld->getSoftBodyArray().size(); i++) { btSoftBody* psb=(btSoftBody*)softWorld->getSoftBodyArray()[i]; if (softWorld->getDebugDrawer() && !(softWorld->getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe))) { btSoftBodyHelpers::DrawFrame(psb,softWorld->getDebugDrawer()); btSoftBodyHelpers::Draw(psb,softWorld->getDebugDrawer(),softWorld->getDrawFlags()); } } DemoApplication::renderme(); }
void PendulumApplication::renderme() { glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); m_dynamicsWorld->debugDrawWorld(); btSoftRigidDynamicsWorld* softWorld = getSoftDynamicsWorld(); for ( int i=0;i<softWorld->getSoftBodyArray().size();i++) { btSoftBody* psb=(btSoftBody*)softWorld->getSoftBodyArray()[i]; if (softWorld->getDebugDrawer() && !(softWorld->getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe))) { btSoftBodyHelpers::DrawFrame(psb,softWorld->getDebugDrawer()); btSoftBodyHelpers::Draw(psb,softWorld->getDebugDrawer(),softWorld->getDrawFlags()); } } /// follow the object if(m_cameraTarget != NULL) m_cameraTargetPosition = m_cameraTarget->getWorldTransform().getOrigin(); DemoApplication::renderme(); }
int mmdpiBullet::getFaceNum( int id ) { btSoftBody* psb = getSoftDynamicsWorld()->getSoftBodyArray()[ id ]; return psb->m_faces.size(); }