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

Method initPhysics

examples/ExtendedTutorials/RigidBodyFromObj.cpp:51–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49};
50
51void RigidBodyFromObjExample::initPhysics()
52{
53 m_guiHelper->setUpAxis(1);
54
55 createEmptyDynamicsWorld();
56
57 m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
58
59 //if (m_dynamicsWorld->getDebugDrawer())
60 // m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints);
61
62 ///create a few basic rigid bodies
63 btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.), btScalar(50.), btScalar(50.)));
64 m_collisionShapes.push_back(groundShape);
65
66 btTransform groundTransform;
67 groundTransform.setIdentity();
68 groundTransform.setOrigin(btVector3(0, -50, 0));
69 {
70 btScalar mass(0.);
71 createRigidBody(mass, groundTransform, groundShape, btVector4(0, 0, 1, 1));
72 }
73
74 //load our obj mesh
75 const char* fileName = "teddy.obj"; //sphere8.obj";//sponza_closed.obj";//sphere8.obj";
76 char relativeFileName[1024];
77 if (b3ResourcePath::findResourcePath(fileName, relativeFileName, 1024,0))
78 {
79 char pathPrefix[1024];
80 b3FileUtils::extractPath(relativeFileName, pathPrefix, 1024);
81 }
82
83 b3BulletDefaultFileIO fileIO;
84 GLInstanceGraphicsShape* glmesh = LoadMeshFromObj(relativeFileName, "",&fileIO);
85 printf("[INFO] Obj loaded: Extracted %d verticed from obj file [%s]\n", glmesh->m_numvertices, fileName);
86
87 const GLInstanceVertex& v = glmesh->m_vertices->at(0);
88 btConvexHullShape* shape = new btConvexHullShape((const btScalar*)(&(v.xyzw[0])), glmesh->m_numvertices, sizeof(GLInstanceVertex));
89
90 float scaling[4] = {0.1, 0.1, 0.1, 1};
91
92 btVector3 localScaling(scaling[0], scaling[1], scaling[2]);
93 shape->setLocalScaling(localScaling);
94
95 if (m_options & OptimizeConvexObj)
96 {
97 shape->optimizeConvexHull();
98 }
99
100 if (m_options & ComputePolyhedralFeatures)
101 {
102 shape->initializePolyhedralFeatures();
103 }
104
105 //shape->setMargin(0.001);
106 m_collisionShapes.push_back(shape);
107
108 btTransform startTransform;

Callers

nothing calls this directly

Calls 15

btVector4Class · 0.85
LoadMeshFromObjFunction · 0.85
optimizeConvexHullMethod · 0.80
btVector3Class · 0.50
setUpAxisMethod · 0.45
push_backMethod · 0.45
setIdentityMethod · 0.45
atMethod · 0.45
setLocalScalingMethod · 0.45
calculateLocalInertiaMethod · 0.45

Tested by

no test coverage detected