summaryrefslogtreecommitdiffhomepage
path: root/src/rmodels.c
diff options
context:
space:
mode:
authorHorrowind <[email protected]>2021-10-13 19:32:30 +0200
committerGitHub <[email protected]>2021-10-13 19:32:30 +0200
commite545286369cdd4d8bf08f4f9064f5b341df384c6 (patch)
tree99d25ce6a00cc190e6c3e29b6b42ce126ddbfe18 /src/rmodels.c
parent942731cc22e20d698ed84b2ca14c6dcd61f0e962 (diff)
downloadraylib-e545286369cdd4d8bf08f4f9064f5b341df384c6.tar.gz
raylib-e545286369cdd4d8bf08f4f9064f5b341df384c6.zip
Fix issue with empty cylinder (#2050)
* Add DrawCylinderEx and DrawCylinderWiresEx * Modify examples/models/models_geometric_shapes.c to show the usage of DrawCylinder(Wires)Ex * Simplified DrawCylinder and DrawCylinderWires to use the -Ex versions. * This reverts commits f49b2598dd3bfc3219d414f24558c68f7ebe9eb5 and 4542b32e4ece9ddae775e7395d4219fa148039a8. * Fixed formatting. Renamed base_angle to baseAngle. Remove most of the raymath.h calls. * Added check for empty cylinder. * Added check for empty cylinder. * Fix bug. Co-authored-by: Horrowind <[email protected]>
Diffstat (limited to 'src/rmodels.c')
-rw-r--r--src/rmodels.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/rmodels.c b/src/rmodels.c
index d98560ba..1063f9ec 100644
--- a/src/rmodels.c
+++ b/src/rmodels.c
@@ -714,6 +714,10 @@ void DrawCylinderEx(Vector3 startPos, Vector3 endPos, float startRadius, float e
if(sides < 3) sides = 3;
Vector3 direction = { endPos.x - startPos.x, endPos.y - startPos.y, endPos.z - startPos.z };
+ if(direction.x == 0 && direction.y == 0 && direction.z == 0) {
+ return;
+ }
+
// Construct a basis of the base and the top face:
Vector3 b1 = Vector3Normalize(Vector3Perpendicular(direction));
Vector3 b2 = Vector3Normalize(Vector3CrossProduct(b1, direction));
@@ -804,10 +808,14 @@ void DrawCylinderWiresEx(Vector3 startPos, Vector3 endPos, float startRadius, fl
int numVertex = sides*6;
rlCheckRenderBatchLimit(numVertex);
- Vector3 difference = Vector3Subtract(endPos, startPos);
+ Vector3 direction = { endPos.x - startPos.x, endPos.y - startPos.y, endPos.z - startPos.z };
+ if(direction.x == 0 && direction.y == 0 && direction.z == 0) {
+ return;
+ }
+
// Construct a basis of the base and the top face:
- Vector3 b1 = Vector3Normalize(Vector3Perpendicular(difference));
- Vector3 b2 = Vector3Normalize(Vector3CrossProduct(b1, difference));
+ Vector3 b1 = Vector3Normalize(Vector3Perpendicular(direction));
+ Vector3 b2 = Vector3Normalize(Vector3CrossProduct(b1, direction));
float baseAngle = (2.0*PI)/sides;