2017-04-14 16:37:50 +03:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
|
|
|
* raylib [shapes] example - Cubic-bezier lines
|
|
|
|
*
|
2022-07-20 02:28:37 +03:00
|
|
|
* Example originally created with raylib 1.7, last time updated with raylib 1.7
|
2017-04-14 16:37:50 +03:00
|
|
|
*
|
2022-07-20 02:28:37 +03:00
|
|
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
|
|
* BSD-like license that allows static linking with closed source software
|
|
|
|
*
|
2023-01-01 18:00:56 +03:00
|
|
|
* Copyright (c) 2017-2023 Ramon Santamaria (@raysan5)
|
2017-04-14 16:37:50 +03:00
|
|
|
*
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
|
2022-06-21 20:53:18 +03:00
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Program main entry point
|
|
|
|
//------------------------------------------------------------------------------------
|
2019-05-20 17:36:42 +03:00
|
|
|
int main(void)
|
2017-04-14 16:37:50 +03:00
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
2019-05-20 17:36:42 +03:00
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 450;
|
2017-04-14 16:37:50 +03:00
|
|
|
|
|
|
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines");
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2017-04-14 16:37:50 +03:00
|
|
|
Vector2 start = { 0, 0 };
|
2021-04-25 19:50:26 +03:00
|
|
|
Vector2 end = { (float)screenWidth, (float)screenHeight };
|
2023-09-08 14:27:13 +03:00
|
|
|
|
|
|
|
Vector2 startControl = { 100, 0 };
|
2023-11-07 21:25:49 +03:00
|
|
|
Vector2 endControl = { GetScreenWidth() - 100, GetScreenHeight() };
|
2019-05-20 17:36:42 +03:00
|
|
|
|
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
2017-04-14 16:37:50 +03:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Main game loop
|
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
|
|
{
|
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
2023-09-08 14:27:13 +03:00
|
|
|
if (IsKeyDown(KEY_LEFT_CONTROL))
|
|
|
|
{
|
|
|
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) startControl = GetMousePosition();
|
|
|
|
else if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) endControl = GetMousePosition();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) start = GetMousePosition();
|
|
|
|
else if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) end = GetMousePosition();
|
|
|
|
}
|
2017-04-14 16:37:50 +03:00
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
BeginDrawing();
|
|
|
|
|
|
|
|
ClearBackground(RAYWHITE);
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2017-04-14 16:37:50 +03:00
|
|
|
DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY);
|
|
|
|
|
2023-11-08 19:41:08 +03:00
|
|
|
// Draw line Cubic Bezier, in-out interpolation (easing), no control points
|
2023-11-07 21:25:49 +03:00
|
|
|
DrawLineBezier(start, end, 3.0f, BLUE);
|
2023-09-08 14:27:13 +03:00
|
|
|
|
2023-11-08 19:41:08 +03:00
|
|
|
// Draw spline Cubic Bezier with control points
|
|
|
|
DrawSplineSegmentBezierCubic(start, startControl, endControl, end, 2.0f, RED);
|
2023-09-08 14:27:13 +03:00
|
|
|
|
|
|
|
DrawLineEx(start, startControl, 1.0, LIGHTGRAY);
|
|
|
|
DrawLineEx(end, endControl, 1.0, LIGHTGRAY);
|
|
|
|
DrawCircleV(startControl, 10, RED);
|
|
|
|
DrawCircleV(endControl, 10, RED);
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2017-04-14 16:37:50 +03:00
|
|
|
EndDrawing();
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
|
|
|
|
// De-Initialization
|
2019-05-20 17:36:42 +03:00
|
|
|
//--------------------------------------------------------------------------------------
|
2017-04-14 16:37:50 +03:00
|
|
|
CloseWindow(); // Close window and OpenGL context
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|