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

Method render

testbed/common/VisualContactPoint.cpp:94–151  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

setIntUniformMethod · 0.80
setVector4UniformMethod · 0.80
setMatrix4x4UniformMethod · 0.80
getUpperLeft3x3MatrixMethod · 0.80
setMatrix3x3UniformMethod · 0.80
getAttribLocationMethod · 0.80
getNbPartsMethod · 0.80
bindMethod · 0.45
getTransposeMethod · 0.45
getInverseMethod · 0.45
getNbFacesMethod · 0.45
unbindMethod · 0.45

Tested by

no test coverage detected