Constructor
| 29 | |
| 30 | // Constructor |
| 31 | HeightField::HeightField(reactphysics3d::BodyType type, bool isSimulationCollider, reactphysics3d::PhysicsCommon& physicsCommon, rp3d::PhysicsWorld* physicsWorld) |
| 32 | : PhysicsObject(physicsCommon), mPhysicsWorld(physicsWorld), mVBOVertices(GL_ARRAY_BUFFER), |
| 33 | mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER), |
| 34 | mVBOIndices(GL_ELEMENT_ARRAY_BUFFER) { |
| 35 | |
| 36 | // Compute the scaling matrix |
| 37 | mScalingMatrix = openglframework::Matrix4(0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1); |
| 38 | |
| 39 | // Generate the height field |
| 40 | generateHeightField(); |
| 41 | |
| 42 | // Generate the graphics mesh |
| 43 | generateGraphicsMesh(); |
| 44 | |
| 45 | // Create the collision shape for the rigid body (convex mesh shape) and |
| 46 | // do not forget to delete it at the end |
| 47 | std::vector<rp3d::Message> messages; |
| 48 | mHeightField = mPhysicsCommon.createHeightField(NB_POINTS_WIDTH, NB_POINTS_LENGTH, |
| 49 | mHeightData, rp3d::HeightField::HeightDataType::HEIGHT_FLOAT_TYPE, |
| 50 | messages); |
| 51 | assert(mHeightField != nullptr); |
| 52 | mHeightFieldShape = mPhysicsCommon.createHeightFieldShape(mHeightField); |
| 53 | mHeightFieldShape->setScale(rp3d::Vector3(0.5, 0.5, 0.5)); |
| 54 | |
| 55 | mPreviousTransform = rp3d::Transform::identity(); |
| 56 | |
| 57 | // Create a body |
| 58 | rp3d::RigidBody* body = physicsWorld->createRigidBody(mPreviousTransform); |
| 59 | body->setType(type); |
| 60 | body->setIsDebugEnabled(true); |
| 61 | mCollider = body->addCollider(mHeightFieldShape, rp3d::Transform::identity()); |
| 62 | mCollider->setIsSimulationCollider(isSimulationCollider); |
| 63 | body->updateMassPropertiesFromColliders(); |
| 64 | mBody = body; |
| 65 | |
| 66 | // Create the VBOs and VAO |
| 67 | createVBOAndVAO(); |
| 68 | |
| 69 | mTransformMatrix = mTransformMatrix * mScalingMatrix; |
| 70 | } |
| 71 | |
| 72 | // Destructor |
| 73 | HeightField::~HeightField() { |
nothing calls this directly
no test coverage detected