Render the sphere at the correct position and with the correct orientation
| 89 | |
| 90 | // Render the sphere at the correct position and with the correct orientation |
| 91 | void HeightField::render(openglframework::Shader& shader, |
| 92 | const openglframework::Matrix4& worldToCameraMatrix) { |
| 93 | |
| 94 | // Bind the shader |
| 95 | shader.bind(); |
| 96 | |
| 97 | // Set the model to camera matrix |
| 98 | shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix); |
| 99 | shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix); |
| 100 | |
| 101 | // Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the |
| 102 | // model-view matrix) |
| 103 | const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix; |
| 104 | const openglframework::Matrix3 normalMatrix = |
| 105 | localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose(); |
| 106 | shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false); |
| 107 | |
| 108 | // Set the vertex color |
| 109 | rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(mBody); |
| 110 | openglframework::Color currentColor = rigidBody != nullptr && rigidBody->isSleeping() ? mSleepingColor : mColor; |
| 111 | openglframework::Vector4 color(currentColor.r, currentColor.g, currentColor.b, currentColor.a); |
| 112 | shader.setVector4Uniform("globalVertexColor", color, false); |
| 113 | |
| 114 | // Bind the VAO |
| 115 | mVAO.bind(); |
| 116 | |
| 117 | mVBOVertices.bind(); |
| 118 | |
| 119 | // Get the location of shader attribute variables |
| 120 | GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition"); |
| 121 | GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false); |
| 122 | |
| 123 | glEnableVertexAttribArray(vertexPositionLoc); |
| 124 | glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); |
| 125 | |
| 126 | mVBONormals.bind(); |
| 127 | |
| 128 | if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); |
| 129 | if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc); |
| 130 | |
| 131 | // For each part of the mesh |
| 132 | for (unsigned int i=0; i<getNbParts(); i++) { |
| 133 | glDrawElements(GL_TRIANGLES, getNbFaces(i) * 3, GL_UNSIGNED_INT, (char*)NULL); |
| 134 | } |
| 135 | |
| 136 | glDisableVertexAttribArray(vertexPositionLoc); |
| 137 | if (vertexNormalLoc != -1) glDisableVertexAttribArray(vertexNormalLoc); |
| 138 | |
| 139 | mVBONormals.unbind(); |
| 140 | mVBOVertices.unbind(); |
| 141 | |
| 142 | // Unbind the VAO |
| 143 | mVAO.unbind(); |
| 144 | |
| 145 | // Unbind the shader |
| 146 | shader.unbind(); |
| 147 | } |
| 148 |
nothing calls this directly
no test coverage detected