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

Method drawBox

src/utils/DebugRenderer.cpp:94–143  ·  view source on GitHub ↗

Draw a box

Source from the content-addressed store, hash-verified

92
93// Draw a box
94void DebugRenderer::drawBox(const Transform& transform, const BoxShape* boxShape, uint32 colorShape, uint32 colorShapeNormals) {
95
96 const bool drawShape = getIsDebugItemDisplayed(DebugItem::COLLISION_SHAPE);
97 const bool drawNormal = getIsDebugItemDisplayed(DebugItem::COLLISION_SHAPE_NORMAL);
98
99 Vector3 halfExtents = boxShape->getHalfExtents();
100 Vector3 vertices[8];
101
102 // Vertices
103 vertices[0] = transform * Vector3(-halfExtents.x, -halfExtents.y, halfExtents.z);
104 vertices[1] = transform * Vector3(halfExtents.x, -halfExtents.y, halfExtents.z);
105 vertices[2] = transform * Vector3(halfExtents.x, -halfExtents.y, -halfExtents.z);
106 vertices[3] = transform * Vector3(-halfExtents.x, -halfExtents.y, -halfExtents.z);
107 vertices[4] = transform * Vector3(-halfExtents.x, halfExtents.y, halfExtents.z);
108 vertices[5] = transform * Vector3(halfExtents.x, halfExtents.y, halfExtents.z);
109 vertices[6] = transform * Vector3(halfExtents.x, halfExtents.y, -halfExtents.z);
110 vertices[7] = transform * Vector3(-halfExtents.x, halfExtents.y, -halfExtents.z);
111
112 if (drawShape) {
113
114 // Triangle faces
115 mTriangles.add(DebugTriangle(vertices[0], vertices[1], vertices[5], colorShape));
116 mTriangles.add(DebugTriangle(vertices[0], vertices[5], vertices[4], colorShape));
117 mTriangles.add(DebugTriangle(vertices[1], vertices[2], vertices[6], colorShape));
118 mTriangles.add(DebugTriangle(vertices[1], vertices[6], vertices[5], colorShape));
119 mTriangles.add(DebugTriangle(vertices[2], vertices[3], vertices[6], colorShape));
120 mTriangles.add(DebugTriangle(vertices[3], vertices[7], vertices[6], colorShape));
121 mTriangles.add(DebugTriangle(vertices[0], vertices[7], vertices[3], colorShape));
122 mTriangles.add(DebugTriangle(vertices[0], vertices[4], vertices[7], colorShape));
123 mTriangles.add(DebugTriangle(vertices[0], vertices[2], vertices[1], colorShape));
124 mTriangles.add(DebugTriangle(vertices[0], vertices[3], vertices[2], colorShape));
125 mTriangles.add(DebugTriangle(vertices[5], vertices[6], vertices[4], colorShape));
126 mTriangles.add(DebugTriangle(vertices[4], vertices[6], vertices[7], colorShape));
127 }
128
129 if (drawNormal) {
130
131 // Face normals
132 for (int f=0; f < 6; f++) {
133
134 const HalfEdgeStructure::Face& face = boxShape->getFace(f);
135 const Vector3 facePoint = 0.25 * (boxShape->getVertexPosition(face.faceVertices[0]) + boxShape->getVertexPosition(face.faceVertices[1]) +
136 boxShape->getVertexPosition(face.faceVertices[2]) + boxShape->getVertexPosition(face.faceVertices[3]));
137 const Vector3 normalPoint = facePoint + mCollisionShapeNormalLength * boxShape->getFaceNormal(f);
138
139 mLines.add(DebugLine(transform * facePoint, transform * normalPoint, colorShapeNormals));
140 }
141 }
142
143}
144
145/// Draw a sphere
146void DebugRenderer::drawSphere(const Vector3& position, decimal radius, uint32 color) {

Callers

nothing calls this directly

Calls 6

DebugTriangleClass · 0.85
DebugLineClass · 0.85
Vector3Class · 0.50
addMethod · 0.45
getVertexPositionMethod · 0.45
getFaceNormalMethod · 0.45

Tested by

no test coverage detected