Modifications in concave shape scene in testbed application
This commit is contained in:
parent
4a5c57c37e
commit
357e0792ea
|
@ -29,13 +29,13 @@
|
|||
// Constructor
|
||||
ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position,
|
||||
reactphysics3d::CollisionWorld* world,
|
||||
const std::string& meshFolderPath)
|
||||
const std::string& meshPath)
|
||||
: openglframework::Mesh(), mVBOVertices(GL_ARRAY_BUFFER),
|
||||
mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER),
|
||||
mVBOIndices(GL_ELEMENT_ARRAY_BUFFER) {
|
||||
|
||||
// Load the mesh from a file
|
||||
openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "concavemesh.obj", *this);
|
||||
openglframework::MeshReaderWriter::loadMeshFromFile(meshPath, *this);
|
||||
|
||||
// Calculate the normals of the mesh
|
||||
calculateNormals();
|
||||
|
@ -86,13 +86,13 @@ ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position,
|
|||
// Constructor
|
||||
ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position, float mass,
|
||||
reactphysics3d::DynamicsWorld* dynamicsWorld,
|
||||
const std::string& meshFolderPath)
|
||||
const std::string& meshPath)
|
||||
: openglframework::Mesh(), mVBOVertices(GL_ARRAY_BUFFER),
|
||||
mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER),
|
||||
mVBOIndices(GL_ELEMENT_ARRAY_BUFFER) {
|
||||
|
||||
// Load the mesh from a file
|
||||
openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "concavemesh.obj", *this);
|
||||
openglframework::MeshReaderWriter::loadMeshFromFile(meshPath, *this);
|
||||
|
||||
// Calculate the normals of the mesh
|
||||
calculateNormals();
|
||||
|
|
|
@ -77,11 +77,11 @@ class ConcaveMesh : public openglframework::Mesh, public PhysicsObject {
|
|||
|
||||
/// Constructor
|
||||
ConcaveMesh(const openglframework::Vector3& position,
|
||||
rp3d::CollisionWorld* world, const std::string& meshFolderPath);
|
||||
rp3d::CollisionWorld* world, const std::string& meshPath);
|
||||
|
||||
/// Constructor
|
||||
ConcaveMesh(const openglframework::Vector3& position, float mass,
|
||||
rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath);
|
||||
rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshPath);
|
||||
|
||||
/// Destructor
|
||||
~ConcaveMesh();
|
||||
|
|
|
@ -29,13 +29,13 @@
|
|||
// Constructor
|
||||
ConvexMesh::ConvexMesh(const openglframework::Vector3 &position,
|
||||
reactphysics3d::CollisionWorld* world,
|
||||
const std::string& meshFolderPath)
|
||||
const std::string& meshPath)
|
||||
: openglframework::Mesh(), mVBOVertices(GL_ARRAY_BUFFER),
|
||||
mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER),
|
||||
mVBOIndices(GL_ELEMENT_ARRAY_BUFFER) {
|
||||
|
||||
// Load the mesh from a file
|
||||
openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "convexmesh.obj", *this);
|
||||
openglframework::MeshReaderWriter::loadMeshFromFile(meshPath, *this);
|
||||
|
||||
// Calculate the normals of the mesh
|
||||
calculateNormals();
|
||||
|
@ -80,13 +80,13 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position,
|
|||
// Constructor
|
||||
ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass,
|
||||
reactphysics3d::DynamicsWorld* dynamicsWorld,
|
||||
const std::string& meshFolderPath)
|
||||
const std::string& meshPath)
|
||||
: openglframework::Mesh(), mVBOVertices(GL_ARRAY_BUFFER),
|
||||
mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER),
|
||||
mVBOIndices(GL_ELEMENT_ARRAY_BUFFER) {
|
||||
|
||||
// Load the mesh from a file
|
||||
openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "convexmesh.obj", *this);
|
||||
openglframework::MeshReaderWriter::loadMeshFromFile(meshPath, *this);
|
||||
|
||||
// Calculate the normals of the mesh
|
||||
calculateNormals();
|
||||
|
|
|
@ -76,11 +76,11 @@ class ConvexMesh : public openglframework::Mesh, public PhysicsObject {
|
|||
|
||||
/// Constructor
|
||||
ConvexMesh(const openglframework::Vector3& position,
|
||||
rp3d::CollisionWorld* world, const std::string& meshFolderPath);
|
||||
rp3d::CollisionWorld* world, const std::string& meshPath);
|
||||
|
||||
/// Constructor
|
||||
ConvexMesh(const openglframework::Vector3& position, float mass,
|
||||
rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath);
|
||||
rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshPath);
|
||||
|
||||
/// Destructor
|
||||
~ConvexMesh();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Blender MTL File: 'concave_terrain.blend'
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl None
|
25823
testbed/meshes/city.obj
Normal file
25823
testbed/meshes/city.obj
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -164,7 +164,7 @@ class Vector3 {
|
|||
Vector3 normalize() {
|
||||
float l = length();
|
||||
if(l < std::numeric_limits<float>::epsilon() ) {
|
||||
assert(false);
|
||||
return *this;
|
||||
}
|
||||
x /= l;
|
||||
y /= l;
|
||||
|
|
|
@ -221,7 +221,7 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name)
|
|||
radius * sin(angle));
|
||||
|
||||
// Create a convex mesh and a corresponding rigid in the dynamics world
|
||||
ConvexMesh* mesh = new ConvexMesh(position, MESH_MASS, mDynamicsWorld, meshFolderPath);
|
||||
ConvexMesh* mesh = new ConvexMesh(position, MESH_MASS, mDynamicsWorld, meshFolderPath + "convexmesh.obj");
|
||||
|
||||
// Set the box color
|
||||
mesh->setColor(mDemoColors[i % mNbDemoColors]);
|
||||
|
|
|
@ -52,21 +52,27 @@ ConcaveMeshScene::ConcaveMeshScene(const std::string& name)
|
|||
// Set the number of iterations of the constraint solver
|
||||
mDynamicsWorld->setNbIterationsVelocitySolver(15);
|
||||
|
||||
// ---------- Create the cube ----------- //
|
||||
// ---------- Create the boxes ----------- //
|
||||
|
||||
// Position
|
||||
openglframework::Vector3 spherePos(15, 10, 0);
|
||||
for (int i=0; i<NB_BOXES_X; i++) {
|
||||
|
||||
// Create a sphere and a corresponding rigid in the dynamics world
|
||||
mBox = new Box(Vector3(3, 3, 3), spherePos, 80.1, mDynamicsWorld);
|
||||
for (int j=0; j<NB_BOXES_Z; j++) {
|
||||
|
||||
// Set the sphere color
|
||||
mBox->setColor(mDemoColors[0]);
|
||||
mBox->setSleepingColor(mRedColorDemo);
|
||||
// Position
|
||||
openglframework::Vector3 boxPosition(-NB_BOXES_X * BOX_SIZE * BOXES_SPACE / 2 + i * BOX_SIZE * BOXES_SPACE, 30, -NB_BOXES_Z * BOX_SIZE * BOXES_SPACE / 2 + j * BOX_SIZE * BOXES_SPACE);
|
||||
|
||||
// Change the material properties of the rigid body
|
||||
rp3d::Material& sphereMat = mBox->getRigidBody()->getMaterial();
|
||||
sphereMat.setBounciness(rp3d::decimal(0.2));
|
||||
// Create a sphere and a corresponding rigid in the dynamics world
|
||||
mBoxes[i * NB_BOXES_Z + j] = new Box(Vector3(BOX_SIZE, BOX_SIZE, BOX_SIZE) * 0.5f, boxPosition, 80.1, mDynamicsWorld);
|
||||
|
||||
// Set the sphere color
|
||||
mBoxes[i * NB_BOXES_Z + j]->setColor(mDemoColors[0]);
|
||||
mBoxes[i * NB_BOXES_Z + j]->setSleepingColor(mRedColorDemo);
|
||||
|
||||
// Change the material properties of the rigid body
|
||||
rp3d::Material& boxMaterial = mBoxes[i * NB_BOXES_Z + j]->getRigidBody()->getMaterial();
|
||||
boxMaterial.setBounciness(rp3d::decimal(0.2));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Create the triangular mesh ---------- //
|
||||
|
||||
|
@ -75,7 +81,7 @@ ConcaveMeshScene::ConcaveMeshScene(const std::string& name)
|
|||
rp3d::decimal mass = 1.0;
|
||||
|
||||
// Create a convex mesh and a corresponding rigid in the dynamics world
|
||||
mConcaveMesh = new ConcaveMesh(position, mass, mDynamicsWorld, meshFolderPath);
|
||||
mConcaveMesh = new ConcaveMesh(position, mass, mDynamicsWorld, meshFolderPath + "city.obj");
|
||||
|
||||
// Set the mesh as beeing static
|
||||
mConcaveMesh->getRigidBody()->setType(rp3d::STATIC);
|
||||
|
@ -104,11 +110,14 @@ ConcaveMeshScene::ConcaveMeshScene(const std::string& name)
|
|||
// Destructor
|
||||
ConcaveMeshScene::~ConcaveMeshScene() {
|
||||
|
||||
mDynamicsWorld->destroyRigidBody(mBox->getRigidBody());
|
||||
// Destroy the corresponding rigid body from the dynamics world
|
||||
mDynamicsWorld->destroyRigidBody(mConcaveMesh->getRigidBody());
|
||||
|
||||
delete mBox;
|
||||
// Destroy the boxes
|
||||
for (int i=0; i<NB_BOXES_X * NB_BOXES_Z; i++) {
|
||||
mDynamicsWorld->destroyRigidBody(mBoxes[i]->getRigidBody());
|
||||
delete mBoxes[i];
|
||||
}
|
||||
|
||||
// Destroy the convex mesh
|
||||
delete mConcaveMesh;
|
||||
|
@ -143,7 +152,10 @@ void ConcaveMeshScene::update() {
|
|||
|
||||
// Update the transform used for the rendering
|
||||
mConcaveMesh->updateTransform(mInterpolationFactor);
|
||||
mBox->updateTransform(mInterpolationFactor);
|
||||
|
||||
for (int i=0; i<NB_BOXES_X * NB_BOXES_Z; i++) {
|
||||
mBoxes[i]->updateTransform(mInterpolationFactor);
|
||||
}
|
||||
}
|
||||
|
||||
// Render the scene in a single pass
|
||||
|
@ -153,7 +165,10 @@ void ConcaveMeshScene::renderSinglePass(Shader& shader, const openglframework::M
|
|||
shader.bind();
|
||||
|
||||
mConcaveMesh->render(shader, worldToCameraMatrix);
|
||||
mBox->render(shader, worldToCameraMatrix);
|
||||
|
||||
for (int i=0; i<NB_BOXES_X * NB_BOXES_Z; i++) {
|
||||
mBoxes[i]->render(shader, worldToCameraMatrix);
|
||||
}
|
||||
|
||||
// Unbind the shader
|
||||
shader.unbind();
|
||||
|
@ -163,13 +178,18 @@ void ConcaveMeshScene::renderSinglePass(Shader& shader, const openglframework::M
|
|||
void ConcaveMeshScene::reset() {
|
||||
|
||||
// Reset the transform
|
||||
rp3d::Quaternion initOrientation(0, 0, 3.141/12);
|
||||
rp3d::Quaternion initOrientation2(0, 0, 3.141/13);
|
||||
//rp3d::Transform transform(rp3d::Vector3(0, 0, 0), initOrientation);
|
||||
rp3d::Transform transform(rp3d::Vector3(0, 0, 0), initOrientation2);
|
||||
rp3d::Transform transform(rp3d::Vector3::zero(), rp3d::Quaternion::identity());
|
||||
mConcaveMesh->resetTransform(transform);
|
||||
|
||||
rp3d::Vector3 spherePos(2, 15, 0);
|
||||
rp3d::Transform sphereTransform(spherePos, initOrientation2);
|
||||
mBox->resetTransform(sphereTransform);
|
||||
for (int i=0; i<NB_BOXES_X; i++) {
|
||||
for (int j=0; j<NB_BOXES_Z; j++) {
|
||||
|
||||
// Position
|
||||
rp3d::Vector3 boxPosition(-NB_BOXES_X * BOX_SIZE * BOXES_SPACE / 2 + i * BOX_SIZE * BOXES_SPACE, 30, -NB_BOXES_Z * BOX_SIZE * BOXES_SPACE / 2 + j * BOX_SIZE * BOXES_SPACE);
|
||||
|
||||
rp3d::Transform boxTransform(boxPosition, rp3d::Quaternion::identity());
|
||||
mBoxes[i * NB_BOXES_Z + j]->resetTransform(boxTransform);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,10 @@ namespace trianglemeshscene {
|
|||
|
||||
// Constants
|
||||
const float SCENE_RADIUS = 30.0f; // Radius of the scene in meters
|
||||
const int NB_BOXES_X = 8;
|
||||
const int NB_BOXES_Z = 8;
|
||||
const float BOX_SIZE = 3.0f;
|
||||
const float BOXES_SPACE = 2.0f;
|
||||
|
||||
// Class TriangleMeshScene
|
||||
class ConcaveMeshScene : public SceneDemo {
|
||||
|
@ -46,7 +50,7 @@ class ConcaveMeshScene : public SceneDemo {
|
|||
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
Box* mBox;
|
||||
Box* mBoxes[NB_BOXES_X * NB_BOXES_Z];
|
||||
|
||||
/// Concave triangles mesh
|
||||
ConcaveMesh* mConcaveMesh;
|
||||
|
|
|
@ -57,16 +57,16 @@ HeightFieldScene::HeightFieldScene(const std::string& name) : SceneDemo(name, SC
|
|||
// Position
|
||||
openglframework::Vector3 position(15, 10 + 6 * i, 0);
|
||||
|
||||
// Create a sphere and a corresponding rigid in the dynamics world
|
||||
// Create a box and a corresponding rigid in the dynamics world
|
||||
mBoxes[i] = new Box(Vector3(3, 3, 3), position, 80.1, mDynamicsWorld);
|
||||
|
||||
// Set the sphere color
|
||||
// Set the box color
|
||||
mBoxes[i]->setColor(mDemoColors[2]);
|
||||
mBoxes[i]->setSleepingColor(mRedColorDemo);
|
||||
|
||||
// Change the material properties of the rigid body
|
||||
rp3d::Material& sphereMat = mBoxes[i]->getRigidBody()->getMaterial();
|
||||
sphereMat.setBounciness(rp3d::decimal(0.2));
|
||||
rp3d::Material& boxMaterial = mBoxes[i]->getRigidBody()->getMaterial();
|
||||
boxMaterial.setBounciness(rp3d::decimal(0.2));
|
||||
}
|
||||
|
||||
// ---------- Create the height field ---------- //
|
||||
|
@ -174,15 +174,14 @@ void HeightFieldScene::renderSinglePass(Shader& shader, const openglframework::M
|
|||
void HeightFieldScene::reset() {
|
||||
|
||||
// Reset the transform
|
||||
rp3d::Quaternion initOrientation = rp3d::Quaternion::identity();
|
||||
rp3d::Transform transform(rp3d::Vector3(0, 0, 0), initOrientation);
|
||||
rp3d::Transform transform(rp3d::Vector3(0, 0, 0), rp3d::Quaternion::identity());
|
||||
mHeightField->resetTransform(transform);
|
||||
|
||||
float heightFieldWidth = 10.0f;
|
||||
float stepDist = heightFieldWidth / (NB_BOXES + 1);
|
||||
for (int i=0; i<NB_BOXES; i++) {
|
||||
rp3d::Vector3 spherePos(-heightFieldWidth * 0.5f + i * stepDist , 14 + 6.0f * i, -heightFieldWidth * 0.5f + i * stepDist);
|
||||
rp3d::Transform sphereTransform(spherePos, initOrientation);
|
||||
mBoxes[i]->resetTransform(sphereTransform);
|
||||
rp3d::Vector3 boxPosition(-heightFieldWidth * 0.5f + i * stepDist , 14 + 6.0f * i, -heightFieldWidth * 0.5f + i * stepDist);
|
||||
rp3d::Transform boxTransform(boxPosition, rp3d::Quaternion::identity());
|
||||
mBoxes[i]->resetTransform(boxTransform);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ RaycastScene::RaycastScene(const std::string& name)
|
|||
openglframework::Vector3 position7(0, 0, 0);
|
||||
|
||||
// Create a convex mesh and a corresponding collision body in the dynamics world
|
||||
mConvexMesh = new ConvexMesh(position7, mCollisionWorld, mMeshFolderPath);
|
||||
mConvexMesh = new ConvexMesh(position7, mCollisionWorld, mMeshFolderPath + "convexmesh.obj");
|
||||
|
||||
// Set the color
|
||||
mConvexMesh->setColor(mGreyColorDemo);
|
||||
|
@ -126,7 +126,7 @@ RaycastScene::RaycastScene(const std::string& name)
|
|||
openglframework::Vector3 position8(0, 0, 0);
|
||||
|
||||
// Create a convex mesh and a corresponding collision body in the dynamics world
|
||||
mConcaveMesh = new ConcaveMesh(position8, mCollisionWorld, mMeshFolderPath);
|
||||
mConcaveMesh = new ConcaveMesh(position8, mCollisionWorld, mMeshFolderPath + "city.obj");
|
||||
|
||||
// Set the color
|
||||
mConcaveMesh->setColor(mGreyColorDemo);
|
||||
|
|
Loading…
Reference in New Issue
Block a user