summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-05-07 12:46:45 +0200
committerraysan5 <[email protected]>2020-05-07 12:46:45 +0200
commitf6ca045735dc5a3da1c329434503ec37df940171 (patch)
tree7ef307398d5120cd535bbfb444e12a68218d42b4 /src
parent2e8299742b33717ea8bba5091aa8217f9780a7d2 (diff)
downloadraylib-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')
-rw-r--r--src/models.c42
-rw-r--r--src/raylib.h3
2 files changed, 44 insertions, 1 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)
diff --git a/src/raylib.h b/src/raylib.h
index 4df397c8..5289061f 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -1259,6 +1259,8 @@ RLAPI const char *CodepointToUtf8(int codepoint, int *byteLength); // Encode
RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space
RLAPI void DrawPoint3D(Vector3 position, Color color); // Draw a point in 3D space, actually a small line
RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space
+RLAPI void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color); // Draw a color-filled triangle (vertex in counter-clockwise order!)
+RLAPI void DrawTriangleStrip3D(Vector3 *points, int pointsCount, Color color); // Draw a triangle strip defined by points
RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube
RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version)
RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires
@@ -1273,7 +1275,6 @@ RLAPI void DrawPlane(Vector3 centerPos, Vector2 size, Color color);
RLAPI void DrawRay(Ray ray, Color color); // Draw a ray line
RLAPI void DrawGrid(int slices, float spacing); // Draw a grid (centered at (0, 0, 0))
RLAPI void DrawGizmo(Vector3 position); // Draw simple gizmo
-//DrawTorus(), DrawTeapot() could be useful?
//------------------------------------------------------------------------------------
// Model 3d Loading and Drawing Functions (Module: models)