MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / initPhysics

Method initPhysics

examples/DeformableDemo/PinchFriction.cpp:204–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202}
203
204void PinchFriction::initPhysics()
205{
206 m_guiHelper->setUpAxis(1);
207
208 m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
209
210 m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
211
212 m_broadphase = new btDbvtBroadphase();
213 btDeformableBodySolver* deformableBodySolver = new btDeformableBodySolver();
214
215 btDeformableMultiBodyConstraintSolver* sol = new btDeformableMultiBodyConstraintSolver();
216 sol->setDeformableSolver(deformableBodySolver);
217 m_solver = sol;
218
219 m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_dispatcher, m_broadphase, sol, m_collisionConfiguration, deformableBodySolver);
220 btVector3 gravity = btVector3(0, -10, 0);
221 m_dynamicsWorld->setGravity(gravity);
222 getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity;
223 getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.setDefaultVoxelsz(0.25);
224 getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.Reset();
225 getDeformableDynamicsWorld()->setSolverCallback(dynamics2);
226 m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
227
228 //create a ground
229 {
230 btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(150.), btScalar(25.), btScalar(150.)));
231
232 m_collisionShapes.push_back(groundShape);
233
234 btTransform groundTransform;
235 groundTransform.setIdentity();
236 groundTransform.setOrigin(btVector3(0, -25, 0));
237 groundTransform.setRotation(btQuaternion(btVector3(1, 0, 0), SIMD_PI * 0));
238 //We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
239 btScalar mass(0.);
240
241 //rigidbody is dynamic if and only if mass is non zero, otherwise static
242 bool isDynamic = (mass != 0.f);
243
244 btVector3 localInertia(0, 0, 0);
245 if (isDynamic)
246 groundShape->calculateLocalInertia(mass, localInertia);
247
248 //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
249 btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
250 btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia);
251 btRigidBody* body = new btRigidBody(rbInfo);
252 body->setFriction(0.5);
253
254 //add the ground to the dynamics world
255 m_dynamicsWorld->addRigidBody(body);
256 }
257
258 // create a soft block
259 {
260 btSoftBody* psb = btSoftBodyHelpers::CreateFromTetGenData(getDeformableDynamicsWorld()->getWorldInfo(),
261 TetraCube::getElements(),

Callers

nothing calls this directly

Calls 15

setDefaultVoxelszMethod · 0.80
setSolverCallbackMethod · 0.80
setSpringStiffnessMethod · 0.80
btVector3Class · 0.50
btQuaternionClass · 0.50
setUpAxisMethod · 0.45
setGravityMethod · 0.45
ResetMethod · 0.45
push_backMethod · 0.45
setIdentityMethod · 0.45
setRotationMethod · 0.45

Tested by

no test coverage detected