Working on debug renderer
This commit is contained in:
parent
0321cf4f89
commit
67e89e081b
|
@ -23,6 +23,7 @@
|
||||||
- A Collider can now be a trigger. This collider will be used to only report collisions with another collider but no collision response will be applied. You can use the Collider::setIsTrigger() method for this.
|
- A Collider can now be a trigger. This collider will be used to only report collisions with another collider but no collision response will be applied. You can use the Collider::setIsTrigger() method for this.
|
||||||
- The EventListener class now has a onTrigger() method that is called when a trigger collider is colling with another collider.
|
- The EventListener class now has a onTrigger() method that is called when a trigger collider is colling with another collider.
|
||||||
- In the EventListener, the onContact() and onTrigger() method now reports the type of event (start, stay, exit) for each contact. This way the user can know whether it's a new contact or not or when two colliders are not in contact anymore.
|
- In the EventListener, the onContact() and onTrigger() method now reports the type of event (start, stay, exit) for each contact. This way the user can know whether it's a new contact or not or when two colliders are not in contact anymore.
|
||||||
|
- A DebugRenderer class has been added in order to display debug info (colliders, AABBs, contacts, ...) using graphics primities (lines, triangles).
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
|
@ -71,25 +71,23 @@ class DebugRenderer : public EventListener {
|
||||||
|
|
||||||
/// Enumeration with debug item to renderer
|
/// Enumeration with debug item to renderer
|
||||||
enum class DebugItem {
|
enum class DebugItem {
|
||||||
|
|
||||||
|
/// Display the AABB for each collider
|
||||||
COLLIDER_AABB = 1 << 0,
|
COLLIDER_AABB = 1 << 0,
|
||||||
|
|
||||||
|
/// Display the fat AABB of the broad phase collision detection for each collider
|
||||||
COLLIDER_BROADPHASE_AABB = 1 << 1,
|
COLLIDER_BROADPHASE_AABB = 1 << 1,
|
||||||
|
|
||||||
|
/// Display the collision shape of each collider
|
||||||
COLLISION_SHAPE = 1 << 2,
|
COLLISION_SHAPE = 1 << 2,
|
||||||
|
|
||||||
|
/// Display the contact points
|
||||||
CONTACT_POINT = 1 << 3,
|
CONTACT_POINT = 1 << 3,
|
||||||
|
|
||||||
|
/// Display the contact normals
|
||||||
CONTACT_NORMAL = 1 << 4,
|
CONTACT_NORMAL = 1 << 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Struture that represents a point of the DebugRenderer
|
|
||||||
struct DebugPoint {
|
|
||||||
|
|
||||||
/// Constructor
|
|
||||||
DebugPoint(const Vector3& point, uint32 color) :point(point), color(color) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 point;
|
|
||||||
uint32 color;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Struture that represents a line of the DebugRenderer
|
/// Struture that represents a line of the DebugRenderer
|
||||||
struct DebugLine {
|
struct DebugLine {
|
||||||
|
|
||||||
|
@ -99,9 +97,16 @@ class DebugRenderer : public EventListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// First point of the line
|
||||||
Vector3 point1;
|
Vector3 point1;
|
||||||
|
|
||||||
|
/// Color of the first point
|
||||||
uint32 color1;
|
uint32 color1;
|
||||||
|
|
||||||
|
/// Second point of the line
|
||||||
Vector3 point2;
|
Vector3 point2;
|
||||||
|
|
||||||
|
/// Color of the second point
|
||||||
uint32 color2;
|
uint32 color2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -114,11 +119,22 @@ class DebugRenderer : public EventListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 point1;
|
/// First point of the triangle
|
||||||
|
Vector3 point1;
|
||||||
|
|
||||||
|
/// Color of the first point
|
||||||
uint32 color1;
|
uint32 color1;
|
||||||
|
|
||||||
|
/// Second point of the triangle
|
||||||
Vector3 point2;
|
Vector3 point2;
|
||||||
|
|
||||||
|
/// Color of the second point
|
||||||
uint32 color2;
|
uint32 color2;
|
||||||
|
|
||||||
|
/// Third point of the triangle
|
||||||
Vector3 point3;
|
Vector3 point3;
|
||||||
|
|
||||||
|
/// Color of the third point
|
||||||
uint32 color3;
|
uint32 color3;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -197,15 +213,6 @@ class DebugRenderer : public EventListener {
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~DebugRenderer();
|
~DebugRenderer();
|
||||||
|
|
||||||
/// Return the number of points
|
|
||||||
uint32 getNbPoints() const;
|
|
||||||
|
|
||||||
/// Return a reference to the list of points
|
|
||||||
const List<DebugPoint>& getPoints() const;
|
|
||||||
|
|
||||||
/// Return a pointer to the array of points
|
|
||||||
const DebugPoint* getPointsArray() const;
|
|
||||||
|
|
||||||
/// Return the number of lines
|
/// Return the number of lines
|
||||||
uint32 getNbLines() const;
|
uint32 getNbLines() const;
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ DebugRenderer::DebugRenderer(MemoryAllocator& allocator)
|
||||||
mContactPointSphereRadius(DEFAULT_CONTACT_POINT_SPHERE_RADIUS), mContactNormalLength(DEFAULT_CONTACT_NORMAL_LENGTH) {
|
mContactPointSphereRadius(DEFAULT_CONTACT_POINT_SPHERE_RADIUS), mContactNormalLength(DEFAULT_CONTACT_NORMAL_LENGTH) {
|
||||||
|
|
||||||
mMapDebugItemWithColor.add(Pair<DebugItem, uint32>(DebugItem::COLLIDER_AABB, static_cast<uint32>(DebugColor::MAGENTA)));
|
mMapDebugItemWithColor.add(Pair<DebugItem, uint32>(DebugItem::COLLIDER_AABB, static_cast<uint32>(DebugColor::MAGENTA)));
|
||||||
mMapDebugItemWithColor.add(Pair<DebugItem, uint32>(DebugItem::COLLIDER_BROADPHASE_AABB, static_cast<uint32>(DebugColor::YELLOW)));
|
mMapDebugItemWithColor.add(Pair<DebugItem, uint32>(DebugItem::COLLIDER_BROADPHASE_AABB, static_cast<uint32>(DebugColor::YELLOW)));
|
||||||
mMapDebugItemWithColor.add(Pair<DebugItem, uint32>(DebugItem::COLLISION_SHAPE, static_cast<uint32>(DebugColor::GREEN)));
|
mMapDebugItemWithColor.add(Pair<DebugItem, uint32>(DebugItem::COLLISION_SHAPE, static_cast<uint32>(DebugColor::GREEN)));
|
||||||
mMapDebugItemWithColor.add(Pair<DebugItem, uint32>(DebugItem::CONTACT_POINT, static_cast<uint32>(DebugColor::RED)));
|
mMapDebugItemWithColor.add(Pair<DebugItem, uint32>(DebugItem::CONTACT_POINT, static_cast<uint32>(DebugColor::RED)));
|
||||||
mMapDebugItemWithColor.add(Pair<DebugItem, uint32>(DebugItem::CONTACT_NORMAL, static_cast<uint32>(DebugColor::WHITE)));
|
mMapDebugItemWithColor.add(Pair<DebugItem, uint32>(DebugItem::CONTACT_NORMAL, static_cast<uint32>(DebugColor::WHITE)));
|
||||||
|
@ -408,30 +408,35 @@ void DebugRenderer::computeDebugRenderingPrimitives(const PhysicsWorld& world) {
|
||||||
// Get a body
|
// Get a body
|
||||||
const CollisionBody* body = b < nbCollisionBodies ? world.getCollisionBody(b) : world.getRigidBody(b - nbCollisionBodies);
|
const CollisionBody* body = b < nbCollisionBodies ? world.getCollisionBody(b) : world.getRigidBody(b - nbCollisionBodies);
|
||||||
|
|
||||||
// For each collider of the body
|
if (body->isActive()) {
|
||||||
for (uint c = 0; c < body->getNbColliders(); c++) {
|
|
||||||
|
|
||||||
// Get a collider
|
// For each collider of the body
|
||||||
const Collider* collider = body->getCollider(c);
|
for (uint c = 0; c < body->getNbColliders(); c++) {
|
||||||
|
|
||||||
// If we need to draw the collider AABB
|
// Get a collider
|
||||||
if (drawColliderAABB) {
|
const Collider* collider = body->getCollider(c);
|
||||||
|
|
||||||
drawAABB(collider->getWorldAABB(), mMapDebugItemWithColor[DebugItem::COLLIDER_AABB]);
|
// If we need to draw the collider AABB
|
||||||
|
if (drawColliderAABB) {
|
||||||
|
|
||||||
|
drawAABB(collider->getWorldAABB(), mMapDebugItemWithColor[DebugItem::COLLIDER_AABB]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we need to draw the collider broad-phase AABB
|
||||||
|
if (drawColliderBroadphaseAABB) {
|
||||||
|
|
||||||
|
if (collider->getBroadPhaseId() != -1) {
|
||||||
|
drawAABB(world.mCollisionDetection.mBroadPhaseSystem.getFatAABB(collider->getBroadPhaseId()), mMapDebugItemWithColor[DebugItem::COLLIDER_BROADPHASE_AABB]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we need to draw the collision shape
|
||||||
|
if (drawCollisionShape) {
|
||||||
|
|
||||||
|
drawCollisionShapeOfCollider(collider, mMapDebugItemWithColor[DebugItem::COLLISION_SHAPE]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// If we need to draw the collider broad-phase AABB
|
|
||||||
if (drawColliderBroadphaseAABB) {
|
|
||||||
|
|
||||||
drawAABB(world.mCollisionDetection.mBroadPhaseSystem.getFatAABB(collider->getBroadPhaseId()), mMapDebugItemWithColor[DebugItem::COLLIDER_BROADPHASE_AABB]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we need to draw the collision shape
|
|
||||||
if (drawCollisionShape) {
|
|
||||||
|
|
||||||
drawCollisionShapeOfCollider(collider, mMapDebugItemWithColor[DebugItem::COLLISION_SHAPE]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,12 @@ using namespace collisiondetectionscene;
|
||||||
// Constructor
|
// Constructor
|
||||||
CollisionDetectionScene::CollisionDetectionScene(const std::string& name, EngineSettings& settings)
|
CollisionDetectionScene::CollisionDetectionScene(const std::string& name, EngineSettings& settings)
|
||||||
: SceneDemo(name, settings, SCENE_RADIUS, false), mMeshFolderPath("meshes/"),
|
: SceneDemo(name, settings, SCENE_RADIUS, false), mMeshFolderPath("meshes/"),
|
||||||
mContactManager(mPhongShader, mMeshFolderPath, mContactPoints),
|
mContactManager(mPhongShader, mMeshFolderPath, mSnapshotsContactPoints),
|
||||||
mAreNormalsDisplayed(false) {
|
mAreNormalsDisplayed(false) {
|
||||||
|
|
||||||
mSelectedShapeIndex = 0;
|
mSelectedShapeIndex = 0;
|
||||||
mIsContactPointsDisplayed = true;
|
mAreContactPointsDisplayed = true;
|
||||||
|
mAreContactNormalsDisplayed = false;
|
||||||
mIsWireframeEnabled = true;
|
mIsWireframeEnabled = true;
|
||||||
|
|
||||||
// Compute the radius and the center of the scene
|
// Compute the radius and the center of the scene
|
||||||
|
@ -218,7 +219,10 @@ CollisionDetectionScene::~CollisionDetectionScene() {
|
||||||
// Take a step for the simulation
|
// Take a step for the simulation
|
||||||
void CollisionDetectionScene::update() {
|
void CollisionDetectionScene::update() {
|
||||||
|
|
||||||
mContactPoints.clear();
|
// Compute debug rendering primitives
|
||||||
|
mPhysicsWorld->getDebugRenderer().reset();
|
||||||
|
mPhysicsWorld->getDebugRenderer().computeDebugRenderingPrimitives(*mPhysicsWorld);
|
||||||
|
mSnapshotsContactPoints.clear();
|
||||||
|
|
||||||
mPhysicsWorld->testCollision(mContactManager);
|
mPhysicsWorld->testCollision(mContactManager);
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ class CollisionDetectionScene : public SceneDemo {
|
||||||
virtual void setIsShadowMappingEnabled(bool isShadowMappingEnabled) override;
|
virtual void setIsShadowMappingEnabled(bool isShadowMappingEnabled) override;
|
||||||
|
|
||||||
/// Display/Hide the contact points
|
/// Display/Hide the contact points
|
||||||
virtual void setIsContactPointsDisplayed(bool display) override;
|
virtual void setAreContactPointsDisplayed(bool display) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Display or not the surface normals at hit points
|
// Display or not the surface normals at hit points
|
||||||
|
@ -156,8 +156,8 @@ inline void CollisionDetectionScene::setIsShadowMappingEnabled(bool isShadowMapp
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display/Hide the contact points
|
// Display/Hide the contact points
|
||||||
inline void CollisionDetectionScene::setIsContactPointsDisplayed(bool display) {
|
inline void CollisionDetectionScene::setAreContactPointsDisplayed(bool display) {
|
||||||
SceneDemo::setIsContactPointsDisplayed(true);
|
SceneDemo::setAreContactPointsDisplayed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,14 +53,6 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name, EngineSettin
|
||||||
physicsWorld->setEventListener(this);
|
physicsWorld->setEventListener(this);
|
||||||
mPhysicsWorld = physicsWorld;
|
mPhysicsWorld = physicsWorld;
|
||||||
|
|
||||||
// TODO : Do not enable by default
|
|
||||||
mPhysicsWorld->setIsDebugRenderingEnabled(true);
|
|
||||||
mPhysicsWorld->getDebugRenderer().setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::COLLIDER_AABB, true);
|
|
||||||
mPhysicsWorld->getDebugRenderer().setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::COLLIDER_BROADPHASE_AABB, true);
|
|
||||||
mPhysicsWorld->getDebugRenderer().setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::COLLISION_SHAPE, true);
|
|
||||||
mPhysicsWorld->getDebugRenderer().setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::CONTACT_POINT, true);
|
|
||||||
mPhysicsWorld->getDebugRenderer().setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::CONTACT_NORMAL, true);
|
|
||||||
|
|
||||||
for (int i=0; i<NB_COMPOUND_SHAPES; i++) {
|
for (int i=0; i<NB_COMPOUND_SHAPES; i++) {
|
||||||
|
|
||||||
// Create a convex mesh and a corresponding rigid in the physics world
|
// Create a convex mesh and a corresponding rigid in the physics world
|
||||||
|
|
|
@ -33,11 +33,9 @@ using namespace raycastscene;
|
||||||
// Constructor
|
// Constructor
|
||||||
RaycastScene::RaycastScene(const std::string& name, EngineSettings& settings)
|
RaycastScene::RaycastScene(const std::string& name, EngineSettings& settings)
|
||||||
: SceneDemo(name, settings, SCENE_RADIUS, false), mMeshFolderPath("meshes/"),
|
: SceneDemo(name, settings, SCENE_RADIUS, false), mMeshFolderPath("meshes/"),
|
||||||
mRaycastManager(mPhongShader, mMeshFolderPath, mContactPoints), mCurrentBodyIndex(-1),
|
mRaycastManager(mMeshFolderPath, mSnapshotsContactPoints), mCurrentBodyIndex(-1),
|
||||||
mAreNormalsDisplayed(false), mVBOVertices(GL_ARRAY_BUFFER) {
|
mAreNormalsDisplayed(false), mVBOVertices(GL_ARRAY_BUFFER) {
|
||||||
|
|
||||||
mIsContactPointsDisplayed = true;
|
|
||||||
|
|
||||||
// Compute the radius and the center of the scene
|
// Compute the radius and the center of the scene
|
||||||
openglframework::Vector3 center(0, 0, 0);
|
openglframework::Vector3 center(0, 0, 0);
|
||||||
|
|
||||||
|
@ -267,11 +265,14 @@ RaycastScene::~RaycastScene() {
|
||||||
// Take a step for the simulation
|
// Take a step for the simulation
|
||||||
void RaycastScene::update() {
|
void RaycastScene::update() {
|
||||||
|
|
||||||
|
// Compute debug rendering primitives
|
||||||
|
mPhysicsWorld->getDebugRenderer().reset();
|
||||||
|
mPhysicsWorld->getDebugRenderer().computeDebugRenderingPrimitives(*mPhysicsWorld);
|
||||||
|
|
||||||
mRaycastManager.resetPoints();
|
mRaycastManager.resetPoints();
|
||||||
|
|
||||||
// For each line of the scene
|
// For each line of the scene
|
||||||
for (std::vector<Line*>::iterator it = mLines.begin(); it != mLines.end();
|
for (std::vector<Line*>::iterator it = mLines.begin(); it != mLines.end(); ++it) {
|
||||||
++it) {
|
|
||||||
|
|
||||||
Line* line = *it;
|
Line* line = *it;
|
||||||
|
|
||||||
|
@ -294,6 +295,10 @@ void RaycastScene::update() {
|
||||||
// Render the scene
|
// Render the scene
|
||||||
void RaycastScene::renderSinglePass(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix) {
|
void RaycastScene::renderSinglePass(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix) {
|
||||||
|
|
||||||
|
if (mIsWireframeEnabled) {
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
|
}
|
||||||
|
|
||||||
// Bind the VAO
|
// Bind the VAO
|
||||||
mVAO.bind();
|
mVAO.bind();
|
||||||
|
|
||||||
|
@ -342,6 +347,10 @@ void RaycastScene::renderSinglePass(openglframework::Shader& shader, const openg
|
||||||
|
|
||||||
// Unbind the shader
|
// Unbind the shader
|
||||||
shader.unbind();
|
shader.unbind();
|
||||||
|
|
||||||
|
if (mIsWireframeEnabled) {
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the Vertex Buffer Objects used to render with OpenGL.
|
// Create the Vertex Buffer Objects used to render with OpenGL.
|
||||||
|
|
|
@ -72,9 +72,8 @@ class RaycastManager : public rp3d::RaycastCallback {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RaycastManager(openglframework::Shader& shader, const std::string& meshFolderPath,
|
RaycastManager(const std::string& meshFolderPath, std::vector<SceneContactPoint>& hitPoints)
|
||||||
std::vector<SceneContactPoint>& hitPoints)
|
: mHitPoints(hitPoints), mMeshFolderPath(meshFolderPath) {
|
||||||
: mMeshFolderPath(meshFolderPath), mHitPoints(hitPoints) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,10 +93,6 @@ class RaycastManager : public rp3d::RaycastCallback {
|
||||||
|
|
||||||
mHitPoints.clear();
|
mHitPoints.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<SceneContactPoint> getHitPoints() const {
|
|
||||||
return mHitPoints;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class RaycastScene
|
// Class RaycastScene
|
||||||
|
@ -146,7 +141,6 @@ class RaycastScene : public SceneDemo {
|
||||||
// Create the Vertex Buffer Objects used to render with OpenGL.
|
// Create the Vertex Buffer Objects used to render with OpenGL.
|
||||||
void createVBOAndVAO();
|
void createVBOAndVAO();
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
@ -180,7 +174,7 @@ class RaycastScene : public SceneDemo {
|
||||||
virtual void setIsShadowMappingEnabled(bool isShadowMappingEnabled) override;
|
virtual void setIsShadowMappingEnabled(bool isShadowMappingEnabled) override;
|
||||||
|
|
||||||
/// Display/Hide the contact points
|
/// Display/Hide the contact points
|
||||||
virtual void setIsContactPointsDisplayed(bool display) override;
|
virtual void setAreContactPointsDisplayed(bool display) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Display or not the surface normals at hit points
|
// Display or not the surface normals at hit points
|
||||||
|
@ -194,8 +188,8 @@ inline void RaycastScene::setIsShadowMappingEnabled(bool isShadowMappingEnabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display/Hide the contact points
|
// Display/Hide the contact points
|
||||||
inline void RaycastScene::setIsContactPointsDisplayed(bool display) {
|
inline void RaycastScene::setAreContactPointsDisplayed(bool display) {
|
||||||
SceneDemo::setIsContactPointsDisplayed(true);
|
SceneDemo::setAreContactPointsDisplayed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,19 +399,55 @@ void Gui::createSettingsPanel() {
|
||||||
mRenderingPanel = new Widget(mSettingsPanel);
|
mRenderingPanel = new Widget(mSettingsPanel);
|
||||||
mRenderingPanel->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 0, 5));
|
mRenderingPanel->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 0, 5));
|
||||||
|
|
||||||
|
// Display/Hide contact points
|
||||||
|
CheckBox* checkboxDebugRendererEnabled = new CheckBox(mRenderingPanel, "Debug rendering");
|
||||||
|
checkboxDebugRendererEnabled->setChecked(mApp->mIsDebugRendererEnabled);
|
||||||
|
|
||||||
// Display/Hide contact points
|
// Display/Hide contact points
|
||||||
CheckBox* checkboxContactPoints = new CheckBox(mRenderingPanel, "Contact points");
|
CheckBox* checkboxContactPoints = new CheckBox(mRenderingPanel, "Contact points");
|
||||||
checkboxContactPoints->setChecked(mApp->mIsContactPointsDisplayed);
|
checkboxContactPoints->setChecked(mApp->mAreContactPointsDisplayed);
|
||||||
|
checkboxContactPoints->setEnabled(false);
|
||||||
checkboxContactPoints->setCallback([&](bool value) {
|
checkboxContactPoints->setCallback([&](bool value) {
|
||||||
mApp->mIsContactPointsDisplayed = value;
|
mApp->mAreContactPointsDisplayed = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Display/Hide contact normals
|
||||||
|
CheckBox* checkboxContactNormals = new CheckBox(mRenderingPanel, "Contact normals");
|
||||||
|
checkboxContactNormals->setChecked(mApp->mAreContactNormalsDisplayed);
|
||||||
|
checkboxContactNormals->setEnabled(false);
|
||||||
|
checkboxContactNormals->setCallback([&](bool value) {
|
||||||
|
mApp->mAreContactNormalsDisplayed = value;
|
||||||
|
});
|
||||||
|
|
||||||
// Display/Hide the AABBs
|
// Display/Hide the Broad-phase AABBs
|
||||||
CheckBox* checkboxAABBs = new CheckBox(mRenderingPanel, "AABBs");
|
CheckBox* checkboxBroadPhaseAABBs = new CheckBox(mRenderingPanel, "Broad phase AABBs");
|
||||||
checkboxAABBs->setChecked(mApp->mIsAABBsDisplayed);
|
checkboxBroadPhaseAABBs->setChecked(mApp->mAreBroadPhaseAABBsDisplayed);
|
||||||
checkboxAABBs->setCallback([&](bool value) {
|
checkboxBroadPhaseAABBs->setEnabled(false);
|
||||||
mApp->mIsAABBsDisplayed = value;
|
checkboxBroadPhaseAABBs->setCallback([&](bool value) {
|
||||||
|
mApp->mAreBroadPhaseAABBsDisplayed = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Display/Hide the colliders AABBs
|
||||||
|
CheckBox* checkboxColliderAABBs = new CheckBox(mRenderingPanel, "Colliders AABBs");
|
||||||
|
checkboxColliderAABBs->setChecked(mApp->mAreCollidersAABBsDisplayed);
|
||||||
|
checkboxColliderAABBs->setEnabled(false);
|
||||||
|
checkboxColliderAABBs->setCallback([&](bool value) {
|
||||||
|
mApp->mAreCollidersAABBsDisplayed = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Display/Hide the collision shapes
|
||||||
|
CheckBox* checkboxCollisionShapes = new CheckBox(mRenderingPanel, "Collision shapes");
|
||||||
|
checkboxCollisionShapes->setChecked(mApp->mAreCollisionShapesDisplayed);
|
||||||
|
checkboxCollisionShapes->setEnabled(false);
|
||||||
|
checkboxCollisionShapes->setCallback([&](bool value) {
|
||||||
|
mApp->mAreCollisionShapesDisplayed = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Enable/Disable wireframe mode
|
||||||
|
CheckBox* checkboxWireframe = new CheckBox(mRenderingPanel, "Objects Wireframe");
|
||||||
|
checkboxWireframe->setChecked(mApp->mAreObjectsWireframeEnabled);
|
||||||
|
checkboxWireframe->setCallback([&](bool value) {
|
||||||
|
mApp->mAreObjectsWireframeEnabled = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Enabled/Disable VSync
|
// Enabled/Disable VSync
|
||||||
|
@ -428,11 +464,15 @@ void Gui::createSettingsPanel() {
|
||||||
mApp->mIsShadowMappingEnabled = value;
|
mApp->mIsShadowMappingEnabled = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Enable/Disable wireframe mode
|
checkboxDebugRendererEnabled->setCallback([&, checkboxContactPoints, checkboxContactNormals,
|
||||||
CheckBox* checkboxWireframe = new CheckBox(mRenderingPanel, "Wireframe");
|
checkboxBroadPhaseAABBs, checkboxColliderAABBs,
|
||||||
checkboxWireframe->setChecked(mApp->mIsWireframeEnabled);
|
checkboxCollisionShapes](bool value) {
|
||||||
checkboxWireframe->setCallback([&](bool value) {
|
mApp->mIsDebugRendererEnabled = value;
|
||||||
mApp->mIsWireframeEnabled = value;
|
checkboxContactPoints->setEnabled(value);
|
||||||
|
checkboxContactNormals->setEnabled(value);
|
||||||
|
checkboxBroadPhaseAABBs->setEnabled(value);
|
||||||
|
checkboxColliderAABBs->setEnabled(value);
|
||||||
|
checkboxCollisionShapes->setEnabled(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
mPhysicsPanel->setVisible(true);
|
mPhysicsPanel->setVisible(true);
|
||||||
|
|
|
@ -33,7 +33,8 @@ using namespace openglframework;
|
||||||
Scene::Scene(const std::string& name, EngineSettings& engineSettings, bool isShadowMappingEnabled)
|
Scene::Scene(const std::string& name, EngineSettings& engineSettings, bool isShadowMappingEnabled)
|
||||||
: mName(name), mEngineSettings(engineSettings), mLastMouseX(0), mLastMouseY(0), mInterpolationFactor(0.0f), mViewportX(0), mViewportY(0),
|
: mName(name), mEngineSettings(engineSettings), mLastMouseX(0), mLastMouseY(0), mInterpolationFactor(0.0f), mViewportX(0), mViewportY(0),
|
||||||
mViewportWidth(0), mViewportHeight(0), mIsShadowMappingEnabled(isShadowMappingEnabled),
|
mViewportWidth(0), mViewportHeight(0), mIsShadowMappingEnabled(isShadowMappingEnabled),
|
||||||
mIsContactPointsDisplayed(true), mIsAABBsDisplayed(false), mIsWireframeEnabled(false) {
|
mAreContactPointsDisplayed(true), mAreContactNormalsDisplayed(false), mAreBroadPhaseAABBsDisplayed(false),
|
||||||
|
mAreCollidersAABBsDisplayed(false), mAreCollisionShapesDisplayed(false), mIsWireframeEnabled(false) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,29 +186,3 @@ void Scene::rotate(int xMouse, int yMouse) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when some contacts occur
|
|
||||||
void Scene::onContact(const rp3d::CollisionCallback::CallbackData& callbackData) {
|
|
||||||
|
|
||||||
// For each contact pair
|
|
||||||
for (uint p=0; p < callbackData.getNbContactPairs(); p++) {
|
|
||||||
|
|
||||||
rp3d::CollisionCallback::ContactPair contactPair = callbackData.getContactPair(p);
|
|
||||||
|
|
||||||
// For each contact point of the contact pair
|
|
||||||
for (uint c=0; c < contactPair.getNbContactPoints(); c++) {
|
|
||||||
|
|
||||||
rp3d::CollisionCallback::ContactPoint contactPoint = contactPair.getContactPoint(c);
|
|
||||||
|
|
||||||
rp3d::Vector3 point = contactPair.getCollider1()->getLocalToWorldTransform() * contactPoint.getLocalPointOnShape1();
|
|
||||||
rp3d::Vector3 normalWorld = contactPoint.getWorldNormal();
|
|
||||||
openglframework::Vector3 normal = openglframework::Vector3(normalWorld.x, normalWorld.y, normalWorld.z);
|
|
||||||
SceneContactPoint contact(openglframework::Vector3(point.x, point.y, point.z), normal, openglframework::Color::red());
|
|
||||||
mContactPoints.push_back(contact);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scene::onTrigger(const rp3d::OverlapCallback::CallbackData& callbackData) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -128,16 +128,25 @@ class Scene : public rp3d::EventListener {
|
||||||
bool mIsShadowMappingEnabled;
|
bool mIsShadowMappingEnabled;
|
||||||
|
|
||||||
/// True if contact points are displayed
|
/// True if contact points are displayed
|
||||||
bool mIsContactPointsDisplayed;
|
bool mAreContactPointsDisplayed;
|
||||||
|
|
||||||
/// True if the AABBs of the physics objects are displayed
|
/// True if contact normals are displayed
|
||||||
bool mIsAABBsDisplayed;
|
bool mAreContactNormalsDisplayed;
|
||||||
|
|
||||||
|
/// True if the broad phase AABBs of the physics objects are displayed
|
||||||
|
bool mAreBroadPhaseAABBsDisplayed;
|
||||||
|
|
||||||
|
/// True if the AABBs of the colliders are displayed
|
||||||
|
bool mAreCollidersAABBsDisplayed;
|
||||||
|
|
||||||
|
/// True if the AABBs of the colliders are displayed
|
||||||
|
bool mAreCollisionShapesDisplayed;
|
||||||
|
|
||||||
/// True if we render shapes in wireframe mode
|
/// True if we render shapes in wireframe mode
|
||||||
bool mIsWireframeEnabled;
|
bool mIsWireframeEnabled;
|
||||||
|
|
||||||
/// Contact points
|
/// Snapshots Contact points (computed with PhysicsWorld::testCollision() or PhysicsWorld::raycast() methods)
|
||||||
std::vector<SceneContactPoint> mContactPoints;
|
std::vector<SceneContactPoint> mSnapshotsContactPoints;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
|
@ -222,10 +231,19 @@ class Scene : public rp3d::EventListener {
|
||||||
void virtual setIsShadowMappingEnabled(bool isShadowMappingEnabled);
|
void virtual setIsShadowMappingEnabled(bool isShadowMappingEnabled);
|
||||||
|
|
||||||
/// Display/Hide the contact points
|
/// Display/Hide the contact points
|
||||||
void virtual setIsContactPointsDisplayed(bool display);
|
void virtual setAreContactPointsDisplayed(bool display);
|
||||||
|
|
||||||
|
/// Display/Hide the contact normals
|
||||||
|
void setAreContactNormalsDisplayed(bool display);
|
||||||
|
|
||||||
/// Display/Hide the AABBs
|
/// Display/Hide the AABBs
|
||||||
void setIsAABBsDisplayed(bool display);
|
void setAreBroadPhaseAABBsDisplayed(bool display);
|
||||||
|
|
||||||
|
/// Display/Hide the colliders AABBs
|
||||||
|
void setAreCollidersAABBsDisplayed(bool display);
|
||||||
|
|
||||||
|
/// Display/Hide the collision shapes
|
||||||
|
void setAreCollisionShapesDisplayed(bool display);
|
||||||
|
|
||||||
/// Return true if wireframe rendering is enabled
|
/// Return true if wireframe rendering is enabled
|
||||||
bool getIsWireframeEnabled() const;
|
bool getIsWireframeEnabled() const;
|
||||||
|
@ -233,13 +251,11 @@ class Scene : public rp3d::EventListener {
|
||||||
/// Enable/disbale wireframe rendering
|
/// Enable/disbale wireframe rendering
|
||||||
void setIsWireframeEnabled(bool isEnabled);
|
void setIsWireframeEnabled(bool isEnabled);
|
||||||
|
|
||||||
|
/// Enable/disable debug rendering
|
||||||
|
virtual void setIsDebugRendererEnabled(bool isEnabled)=0;
|
||||||
|
|
||||||
/// Update the engine settings
|
/// Update the engine settings
|
||||||
virtual void updateEngineSettings() = 0;
|
virtual void updateEngineSettings() = 0;
|
||||||
|
|
||||||
/// Called when some contacts occur
|
|
||||||
virtual void onContact(const rp3d::CollisionCallback::CallbackData& callbackData) override;
|
|
||||||
|
|
||||||
virtual void onTrigger(const rp3d::OverlapCallback::CallbackData& callbackData) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Called when a keyboard event occurs
|
// Called when a keyboard event occurs
|
||||||
|
@ -254,7 +270,7 @@ inline void Scene::reshape(int width, int height) {
|
||||||
|
|
||||||
// Reset the scene
|
// Reset the scene
|
||||||
inline void Scene::reset() {
|
inline void Scene::reset() {
|
||||||
mContactPoints.clear();
|
mSnapshotsContactPoints.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a reference to the camera
|
// Return a reference to the camera
|
||||||
|
@ -297,13 +313,28 @@ inline void Scene::setIsShadowMappingEnabled(bool isShadowMappingEnabled) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display/Hide the contact points
|
// Display/Hide the contact points
|
||||||
inline void Scene::setIsContactPointsDisplayed(bool display) {
|
inline void Scene::setAreContactPointsDisplayed(bool display) {
|
||||||
mIsContactPointsDisplayed = display;
|
mAreContactPointsDisplayed = display;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display/Hide the AABBs
|
// Display/Hide the contact normals
|
||||||
inline void Scene::setIsAABBsDisplayed(bool display) {
|
inline void Scene::setAreContactNormalsDisplayed(bool display) {
|
||||||
mIsAABBsDisplayed = display;
|
mAreContactNormalsDisplayed = display;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display/Hide the broad phase AABBs
|
||||||
|
inline void Scene::setAreBroadPhaseAABBsDisplayed(bool display) {
|
||||||
|
mAreBroadPhaseAABBsDisplayed = display;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display/Hide the colliders AABBs
|
||||||
|
inline void Scene::setAreCollidersAABBsDisplayed(bool display) {
|
||||||
|
mAreCollidersAABBsDisplayed = display;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display/Hide the collision shapes
|
||||||
|
inline void Scene::setAreCollisionShapesDisplayed(bool display) {
|
||||||
|
mAreCollisionShapesDisplayed = display;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if wireframe rendering is enabled
|
// Return true if wireframe rendering is enabled
|
||||||
|
@ -311,7 +342,7 @@ inline bool Scene::getIsWireframeEnabled() const {
|
||||||
return mIsWireframeEnabled;
|
return mIsWireframeEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable/disbale wireframe rendering
|
// Enable/disable wireframe rendering
|
||||||
inline void Scene::setIsWireframeEnabled(bool isEnabled) {
|
inline void Scene::setIsWireframeEnabled(bool isEnabled) {
|
||||||
mIsWireframeEnabled = isEnabled;
|
mIsWireframeEnabled = isEnabled;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,8 +127,14 @@ SceneDemo::~SceneDemo() {
|
||||||
// Update the scene
|
// Update the scene
|
||||||
void SceneDemo::update() {
|
void SceneDemo::update() {
|
||||||
|
|
||||||
|
mPhysicsWorld->getDebugRenderer().setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::CONTACT_POINT, mAreContactPointsDisplayed);
|
||||||
|
mPhysicsWorld->getDebugRenderer().setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::CONTACT_NORMAL, mAreContactNormalsDisplayed);
|
||||||
|
mPhysicsWorld->getDebugRenderer().setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::COLLIDER_BROADPHASE_AABB, mAreBroadPhaseAABBsDisplayed);
|
||||||
|
mPhysicsWorld->getDebugRenderer().setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::COLLIDER_AABB, mAreCollidersAABBsDisplayed);
|
||||||
|
mPhysicsWorld->getDebugRenderer().setIsDebugItemDisplayed(rp3d::DebugRenderer::DebugItem::COLLISION_SHAPE, mAreCollisionShapesDisplayed);
|
||||||
|
|
||||||
// Update the contact points
|
// Update the contact points
|
||||||
updateContactPoints();
|
updateSnapshotContactPoints();
|
||||||
|
|
||||||
// Update the position and orientation of the physics objects
|
// Update the position and orientation of the physics objects
|
||||||
for (std::vector<PhysicsObject*>::iterator it = mPhysicsObjects.begin(); it != mPhysicsObjects.end(); ++it) {
|
for (std::vector<PhysicsObject*>::iterator it = mPhysicsObjects.begin(); it != mPhysicsObjects.end(); ++it) {
|
||||||
|
@ -143,7 +149,7 @@ void SceneDemo::update() {
|
||||||
void SceneDemo::updatePhysics() {
|
void SceneDemo::updatePhysics() {
|
||||||
|
|
||||||
// Clear contacts points
|
// Clear contacts points
|
||||||
mContactPoints.clear();
|
mSnapshotsContactPoints.clear();
|
||||||
|
|
||||||
if (mIsPhysicsWorldSimulated) {
|
if (mIsPhysicsWorldSimulated) {
|
||||||
|
|
||||||
|
@ -269,15 +275,8 @@ void SceneDemo::render() {
|
||||||
// Render the objects of the scene
|
// Render the objects of the scene
|
||||||
renderSinglePass(mPhongShader, worldToCameraMatrix);
|
renderSinglePass(mPhongShader, worldToCameraMatrix);
|
||||||
|
|
||||||
// Render the contact points
|
// Render the snapshots contact points
|
||||||
if (mIsContactPointsDisplayed) {
|
renderSnapshotsContactPoints(mPhongShader, worldToCameraMatrix);
|
||||||
renderContactPoints(mPhongShader, worldToCameraMatrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render the AABBs
|
|
||||||
if (mIsAABBsDisplayed) {
|
|
||||||
renderAABBs(worldToCameraMatrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render the debug infos
|
// Render the debug infos
|
||||||
if (mPhysicsWorld->getIsDebugRenderingEnabled()) {
|
if (mPhysicsWorld->getIsDebugRenderingEnabled()) {
|
||||||
|
@ -456,27 +455,24 @@ void SceneDemo::drawTextureQuad() {
|
||||||
mVAOQuad.unbind();
|
mVAOQuad.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gather and create contact points
|
// Gather and create snapshots contact points
|
||||||
void SceneDemo::updateContactPoints() {
|
void SceneDemo::updateSnapshotContactPoints() {
|
||||||
|
|
||||||
// Remove the previous contact points
|
// Remove the previous contact points
|
||||||
removeAllVisualContactPoints();
|
removeAllVisualContactPoints();
|
||||||
|
|
||||||
if (mIsContactPointsDisplayed) {
|
// For each contact point
|
||||||
|
std::vector<SceneContactPoint>::const_iterator it;
|
||||||
|
for (it = mSnapshotsContactPoints.begin(); it != mSnapshotsContactPoints.end(); ++it) {
|
||||||
|
|
||||||
// For each contact point
|
// Create a visual contact point for rendering
|
||||||
std::vector<SceneContactPoint>::const_iterator it;
|
VisualContactPoint* point = new VisualContactPoint(it->point, mMeshFolderPath, it->point + it->normal, it->color);
|
||||||
for (it = mContactPoints.begin(); it != mContactPoints.end(); ++it) {
|
mVisualContactPoints.push_back(point);
|
||||||
|
|
||||||
// Create a visual contact point for rendering
|
|
||||||
VisualContactPoint* point = new VisualContactPoint(it->point, mMeshFolderPath, it->point + it->normal, it->color);
|
|
||||||
mVisualContactPoints.push_back(point);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the contact points
|
// Render the contact points
|
||||||
void SceneDemo::renderContactPoints(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix) {
|
void SceneDemo::renderSnapshotsContactPoints(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix) {
|
||||||
|
|
||||||
// Render all the contact points
|
// Render all the contact points
|
||||||
for (std::vector<VisualContactPoint*>::iterator it = mVisualContactPoints.begin();
|
for (std::vector<VisualContactPoint*>::iterator it = mVisualContactPoints.begin();
|
||||||
|
@ -606,30 +602,6 @@ void SceneDemo::renderDebugInfos(openglframework::Shader& shader, const openglfr
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the AABBs
|
|
||||||
void SceneDemo::renderAABBs(const openglframework::Matrix4& worldToCameraMatrix) {
|
|
||||||
|
|
||||||
// For each physics object of the scene
|
|
||||||
for (std::vector<PhysicsObject*>::iterator it = mPhysicsObjects.begin(); it != mPhysicsObjects.end(); ++it) {
|
|
||||||
|
|
||||||
// For each collider of the object
|
|
||||||
for (uint i=0; i < (*it)->getCollisionBody()->getNbColliders(); i++) {
|
|
||||||
|
|
||||||
rp3d::Collider* collider = (*it)->getCollisionBody()->getCollider(i);
|
|
||||||
|
|
||||||
// Get the broad-phase AABB corresponding to the collider
|
|
||||||
rp3d::AABB aabb = mPhysicsWorld->getWorldAABB(collider);
|
|
||||||
|
|
||||||
openglframework::Vector3 aabbCenter(aabb.getCenter().x, aabb.getCenter().y, aabb.getCenter().z);
|
|
||||||
openglframework::Vector3 aabbMin(aabb.getMin().x, aabb.getMin().y, aabb.getMin().z);
|
|
||||||
openglframework::Vector3 aabbMax(aabb.getMax().x, aabb.getMax().y, aabb.getMax().z);
|
|
||||||
|
|
||||||
// Render the AABB
|
|
||||||
AABB::render(aabbCenter, aabbMax - aabbMin, Color::green(), mColorShader, worldToCameraMatrix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneDemo::removeAllVisualContactPoints() {
|
void SceneDemo::removeAllVisualContactPoints() {
|
||||||
|
|
||||||
// Destroy all the visual contact points
|
// Destroy all the visual contact points
|
||||||
|
|
|
@ -138,10 +138,10 @@ class SceneDemo : public Scene {
|
||||||
void drawTextureQuad();
|
void drawTextureQuad();
|
||||||
|
|
||||||
/// Update the contact points
|
/// Update the contact points
|
||||||
void updateContactPoints();
|
void updateSnapshotContactPoints();
|
||||||
|
|
||||||
/// Render the contact points
|
/// Render the contact points
|
||||||
void renderContactPoints(openglframework::Shader& shader,
|
void renderSnapshotsContactPoints(openglframework::Shader& shader,
|
||||||
const openglframework::Matrix4& worldToCameraMatrix);
|
const openglframework::Matrix4& worldToCameraMatrix);
|
||||||
|
|
||||||
/// Update VBO with vertices and indices of debug info
|
/// Update VBO with vertices and indices of debug info
|
||||||
|
@ -150,9 +150,6 @@ class SceneDemo : public Scene {
|
||||||
/// Render Debug Infos
|
/// Render Debug Infos
|
||||||
void renderDebugInfos(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix);
|
void renderDebugInfos(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix);
|
||||||
|
|
||||||
/// Render the AABBs
|
|
||||||
void renderAABBs(const openglframework::Matrix4& worldToCameraMatrix);
|
|
||||||
|
|
||||||
/// Remove all contact points
|
/// Remove all contact points
|
||||||
void removeAllVisualContactPoints();
|
void removeAllVisualContactPoints();
|
||||||
|
|
||||||
|
@ -184,6 +181,9 @@ class SceneDemo : public Scene {
|
||||||
|
|
||||||
/// Enabled/Disable the shadow mapping
|
/// Enabled/Disable the shadow mapping
|
||||||
virtual void setIsShadowMappingEnabled(bool isShadowMappingEnabled) override;
|
virtual void setIsShadowMappingEnabled(bool isShadowMappingEnabled) override;
|
||||||
|
|
||||||
|
/// Enable/disable debug rendering
|
||||||
|
virtual void setIsDebugRendererEnabled(bool isEnabled) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Enabled/Disable the shadow mapping
|
// Enabled/Disable the shadow mapping
|
||||||
|
@ -196,4 +196,9 @@ inline void SceneDemo::setIsShadowMappingEnabled(bool isShadowMappingEnabled) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable/disable debug rendering
|
||||||
|
inline void SceneDemo::setIsDebugRendererEnabled(bool isEnabled) {
|
||||||
|
mPhysicsWorld->setIsDebugRenderingEnabled(isEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -63,8 +63,10 @@ TestbedApplication::TestbedApplication(bool isFullscreen, int windowWidth, int w
|
||||||
mWidth(windowWidth), mHeight(windowHeight),
|
mWidth(windowWidth), mHeight(windowHeight),
|
||||||
mSinglePhysicsStepEnabled(false), mSinglePhysicsStepDone(false),
|
mSinglePhysicsStepEnabled(false), mSinglePhysicsStepDone(false),
|
||||||
mWindowToFramebufferRatio(Vector2(1, 1)), mIsShadowMappingEnabled(true),
|
mWindowToFramebufferRatio(Vector2(1, 1)), mIsShadowMappingEnabled(true),
|
||||||
mIsContactPointsDisplayed(false), mIsAABBsDisplayed(false), mIsWireframeEnabled(false),
|
mAreContactPointsDisplayed(false), mAreContactNormalsDisplayed(false),
|
||||||
mIsVSyncEnabled(true) {
|
mAreBroadPhaseAABBsDisplayed(false), mAreCollidersAABBsDisplayed(false),
|
||||||
|
mAreCollisionShapesDisplayed(false), mAreObjectsWireframeEnabled(false),
|
||||||
|
mIsVSyncEnabled(true), mIsDebugRendererEnabled(false) {
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
@ -89,6 +91,10 @@ void TestbedApplication::init() {
|
||||||
|
|
||||||
mTimer.start();
|
mTimer.start();
|
||||||
|
|
||||||
|
// Enable OpenGL error reporting
|
||||||
|
glEnable(GL_DEBUG_OUTPUT);
|
||||||
|
glDebugMessageCallback(onOpenGLError, 0);
|
||||||
|
|
||||||
mIsInitialized = true;
|
mIsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +191,8 @@ void TestbedApplication::update() {
|
||||||
|
|
||||||
double currentTime = glfwGetTime();
|
double currentTime = glfwGetTime();
|
||||||
|
|
||||||
|
mCurrentScene->setIsDebugRendererEnabled(mIsDebugRendererEnabled);
|
||||||
|
|
||||||
// Update the physics
|
// Update the physics
|
||||||
if (mSinglePhysicsStepEnabled && !mSinglePhysicsStepDone) {
|
if (mSinglePhysicsStepEnabled && !mSinglePhysicsStepDone) {
|
||||||
updateSinglePhysicsStep();
|
updateSinglePhysicsStep();
|
||||||
|
@ -208,13 +216,22 @@ void TestbedApplication::update() {
|
||||||
mCurrentScene->setIsShadowMappingEnabled(mIsShadowMappingEnabled);
|
mCurrentScene->setIsShadowMappingEnabled(mIsShadowMappingEnabled);
|
||||||
|
|
||||||
// Display/Hide contact points
|
// Display/Hide contact points
|
||||||
mCurrentScene->setIsContactPointsDisplayed(mIsContactPointsDisplayed);
|
mCurrentScene->setAreContactPointsDisplayed(mAreContactPointsDisplayed);
|
||||||
|
|
||||||
// Display/Hide the AABBs
|
// Display/Hide contact normals
|
||||||
mCurrentScene->setIsAABBsDisplayed(mIsAABBsDisplayed);
|
mCurrentScene->setAreContactNormalsDisplayed(mAreContactNormalsDisplayed);
|
||||||
|
|
||||||
|
// Display/Hide the broad phase AABBs
|
||||||
|
mCurrentScene->setAreBroadPhaseAABBsDisplayed(mAreBroadPhaseAABBsDisplayed);
|
||||||
|
|
||||||
|
// Display/Hide the colliders AABBs
|
||||||
|
mCurrentScene->setAreCollidersAABBsDisplayed(mAreCollidersAABBsDisplayed);
|
||||||
|
|
||||||
|
// Display/Hide the collision shapes
|
||||||
|
mCurrentScene->setAreCollisionShapesDisplayed(mAreCollisionShapesDisplayed);
|
||||||
|
|
||||||
// Enable/Disable wireframe mode
|
// Enable/Disable wireframe mode
|
||||||
mCurrentScene->setIsWireframeEnabled(mIsWireframeEnabled);
|
mCurrentScene->setIsWireframeEnabled(mAreObjectsWireframeEnabled);
|
||||||
|
|
||||||
// Update the scene
|
// Update the scene
|
||||||
mCurrentScene->update();
|
mCurrentScene->update();
|
||||||
|
@ -234,9 +251,6 @@ void TestbedApplication::drawContents() {
|
||||||
// Render the scene
|
// Render the scene
|
||||||
mCurrentScene->render();
|
mCurrentScene->render();
|
||||||
|
|
||||||
// Check the OpenGL errors
|
|
||||||
checkOpenGLErrors();
|
|
||||||
|
|
||||||
mGui.update();
|
mGui.update();
|
||||||
|
|
||||||
// Compute the current framerate
|
// Compute the current framerate
|
||||||
|
@ -283,34 +297,16 @@ void TestbedApplication::notifyEngineSetttingsChanged() {
|
||||||
mCurrentScene->updateEngineSettings();
|
mCurrentScene->updateEngineSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the OpenGL errors
|
void GLAPIENTRY TestbedApplication::onOpenGLError(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
|
||||||
void TestbedApplication::checkOpenGLErrorsInternal(const char* file, int line) {
|
const GLchar* message, const void* userParam ) {
|
||||||
GLenum glError;
|
|
||||||
|
|
||||||
// Get the OpenGL errors
|
if (type == GL_DEBUG_TYPE_ERROR) {
|
||||||
glError = glGetError();
|
fprintf( stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
|
||||||
|
("** GL ERROR **" ),
|
||||||
// While there are errors
|
type, severity, message );
|
||||||
while (glError != GL_NO_ERROR) {
|
|
||||||
|
|
||||||
std::string error;
|
|
||||||
|
|
||||||
switch(glError) {
|
|
||||||
case GL_INVALID_OPERATION: error="INVALID_OPERATION"; break;
|
|
||||||
case GL_INVALID_ENUM: error="INVALID_ENUM"; break;
|
|
||||||
case GL_INVALID_VALUE: error="INVALID_VALUE"; break;
|
|
||||||
case GL_OUT_OF_MEMORY: error="OUT_OF_MEMORY"; break;
|
|
||||||
case GL_INVALID_FRAMEBUFFER_OPERATION: error="INVALID_FRAMEBUFFER_OPERATION"; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << "OpenGL Error #" << error.c_str() << " - " << file << ": " << line << std::endl;
|
|
||||||
|
|
||||||
// Get the next error
|
|
||||||
glError = glGetError();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Compute the FPS
|
// Compute the FPS
|
||||||
void TestbedApplication::computeFPS() {
|
void TestbedApplication::computeFPS() {
|
||||||
|
|
||||||
|
|
|
@ -104,17 +104,29 @@ class TestbedApplication : public Screen {
|
||||||
bool mIsShadowMappingEnabled;
|
bool mIsShadowMappingEnabled;
|
||||||
|
|
||||||
/// True if contact points are displayed
|
/// True if contact points are displayed
|
||||||
bool mIsContactPointsDisplayed;
|
bool mAreContactPointsDisplayed;
|
||||||
|
|
||||||
/// True if the AABBs of physics objects are displayed
|
/// True if contact normals are displayed
|
||||||
bool mIsAABBsDisplayed;
|
bool mAreContactNormalsDisplayed;
|
||||||
|
|
||||||
|
/// True if the broad phase AABBs are displayed
|
||||||
|
bool mAreBroadPhaseAABBsDisplayed;
|
||||||
|
|
||||||
|
/// True if the AABBs of the colliders are displayed
|
||||||
|
bool mAreCollidersAABBsDisplayed;
|
||||||
|
|
||||||
|
/// True if the collision shapes are displayed
|
||||||
|
bool mAreCollisionShapesDisplayed;
|
||||||
|
|
||||||
/// True if the wireframe rendering is enabled
|
/// True if the wireframe rendering is enabled
|
||||||
bool mIsWireframeEnabled;
|
bool mAreObjectsWireframeEnabled;
|
||||||
|
|
||||||
/// True if vsync is enabled
|
/// True if vsync is enabled
|
||||||
bool mIsVSyncEnabled;
|
bool mIsVSyncEnabled;
|
||||||
|
|
||||||
|
/// True if the debug renderer is enabled
|
||||||
|
bool mIsDebugRendererEnabled;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Private copy-constructor (for the singleton class)
|
/// Private copy-constructor (for the singleton class)
|
||||||
|
@ -132,9 +144,6 @@ class TestbedApplication : public Screen {
|
||||||
/// Update the simulation by taking a single physics step
|
/// Update the simulation by taking a single physics step
|
||||||
void updateSinglePhysicsStep();
|
void updateSinglePhysicsStep();
|
||||||
|
|
||||||
/// Check the OpenGL errors
|
|
||||||
static void checkOpenGLErrorsInternal(const char* file, int line);
|
|
||||||
|
|
||||||
/// Compute the FPS
|
/// Compute the FPS
|
||||||
void computeFPS();
|
void computeFPS();
|
||||||
|
|
||||||
|
@ -202,6 +211,10 @@ class TestbedApplication : public Screen {
|
||||||
/// Notify that the engine settings have changed
|
/// Notify that the engine settings have changed
|
||||||
void notifyEngineSetttingsChanged();
|
void notifyEngineSetttingsChanged();
|
||||||
|
|
||||||
|
/// Called when an OpenGL Error occurs
|
||||||
|
static void GLAPIENTRY onOpenGLError(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
|
||||||
|
const GLchar* message, const void* userParam );
|
||||||
|
|
||||||
// -------------------- Friendship -------------------- //
|
// -------------------- Friendship -------------------- //
|
||||||
|
|
||||||
friend class Gui;
|
friend class Gui;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user