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

Method Box

testbed/common/Box.cpp:41–82  ·  view source on GitHub ↗

Constructor

Source from the content-addressed store, hash-verified

39
40// Constructor
41Box::Box(reactphysics3d::BodyType type, bool isSimulationCollider, const openglframework::Vector3& size, reactphysics3d::PhysicsCommon& physicsCommon, reactphysics3d::PhysicsWorld* world,
42 const std::string& meshFolderPath)
43 : PhysicsObject(physicsCommon, meshFolderPath + "cube.obj"), mPhysicsWorld(world) {
44
45 // Initialize the size of the box
46 mSize[0] = size.x * 0.5f;
47 mSize[1] = size.y * 0.5f;
48 mSize[2] = size.z * 0.5f;
49
50 // Compute the scaling matrix
51 mScalingMatrix = openglframework::Matrix4(mSize[0], 0, 0, 0,
52 0, mSize[1], 0, 0,
53 0, 0, mSize[2], 0,
54 0, 0, 0, 1);
55
56 // Create the collision shape for the rigid body (box shape)
57 // ReactPhysics3D will clone this object to create an internal one. Therefore,
58 // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape()
59 mBoxShape = mPhysicsCommon.createBoxShape(rp3d::Vector3(mSize[0], mSize[1], mSize[2]));
60
61 mPreviousTransform = rp3d::Transform::identity();
62
63 // Create a rigid body in the physics world
64 rp3d::RigidBody* body = world->createRigidBody(mPreviousTransform);
65 body->setType(type);
66 body->setIsDebugEnabled(true);
67 mCollider = body->addCollider(mBoxShape, rp3d::Transform::identity());
68 mCollider->setIsSimulationCollider(isSimulationCollider);
69 body->updateMassPropertiesFromColliders();
70 mBody = body;
71
72 // If the Vertex Buffer object has not been created yet
73 if (totalNbBoxes == 0) {
74
75 // Create the Vertex Buffer
76 createVBOAndVAO();
77 }
78
79 totalNbBoxes++;
80
81 mTransformMatrix = mTransformMatrix * mScalingMatrix;
82}
83
84// Destructor
85Box::~Box() {

Callers

nothing calls this directly

Calls 9

Matrix4Class · 0.85
createBoxShapeMethod · 0.80
createRigidBodyMethod · 0.80
setTypeMethod · 0.80
setIsDebugEnabledMethod · 0.80
Vector3Class · 0.50
addColliderMethod · 0.45

Tested by

no test coverage detected