Implemented J3D::DrawCubicBezierCurve
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m42s

This commit is contained in:
2024-10-25 13:17:07 -04:00
parent 0cc18cfdad
commit 779f212a29
4 changed files with 46 additions and 1 deletions

View File

@@ -22,7 +22,7 @@ CPMAddPackage(
CPMAddPackage(
NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.2.zip
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.3.zip
)
CPMAddPackage(

View File

@@ -337,6 +337,19 @@ namespace JGL {
/// @param thickness The line-width to draw the line segment with.
void DrawLine(const Color4 &color, const Vector3 &A, const Vector3 &B, float thickness = 1.f);
/// Draws a smooth, curved line segment between two control points, with the curve controlled by the two inner points.
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
/// @param controlA The first control point, which can be considered the start of the line.
/// @param pointA The first inner point, which controls the contour of the curve.
/// @param pointB The second inner point, which controls the contour of the curve.
/// @param controlB The second control point, which can be considered the end of the line.
/// @param subdivisions The accuracy of the approximation of the curve, measured in iteration steps taken.
/// @param thickness The line-width to draw the curve with.
/// @see J3ML::Algorithm::Bezier
void DrawCubicBezierCurve(const Color4& color, const Vector3& controlA, const Vector3& pointA, const Vector3& pointB, const Vector3& controlB,
int subdivisions = 10, float thickness = 1);
/// Draws the outline of an Icosahedron in 3D space.
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
/// @param position The point in 3D space at which to draw the Icosahedron.

View File

@@ -171,6 +171,9 @@ public:
//J3D::FillAABB(Colors::Whites::AliceBlue, {0,0,0.5f}, {0.1f, 0.05f, 0.1f});
J3D::WireframeAABB(Colors::Gray, {0,0,0.5f}, {0.11f, 0.06f, 0.11f});
J3D::DrawCubicBezierCurve(Colors::Blue, {0,0,0.3}, {0,0,0.5}, {0.2,0,0.3}, {0.2, 0.3, 0.1}, 30);
//J3D::WireframeIcosahedron(Colors::Green, {0,0,0.5f}, 0.125f, 1.f);
J3D::End();

View File

@@ -1407,5 +1407,34 @@ namespace JGL {
WireframeAABB(color, aabb.Centroid(), aabb.Size(), thickness);
}
float ComputeBinomial(int n, int k)
{
float value = 1.f;
for (int i = 1; i <= k; i++)
value = value * ((n + 1 - i) / i);
if (n == k)
value = 1;
return value;
}
void J3D::DrawCubicBezierCurve(const Color4 &color, const Vector3 &controlA, const Vector3 &pointA,
const Vector3 &pointB, const Vector3 &controlB, int subdivisions, float thickness) {
Vector3 last = controlA;
const Vector3& first = controlB;
for (int i = 0; i < subdivisions; ++i)
{
float alpha = (float) i / (float) subdivisions;
Vector3 step = J3ML::Algorithm::Bezier(alpha, controlA, pointA, pointB, controlB);
DrawLine(color, last, step, thickness);
last = step;
}
// Have to manually draw the last segment of the curve.
DrawLine(color, last, first, thickness);
}
#pragma endregion
}