From 28e60ebb645b93d9ea993451d3d71cfe04fb3e61 Mon Sep 17 00:00:00 2001 From: smalltimewizard <83366732+smalltimewizard@users.noreply.github.com> Date: Tue, 25 Jun 2024 19:39:46 -0400 Subject: [PATCH] Bugfix to optimized DrawSphereEx() OBO error -- added 1 additional precalculated cos/sin value to each array to complete the 360-degree wraparound. Technically the value of these last elements will always be the same as the first element due to 360-degree wraparound, but this is the simplest solution. --- src/rmodels.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rmodels.c b/src/rmodels.c index 7d1fdf6f5..31a88d141 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -436,16 +436,16 @@ void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color float *sinring; float *cosslice; float *sinslice; - cosring = (float *)RL_CALLOC(rings + 2, sizeof(float)); - sinring = (float *)RL_CALLOC(rings + 2, sizeof(float)); - cosslice = (float *)RL_CALLOC(slices, sizeof(float)); - sinslice = (float *)RL_CALLOC(slices, sizeof(float)); - for (int i = 0; i < (rings + 2); i++) + cosring = (float *)RL_CALLOC(rings + 2 + 1, sizeof(float)); + sinring = (float *)RL_CALLOC(rings + 2 + 1, sizeof(float)); + cosslice = (float *)RL_CALLOC(slices + 1, sizeof(float)); + sinslice = (float *)RL_CALLOC(slices + 1, sizeof(float)); + for (int i = 0; i < (rings + 2 + 1); i++) { cosring[i] = cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*i)); // Precalculate position on unit circle required for each ring sinring[i] = sinf(DEG2RAD*(270 + (180.0f/(rings + 1))*i)); } - for (int j = 0; j < slices; j++) + for (int j = 0; j < slices + 1; j++) { cosslice[j] = cosf(DEG2RAD*(360.0f*j/slices)); // Precalculate position on unit circle required for each slice sinslice[j] = sinf(DEG2RAD*(360.0f*j/slices));