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

Method render

testbed/common/AABB.cpp:54–127  ·  view source on GitHub ↗

Render the AABB

Source from the content-addressed store, hash-verified

52
53// Render the AABB
54void AABB::render(const openglframework::Vector3& position, const openglframework::Vector3& dimension,
55 openglframework::Color color, openglframework::Shader& shader,
56 const openglframework::Matrix4& worldToCameraMatrix) {
57
58 // Render in wireframe mode
59 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
60
61 // Bind the shader
62 shader.bind();
63
64 // Transform matrix
65 openglframework::Matrix4 transformMatrix = openglframework::Matrix4::identity();
66 transformMatrix = openglframework::Matrix4::translationMatrix(position) * transformMatrix;
67
68 // Set the normal matrix (inverse transpose of the 3x3 upper-left sub matrix of the
69 // model-view matrix)
70 const openglframework::Matrix4 localToCameraMatrix = worldToCameraMatrix * transformMatrix;
71 const openglframework::Matrix3 normalMatrix =
72 localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose();
73 shader.setMatrix3x3Uniform("normalMatrix", normalMatrix, false);
74
75
76 // Compute the scaling matrix
77 openglframework::Matrix4 scalingMatrix = openglframework::Matrix4(dimension.x, 0, 0, 0,
78 0, dimension.y, 0, 0,
79 0, 0, dimension.z, 0,
80 0, 0, 0, 1);
81
82 transformMatrix = transformMatrix * scalingMatrix;
83
84 // Set the model to camera matrix
85 shader.setMatrix4x4Uniform("localToWorldMatrix", transformMatrix);
86 shader.setMatrix4x4Uniform("worldToCameraMatrix", worldToCameraMatrix);
87
88 // Set the vertex color
89 openglframework::Vector4 colorVec(color.r, color.g, color.b, color.a);
90 shader.setIntUniform("isGlobalVertexColorEnabled", 1, false);
91 shader.setVector4Uniform("globalVertexColor", colorVec, false);
92
93 // Bind the VAO
94 mVAO.bind();
95
96 mVBOVertices.bind();
97
98 // Get the location of shader attribute variables
99 GLint vertexPositionLoc = shader.getAttribLocation("vertexPosition");
100 GLint vertexNormalLoc = shader.getAttribLocation("vertexNormal", false);
101
102 glEnableVertexAttribArray(vertexPositionLoc);
103 glVertexAttribPointer(vertexPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr);
104
105 mVBONormals.bind();
106
107 if (vertexNormalLoc != -1) glVertexAttribPointer(vertexNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, (char*)nullptr);
108 if (vertexNormalLoc != -1) glEnableVertexAttribArray(vertexNormalLoc);
109
110 // Draw the geometry
111 glDrawElements(GL_LINES, 12 * 2, GL_UNSIGNED_INT, (char*)nullptr);

Callers

nothing calls this directly

Calls 11

Matrix4Class · 0.85
getUpperLeft3x3MatrixMethod · 0.80
setMatrix3x3UniformMethod · 0.80
setMatrix4x4UniformMethod · 0.80
setIntUniformMethod · 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