Modify scenes to use the SceneDome class

This commit is contained in:
Daniel Chappuis 2015-07-29 18:15:20 +02:00
parent 6884adf0c2
commit a35340a930
32 changed files with 332 additions and 365 deletions

View File

@ -36,7 +36,7 @@ int Capsule::totalNbCapsules = 0;
// Constructor
Capsule::Capsule(float radius, float height, const openglframework::Vector3& position,
reactphysics3d::CollisionWorld* world,
const std::string& meshFolderPath, openglframework::Shader& shader)
const std::string& meshFolderPath)
: openglframework::Mesh(), mRadius(radius), mHeight(height) {
// Load the mesh from a file
@ -76,7 +76,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos
// Create the VBOs and VAO
if (totalNbCapsules == 0) {
createVBOAndVAO(shader);
createVBOAndVAO();
}
totalNbCapsules++;
@ -85,7 +85,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos
// Constructor
Capsule::Capsule(float radius, float height, const openglframework::Vector3& position,
float mass, reactphysics3d::DynamicsWorld* dynamicsWorld,
const std::string& meshFolderPath, openglframework::Shader &shader)
const std::string& meshFolderPath)
: openglframework::Mesh(), mRadius(radius), mHeight(height),
mColor(0.5f, 0.5f, 0.5f, 1.0f) {
@ -126,7 +126,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos
// Create the VBOs and VAO
if (totalNbCapsules == 0) {
createVBOAndVAO(shader);
createVBOAndVAO();
}
totalNbCapsules++;
@ -159,27 +159,45 @@ void Capsule::render(openglframework::Shader& shader,
shader.bind();
// Set the model to camera matrix
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
shader.setMatrix4x4Uniform("localToCameraMatrix", localToCameraMatrix);
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
// model-view matrix)
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
const openglframework::Matrix3 normalMatrix =
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix);
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
// Set the vertex color
openglframework::Vector4 color(mColor.r, mColor.g, mColor.b, mColor.a);
shader.setVector4Uniform("vertexColor", color);
shader.setVector4Uniform("vertexColor", color, false);
// Bind the VAO
mVAO.bind();
mVBOVertices.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false);
glEnableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// For each part of the mesh
for (unsigned int i=0; i<getNbParts(); i++) {
glDrawElements(GL_TRIANGLES, getNbFaces(i) * 3, GL_UNSIGNED_INT, (char*)NULL);
}
glDisableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glDisableVertexAttribArray(vertexNormalLoc);
mVBOVertices.unbind();
// Unbind the VAO
mVAO.unbind();
@ -213,15 +231,7 @@ void Capsule::updateTransform(float interpolationFactor) {
// Create the Vertex Buffer Objects used to render with OpenGL.
/// We create two VBOs (one for vertices and one for indices)
void Capsule::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the shader
shader.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal");
GLint vertexTexCoordLoc = shader.getAttribLocation("textureCoords");
void Capsule::createVBOAndVAO() {
// Create the VBO for the vertices data
mVBOVertices.create();
@ -259,19 +269,13 @@ void Capsule::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the VBO of vertices
mVBOVertices.bind();
glEnableVertexAttribArray(vertexPositionLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// Bind the VBO of normals
mVBONormals.bind();
glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (hasTexture()) {
// Bind the VBO of texture coords
mVBOTextureCoords.bind();
glEnableVertexAttribArray(vertexTexCoordLoc);
glVertexAttribPointer(vertexTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
}
// Bind the VBO of indices
@ -279,9 +283,6 @@ void Capsule::createVBOAndVAO(openglframework::Shader& shader) {
// Unbind the VAO
mVAO.unbind();
// Unbind the shader
shader.unbind();
}
// Reset the transform

View File

@ -76,7 +76,7 @@ class Capsule : public openglframework::Mesh {
// -------------------- Methods -------------------- //
// Create the Vertex Buffer Objects used to render with OpenGL.
void createVBOAndVAO(openglframework::Shader& shader);
void createVBOAndVAO();
public :
@ -84,13 +84,12 @@ class Capsule : public openglframework::Mesh {
/// Constructor
Capsule(float radius, float height, const openglframework::Vector3& position,
reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath,
openglframework::Shader& shader);
reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath);
/// Constructor
Capsule(float radius, float height, const openglframework::Vector3& position,
float mass, reactphysics3d::DynamicsWorld* dynamicsWorld,
const std::string& meshFolderPath, openglframework::Shader& shader);
const std::string& meshFolderPath);
/// Destructor
~Capsule();

View File

@ -36,7 +36,7 @@ int Cone::totalNbCones = 0;
// Constructor
Cone::Cone(float radius, float height, const openglframework::Vector3 &position,
reactphysics3d::CollisionWorld* world,
const std::string& meshFolderPath, openglframework::Shader& shader)
const std::string& meshFolderPath)
: openglframework::Mesh(), mRadius(radius), mHeight(height),
mColor(0.5f, 0.5f, 0.5f, 1.0f) {
@ -77,7 +77,7 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position,
// Create the VBOs and VAO
if (totalNbCones == 0) {
createVBOAndVAO(shader);
createVBOAndVAO();
}
totalNbCones++;
@ -86,7 +86,7 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position,
// Constructor
Cone::Cone(float radius, float height, const openglframework::Vector3 &position,
float mass, reactphysics3d::DynamicsWorld* dynamicsWorld,
const std::string& meshFolderPath, openglframework::Shader &shader)
const std::string& meshFolderPath)
: openglframework::Mesh(), mRadius(radius), mHeight(height),
mColor(0.5f, 0.5f, 0.5f, 1.0f) {
@ -127,7 +127,7 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position,
// Create the VBOs and VAO
if (totalNbCones == 0) {
createVBOAndVAO(shader);
createVBOAndVAO();
}
totalNbCones++;
@ -159,27 +159,45 @@ void Cone::render(openglframework::Shader& shader,
shader.bind();
// Set the model to camera matrix
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
shader.setMatrix4x4Uniform("localToCameraMatrix", localToCameraMatrix);
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
// model-view matrix)
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
const openglframework::Matrix3 normalMatrix =
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix);
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
// Set the vertex color
openglframework::Vector4 color(mColor.r, mColor.g, mColor.b, mColor.a);
shader.setVector4Uniform("vertexColor", color);
shader.setVector4Uniform("vertexColor", color, false);
// Bind the VAO
mVAO.bind();
mVBOVertices.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false);
glEnableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// For each part of the mesh
for (unsigned int i=0; i<getNbParts(); i++) {
glDrawElements(GL_TRIANGLES, getNbFaces(i) * 3, GL_UNSIGNED_INT, (char*)NULL);
}
glDisableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glDisableVertexAttribArray(vertexNormalLoc);
mVBOVertices.unbind();
// Unbind the VAO
mVAO.unbind();
@ -214,15 +232,7 @@ void Cone::updateTransform(float interpolationFactor) {
// Create the Vertex Buffer Objects used to render with OpenGL.
/// We create two VBOs (one for vertices and one for indices)
void Cone::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the shader
shader.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal");
GLint vertexTexCoordLoc = shader.getAttribLocation("textureCoords");
void Cone::createVBOAndVAO() {
// Create the VBO for the vertices data
mVBOVertices.create();
@ -260,19 +270,13 @@ void Cone::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the VBO of vertices
mVBOVertices.bind();
glEnableVertexAttribArray(vertexPositionLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// Bind the VBO of normals
mVBONormals.bind();
glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (hasTexture()) {
// Bind the VBO of texture coords
mVBOTextureCoords.bind();
glEnableVertexAttribArray(vertexTexCoordLoc);
glVertexAttribPointer(vertexTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
}
// Bind the VBO of indices
@ -280,9 +284,6 @@ void Cone::createVBOAndVAO(openglframework::Shader& shader) {
// Unbind the VAO
mVAO.unbind();
// Unbind the shader
shader.unbind();
}
// Reset the transform

View File

@ -76,7 +76,7 @@ class Cone : public openglframework::Mesh {
// -------------------- Methods -------------------- //
// Create the Vertex Buffer Objects used to render with OpenGL.
void createVBOAndVAO(openglframework::Shader& shader);
void createVBOAndVAO();
public :
@ -84,12 +84,11 @@ class Cone : public openglframework::Mesh {
/// Constructor
Cone(float radius, float height, const openglframework::Vector3& position,
rp3d::CollisionWorld* world, const std::string& meshFolderPath, openglframework::Shader &shader);
rp3d::CollisionWorld* world, const std::string& meshFolderPath);
/// Constructor
Cone(float radius, float height, const openglframework::Vector3& position,
float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath,
openglframework::Shader& shader);
float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath);
/// Destructor
~Cone();

View File

@ -29,8 +29,7 @@
// Constructor
ConvexMesh::ConvexMesh(const openglframework::Vector3 &position,
reactphysics3d::CollisionWorld* world,
const std::string& meshFolderPath,
openglframework::Shader& shader)
const std::string& meshFolderPath)
: openglframework::Mesh(), mVBOVertices(GL_ARRAY_BUFFER),
mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER),
mVBOIndices(GL_ELEMENT_ARRAY_BUFFER), mColor(0.5f, 0.5f, 0.5f, 1.0f) {
@ -91,13 +90,13 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position,
mRigidBody->addCollisionShape(collisionShape, rp3d::Transform::identity());
// Create the VBOs and VAO
createVBOAndVAO(shader);
createVBOAndVAO();
}
// Constructor
ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass,
reactphysics3d::DynamicsWorld* dynamicsWorld,
const std::string& meshFolderPath, openglframework::Shader &shader)
const std::string& meshFolderPath)
: openglframework::Mesh(), mVBOVertices(GL_ARRAY_BUFFER),
mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER),
mVBOIndices(GL_ELEMENT_ARRAY_BUFFER), mColor(0.5f, 0.5f, 0.5f, 1.0f) {
@ -157,7 +156,7 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass,
mRigidBody = body;
// Create the VBOs and VAO
createVBOAndVAO(shader);
createVBOAndVAO();
}
// Destructor
@ -182,27 +181,45 @@ void ConvexMesh::render(openglframework::Shader& shader,
shader.bind();
// Set the model to camera matrix
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
shader.setMatrix4x4Uniform("localToCameraMatrix", localToCameraMatrix);
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
// model-view matrix)
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
const openglframework::Matrix3 normalMatrix =
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix);
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
// Set the vertex color
openglframework::Vector4 color(mColor.r, mColor.g, mColor.b, mColor.a);
shader.setVector4Uniform("vertexColor", color);
shader.setVector4Uniform("vertexColor", color, false);
// Bind the VAO
mVAO.bind();
mVBOVertices.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false);
glEnableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// For each part of the mesh
for (unsigned int i=0; i<getNbParts(); i++) {
glDrawElements(GL_TRIANGLES, getNbFaces(i) * 3, GL_UNSIGNED_INT, (char*)NULL);
}
glDisableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glDisableVertexAttribArray(vertexNormalLoc);
mVBOVertices.unbind();
// Unbind the VAO
mVAO.unbind();
@ -236,15 +253,7 @@ void ConvexMesh::updateTransform(float interpolationFactor) {
// Create the Vertex Buffer Objects used to render with OpenGL.
/// We create two VBOs (one for vertices and one for indices)
void ConvexMesh::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the shader
shader.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal");
GLint vertexTexCoordLoc = shader.getAttribLocation("textureCoords");
void ConvexMesh::createVBOAndVAO() {
// Create the VBO for the vertices data
mVBOVertices.create();
@ -282,19 +291,13 @@ void ConvexMesh::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the VBO of vertices
mVBOVertices.bind();
glEnableVertexAttribArray(vertexPositionLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// Bind the VBO of normals
mVBONormals.bind();
glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (hasTexture()) {
// Bind the VBO of texture coords
mVBOTextureCoords.bind();
glEnableVertexAttribArray(vertexTexCoordLoc);
glVertexAttribPointer(vertexTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
}
// Bind the VBO of indices
@ -302,9 +305,6 @@ void ConvexMesh::createVBOAndVAO(openglframework::Shader& shader) {
// Unbind the VAO
mVAO.unbind();
// Unbind the shader
shader.unbind();
}
// Reset the transform

View File

@ -64,7 +64,7 @@ class ConvexMesh : public openglframework::Mesh {
// -------------------- Methods -------------------- //
// Create the Vertex Buffer Objects used to render with OpenGL.
void createVBOAndVAO(openglframework::Shader& shader);
void createVBOAndVAO();
public :
@ -72,12 +72,11 @@ class ConvexMesh : public openglframework::Mesh {
/// Constructor
ConvexMesh(const openglframework::Vector3& position,
rp3d::CollisionWorld* world, const std::string& meshFolderPath, openglframework::Shader &shader);
rp3d::CollisionWorld* world, const std::string& meshFolderPath);
/// Constructor
ConvexMesh(const openglframework::Vector3& position, float mass,
rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath,
openglframework::Shader& shader);
rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath);
/// Destructor
~ConvexMesh();

View File

@ -36,8 +36,7 @@ int Cylinder::totalNbCylinders = 0;
// Constructor
Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& position,
reactphysics3d::CollisionWorld* world,
const std::string& meshFolderPath,
openglframework::Shader& shader)
const std::string& meshFolderPath)
: openglframework::Mesh(), mRadius(radius), mHeight(height),
mColor(0.5f, 0.5f, 0.5f, 1.0f) {
@ -78,7 +77,7 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p
// Create the VBOs and VAO
if (totalNbCylinders == 0) {
createVBOAndVAO(shader);
createVBOAndVAO();
}
totalNbCylinders++;
@ -87,7 +86,7 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p
// Constructor
Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& position,
float mass, reactphysics3d::DynamicsWorld* dynamicsWorld,
const std::string& meshFolderPath, openglframework::Shader& shader)
const std::string& meshFolderPath)
: openglframework::Mesh(), mRadius(radius), mHeight(height),
mColor(0.5f, 0.5f, 0.5f, 1.0f) {
@ -128,7 +127,7 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p
// Create the VBOs and VAO
if (totalNbCylinders == 0) {
createVBOAndVAO(shader);
createVBOAndVAO();
}
totalNbCylinders++;
@ -161,27 +160,45 @@ void Cylinder::render(openglframework::Shader& shader,
shader.bind();
// Set the model to camera matrix
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
shader.setMatrix4x4Uniform("localToCameraMatrix", localToCameraMatrix);
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
// model-view matrix)
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
const openglframework::Matrix3 normalMatrix =
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix);
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
// Set the vertex color
openglframework::Vector4 color(mColor.r, mColor.g, mColor.b, mColor.a);
shader.setVector4Uniform("vertexColor", color);
shader.setVector4Uniform("vertexColor", color, false);
// Bind the VAO
mVAO.bind();
mVBOVertices.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false);
glEnableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// For each part of the mesh
for (unsigned int i=0; i<getNbParts(); i++) {
glDrawElements(GL_TRIANGLES, getNbFaces(i) * 3, GL_UNSIGNED_INT, (char*)NULL);
}
glDisableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glDisableVertexAttribArray(vertexNormalLoc);
mVBOVertices.unbind();
// Unbind the VAO
mVAO.unbind();
@ -215,15 +232,7 @@ void Cylinder::updateTransform(float interpolationFactor) {
// Create the Vertex Buffer Objects used to render with OpenGL.
/// We create two VBOs (one for vertices and one for indices)
void Cylinder::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the shader
shader.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal");
GLint vertexTexCoordLoc = shader.getAttribLocation("textureCoords");
void Cylinder::createVBOAndVAO() {
// Create the VBO for the vertices data
mVBOVertices.create();
@ -261,19 +270,13 @@ void Cylinder::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the VBO of vertices
mVBOVertices.bind();
glEnableVertexAttribArray(vertexPositionLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// Bind the VBO of normals
mVBONormals.bind();
glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (hasTexture()) {
// Bind the VBO of texture coords
mVBOTextureCoords.bind();
glEnableVertexAttribArray(vertexTexCoordLoc);
glVertexAttribPointer(vertexTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
}
// Bind the VBO of indices
@ -281,9 +284,6 @@ void Cylinder::createVBOAndVAO(openglframework::Shader& shader) {
// Unbind the VAO
mVAO.unbind();
// Unbind the shader
shader.unbind();
}
// Reset the transform

View File

@ -76,7 +76,7 @@ class Cylinder : public openglframework::Mesh {
// -------------------- Methods -------------------- //
// Create the Vertex Buffer Objects used to render with OpenGL.
void createVBOAndVAO(openglframework::Shader& shader);
void createVBOAndVAO();
public :
@ -84,13 +84,11 @@ class Cylinder : public openglframework::Mesh {
/// Constructor
Cylinder(float radius, float height, const openglframework::Vector3& position,
rp3d::CollisionWorld* world, const std::string &meshFolderPath,
openglframework::Shader& shader);
rp3d::CollisionWorld* world, const std::string &meshFolderPath);
/// Constructor
Cylinder(float radius, float height, const openglframework::Vector3& position,
float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string &meshFolderPath,
openglframework::Shader &shader);
float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string &meshFolderPath);
/// Destructor
~Cylinder();

View File

@ -35,8 +35,7 @@ int Dumbbell::totalNbDumbbells = 0;
// Constructor
Dumbbell::Dumbbell(const openglframework::Vector3 &position,
reactphysics3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath,
openglframework::Shader& shader)
reactphysics3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath)
: openglframework::Mesh(), mColor(0.5f, 0.5f, 0.5f, 1.0f) {
// Load the mesh from a file
@ -97,7 +96,7 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
// Create the VBOs and VAO
if (totalNbDumbbells == 0) {
createVBOAndVAO(shader);
createVBOAndVAO();
}
totalNbDumbbells++;
@ -105,8 +104,7 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
// Constructor
Dumbbell::Dumbbell(const openglframework::Vector3 &position,
reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath,
openglframework::Shader& shader)
reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath)
: openglframework::Mesh(), mColor(0.5f, 0.5f, 0.5f, 1.0f) {
// Load the mesh from a file
@ -163,7 +161,7 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
// Create the VBOs and VAO
if (totalNbDumbbells == 0) {
createVBOAndVAO(shader);
createVBOAndVAO();
}
totalNbDumbbells++;
@ -196,27 +194,45 @@ void Dumbbell::render(openglframework::Shader& shader,
shader.bind();
// Set the model to camera matrix
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
shader.setMatrix4x4Uniform("localToCameraMatrix", localToCameraMatrix);
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
// model-view matrix)
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
const openglframework::Matrix3 normalMatrix =
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix);
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
// Set the vertex color
openglframework::Vector4 color(mColor.r, mColor.g, mColor.b, mColor.a);
shader.setVector4Uniform("vertexColor", color);
shader.setVector4Uniform("vertexColor", color, false);
// Bind the VAO
mVAO.bind();
mVBOVertices.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false);
glEnableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// For each part of the mesh
for (unsigned int i=0; i<getNbParts(); i++) {
glDrawElements(GL_TRIANGLES, getNbFaces(i) * 3, GL_UNSIGNED_INT, (char*)NULL);
}
glDisableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glDisableVertexAttribArray(vertexNormalLoc);
mVBOVertices.unbind();
// Unbind the VAO
mVAO.unbind();
@ -250,15 +266,7 @@ void Dumbbell::updateTransform(float interpolationFactor) {
// Create the Vertex Buffer Objects used to render with OpenGL.
/// We create two VBOs (one for vertices and one for indices)
void Dumbbell::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the shader
shader.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal");
GLint vertexTexCoordLoc = shader.getAttribLocation("textureCoords");
void Dumbbell::createVBOAndVAO() {
// Create the VBO for the vertices data
mVBOVertices.create();
@ -296,19 +304,13 @@ void Dumbbell::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the VBO of vertices
mVBOVertices.bind();
glEnableVertexAttribArray(vertexPositionLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// Bind the VBO of normals
mVBONormals.bind();
glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (hasTexture()) {
// Bind the VBO of texture coords
mVBOTextureCoords.bind();
glEnableVertexAttribArray(vertexTexCoordLoc);
glVertexAttribPointer(vertexTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
}
// Bind the VBO of indices
@ -316,9 +318,6 @@ void Dumbbell::createVBOAndVAO(openglframework::Shader& shader) {
// Unbind the VAO
mVAO.unbind();
// Unbind the shader
shader.unbind();
}
// Reset the transform

View File

@ -73,7 +73,7 @@ class Dumbbell : public openglframework::Mesh {
// -------------------- Methods -------------------- //
// Create the Vertex Buffer Objects used to render with OpenGL.
void createVBOAndVAO(openglframework::Shader& shader);
void createVBOAndVAO();
public :
@ -81,11 +81,11 @@ class Dumbbell : public openglframework::Mesh {
/// Constructor
Dumbbell(const openglframework::Vector3& position, rp3d::DynamicsWorld* dynamicsWorld,
const std::string& meshFolderPath, openglframework::Shader &shader);
const std::string& meshFolderPath);
/// Constructor
Dumbbell(const openglframework::Vector3& position, rp3d::CollisionWorld* world,
const std::string& meshFolderPath, openglframework::Shader& shader);
const std::string& meshFolderPath);
/// Destructor

View File

@ -47,11 +47,12 @@ void Line::render(openglframework::Shader& shader,
shader.bind();
// Set the model to camera matrix
shader.setMatrix4x4Uniform("localToCameraMatrix", worldToCameraMatrix);
shader.setMatrix4x4Uniform("localToWorldMatrix", openglframework::Matrix4::identity());
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
// Set the vertex color
openglframework::Vector4 color(1, 0, 0, 1);
shader.setVector4Uniform("vertexColor", color);
shader.setVector4Uniform("vertexColor", color, false);
glBegin(GL_LINES);
glVertex3f(mWorldPoint1.x, mWorldPoint1.y, mWorldPoint1.z);

View File

@ -36,7 +36,7 @@ int Sphere::totalNbSpheres = 0;
// Constructor
Sphere::Sphere(float radius, const openglframework::Vector3 &position,
reactphysics3d::CollisionWorld* world,
const std::string& meshFolderPath, openglframework::Shader& shader)
const std::string& meshFolderPath)
: openglframework::Mesh(), mRadius(radius), mColor(0.5f, 0.5f, 0.5f, 1.0f) {
// Load the mesh from a file
@ -76,7 +76,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position,
// Create the VBOs and VAO
if (totalNbSpheres == 0) {
createVBOAndVAO(shader);
createVBOAndVAO();
}
totalNbSpheres++;
@ -85,7 +85,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position,
// Constructor
Sphere::Sphere(float radius, const openglframework::Vector3 &position,
float mass, reactphysics3d::DynamicsWorld* world,
const std::string& meshFolderPath, openglframework::Shader& shader)
const std::string& meshFolderPath)
: openglframework::Mesh(), mRadius(radius), mColor(0.5f, 0.5f, 0.5f, 1.0f) {
// Load the mesh from a file
@ -125,7 +125,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position,
// Create the VBOs and VAO
if (totalNbSpheres == 0) {
createVBOAndVAO(shader);
createVBOAndVAO();
}
totalNbSpheres++;
@ -157,27 +157,45 @@ void Sphere::render(openglframework::Shader& shader,
shader.bind();
// Set the model to camera matrix
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
shader.setMatrix4x4Uniform("localToCameraMatrix", localToCameraMatrix);
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
// model-view matrix)
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
const openglframework::Matrix3 normalMatrix =
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix);
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
// Set the vertex color
openglframework::Vector4 color(mColor.r, mColor.g, mColor.b, mColor.a);
shader.setVector4Uniform("vertexColor", color);
shader.setVector4Uniform("vertexColor", color, false);
// Bind the VAO
mVAO.bind();
mVBOVertices.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false);
glEnableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// For each part of the mesh
for (unsigned int i=0; i<getNbParts(); i++) {
glDrawElements(GL_TRIANGLES, getNbFaces(i) * 3, GL_UNSIGNED_INT, (char*)NULL);
}
glDisableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glDisableVertexAttribArray(vertexNormalLoc);
mVBOVertices.unbind();
// Unbind the VAO
mVAO.unbind();
@ -211,15 +229,7 @@ void Sphere::updateTransform(float interpolationFactor) {
// Create the Vertex Buffer Objects used to render with OpenGL.
/// We create two VBOs (one for vertices and one for indices)
void Sphere::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the shader
shader.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal");
GLint vertexTexCoordLoc = shader.getAttribLocation("textureCoords");
void Sphere::createVBOAndVAO() {
// Create the VBO for the vertices data
mVBOVertices.create();
@ -257,19 +267,13 @@ void Sphere::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the VBO of vertices
mVBOVertices.bind();
glEnableVertexAttribArray(vertexPositionLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// Bind the VBO of normals
mVBONormals.bind();
glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (hasTexture()) {
// Bind the VBO of texture coords
mVBOTextureCoords.bind();
glEnableVertexAttribArray(vertexTexCoordLoc);
glVertexAttribPointer(vertexTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
}
// Bind the VBO of indices
@ -277,9 +281,6 @@ void Sphere::createVBOAndVAO(openglframework::Shader& shader) {
// Unbind the VAO
mVAO.unbind();
// Unbind the shader
shader.unbind();
}
// Reset the transform

View File

@ -73,7 +73,7 @@ class Sphere : public openglframework::Mesh {
// -------------------- Methods -------------------- //
// Create the Vertex Buffer Objects used to render with OpenGL.
void createVBOAndVAO(openglframework::Shader& shader);
void createVBOAndVAO();
public :
@ -81,13 +81,11 @@ class Sphere : public openglframework::Mesh {
/// Constructor
Sphere(float radius, const openglframework::Vector3& position,
rp3d::CollisionWorld* world, const std::string& meshFolderPath,
openglframework::Shader& shader);
rp3d::CollisionWorld* world, const std::string& meshFolderPath);
/// Constructor
Sphere(float radius, const openglframework::Vector3& position,
float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath,
openglframework::Shader& shader);
float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath);
/// Destructor
~Sphere();

View File

@ -37,7 +37,6 @@ int VisualContactPoint::totalNbBoxes = 0;
// Constructor
VisualContactPoint::VisualContactPoint(const openglframework::Vector3& position,
openglframework::Shader& shader,
const std::string& meshFolderPath)
: mColor(1.0f, 0.0f, 0.0f, 1.0f) {
@ -47,7 +46,7 @@ VisualContactPoint::VisualContactPoint(const openglframework::Vector3& position,
// Create the VBOs and VAO
if (totalNbBoxes == 0) {
createStaticData(meshFolderPath);
createVBOAndVAO(shader);
createVBOAndVAO();
}
totalNbBoxes++;
@ -96,27 +95,45 @@ void VisualContactPoint::render(openglframework::Shader& shader,
shader.bind();
// Set the model to camera matrix
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
shader.setMatrix4x4Uniform("localToCameraMatrix", localToCameraMatrix);
shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix);
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
// model-view matrix)
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix;
const openglframework::Matrix3 normalMatrix =
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix);
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
// Set the vertex color
openglframework::Vector4 color(mColor.r, mColor.g, mColor.b, mColor.a);
shader.setVector4Uniform("vertexColor", color);
shader.setVector4Uniform("vertexColor", color, false);
// Bind the VAO
mVAO.bind();
mVBOVertices.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false);
glEnableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// For each part of the mesh
for (unsigned int i=0; i<mMesh.getNbParts(); i++) {
glDrawElements(GL_TRIANGLES, mMesh.getNbFaces(i) * 3, GL_UNSIGNED_INT, (char*)NULL);
}
glDisableVertexAttribArray(vertexPositionLoc);
if (vertexNormalLoc != -1) glDisableVertexAttribArray(vertexNormalLoc);
mVBOVertices.unbind();
// Unbind the VAO
mVAO.unbind();
@ -126,15 +143,7 @@ void VisualContactPoint::render(openglframework::Shader& shader,
// Create the Vertex Buffer Objects used to render with OpenGL.
/// We create two VBOs (one for vertices and one for indices)
void VisualContactPoint::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the shader
shader.bind();
// Get the location of shader attribute variables
GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal");
GLint vertexTexCoordLoc = shader.getAttribLocation("textureCoords");
void VisualContactPoint::createVBOAndVAO() {
// Create the VBO for the vertices data
mVBOVertices.create();
@ -163,20 +172,13 @@ void VisualContactPoint::createVBOAndVAO(openglframework::Shader& shader) {
// Bind the VBO of vertices
mVBOVertices.bind();
glEnableVertexAttribArray(vertexPositionLoc);
glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// Bind the VBO of normals
mVBONormals.bind();
glEnableVertexAttribArray(vertexNormalLoc);
glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL);
// Bind the VBO of indices
mVBOIndices.bind();
// Unbind the VAO
mVAO.unbind();
// Unbind the shader
shader.unbind();
}

View File

@ -63,7 +63,7 @@ class VisualContactPoint : public openglframework::Object3D {
openglframework::Color mColor;
// Create the Vertex Buffer Objects used to render with OpenGL.
static void createVBOAndVAO(openglframework::Shader& shader);
static void createVBOAndVAO();
// -------------------- Methods -------------------- //
@ -73,7 +73,6 @@ class VisualContactPoint : public openglframework::Object3D {
/// Constructor
VisualContactPoint(const openglframework::Vector3& position,
openglframework::Shader &shader,
const std::string &meshFolderPath);
/// Destructor

View File

@ -37,7 +37,7 @@ FrameBufferObject::FrameBufferObject() : mFrameBufferID(0), mRenderBufferID (0)
// Destructor
FrameBufferObject::~FrameBufferObject() {
destroy();
}
// Create the frame buffer object

View File

@ -48,7 +48,7 @@ Shader::Shader(const std::string vertexShaderFilename, const std::string fragmen
// Destructor
Shader::~Shader() {
destroy();
}
// Create the shader

View File

@ -180,8 +180,10 @@ inline GLint Shader::getAttribLocation(const std::string& variableName, bool err
// Clear the shader
inline void Shader::destroy() {
glDeleteProgram(mProgramObjectID);
mProgramObjectID = 0;
if (mProgramObjectID != 0) {
glDeleteProgram(mProgramObjectID);
mProgramObjectID = 0;
}
}
// Set a float uniform value to this shader (be careful if the uniform is not

View File

@ -47,7 +47,7 @@ Texture2D::Texture2D(uint width, uint height, uint internalFormat, uint format,
// Destructor
Texture2D::~Texture2D() {
destroy();
}
// Create the texture

View File

@ -35,7 +35,7 @@ VertexArrayObject::VertexArrayObject() : mVertexArrayID(0) {
// Destructor
VertexArrayObject::~VertexArrayObject() {
destroy();
}
// Create the vertex buffer object
@ -63,7 +63,7 @@ bool VertexArrayObject::create() {
void VertexArrayObject::destroy() {
// Delete the vertex buffer object
if (mVertexArrayID) {
if (mVertexArrayID != 0) {
glDeleteVertexArrays(1, &mVertexArrayID);
mVertexArrayID = 0;
}

View File

@ -36,7 +36,7 @@ VertexBufferObject::VertexBufferObject(GLenum targetData)
// Destructor
VertexBufferObject::~VertexBufferObject() {
destroy();
}
// Create the vertex buffer object
@ -71,7 +71,7 @@ void VertexBufferObject::copyDataIntoVBO(GLsizei size, const void* data, GLenum
void VertexBufferObject::destroy() {
// Delete the vertex buffer object
if (mVertexBufferID) {
if (mVertexBufferID != 0) {
glDeleteFramebuffers(1, &mVertexBufferID);
mVertexBufferID = 0;
}

View File

@ -272,6 +272,13 @@ class Matrix3 {
m[2][0] *= nb; m[2][1] *= nb; m[2][2] *= nb;
return *this;
}
// Return the identity matrix
static Matrix3 identity() {
return Matrix3(1, 0, 0,
0, 1, 0,
0, 0, 1);
}
};
}

View File

@ -385,6 +385,9 @@ class Matrix4 {
// Return a 4x4 orthographic projection matrix
static Matrix4 orthoProjectionMatrix(float near, float far, int width,
int height);
// Return the identity matrix
static Matrix4 identity();
};
// * operator
@ -478,6 +481,14 @@ inline Matrix4 Matrix4::orthoProjectionMatrix(float near, float far, int width,
0, 0, 0, 1);
}
// Return the identity matrix
inline Matrix4 Matrix4::identity() {
return Matrix4(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
}
}
#endif //_MATRIX4_H

View File

@ -32,19 +32,15 @@ using namespace collisionshapesscene;
// Constructor
CollisionShapesScene::CollisionShapesScene(const std::string& name)
: Scene(name), mLight0(0), mPhongShader("shaders/phong.vert", "shaders/phong.frag") {
: SceneDemo(name, SCENE_RADIUS) {
std::string meshFolderPath("meshes/");
// Move the light 0
mLight0.translateWorld(Vector3(50, 50, 50));
// Compute the radius and the center of the scene
float radiusScene = 30.0f;
openglframework::Vector3 center(0, 5, 0);
// Set the center of the scene
setScenePosition(center, radiusScene);
setScenePosition(center, SCENE_RADIUS);
// Gravity vector in the dynamics world
rp3d::Vector3 gravity(0, -9.81, 0);
@ -69,8 +65,7 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name)
radius * sin(angle));
// Create a convex mesh and a corresponding rigid in the dynamics world
Dumbbell* dumbbell = new Dumbbell(position, mDynamicsWorld, meshFolderPath,
mPhongShader);
Dumbbell* dumbbell = new Dumbbell(position, mDynamicsWorld, meshFolderPath);
// Change the material properties of the rigid body
rp3d::Material& material = dumbbell->getRigidBody()->getMaterial();
@ -111,7 +106,7 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name)
// Create a sphere and a corresponding rigid in the dynamics world
Sphere* sphere = new Sphere(SPHERE_RADIUS, position , BOX_MASS, mDynamicsWorld,
meshFolderPath, mPhongShader);
meshFolderPath);
// Change the material properties of the rigid body
rp3d::Material& material = sphere->getRigidBody()->getMaterial();
@ -132,7 +127,7 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name)
// Create a cone and a corresponding rigid in the dynamics world
Cone* cone = new Cone(CONE_RADIUS, CONE_HEIGHT, position, CONE_MASS, mDynamicsWorld,
meshFolderPath, mPhongShader);
meshFolderPath);
// Change the material properties of the rigid body
rp3d::Material& material = cone->getRigidBody()->getMaterial();
@ -153,7 +148,7 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name)
// Create a cylinder and a corresponding rigid in the dynamics world
Cylinder* cylinder = new Cylinder(CYLINDER_RADIUS, CYLINDER_HEIGHT, position ,
CYLINDER_MASS, mDynamicsWorld, meshFolderPath, mPhongShader);
CYLINDER_MASS, mDynamicsWorld, meshFolderPath);
// Change the material properties of the rigid body
rp3d::Material& material = cylinder->getRigidBody()->getMaterial();
@ -174,8 +169,7 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name)
// Create a cylinder and a corresponding rigid in the dynamics world
Capsule* capsule = new Capsule(CAPSULE_RADIUS, CAPSULE_HEIGHT, position ,
CAPSULE_MASS, mDynamicsWorld, meshFolderPath,
mPhongShader);
CAPSULE_MASS, mDynamicsWorld, meshFolderPath);
// Change the material properties of the rigid body
rp3d::Material& material = capsule->getRigidBody()->getMaterial();
@ -195,8 +189,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,
mPhongShader);
ConvexMesh* mesh = new ConvexMesh(position, MESH_MASS, mDynamicsWorld, meshFolderPath);
// Change the material properties of the rigid body
rp3d::Material& material = mesh->getRigidBody()->getMaterial();
@ -394,70 +387,54 @@ void CollisionShapesScene::update() {
}
// Render the scene
void CollisionShapesScene::render() {
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_CULL_FACE);
// Get the world-space to camera-space matrix
const openglframework::Matrix4 worldToCameraMatrix = mCamera.getTransformMatrix().getInverse();
void CollisionShapesScene::renderSinglePass(openglframework::Shader& shader,
const openglframework::Matrix4& worldToCameraMatrix) {
// Bind the shader
mPhongShader.bind();
// Set the variables of the shader
mPhongShader.setMatrix4x4Uniform("projectionMatrix", mCamera.getProjectionMatrix());
mPhongShader.setVector3Uniform("light0PosCameraSpace", worldToCameraMatrix * mLight0.getOrigin());
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
const Color& diffColLight0 = mLight0.getDiffuseColor();
const Color& specColLight0 = mLight0.getSpecularColor();
mPhongShader.setVector3Uniform("light0DiffuseColor", Vector3(diffColLight0.r, diffColLight0.g, diffColLight0.b));
mPhongShader.setVector3Uniform("light0SpecularColor", Vector3(specColLight0.r, specColLight0.g, specColLight0.b));
mPhongShader.setFloatUniform("shininess", 200.0f);
shader.bind();
// Render all the boxes of the scene
for (std::vector<Box*>::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) {
(*it)->render(mPhongShader, worldToCameraMatrix);
(*it)->render(shader, worldToCameraMatrix);
}
// Render all the sphere of the scene
for (std::vector<Sphere*>::iterator it = mSpheres.begin(); it != mSpheres.end(); ++it) {
(*it)->render(mPhongShader, worldToCameraMatrix);
(*it)->render(shader, worldToCameraMatrix);
}
// Render all the cones of the scene
for (std::vector<Cone*>::iterator it = mCones.begin(); it != mCones.end(); ++it) {
(*it)->render(mPhongShader, worldToCameraMatrix);
(*it)->render(shader, worldToCameraMatrix);
}
// Render all the cylinders of the scene
for (std::vector<Cylinder*>::iterator it = mCylinders.begin(); it != mCylinders.end(); ++it) {
(*it)->render(mPhongShader, worldToCameraMatrix);
(*it)->render(shader, worldToCameraMatrix);
}
// Render all the capsules of the scene
for (std::vector<Capsule*>::iterator it = mCapsules.begin(); it != mCapsules.end(); ++it) {
(*it)->render(mPhongShader, worldToCameraMatrix);
(*it)->render(shader, worldToCameraMatrix);
}
// Render all the convex meshes of the scene
for (std::vector<ConvexMesh*>::iterator it = mConvexMeshes.begin();
it != mConvexMeshes.end(); ++it) {
(*it)->render(mPhongShader, worldToCameraMatrix);
(*it)->render(shader, worldToCameraMatrix);
}
// Render all the dumbbells of the scene
for (std::vector<Dumbbell*>::iterator it = mDumbbells.begin();
it != mDumbbells.end(); ++it) {
(*it)->render(mPhongShader, worldToCameraMatrix);
(*it)->render(shader, worldToCameraMatrix);
}
// Render the floor
mFloor->render(mPhongShader, worldToCameraMatrix);
mFloor->render(shader, worldToCameraMatrix);
// Unbind the shader
mPhongShader.unbind();
shader.unbind();
}
/// Reset the scene

View File

@ -29,7 +29,7 @@
// Libraries
#include "openglframework.h"
#include "reactphysics3d.h"
#include "Scene.h"
#include "SceneDemo.h"
#include "Sphere.h"
#include "Box.h"
#include "Cone.h"
@ -44,6 +44,7 @@ namespace collisionshapesscene {
// Constants
const float SCENE_RADIUS = 30.0f;
const int NB_BOXES = 3;
const int NB_CUBES = 3;
const int NB_CONES = 3;
@ -69,15 +70,12 @@ const float MESH_MASS = 1.0f;
const float FLOOR_MASS = 100.0f; // Floor mass in kilograms
// Class CollisionShapesScene
class CollisionShapesScene : public Scene{
class CollisionShapesScene : public SceneDemo {
private :
// -------------------- Attributes -------------------- //
/// Light 0
openglframework::Light mLight0;
/// Phong shader
openglframework::Shader mPhongShader;
@ -121,8 +119,9 @@ class CollisionShapesScene : public Scene{
/// Take a step for the simulation
virtual void update();
/// Render the scene
virtual void render();
/// Render the scene in a single pass
virtual void renderSinglePass(openglframework::Shader& shader,
const openglframework::Matrix4& worldToCameraMatrix);
/// Reset the scene
virtual void reset();

View File

@ -33,18 +33,17 @@ using namespace jointsscene;
// Constructor
JointsScene::JointsScene(const std::string& name)
: Scene(name), mLight0(0), mPhongShader("shaders/phong.vert",
: SceneDemo(name, SCENE_RADIUS), mLight0(0), mPhongShader("shaders/phong.vert",
"shaders/phong.frag") {
// Move the light 0
mLight0.translateWorld(Vector3(7, 15, 15));
// Compute the radius and the center of the scene
float radiusScene = 30.0f;
openglframework::Vector3 center(0, 5, 0);
// Set the center of the scene
setScenePosition(center, radiusScene);
setScenePosition(center, SCENE_RADIUS);
// Gravity vector in the dynamics world
rp3d::Vector3 gravity(0, rp3d::decimal(-9.81), 0);
@ -168,43 +167,27 @@ void JointsScene::update() {
}
// Render the scene
void JointsScene::render() {
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_CULL_FACE);
// Get the world-space to camera-space matrix
const openglframework::Matrix4 worldToCameraMatrix = mCamera.getTransformMatrix().getInverse();
void JointsScene::renderSinglePass(openglframework::Shader& shader,
const openglframework::Matrix4& worldToCameraMatrix) {
// Bind the shader
mPhongShader.bind();
// Set the variables of the shader
mPhongShader.setVector3Uniform("light0PosCameraSpace",worldToCameraMatrix * mLight0.getOrigin());
mPhongShader.setMatrix4x4Uniform("projectionMatrix", mCamera.getProjectionMatrix());
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
const Color& diffCol = mLight0.getDiffuseColor();
const Color& specCol = mLight0.getSpecularColor();
mPhongShader.setVector3Uniform("light0DiffuseColor", Vector3(diffCol.r, diffCol.g, diffCol.b));
mPhongShader.setVector3Uniform("light0SpecularColor", Vector3(specCol.r, specCol.g, specCol.b));
mPhongShader.setFloatUniform("shininess", 60.0f);
shader.bind();
// Render all the boxes
mSliderJointBottomBox->render(mPhongShader, worldToCameraMatrix);
mSliderJointTopBox->render(mPhongShader, worldToCameraMatrix);
mPropellerBox->render(mPhongShader, worldToCameraMatrix);
mFixedJointBox1->render(mPhongShader, worldToCameraMatrix);
mFixedJointBox2->render(mPhongShader, worldToCameraMatrix);
mSliderJointBottomBox->render(shader, worldToCameraMatrix);
mSliderJointTopBox->render(shader, worldToCameraMatrix);
mPropellerBox->render(shader, worldToCameraMatrix);
mFixedJointBox1->render(shader, worldToCameraMatrix);
mFixedJointBox2->render(shader, worldToCameraMatrix);
for (int i=0; i<NB_BALLSOCKETJOINT_BOXES; i++) {
mBallAndSocketJointChainBoxes[i]->render(mPhongShader, worldToCameraMatrix);
mBallAndSocketJointChainBoxes[i]->render(shader, worldToCameraMatrix);
}
// Render the floor
mFloor->render(mPhongShader, worldToCameraMatrix);
mFloor->render(shader, worldToCameraMatrix);
// Unbind the shader
mPhongShader.unbind();
shader.unbind();
}
// Reset the scene

View File

@ -30,11 +30,12 @@
#include "openglframework.h"
#include "reactphysics3d.h"
#include "Box.h"
#include "Scene.h"
#include "SceneDemo.h"
namespace jointsscene {
// Constants
const float SCENE_RADIUS = 30.0f;
const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters
const openglframework::Vector3 FLOOR_SIZE(20, 0.5f, 20); // Floor dimensions in meters
const float BOX_MASS = 1.0f; // Box mass in kilograms
@ -43,7 +44,7 @@ const int NB_BALLSOCKETJOINT_BOXES = 7; // Number of Ball-An
const int NB_HINGE_BOXES = 7; // Number of Hinge chain boxes
// Class JointsScene
class JointsScene : public Scene {
class JointsScene : public SceneDemo {
protected :
@ -134,8 +135,9 @@ class JointsScene : public Scene {
/// Take a step for the simulation
virtual void update();
/// Render the scene
virtual void render();
/// Render the scene in a single pass
virtual void renderSinglePass(openglframework::Shader& shader,
const openglframework::Matrix4& worldToCameraMatrix);
/// Reset the scene
virtual void reset();

View File

@ -32,7 +32,7 @@ using namespace raycastscene;
// Constructor
RaycastScene::RaycastScene(const std::string& name)
: Scene(name), mLight0(0), mCurrentBodyIndex(-1), mAreNormalsDisplayed(false),
: SceneDemo(name, SCENE_RADIUS), mLight0(0), mCurrentBodyIndex(-1), mAreNormalsDisplayed(false),
mPhongShader("shaders/phong.vert", "shaders/phong.frag"),
mMeshFolderPath("meshes/"), mRaycastManager(mPhongShader, mMeshFolderPath),
mVBOVertices(GL_ARRAY_BUFFER) {
@ -41,11 +41,10 @@ RaycastScene::RaycastScene(const std::string& name)
mLight0.translateWorld(Vector3(50, 50, 50));
// Compute the radius and the center of the scene
float radiusScene = 30.0f;
openglframework::Vector3 center(0, 0, 0);
// Set the center of the scene
setScenePosition(center, radiusScene);
setScenePosition(center, SCENE_RADIUS);
// Create the dynamics world for the physics simulation
mCollisionWorld = new rp3d::CollisionWorld();
@ -54,7 +53,7 @@ RaycastScene::RaycastScene(const std::string& name)
openglframework::Vector3 position1(0, 0, 0);
// Create a convex mesh and a corresponding collision body in the dynamics world
mDumbbell = new Dumbbell(position1, mCollisionWorld, mMeshFolderPath, mPhongShader);
mDumbbell = new Dumbbell(position1, mCollisionWorld, mMeshFolderPath);
// ---------- Box ---------- //
openglframework::Vector3 position2(0, 0, 0);
@ -68,34 +67,34 @@ RaycastScene::RaycastScene(const std::string& name)
// Create a sphere and a corresponding collision body in the dynamics world
mSphere = new Sphere(SPHERE_RADIUS, position3, mCollisionWorld,
mMeshFolderPath, mPhongShader);
mMeshFolderPath);
// ---------- Cone ---------- //
openglframework::Vector3 position4(0, 0, 0);
// Create a cone and a corresponding collision body in the dynamics world
mCone = new Cone(CONE_RADIUS, CONE_HEIGHT, position4, mCollisionWorld,
mMeshFolderPath, mPhongShader);
mMeshFolderPath);
// ---------- Cylinder ---------- //
openglframework::Vector3 position5(0, 0, 0);
// Create a cylinder and a corresponding collision body in the dynamics world
mCylinder = new Cylinder(CYLINDER_RADIUS, CYLINDER_HEIGHT, position5,
mCollisionWorld, mMeshFolderPath, mPhongShader);
mCollisionWorld, mMeshFolderPath);
// ---------- Capsule ---------- //
openglframework::Vector3 position6(0, 0, 0);
// Create a cylinder and a corresponding collision body in the dynamics world
mCapsule = new Capsule(CAPSULE_RADIUS, CAPSULE_HEIGHT, position6 ,
mCollisionWorld, mMeshFolderPath, mPhongShader);
mCollisionWorld, mMeshFolderPath);
// ---------- Convex Mesh ---------- //
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, mPhongShader);
mConvexMesh = new ConvexMesh(position7, mCollisionWorld, mMeshFolderPath);
// Create the lines that will be used for raycasting
createLines();
@ -266,41 +265,26 @@ void RaycastScene::update() {
}
// Render the scene
void RaycastScene::render() {
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_CULL_FACE);
void RaycastScene::renderSinglePass(openglframework::Shader& shader,
const openglframework::Matrix4& worldToCameraMatrix) {
// Bind the shader
mPhongShader.bind();
// Get the world-space to camera-space matrix
const openglframework::Matrix4 worldToCameraMatrix = mCamera.getTransformMatrix().getInverse();
// Set the variables of the shader
mPhongShader.setMatrix4x4Uniform("projectionMatrix", mCamera.getProjectionMatrix());
mPhongShader.setVector3Uniform("light0PosCameraSpace",worldToCameraMatrix * mLight0.getOrigin());
mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f));
const Color& diffCol = mLight0.getDiffuseColor();
const Color& specCol = mLight0.getSpecularColor();
mPhongShader.setVector3Uniform("light0DiffuseColor", Vector3(diffCol.r, diffCol.g, diffCol.b));
mPhongShader.setVector3Uniform("light0SpecularColor", Vector3(specCol.r, specCol.g, specCol.b));
mPhongShader.setFloatUniform("shininess", 60.0f);
shader.bind();
// Set the model to camera matrix
const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix;
mPhongShader.setMatrix4x4Uniform("localToCameraMatrix", localToCameraMatrix);
const Matrix4 localToCameraMatrix = Matrix4::identity();
shader.setMatrix4x4Uniform("localToWorldMatrix", localToCameraMatrix);
shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
// Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
// model-view matrix)
const openglframework::Matrix3 normalMatrix =
localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
mPhongShader.setMatrix3x3Uniform("normalMatrix", normalMatrix);
shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
// Set the vertex color
openglframework::Vector4 color(1, 0, 0, 1);
mPhongShader.setVector4Uniform("vertexColor", color);
shader.setVector4Uniform("vertexColor", color, false);
// Bind the VAO
mVAO.bind();
@ -311,41 +295,40 @@ void RaycastScene::render() {
// Unbind the VAO
mVAO.unbind();
mPhongShader.unbind();
shader.unbind();
// Render the shapes
if (mBox->getCollisionBody()->isActive()) mBox->render(mPhongShader, worldToCameraMatrix);
if (mSphere->getCollisionBody()->isActive()) mSphere->render(mPhongShader, worldToCameraMatrix);
if (mCone->getCollisionBody()->isActive()) mCone->render(mPhongShader, worldToCameraMatrix);
if (mCylinder->getCollisionBody()->isActive()) mCylinder->render(mPhongShader, worldToCameraMatrix);
if (mCapsule->getCollisionBody()->isActive()) mCapsule->render(mPhongShader, worldToCameraMatrix);
if (mConvexMesh->getCollisionBody()->isActive()) mConvexMesh->render(mPhongShader, worldToCameraMatrix);
if (mDumbbell->getCollisionBody()->isActive()) mDumbbell->render(mPhongShader, worldToCameraMatrix);
if (mBox->getCollisionBody()->isActive()) mBox->render(shader, worldToCameraMatrix);
if (mSphere->getCollisionBody()->isActive()) mSphere->render(shader, worldToCameraMatrix);
if (mCone->getCollisionBody()->isActive()) mCone->render(shader, worldToCameraMatrix);
if (mCylinder->getCollisionBody()->isActive()) mCylinder->render(shader, worldToCameraMatrix);
if (mCapsule->getCollisionBody()->isActive()) mCapsule->render(shader, worldToCameraMatrix);
if (mConvexMesh->getCollisionBody()->isActive()) mConvexMesh->render(shader, worldToCameraMatrix);
if (mDumbbell->getCollisionBody()->isActive()) mDumbbell->render(shader, worldToCameraMatrix);
//mPhongShader.unbind();
mPhongShader.bind();
shader.bind();
mPhongShader.setVector3Uniform("light0SpecularColor", Vector3(0, 0, 0));
openglframework::Vector4 redColor(1, 0, 0, 1);
mPhongShader.setVector4Uniform("vertexColor", redColor);
shader.setVector4Uniform("vertexColor", redColor, false);
// Render all the raycast hit points
mRaycastManager.render(worldToCameraMatrix, mAreNormalsDisplayed);
mPhongShader.unbind();
mPhongShader.bind();
shader.unbind();
shader.bind();
openglframework::Vector4 blueColor(0, 0.62, 0.92, 1);
mPhongShader.setVector4Uniform("vertexColor", blueColor);
shader.setVector4Uniform("vertexColor", blueColor, false);
// Render the lines
for (std::vector<Line*>::iterator it = mLines.begin(); it != mLines.end();
++it) {
(*it)->render(mPhongShader, worldToCameraMatrix);
(*it)->render(shader, worldToCameraMatrix);
}
// Unbind the shader
mPhongShader.unbind();
shader.unbind();
}
// Create the Vertex Buffer Objects used to render with OpenGL.

View File

@ -31,7 +31,7 @@
#include <cmath>
#include "openglframework.h"
#include "reactphysics3d.h"
#include "Scene.h"
#include "SceneDemo.h"
#include "Sphere.h"
#include "Box.h"
#include "Cone.h"
@ -46,6 +46,7 @@
namespace raycastscene {
// Constants
const float SCENE_RADIUS = 30.0f;
const openglframework::Vector3 BOX_SIZE(4, 2, 1);
const float SPHERE_RADIUS = 3.0f;
const float CONE_RADIUS = 3.0f;
@ -87,7 +88,7 @@ class RaycastManager : public rp3d::RaycastCallback {
virtual rp3d::decimal notifyRaycastHit(const rp3d::RaycastInfo& raycastInfo) {
rp3d::Vector3 hitPos = raycastInfo.worldPoint;
openglframework::Vector3 position(hitPos.x, hitPos.y, hitPos.z);
VisualContactPoint* point = new VisualContactPoint(position, mShader, mMeshFolderPath);
VisualContactPoint* point = new VisualContactPoint(position, mMeshFolderPath);
mHitPoints.push_back(point);
// Create a line to display the normal at hit point
@ -137,7 +138,7 @@ class RaycastManager : public rp3d::RaycastCallback {
};
// Class RaycastScene
class RaycastScene : public Scene {
class RaycastScene : public SceneDemo {
private :
@ -211,8 +212,9 @@ class RaycastScene : public Scene {
/// Take a step for the simulation
virtual void update();
/// Render the scene
virtual void render();
/// Render the scene in a single pass
virtual void renderSinglePass(openglframework::Shader& shader,
const openglframework::Matrix4& worldToCameraMatrix);
/// Reset the scene
virtual void reset();

View File

@ -70,12 +70,14 @@ void main() {
vec3 specular = light0SpecularColor * specularFactor;
// Compute shadow factor
vec4 shadowMapCoordsOverW = shadowMapCoords / shadowMapCoords.w ;
//shadowMapCoordsOverW += 0.0005;
float shadowBias = 0.005;
vec4 shadowMapUV = shadowMapCoords;
shadowMapUV.z -= shadowBias;
vec4 shadowMapCoordsOverW = shadowMapUV / shadowMapUV.w ;
float distanceInShadowMap = texture(shadowMapSampler, shadowMapCoordsOverW.xy).r;
float shadow = 0.0;
if (shadowMapCoords.w > 0) {
shadow = distanceInShadowMap < shadowMapCoordsOverW.z ? 0.0 : 1.0;
shadow = distanceInShadowMap < shadowMapCoordsOverW.z ? 0.5 : 1.0;
}
// Compute the final color

View File

@ -37,11 +37,11 @@ SceneDemo::SceneDemo(const std::string& name, float sceneRadius) : Scene(name),
mVBOQuad(GL_ARRAY_BUFFER) {
// Move the light0
mLight0.translateWorld(Vector3(0, 60, 00));
mLight0.translateWorld(Vector3(0, 40, 40));
// Camera at light0 postion for the shadow map
mShadowMapLightCamera.translateWorld(mLight0.getOrigin());
mShadowMapLightCamera.rotateLocal(Vector3(1, 0, 0), -PI / 2.0f);
mShadowMapLightCamera.rotateLocal(Vector3(1, 0, 0), -PI / 4.0f);
mShadowMapLightCamera.setDimensions(SHADOWMAP_WIDTH, SHADOWMAP_HEIGHT);
mShadowMapLightCamera.setFieldOfView(70.0f);
mShadowMapLightCamera.setSceneRadius(200);
@ -64,6 +64,8 @@ SceneDemo::~SceneDemo() {
mShadowMapTexture.destroy();
mFBOShadowMap.destroy();
mVBOQuad.destroy();
}
// Render the scene (in multiple passes for shadow mapping)
@ -75,7 +77,7 @@ void SceneDemo::render() {
// ---------- Render the scene to generate the shadow map (first pass) ----------- //
// Culling switching, rendering only backface, this is done to avoid self-shadowing
glCullFace(GL_FRONT);
glCullFace(GL_BACK);
Matrix4 shadowMapProjMatrix = mShadowMapLightCamera.getProjectionMatrix();

View File

@ -30,8 +30,8 @@
#include "Scene.h"
// Constants
const int SHADOWMAP_WIDTH = 1024;
const int SHADOWMAP_HEIGHT = 1024;
const int SHADOWMAP_WIDTH = 2048;
const int SHADOWMAP_HEIGHT = 2048;
// Class SceneDemo
// Abstract class that represents a 3D scene for the ReactPhysics3D examples.