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.
This commit is contained in:
smalltimewizard 2024-06-25 19:39:46 -04:00 committed by GitHub
parent a8b687da3c
commit 28e60ebb64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -436,16 +436,16 @@ void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color
float *sinring; float *sinring;
float *cosslice; float *cosslice;
float *sinslice; float *sinslice;
cosring = (float *)RL_CALLOC(rings + 2, sizeof(float)); cosring = (float *)RL_CALLOC(rings + 2 + 1, sizeof(float));
sinring = (float *)RL_CALLOC(rings + 2, sizeof(float)); sinring = (float *)RL_CALLOC(rings + 2 + 1, sizeof(float));
cosslice = (float *)RL_CALLOC(slices, sizeof(float)); cosslice = (float *)RL_CALLOC(slices + 1, sizeof(float));
sinslice = (float *)RL_CALLOC(slices, sizeof(float)); sinslice = (float *)RL_CALLOC(slices + 1, sizeof(float));
for (int i = 0; i < (rings + 2); i++) 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 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)); 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 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)); sinslice[j] = sinf(DEG2RAD*(360.0f*j/slices));