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

Method createJoint

src/engine/PhysicsWorld.cpp:483–600  ·  view source on GitHub ↗

Create a joint between two bodies in the world and return a pointer to the new joint * @param jointInfo The information that is necessary to create the joint * @return A pointer to the joint that has been created in the world */

Source from the content-addressed store, hash-verified

481 * @return A pointer to the joint that has been created in the world
482 */
483Joint* PhysicsWorld::createJoint(const JointInfo& jointInfo) {
484
485 // Create a new entity for the joint
486 Entity entity = mEntityManager.createEntity();
487
488 Joint* newJoint = nullptr;
489
490 const bool isJointDisabled = mRigidBodyComponents.getIsEntityDisabled(jointInfo.body1->getEntity()) &&
491 mRigidBodyComponents.getIsEntityDisabled(jointInfo.body2->getEntity());
492
493 // Allocate memory to create the new joint
494 switch(jointInfo.type) {
495
496 // Ball-and-Socket joint
497 case JointType::BALLSOCKETJOINT:
498 {
499 // Create a BallAndSocketJoint component
500 BallAndSocketJointComponents::BallAndSocketJointComponent ballAndSocketJointComponent(false, PI_RP3D);
501 mBallAndSocketJointsComponents.addComponent(entity, isJointDisabled, ballAndSocketJointComponent);
502
503 void* allocatedMemory = mMemoryManager.allocate(MemoryManager::AllocationType::Pool,
504 sizeof(BallAndSocketJoint));
505 const BallAndSocketJointInfo& info = static_cast<const BallAndSocketJointInfo&>(jointInfo);
506 BallAndSocketJoint* joint = new (allocatedMemory) BallAndSocketJoint(entity, *this, info);
507
508 newJoint = joint;
509 mBallAndSocketJointsComponents.setJoint(entity, joint);
510 break;
511 }
512
513 // Slider joint
514 case JointType::SLIDERJOINT:
515 {
516 const SliderJointInfo& info = static_cast<const SliderJointInfo&>(jointInfo);
517
518 // Create a SliderJoint component
519 SliderJointComponents::SliderJointComponent sliderJointComponent(info.isLimitEnabled, info.isMotorEnabled,
520 info.minTranslationLimit, info.maxTranslationLimit,
521 info.motorSpeed, info.maxMotorForce);
522 mSliderJointsComponents.addComponent(entity, isJointDisabled, sliderJointComponent);
523
524 void* allocatedMemory = mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(SliderJoint));
525 SliderJoint* joint = new (allocatedMemory) SliderJoint(entity, *this, info);
526
527 newJoint = joint;
528 mSliderJointsComponents.setJoint(entity, joint);
529
530 break;
531 }
532
533 // Hinge joint
534 case JointType::HINGEJOINT:
535 {
536 const HingeJointInfo& info = static_cast<const HingeJointInfo&>(jointInfo);
537
538 // Create a HingeJoint component
539 HingeJointComponents::HingeJointComponent hingeJointComponent(info.isLimitEnabled, info.isMotorEnabled,
540 info.minAngleLimit, info.maxAngleLimit,

Callers 14

createJointsMethod · 0.80
createJointsMethod · 0.80
createJointsMethod · 0.80
createSliderJointMethod · 0.80
createJointsMethod · 0.80
createRagdollsMethod · 0.80
createFixedJointMethod · 0.80
createSliderJointMethod · 0.80
createFixedJointsMethod · 0.80

Calls 8

createEntityMethod · 0.80
getIsEntityDisabledMethod · 0.80
addNoCollisionPairMethod · 0.80
getEntityMethod · 0.45
addComponentMethod · 0.45
allocateMethod · 0.45
setJointMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected