Fix rendering issue in RaycastScene
This commit is contained in:
parent
ce80426a2c
commit
06e68baa39
|
@ -33,6 +33,7 @@ openglframework::VertexBufferObject VisualContactPoint::mVBOIndices(GL_ELEMENT_A
|
||||||
openglframework::VertexArrayObject VisualContactPoint::mVAO;
|
openglframework::VertexArrayObject VisualContactPoint::mVAO;
|
||||||
int VisualContactPoint::mNbTotalPoints = 0;
|
int VisualContactPoint::mNbTotalPoints = 0;
|
||||||
openglframework::Mesh VisualContactPoint::mMesh;
|
openglframework::Mesh VisualContactPoint::mMesh;
|
||||||
|
bool VisualContactPoint::mStaticDataCreated = false;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
VisualContactPoint::VisualContactPoint(const openglframework::Vector3& position,
|
VisualContactPoint::VisualContactPoint(const openglframework::Vector3& position,
|
||||||
|
@ -51,6 +52,8 @@ VisualContactPoint::~VisualContactPoint() {
|
||||||
// Load and initialize the mesh for all the contact points
|
// Load and initialize the mesh for all the contact points
|
||||||
void VisualContactPoint::createStaticData(const std::string& meshFolderPath) {
|
void VisualContactPoint::createStaticData(const std::string& meshFolderPath) {
|
||||||
|
|
||||||
|
if (mStaticDataCreated) return;
|
||||||
|
|
||||||
// Load the mesh from a file
|
// Load the mesh from a file
|
||||||
openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "sphere.obj", mMesh);
|
openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "sphere.obj", mMesh);
|
||||||
|
|
||||||
|
@ -60,11 +63,15 @@ void VisualContactPoint::createStaticData(const std::string& meshFolderPath) {
|
||||||
mMesh.scaleVertices(VISUAL_CONTACT_POINT_RADIUS);
|
mMesh.scaleVertices(VISUAL_CONTACT_POINT_RADIUS);
|
||||||
|
|
||||||
createVBOAndVAO();
|
createVBOAndVAO();
|
||||||
|
|
||||||
|
mStaticDataCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy the mesh for the contact points
|
// Destroy the mesh for the contact points
|
||||||
void VisualContactPoint::destroyStaticData() {
|
void VisualContactPoint::destroyStaticData() {
|
||||||
|
|
||||||
|
if (!mStaticDataCreated) return;
|
||||||
|
|
||||||
// Destroy the VBOs and VAO
|
// Destroy the VBOs and VAO
|
||||||
mVBOIndices.destroy();
|
mVBOIndices.destroy();
|
||||||
mVBOVertices.destroy();
|
mVBOVertices.destroy();
|
||||||
|
@ -72,15 +79,22 @@ void VisualContactPoint::destroyStaticData() {
|
||||||
mVAO.destroy();
|
mVAO.destroy();
|
||||||
|
|
||||||
mMesh.destroy();
|
mMesh.destroy();
|
||||||
|
|
||||||
|
mStaticDataCreated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the sphere at the correct position and with the correct orientation
|
// Render the sphere at the correct position and with the correct orientation
|
||||||
void VisualContactPoint::render(openglframework::Shader& shader,
|
void VisualContactPoint::render(openglframework::Shader& shader,
|
||||||
const openglframework::Matrix4& worldToCameraMatrix) {
|
const openglframework::Matrix4& worldToCameraMatrix) {
|
||||||
|
|
||||||
|
// Bind the VAO
|
||||||
|
mVAO.bind();
|
||||||
|
|
||||||
// Bind the shader
|
// Bind the shader
|
||||||
shader.bind();
|
shader.bind();
|
||||||
|
|
||||||
|
mVBOVertices.bind();
|
||||||
|
|
||||||
// Set the model to camera matrix
|
// Set the model to camera matrix
|
||||||
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
|
||||||
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
|
||||||
|
@ -96,11 +110,6 @@ void VisualContactPoint::render(openglframework::Shader& shader,
|
||||||
openglframework::Vector4 color(mColor.r, mColor.g, mColor.b, mColor.a);
|
openglframework::Vector4 color(mColor.r, mColor.g, mColor.b, mColor.a);
|
||||||
shader.setVector4Uniform("vertexColor", color, false);
|
shader.setVector4Uniform("vertexColor", color, false);
|
||||||
|
|
||||||
// Bind the VAO
|
|
||||||
mVAO.bind();
|
|
||||||
|
|
||||||
mVBOVertices.bind();
|
|
||||||
|
|
||||||
// Get the location of shader attribute variables
|
// Get the location of shader attribute variables
|
||||||
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
|
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
|
||||||
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false);
|
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false);
|
||||||
|
|
|
@ -56,6 +56,9 @@ class VisualContactPoint : public openglframework::Object3D {
|
||||||
/// Vertex Array Object for the vertex data
|
/// Vertex Array Object for the vertex data
|
||||||
static openglframework::VertexArrayObject mVAO;
|
static openglframework::VertexArrayObject mVAO;
|
||||||
|
|
||||||
|
/// True if static data (VBO, VAO) has been created already
|
||||||
|
static bool mStaticDataCreated;
|
||||||
|
|
||||||
/// Color
|
/// Color
|
||||||
openglframework::Color mColor;
|
openglframework::Color mColor;
|
||||||
|
|
||||||
|
|
|
@ -296,9 +296,14 @@ void RaycastScene::update() {
|
||||||
void RaycastScene::renderSinglePass(openglframework::Shader& shader,
|
void RaycastScene::renderSinglePass(openglframework::Shader& shader,
|
||||||
const openglframework::Matrix4& worldToCameraMatrix) {
|
const openglframework::Matrix4& worldToCameraMatrix) {
|
||||||
|
|
||||||
|
// Bind the VAO
|
||||||
|
mVAO.bind();
|
||||||
|
|
||||||
// Bind the shader
|
// Bind the shader
|
||||||
shader.bind();
|
shader.bind();
|
||||||
|
|
||||||
|
mVBOVertices.bind();
|
||||||
|
|
||||||
// Set the model to camera matrix
|
// Set the model to camera matrix
|
||||||
const Matrix4 localToCameraMatrix = Matrix4::identity();
|
const Matrix4 localToCameraMatrix = Matrix4::identity();
|
||||||
shader.setMatrix4x4Uniform("localToWorldMatrix", localToCameraMatrix);
|
shader.setMatrix4x4Uniform("localToWorldMatrix", localToCameraMatrix);
|
||||||
|
@ -314,12 +319,19 @@ void RaycastScene::renderSinglePass(openglframework::Shader& shader,
|
||||||
openglframework::Vector4 color(1, 0, 0, 1);
|
openglframework::Vector4 color(1, 0, 0, 1);
|
||||||
shader.setVector4Uniform("vertexColor", color, false);
|
shader.setVector4Uniform("vertexColor", color, false);
|
||||||
|
|
||||||
// Bind the VAO
|
// Get the location of shader attribute variables
|
||||||
mVAO.bind();
|
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(vertexPositionLoc);
|
||||||
|
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
|
||||||
|
|
||||||
// Draw the lines
|
// Draw the lines
|
||||||
glDrawArrays(GL_LINES, 0, NB_RAYS);
|
glDrawArrays(GL_LINES, 0, NB_RAYS);
|
||||||
|
|
||||||
|
glDisableVertexAttribArray(vertexPositionLoc);
|
||||||
|
|
||||||
|
mVBOVertices.unbind();
|
||||||
|
|
||||||
// Unbind the VAO
|
// Unbind the VAO
|
||||||
mVAO.unbind();
|
mVAO.unbind();
|
||||||
|
|
||||||
|
@ -335,27 +347,6 @@ void RaycastScene::renderSinglePass(openglframework::Shader& shader,
|
||||||
if (mDumbbell->getCollisionBody()->isActive()) mDumbbell->render(shader, worldToCameraMatrix);
|
if (mDumbbell->getCollisionBody()->isActive()) mDumbbell->render(shader, worldToCameraMatrix);
|
||||||
|
|
||||||
//mPhongShader.unbind();
|
//mPhongShader.unbind();
|
||||||
shader.bind();
|
|
||||||
|
|
||||||
openglframework::Vector4 redColor(1, 0, 0, 1);
|
|
||||||
shader.setVector4Uniform("vertexColor", redColor, false);
|
|
||||||
|
|
||||||
// Render all the raycast hit points
|
|
||||||
mRaycastManager.render(worldToCameraMatrix, mAreNormalsDisplayed);
|
|
||||||
|
|
||||||
shader.unbind();
|
|
||||||
shader.bind();
|
|
||||||
|
|
||||||
openglframework::Vector4 blueColor(0, 0.62, 0.92, 1);
|
|
||||||
shader.setVector4Uniform("vertexColor", blueColor, false);
|
|
||||||
|
|
||||||
// Render the lines
|
|
||||||
for (std::vector<Line*>::iterator it = mLines.begin(); it != mLines.end();
|
|
||||||
++it) {
|
|
||||||
(*it)->render(shader, worldToCameraMatrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unbind the shader
|
|
||||||
shader.unbind();
|
shader.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,9 +357,6 @@ void RaycastScene::createVBOAndVAO(openglframework::Shader& shader) {
|
||||||
// Bind the shader
|
// Bind the shader
|
||||||
shader.bind();
|
shader.bind();
|
||||||
|
|
||||||
// Get the location of shader attribute variables
|
|
||||||
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
|
|
||||||
|
|
||||||
// Create the VBO for the vertices data
|
// Create the VBO for the vertices data
|
||||||
mVBOVertices.create();
|
mVBOVertices.create();
|
||||||
mVBOVertices.bind();
|
mVBOVertices.bind();
|
||||||
|
@ -382,8 +370,6 @@ void RaycastScene::createVBOAndVAO(openglframework::Shader& shader) {
|
||||||
|
|
||||||
// Bind the VBO of vertices
|
// Bind the VBO of vertices
|
||||||
mVBOVertices.bind();
|
mVBOVertices.bind();
|
||||||
glEnableVertexAttribArray(vertexPositionLoc);
|
|
||||||
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
|
|
||||||
|
|
||||||
// Unbind the VAO
|
// Unbind the VAO
|
||||||
mVAO.unbind();
|
mVAO.unbind();
|
||||||
|
|
|
@ -99,36 +99,8 @@ class RaycastManager : public rp3d::RaycastCallback {
|
||||||
return raycastInfo.hitFraction;
|
return raycastInfo.hitFraction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(const openglframework::Matrix4& worldToCameraMatrix,
|
|
||||||
bool showNormals) {
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Render all the raycast hit points
|
|
||||||
for (std::vector<ContactPoint>::iterator it = mHitPoints.begin();
|
|
||||||
it != mHitPoints.end(); ++it) {
|
|
||||||
(*it)->render(mShader, worldToCameraMatrix);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (showNormals) {
|
|
||||||
|
|
||||||
// Render all the normals at hit points
|
|
||||||
for (std::vector<Line*>::iterator it = mNormals.begin();
|
|
||||||
it != mNormals.end(); ++it) {
|
|
||||||
(*it)->render(mShader, worldToCameraMatrix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void resetPoints() {
|
void resetPoints() {
|
||||||
|
|
||||||
/*
|
|
||||||
// Destroy all the visual contact points
|
|
||||||
for (std::vector<VisualContactPoint*>::iterator it = mHitPoints.begin();
|
|
||||||
it != mHitPoints.end(); ++it) {
|
|
||||||
delete (*it);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
mHitPoints.clear();
|
mHitPoints.clear();
|
||||||
|
|
||||||
// Destroy all the normals
|
// Destroy all the normals
|
||||||
|
|
|
@ -188,7 +188,7 @@ void SceneDemo::render() {
|
||||||
if (mIsShadowMappingEnabled) mShadowMapTexture.unbind();
|
if (mIsShadowMappingEnabled) mShadowMapTexture.unbind();
|
||||||
mPhongShader.unbind();
|
mPhongShader.unbind();
|
||||||
|
|
||||||
drawTextureQuad();
|
//drawTextureQuad();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the Shadow map FBO and texture
|
// Create the Shadow map FBO and texture
|
||||||
|
|
Loading…
Reference in New Issue
Block a user