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

Method initPhysics

examples/DeformableDemo/DeformableContact.cpp:78–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76};
77
78void DeformableContact::initPhysics()
79{
80 m_guiHelper->setUpAxis(1);
81
82 ///collision configuration contains default setup for memory, collision setup
83 m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
84
85 ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
86 m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
87
88 m_broadphase = new btDbvtBroadphase();
89 btDeformableBodySolver* deformableBodySolver = new btDeformableBodySolver();
90
91 ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
92 btDeformableMultiBodyConstraintSolver* sol = new btDeformableMultiBodyConstraintSolver();
93 sol->setDeformableSolver(deformableBodySolver);
94 m_solver = sol;
95
96 m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_dispatcher, m_broadphase, sol, m_collisionConfiguration, deformableBodySolver);
97 btVector3 gravity = btVector3(0, -10, 0);
98 m_dynamicsWorld->setGravity(gravity);
99 getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity;
100 getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.setDefaultVoxelsz(0.25);
101 getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.Reset();
102 m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
103
104 {
105 ///create a ground
106 btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(150), btScalar(25.), btScalar(150)));
107
108 m_collisionShapes.push_back(groundShape);
109
110 btTransform groundTransform;
111 groundTransform.setIdentity();
112 groundTransform.setOrigin(btVector3(0, -32, 0));
113 groundTransform.setRotation(btQuaternion(btVector3(1, 0, 0), SIMD_PI * 0.));
114 //We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
115 btScalar mass(0.);
116
117 //rigidbody is dynamic if and only if mass is non zero, otherwise static
118 bool isDynamic = (mass != 0.f);
119
120 btVector3 localInertia(0, 0, 0);
121 if (isDynamic)
122 groundShape->calculateLocalInertia(mass, localInertia);
123
124 //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
125 btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
126 btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia);
127 btRigidBody* body = new btRigidBody(rbInfo);
128 body->setFriction(2);
129
130 //add the ground to the dynamics world
131 m_dynamicsWorld->addRigidBody(body);
132 }
133
134 // create a piece of cloth
135 {

Callers

nothing calls this directly

Calls 15

setDefaultVoxelszMethod · 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