diff options
| author | raysan5 <[email protected]> | 2020-05-07 12:46:45 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2020-05-07 12:46:45 +0200 |
| commit | f6ca045735dc5a3da1c329434503ec37df940171 (patch) | |
| tree | 7ef307398d5120cd535bbfb444e12a68218d42b4 /src/models.c | |
| parent | 2e8299742b33717ea8bba5091aa8217f9780a7d2 (diff) | |
| download | raylib-f6ca045735dc5a3da1c329434503ec37df940171.tar.gz raylib-f6ca045735dc5a3da1c329434503ec37df940171.zip | |
ADDED: DrawTriangle3D() and DrawTriangleStrip3D()
Those functions could be very useful for custom triangle data drawing, using internal batch system.
Diffstat (limited to 'src/models.c')
| -rw-r--r-- | src/models.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/models.c b/src/models.c index dfc070c6..00d3b516 100644 --- a/src/models.c +++ b/src/models.c @@ -169,6 +169,48 @@ void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rota rlPopMatrix(); } +// Draw a color-filled triangle (vertex in counter-clockwise order!) +void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color) +{ + if (rlCheckBufferLimit(3)) rlglDraw(); + + rlBegin(RL_TRIANGLES); + rlColor4ub(color.r, color.g, color.b, color.a); + rlVertex3f(v1.x, v1.y, v1.z); + rlVertex3f(v2.x, v2.y, v2.z); + rlVertex3f(v3.x, v3.y, v3.z); + rlEnd(); +} + +// Draw a triangle strip defined by points +void DrawTriangleStrip3D(Vector3 *points, int pointsCount, Color color) +{ + if (pointsCount >= 3) + { + if (rlCheckBufferLimit(3*(pointsCount - 2))) rlglDraw(); + + rlBegin(RL_TRIANGLES); + rlColor4ub(color.r, color.g, color.b, color.a); + + for (int i = 2; i < pointsCount; i++) + { + if ((i%2) == 0) + { + rlVertex3f(points[i].x, points[i].y, points[i].z); + rlVertex3f(points[i - 2].x, points[i - 2].y, points[i - 2].z); + rlVertex3f(points[i - 1].x, points[i - 1].y, points[i - 1].z); + } + else + { + rlVertex3f(points[i].x, points[i].y, points[i].z); + rlVertex3f(points[i - 1].x, points[i - 1].y, points[i - 1].z); + rlVertex3f(points[i - 2].x, points[i - 2].y, points[i - 2].z); + } + } + rlEnd(); + } +} + // Draw cube // NOTE: Cube position is the center position void DrawCube(Vector3 position, float width, float height, float length, Color color) |
