raylib/examples/shapes/shapes_lines_bezier.c

86 lines
3.5 KiB
C
Raw Normal View History

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
*
2024-01-02 22:58:12 +03:00
* Copyright (c) 2017-2024 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
2023-11-09 11:53:25 +03:00
Vector2 startPoint = { 30, 30 };
Vector2 endPoint = { (float)screenWidth - 30, (float)screenHeight - 30 };
bool moveStartPoint = false;
bool moveEndPoint = false;
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-11-09 11:53:25 +03:00
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)
2023-09-08 14:27:13 +03:00
{
2023-11-09 11:53:25 +03:00
startPoint = mouse;
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) moveStartPoint = false;
2023-09-08 14:27:13 +03:00
}
2023-11-09 11:53:25 +03:00
if (moveEndPoint)
2023-09-08 14:27:13 +03:00
{
2023-11-09 11:53:25 +03:00
endPoint = mouse;
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) moveEndPoint = false;
2023-09-08 14:27:13 +03:00
}
2017-04-14 16:37:50 +03:00
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
2019-05-20 17:36:42 +03:00
2023-11-09 11:53:25 +03:00
DrawText("MOVE START-END POINTS WITH MOUSE", 15, 20, 20, GRAY);
2017-04-14 16:37:50 +03:00
// Draw line Cubic Bezier, in-out interpolation (easing), no control points
2023-11-09 11:53:25 +03:00
DrawLineBezier(startPoint, endPoint, 4.0f, BLUE);
2023-09-08 14:27:13 +03:00
2023-11-09 11:53:25 +03:00
// Draw start-end spline circles with some details
DrawCircleV(startPoint, CheckCollisionPointCircle(mouse, startPoint, 10.0f)? 14.0f : 8.0f, moveStartPoint? RED : BLUE);
DrawCircleV(endPoint, CheckCollisionPointCircle(mouse, endPoint, 10.0f)? 14.0f : 8.0f, moveEndPoint? RED : BLUE);
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;
}