Render the sphere at the correct position and with the correct orientation
| 115 | |
| 116 | // Render the sphere at the correct position and with the correct orientation |
| 117 | void Dumbbell::render(openglframework::Shader& shader, |
| 118 | const openglframework::Matrix4& worldToCameraMatrix) { |
| 119 | |
| 120 | // Bind the shader |
| 121 | shader.bind(); |
| 122 | |
| 123 | // Set the model to camera matrix |
| 124 | shader.setMatrix4x4Uniform("localToWorldMatrix", mTransformMatrix); |
| 125 | shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix); |
| 126 | |
| 127 | // Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the |
| 128 | // model-view matrix) |
| 129 | const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * mTransformMatrix; |
| 130 | const openglframework::Matrix3 normalMatrix = |
| 131 | localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose(); |
| 132 | shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false); |
| 133 | |
| 134 | // Set the vertex color |
| 135 | rp3d::RigidBody* rigidBody = dynamic_cast<rp3d::RigidBody*>(mBody); |
| 136 | openglframework::Color currentColor = rigidBody != nullptr && rigidBody->isSleeping() ? mSleepingColor : mColor; |
| 137 | openglframework::Vector4 color(currentColor.r, currentColor.g, currentColor.b, currentColor.a); |
| 138 | shader.setVector4Uniform("globalVertexColor", color, false); |
| 139 | |
| 140 | // Bind the VAO |
| 141 | mVAO.bind(); |
| 142 | |
| 143 | mVBOVertices.bind(); |
| 144 | |
| 145 | // Get the location of shader attribute variables |
| 146 | GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition"); |
| 147 | GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false); |
| 148 | |
| 149 | glEnableVertexAttribArray(vertexPositionLoc); |
| 150 | glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); |
| 151 | |
| 152 | mVBONormals.bind(); |
| 153 | |
| 154 | if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc); |
| 155 | if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)NULL); |
| 156 | |
| 157 | // For each part of the mesh |
| 158 | for (unsigned int i=0; i<getNbParts(); i++) { |
| 159 | glDrawElements(GL_TRIANGLES, getNbFaces(i) * 3, GL_UNSIGNED_INT, (char*)NULL); |
| 160 | } |
| 161 | |
| 162 | glDisableVertexAttribArray(vertexPositionLoc); |
| 163 | if (vertexNormalLoc != -1) glDisableVertexAttribArray(vertexNormalLoc); |
| 164 | |
| 165 | mVBONormals.unbind(); |
| 166 | mVBOVertices.unbind(); |
| 167 | |
| 168 | // Unbind the VAO |
| 169 | mVAO.unbind(); |
| 170 | |
| 171 | // Unbind the shader |
| 172 | shader.unbind(); |
| 173 | } |
| 174 |
nothing calls this directly
no test coverage detected