Draw a capsule
| 192 | |
| 193 | // Draw a capsule |
| 194 | void DebugRenderer::drawCapsule(const Transform& transform, decimal radius, decimal height, uint32 color) { |
| 195 | |
| 196 | Vector3 vertices[(NB_SECTORS_SPHERE + 1) * (NB_STACKS_SPHERE + 1) + (NB_SECTORS_SPHERE + 1)]; |
| 197 | |
| 198 | const decimal halfHeight = decimal(0.5) * height; |
| 199 | |
| 200 | // Use an even number of stacks |
| 201 | const uint32 nbStacks = NB_STACKS_SPHERE % 2 == 0 ? NB_STACKS_SPHERE : NB_STACKS_SPHERE - 1; |
| 202 | const uint32 nbHalfStacks = nbStacks / 2; |
| 203 | |
| 204 | // Vertices |
| 205 | const decimal sectorStep = 2 * PI_RP3D / NB_SECTORS_SPHERE; |
| 206 | const decimal stackStep = PI_RP3D / nbStacks; |
| 207 | |
| 208 | uint32 vertexIndex = 0; |
| 209 | |
| 210 | // Top cap sphere vertices |
| 211 | for (uint32 i = 0; i <= nbHalfStacks; i++) { |
| 212 | |
| 213 | const decimal stackAngle = PI_RP3D / 2 - i * stackStep; |
| 214 | const decimal radiusCosStackAngle = radius * std::cos(stackAngle); |
| 215 | const decimal y = radius * std::sin(stackAngle); |
| 216 | |
| 217 | for (uint32 j = 0; j <= NB_SECTORS_SPHERE; j++) { |
| 218 | |
| 219 | const decimal sectorAngle = j * sectorStep; |
| 220 | const decimal x = radiusCosStackAngle * std::sin(sectorAngle); |
| 221 | const decimal z = radiusCosStackAngle * std::cos(sectorAngle); |
| 222 | |
| 223 | assert(vertexIndex < (NB_SECTORS_SPHERE + 1) * (nbStacks + 1) + (NB_SECTORS_SPHERE + 1)); |
| 224 | vertices[vertexIndex] = transform * Vector3(x, y + halfHeight, z); |
| 225 | |
| 226 | vertexIndex++; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | // Bottom cap sphere vertices |
| 231 | for (uint32 i = 0; i <= nbHalfStacks; i++) { |
| 232 | |
| 233 | const decimal stackAngle = PI_RP3D / 2 - (nbHalfStacks + i) * stackStep; |
| 234 | const decimal radiusCosStackAngle = radius * std::cos(stackAngle); |
| 235 | const decimal y = radius * std::sin(stackAngle); |
| 236 | |
| 237 | for (uint32 j = 0; j <= NB_SECTORS_SPHERE; j++) { |
| 238 | |
| 239 | const decimal sectorAngle = j * sectorStep; |
| 240 | const decimal x = radiusCosStackAngle * std::sin(sectorAngle); |
| 241 | const decimal z = radiusCosStackAngle * std::cos(sectorAngle); |
| 242 | |
| 243 | assert(vertexIndex < (NB_SECTORS_SPHERE + 1) * (nbStacks + 1) + (NB_SECTORS_SPHERE + 1)); |
| 244 | vertices[vertexIndex] = transform * Vector3(x, y - halfHeight, z); |
| 245 | |
| 246 | vertexIndex++; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | // Faces of the top cap sphere |
| 251 | for (uint32 i = 0; i < nbHalfStacks; i++) { |
nothing calls this directly
no test coverage detected