fix circle rendering over new impl
This commit is contained in:
@ -27,8 +27,10 @@ void create_circle_geometry(Vec2 position,
|
||||
size_t num_vertices,
|
||||
Vec2 vertices[])
|
||||
{
|
||||
SDL_assert(num_vertices <= CIRCLE_VERTICES_MAX);
|
||||
|
||||
/* the angle (in radians) to rotate by on each iteration */
|
||||
float seg_rotation_angle = (360.0f / (float)num_vertices) * ((float)M_PI / 180);
|
||||
float seg_rotation_angle = (360.0f / (float)(num_vertices - 2)) * ((float)M_PI / 180);
|
||||
|
||||
vertices[0].x = (float)position.x;
|
||||
vertices[0].y = (float)position.y;
|
||||
@ -37,7 +39,7 @@ void create_circle_geometry(Vec2 position,
|
||||
float start_x = 0.0f - radius;
|
||||
float start_y = 0.0f;
|
||||
|
||||
for (size_t i = 1; i < num_vertices + 1; ++i) {
|
||||
for (size_t i = 1; i < num_vertices - 1; ++i) {
|
||||
float final_seg_rotation_angle = (float)i * seg_rotation_angle;
|
||||
|
||||
float c, s;
|
||||
@ -49,4 +51,18 @@ void create_circle_geometry(Vec2 position,
|
||||
vertices[i].x += position.x;
|
||||
vertices[i].y += position.y;
|
||||
}
|
||||
|
||||
// place a redundant vertex to make proper circling over shared element buffer
|
||||
{
|
||||
float final_seg_rotation_angle = (float)1 * seg_rotation_angle;
|
||||
|
||||
float c, s;
|
||||
sincosf(final_seg_rotation_angle, &s, &c);
|
||||
|
||||
vertices[num_vertices - 1].x = c * start_x - s * start_y;
|
||||
vertices[num_vertices - 1].y = c * start_y + s * start_x;
|
||||
|
||||
vertices[num_vertices - 1].x += position.x;
|
||||
vertices[num_vertices - 1].y += position.y;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user