mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-06 03:18:14 +00:00
REVIEWED: DrawLineCatmullRom()
This commit is contained in:
@@ -437,11 +437,9 @@ void DrawLineCatmullRom(Vector2 *points, int pointCount, float thick, Color colo
|
|||||||
vertices[1].y = currentPoint.y + dx*size;
|
vertices[1].y = currentPoint.y + dx*size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Something is wrong with this implementation,
|
for (int j = 1; j <= SPLINE_LINE_DIVISIONS; j++)
|
||||||
// it should use 'j' instead of 'i' but it does not work...
|
|
||||||
for (int i = 1; i <= SPLINE_LINE_DIVISIONS; i++)
|
|
||||||
{
|
{
|
||||||
t = ((float)i)/((float)SPLINE_LINE_DIVISIONS);
|
t = ((float)j)/((float)SPLINE_LINE_DIVISIONS);
|
||||||
|
|
||||||
float q0 = (-1.0f*t*t*t) + (2.0f*t*t) + (-1.0f*t);
|
float q0 = (-1.0f*t*t*t) + (2.0f*t*t) + (-1.0f*t);
|
||||||
float q1 = (3.0f*t*t*t) + (-5.0f*t*t) + 2.0f;
|
float q1 = (3.0f*t*t*t) + (-5.0f*t*t) + 2.0f;
|
||||||
@@ -451,11 +449,11 @@ void DrawLineCatmullRom(Vector2 *points, int pointCount, float thick, Color colo
|
|||||||
nextPoint.x = 0.5f*((p1.x*q0) + (p2.x*q1) + (p3.x*q2) + (p4.x*q3));
|
nextPoint.x = 0.5f*((p1.x*q0) + (p2.x*q1) + (p3.x*q2) + (p4.x*q3));
|
||||||
nextPoint.y = 0.5f*((p1.y*q0) + (p2.y*q1) + (p3.y*q2) + (p4.y*q3));
|
nextPoint.y = 0.5f*((p1.y*q0) + (p2.y*q1) + (p3.y*q2) + (p4.y*q3));
|
||||||
|
|
||||||
float dy = nextPoint.y - currentPoint.y;
|
dy = nextPoint.y - currentPoint.y;
|
||||||
float dx = nextPoint.x - currentPoint.x;
|
dx = nextPoint.x - currentPoint.x;
|
||||||
float size = (0.5f*thick)/sqrtf(dx*dx + dy*dy);
|
size = (0.5f*thick)/sqrtf(dx*dx + dy*dy);
|
||||||
|
|
||||||
if (i == 1)
|
if ((i == 0) && (j == 1))
|
||||||
{
|
{
|
||||||
vertices[0].x = currentPoint.x + dy*size;
|
vertices[0].x = currentPoint.x + dy*size;
|
||||||
vertices[0].y = currentPoint.y - dx*size;
|
vertices[0].y = currentPoint.y - dx*size;
|
||||||
@@ -463,19 +461,18 @@ void DrawLineCatmullRom(Vector2 *points, int pointCount, float thick, Color colo
|
|||||||
vertices[1].y = currentPoint.y + dx*size;
|
vertices[1].y = currentPoint.y + dx*size;
|
||||||
}
|
}
|
||||||
|
|
||||||
vertices[2*i + 1].x = nextPoint.x - dy*size;
|
vertices[2*j + 1].x = nextPoint.x - dy*size;
|
||||||
vertices[2*i + 1].y = nextPoint.y + dx*size;
|
vertices[2*j + 1].y = nextPoint.y + dx*size;
|
||||||
vertices[2*i].x = nextPoint.x + dy*size;
|
vertices[2*j].x = nextPoint.x + dy*size;
|
||||||
vertices[2*i].y = nextPoint.y - dx*size;
|
vertices[2*j].y = nextPoint.y - dx*size;
|
||||||
|
|
||||||
currentPoint = nextPoint;
|
currentPoint = nextPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawTriangleStrip(vertices, 2*SPLINE_LINE_DIVISIONS + 2, color);
|
DrawTriangleStrip(vertices, 2*SPLINE_LINE_DIVISIONS + 2, color);
|
||||||
|
|
||||||
// TODO: REVIEW: HACK: Drawing a circle at points intersection to hide broken strip
|
|
||||||
DrawCircleV(currentPoint, thick/2.0f, color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DrawCircleV(currentPoint, thick/2.0f, color); // Draw end line circle-cap
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw lines sequence
|
// Draw lines sequence
|
||||||
|
Reference in New Issue
Block a user