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

Method Sphere

testbed/common/Sphere.cpp:37–71  ·  view source on GitHub ↗

Constructor

Source from the content-addressed store, hash-verified

35
36// Constructor
37Sphere::Sphere(rp3d::BodyType type, bool isSimulationCollider, float radius, rp3d::PhysicsCommon& physicsCommon, rp3d::PhysicsWorld* world,
38 const std::string& meshFolderPath)
39 : PhysicsObject(physicsCommon, meshFolderPath + "sphere.obj"), mRadius(radius), mPhysicsWorld(world) {
40
41 // Compute the scaling matrix
42 mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0,
43 0, mRadius, 0, 0,
44 0, 0, mRadius, 0,
45 0, 0, 0, 1);
46
47 // Create the collision shape for the rigid body (sphere shape)
48 // ReactPhysics3D will clone this object to create an internal one. Therefore,
49 // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape()
50 mCollisionShape = mPhysicsCommon.createSphereShape(mRadius);
51
52 mPreviousTransform = rp3d::Transform::identity();
53
54 // Create a rigid body corresponding to the sphere in the physics world
55 rp3d::RigidBody* body = world->createRigidBody(mPreviousTransform);
56 body->setType(type);
57 body->setIsDebugEnabled(true);
58 mCollider = body->addCollider(mCollisionShape, rp3d::Transform::identity());
59 mCollider->setIsSimulationCollider(isSimulationCollider);
60 body->updateMassPropertiesFromColliders();
61 mBody = body;
62
63 mTransformMatrix = mTransformMatrix * mScalingMatrix;
64
65 // Create the VBOs and VAO
66 if (totalNbSpheres == 0) {
67 createVBOAndVAO();
68 }
69
70 totalNbSpheres++;
71}
72
73// Destructor
74Sphere::~Sphere() {

Callers

nothing calls this directly

Calls 8

Matrix4Class · 0.85
createSphereShapeMethod · 0.80
createRigidBodyMethod · 0.80
setTypeMethod · 0.80
setIsDebugEnabledMethod · 0.80
addColliderMethod · 0.45

Tested by

no test coverage detected