diff options
| author | Uneven Prankster <unevenprankster@protonmail.com> | 2023-11-16 21:12:27 -0300 |
|---|---|---|
| committer | Uneven Prankster <unevenprankster@protonmail.com> | 2023-11-16 21:12:27 -0300 |
| commit | 2bbf92ad5ae7708bf18ac7ef333e9a979d8d1bde (patch) | |
| tree | c9d22bb0d73d9cc0c8586e4d31c93a561ea8e910 /raylib/examples/shapes/shapes_lines_bezier.c | |
| parent | 1c0cc775732201f4c4d3ee0d6772be786b3b4aa1 (diff) | |
Working so hard like a soldiermain
Can't afford a thing on TV
Diffstat (limited to 'raylib/examples/shapes/shapes_lines_bezier.c')
| -rw-r--r-- | raylib/examples/shapes/shapes_lines_bezier.c | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/raylib/examples/shapes/shapes_lines_bezier.c b/raylib/examples/shapes/shapes_lines_bezier.c index f015768..aaad680 100644 --- a/raylib/examples/shapes/shapes_lines_bezier.c +++ b/raylib/examples/shapes/shapes_lines_bezier.c @@ -26,11 +26,10 @@ int main(void) SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines"); - Vector2 start = { 0, 0 }; - Vector2 end = { (float)screenWidth, (float)screenHeight }; - - Vector2 startControl = { 100, 0 }; - Vector2 endControl = { GetScreenWidth() - 100, GetScreenHeight() }; + Vector2 startPoint = { 30, 30 }; + Vector2 endPoint = { (float)screenWidth - 30, (float)screenHeight - 30 }; + bool moveStartPoint = false; + bool moveEndPoint = false; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -40,15 +39,21 @@ int main(void) { // Update //---------------------------------------------------------------------------------- - if (IsKeyDown(KEY_LEFT_CONTROL)) + Vector2 mouse = GetMousePosition(); + + if (CheckCollisionPointCircle(mouse, startPoint, 10.0f) && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) moveStartPoint = true; + else if (CheckCollisionPointCircle(mouse, endPoint, 10.0f) && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) moveEndPoint = true; + + if (moveStartPoint) { - if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) startControl = GetMousePosition(); - else if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) endControl = GetMousePosition(); + startPoint = mouse; + if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) moveStartPoint = false; } - else + + if (moveEndPoint) { - if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) start = GetMousePosition(); - else if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) end = GetMousePosition(); + endPoint = mouse; + if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) moveEndPoint = false; } //---------------------------------------------------------------------------------- @@ -58,16 +63,14 @@ int main(void) ClearBackground(RAYWHITE); - DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY); + DrawText("MOVE START-END POINTS WITH MOUSE", 15, 20, 20, GRAY); - //DrawLineBezier(start, end, 2.0f, RED); - - DrawLineBezierCubic(start, end, startControl, endControl, 2.0f, RED); + // Draw line Cubic Bezier, in-out interpolation (easing), no control points + DrawLineBezier(startPoint, endPoint, 4.0f, BLUE); - DrawLineEx(start, startControl, 1.0, LIGHTGRAY); - DrawLineEx(end, endControl, 1.0, LIGHTGRAY); - DrawCircleV(startControl, 10, RED); - DrawCircleV(endControl, 10, RED); + // Draw start-end spline circles with some details + DrawCircleV(startPoint, CheckCollisionPointCircle(mouse, startPoint, 10.0f)? 14 : 8, moveStartPoint? RED : BLUE); + DrawCircleV(endPoint, CheckCollisionPointCircle(mouse, endPoint, 10.0f)? 14 : 8, moveEndPoint? RED : BLUE); EndDrawing(); //---------------------------------------------------------------------------------- |
