MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / createRigidBody

Method createRigidBody

src/engine/PhysicsWorld.cpp:401–442  ·  view source on GitHub ↗

Create a rigid body into the physics world * @param transform Transformation from body local-space to world-space * @return A pointer to the body that has been created in the world */

Source from the content-addressed store, hash-verified

399 * @return A pointer to the body that has been created in the world
400 */
401RigidBody* PhysicsWorld::createRigidBody(const Transform& transform) {
402
403 // Create a new entity for the body
404 Entity entity = mEntityManager.createEntity();
405
406 // Check that the transform is valid
407 if (!transform.isValid()) {
408 RP3D_LOG(mConfig.worldName, Logger::Level::Error, Logger::Category::Body,
409 "Error when creating a rigid body: the init transform is not valid", __FILE__, __LINE__);
410 }
411 assert(transform.isValid());
412
413 mTransformComponents.addComponent(entity, false, TransformComponents::TransformComponent(transform));
414
415 // Create the rigid body
416 RigidBody* rigidBody = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool,
417 sizeof(RigidBody))) RigidBody(*this, entity);
418 assert(rigidBody != nullptr);
419
420 BodyComponents::BodyComponent bodyComponent(rigidBody);
421 mBodyComponents.addComponent(entity, false, bodyComponent);
422
423 RigidBodyComponents::RigidBodyComponent rigidBodyComponent(rigidBody, BodyType::DYNAMIC, transform.getPosition());
424 mRigidBodyComponents.addComponent(entity, false, rigidBodyComponent);
425
426 // Compute the inverse mass
427 mRigidBodyComponents.setMassInverse(entity, decimal(1.0) / mRigidBodyComponents.getMass(entity));
428
429 // Add the rigid body to the physics world
430 mRigidBodies.add(rigidBody);
431
432#ifdef IS_RP3D_PROFILING_ENABLED
433
434 rigidBody->setProfiler(mProfiler);
435#endif
436
437 RP3D_LOG(mConfig.worldName, Logger::Level::Information, Logger::Category::Body,
438 "Body " + std::to_string(entity.id) + ": New collision body created", __FILE__, __LINE__);
439
440 // Return the pointer to the rigid body
441 return rigidBody;
442}
443
444// Destroy a rigid body and all the joints which it belongs
445/**

Callers 13

mainFunction · 0.80
TestRigidBodyMethod · 0.80
TestPointInsideMethod · 0.80
TestRaycastMethod · 0.80
TestWorldQueriesMethod · 0.80
ConcaveMeshMethod · 0.80
DumbbellMethod · 0.80
ConvexMeshMethod · 0.80
BoxMethod · 0.80
CapsuleMethod · 0.80
HeightFieldMethod · 0.80
SphereMethod · 0.80

Calls 9

TransformComponentClass · 0.85
createEntityMethod · 0.80
setMassInverseMethod · 0.80
isValidMethod · 0.45
addComponentMethod · 0.45
allocateMethod · 0.45
getMassMethod · 0.45
addMethod · 0.45
setProfilerMethod · 0.45

Tested by 4

TestRigidBodyMethod · 0.64
TestPointInsideMethod · 0.64
TestRaycastMethod · 0.64
TestWorldQueriesMethod · 0.64