Browse Source

Fix triangle strip array size and simplify loop (#5280)

Jopestpe 2 months ago
parent
commit
087aa1bc3f
1 changed files with 15 additions and 10 deletions
  1. 15 10
      examples/shapes/shapes_triangle_strip.c

+ 15 - 10
examples/shapes/shapes_triangle_strip.c

@@ -33,7 +33,7 @@ int main(void)
 
     InitWindow(screenWidth, screenHeight, "raylib [shapes] example - triangle strip");
 
-    Vector2 points[120] = { 0 };
+    Vector2 points[122] = { 0 };
     Vector2 center = { (screenWidth/2.0f) - 125.f, screenHeight/2.0f };
     float segments = 6.0f;
     float insideRadius = 100.0f;
@@ -69,17 +69,22 @@ int main(void)
 
             ClearBackground(RAYWHITE);
 
-            for (int i = 0, i2 = 0; i < pointCount; i++, i2 += 2)
+            for (int i = 0; i < pointCount; i++)
             {
+                Vector2 a = points[i*2];
+                Vector2 b = points[i*2 + 1];
+                Vector2 c = points[i*2 + 2];
+                Vector2 d = points[i*2 + 3];
+
                 float angle1 = i*angleStep;
-                Color color = ColorFromHSV(angle1*RAD2DEG, 1.0f, 1.0f);
-                DrawTriangle(points[i2 + 2], points[i2 + 1], points[i2], color);
-                if (outline) DrawTriangleLines(points[i2], points[i2 + 1], points[i2 + 2], BLACK);
-
-                float angle2 = angle1 + angleStep/2.0f;
-                color = ColorFromHSV(angle2*RAD2DEG, 1.0f, 1.0f);
-                DrawTriangle(points[i2 + 3], points[i2 + 1], points[i2 + 2], color);
-                if (outline) DrawTriangleLines(points[i2 + 2], points[i2 + 1], points[i2 + 3], BLACK);
+                DrawTriangle(c, b, a, ColorFromHSV(angle1*RAD2DEG, 1.0f, 1.0f));
+                DrawTriangle(d, b, c, ColorFromHSV((angle1 + angleStep/2)*RAD2DEG, 1.0f, 1.0f));
+                
+                if (outline)
+                {
+                    DrawTriangleLines(a, b, c, BLACK);
+                    DrawTriangleLines(c, b, d, BLACK);
+                }
             }
  
             DrawLine(580, 0, 580, GetScreenHeight(), (Color){ 218, 218, 218, 255 });