MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / render

Method render

testbed/common/ConcaveMesh.cpp:109–165  ·  view source on GitHub ↗

Render the sphere at the correct position and with the correct orientation

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 10

setMatrix4x4UniformMethod · 0.80
getUpperLeft3x3MatrixMethod · 0.80
setMatrix3x3UniformMethod · 0.80
isSleepingMethod · 0.80
setVector4UniformMethod · 0.80
getAttribLocationMethod · 0.80
bindMethod · 0.45
getTransposeMethod · 0.45
getInverseMethod · 0.45
unbindMethod · 0.45

Tested by

no test coverage detected