Working on the testbed application (raycast and heightfield scenes)

This commit is contained in:
Daniel Chappuis 2016-02-08 22:27:11 +01:00
parent 4931e1450a
commit 7dae30718b
4 changed files with 25 additions and 4 deletions

View File

@ -208,7 +208,7 @@ void HeightField::generateGraphicsMesh() {
for (int j=0; j<HEIGHTFIELD_LENGTH; j++) { for (int j=0; j<HEIGHTFIELD_LENGTH; j++) {
float height = mHeightData[i][j] - (mMaxHeight - mMinHeight) * 0.5f; float height = mHeightData[i][j] - (mMaxHeight - mMinHeight) * 0.5f;
openglframework::Vector3 vertex(-HEIGHTFIELD_WIDTH * 0.5f + i, height, -HEIGHTFIELD_LENGTH * 0.5 + j); openglframework::Vector3 vertex(-(HEIGHTFIELD_WIDTH - 1) * 0.5f + i, height, -(HEIGHTFIELD_LENGTH - 1) * 0.5 + j);
mVertices.push_back(vertex); mVertices.push_back(vertex);

View File

@ -52,7 +52,6 @@ HeightFieldScene::HeightFieldScene(const std::string& name) : SceneDemo(name, SC
// ---------- Create the cube ----------- // // ---------- Create the cube ----------- //
// Position // Position
rp3d::decimal radius = 2.0;
openglframework::Vector3 spherePos(15, 10, 0); openglframework::Vector3 spherePos(15, 10, 0);
// Create a sphere and a corresponding rigid in the dynamics world // Create a sphere and a corresponding rigid in the dynamics world
@ -165,7 +164,7 @@ void HeightFieldScene::reset() {
rp3d::Transform transform(rp3d::Vector3(0, 0, 0), initOrientation); rp3d::Transform transform(rp3d::Vector3(0, 0, 0), initOrientation);
mHeightField->resetTransform(transform); mHeightField->resetTransform(transform);
rp3d::Vector3 spherePos(2, 15, 0); rp3d::Vector3 spherePos(-3.6, 15, 1.7);
rp3d::Transform sphereTransform(spherePos, initOrientation); rp3d::Transform sphereTransform(spherePos, initOrientation);
mBox->resetTransform(sphereTransform); mBox->resetTransform(sphereTransform);
} }

View File

@ -132,6 +132,16 @@ RaycastScene::RaycastScene(const std::string& name)
mConcaveMesh->setColor(mGreyColorDemo); mConcaveMesh->setColor(mGreyColorDemo);
mConcaveMesh->setSleepingColor(mRedColorDemo); mConcaveMesh->setSleepingColor(mRedColorDemo);
// ---------- Heightfield ---------- //
openglframework::Vector3 position9(0, 0, 0);
// Create a convex mesh and a corresponding collision body in the dynamics world
mHeightField = new HeightField(position9, mCollisionWorld);
// Set the color
mHeightField->setColor(mGreyColorDemo);
mHeightField->setSleepingColor(mRedColorDemo);
// Create the lines that will be used for raycasting // Create the lines that will be used for raycasting
createLines(); createLines();
@ -184,6 +194,7 @@ void RaycastScene::changeBody() {
mConvexMesh->getCollisionBody()->setIsActive(false); mConvexMesh->getCollisionBody()->setIsActive(false);
mDumbbell->getCollisionBody()->setIsActive(false); mDumbbell->getCollisionBody()->setIsActive(false);
mConcaveMesh->getCollisionBody()->setIsActive(false); mConcaveMesh->getCollisionBody()->setIsActive(false);
mHeightField->getCollisionBody()->setIsActive(false);
switch(mCurrentBodyIndex) { switch(mCurrentBodyIndex) {
case 0: mSphere->getCollisionBody()->setIsActive(true); case 0: mSphere->getCollisionBody()->setIsActive(true);
@ -202,6 +213,8 @@ void RaycastScene::changeBody() {
break; break;
case 7: mConcaveMesh->getCollisionBody()->setIsActive(true); case 7: mConcaveMesh->getCollisionBody()->setIsActive(true);
break; break;
case 8: mHeightField->getCollisionBody()->setIsActive(true);
break;
} }
} }
@ -259,6 +272,12 @@ RaycastScene::~RaycastScene() {
// Destroy the convex mesh // Destroy the convex mesh
delete mConcaveMesh; delete mConcaveMesh;
// Destroy the corresponding rigid body from the dynamics world
mCollisionWorld->destroyCollisionBody(mHeightField->getCollisionBody());
// Destroy the convex mesh
delete mHeightField;
mRaycastManager.resetPoints(); mRaycastManager.resetPoints();
// Destroy the static data for the visual contact points // Destroy the static data for the visual contact points
@ -365,6 +384,7 @@ void RaycastScene::renderSinglePass(openglframework::Shader& shader,
if (mConvexMesh->getCollisionBody()->isActive()) mConvexMesh->render(shader, worldToCameraMatrix); if (mConvexMesh->getCollisionBody()->isActive()) mConvexMesh->render(shader, worldToCameraMatrix);
if (mDumbbell->getCollisionBody()->isActive()) mDumbbell->render(shader, worldToCameraMatrix); if (mDumbbell->getCollisionBody()->isActive()) mDumbbell->render(shader, worldToCameraMatrix);
if (mConcaveMesh->getCollisionBody()->isActive()) mConcaveMesh->render(shader, worldToCameraMatrix); if (mConcaveMesh->getCollisionBody()->isActive()) mConcaveMesh->render(shader, worldToCameraMatrix);
if (mHeightField->getCollisionBody()->isActive()) mHeightField->render(shader, worldToCameraMatrix);
shader.unbind(); shader.unbind();
} }

View File

@ -40,6 +40,7 @@
#include "Line.h" #include "Line.h"
#include "ConvexMesh.h" #include "ConvexMesh.h"
#include "ConcaveMesh.h" #include "ConcaveMesh.h"
#include "HeightField.h"
#include "Dumbbell.h" #include "Dumbbell.h"
#include "VisualContactPoint.h" #include "VisualContactPoint.h"
#include "../common/Viewer.h" #include "../common/Viewer.h"
@ -59,7 +60,7 @@ const float CAPSULE_HEIGHT = 5.0f;
const float DUMBBELL_HEIGHT = 5.0f; const float DUMBBELL_HEIGHT = 5.0f;
const int NB_RAYS = 100; const int NB_RAYS = 100;
const float RAY_LENGTH = 30.0f; const float RAY_LENGTH = 30.0f;
const int NB_BODIES = 8; const int NB_BODIES = 9;
// Raycast manager // Raycast manager
class RaycastManager : public rp3d::RaycastCallback { class RaycastManager : public rp3d::RaycastCallback {
@ -147,6 +148,7 @@ class RaycastScene : public SceneDemo {
ConvexMesh* mConvexMesh; ConvexMesh* mConvexMesh;
Dumbbell* mDumbbell; Dumbbell* mDumbbell;
ConcaveMesh* mConcaveMesh; ConcaveMesh* mConcaveMesh;
HeightField* mHeightField;
/// Collision world used for the physics simulation /// Collision world used for the physics simulation
rp3d::CollisionWorld* mCollisionWorld; rp3d::CollisionWorld* mCollisionWorld;