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

Method drawSphere

src/utils/DebugRenderer.cpp:146–191  ·  view source on GitHub ↗

Draw a sphere

Source from the content-addressed store, hash-verified

144
145/// Draw a sphere
146void DebugRenderer::drawSphere(const Vector3& position, decimal radius, uint32 color) {
147
148 Vector3 vertices[(NB_SECTORS_SPHERE + 1) * (NB_STACKS_SPHERE + 1) + (NB_SECTORS_SPHERE + 1)];
149
150 // Vertices
151 const decimal sectorStep = 2 * PI_RP3D / NB_SECTORS_SPHERE;
152 const decimal stackStep = PI_RP3D / NB_STACKS_SPHERE;
153
154 for (uint32 i = 0; i <= NB_STACKS_SPHERE; i++) {
155
156 const decimal stackAngle = PI_RP3D / 2 - i * stackStep;
157 const decimal radiusCosStackAngle = radius * std::cos(stackAngle);
158 const decimal z = radius * std::sin(stackAngle);
159
160 for (uint32 j = 0; j <= NB_SECTORS_SPHERE; j++) {
161
162 const decimal sectorAngle = j * sectorStep;
163 const decimal x = radiusCosStackAngle * std::cos(sectorAngle);
164 const decimal y = radiusCosStackAngle * std::sin(sectorAngle);
165
166 vertices[i * (NB_SECTORS_SPHERE + 1) + j] = position + Vector3(x, y, z);
167 }
168 }
169
170 // Faces
171 for (uint32 i = 0; i < NB_STACKS_SPHERE; i++) {
172
173 uint32 a1 = i * (NB_SECTORS_SPHERE + 1);
174 uint32 a2 = a1 + NB_SECTORS_SPHERE + 1;
175
176 for (uint32 j = 0; j < NB_SECTORS_SPHERE; j++, a1++, a2++) {
177
178 // 2 triangles per sector except for the first and last stacks
179
180 if (i != 0) {
181
182 mTriangles.add(DebugTriangle(vertices[a1], vertices[a2], vertices[a1 + 1], color));
183 }
184
185 if (i != (NB_STACKS_SPHERE - 1)) {
186
187 mTriangles.add(DebugTriangle(vertices[a1 + 1], vertices[a2], vertices[a2 + 1], color));
188 }
189 }
190 }
191}
192
193// Draw a capsule
194void DebugRenderer::drawCapsule(const Transform& transform, decimal radius, decimal height, uint32 color) {

Callers

nothing calls this directly

Calls 3

DebugTriangleClass · 0.85
Vector3Class · 0.50
addMethod · 0.45

Tested by

no test coverage detected