mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-06 14:23:12 +00:00
Merge branch 'master' of https://github.com/raysan5/raylib
This commit is contained in:
commit
c991f9e89f
@ -16,7 +16,10 @@
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
#include <string.h>
|
||||
|
||||
#define RAYGUI_IMPLEMENTATION
|
||||
#include "raygui.h"
|
||||
#include "raymath.h"
|
||||
|
||||
#define MAX_DRAW_LINES 8192
|
||||
@ -47,6 +50,9 @@ int main(void)
|
||||
int symmetry = 6;
|
||||
float angle = 360.0f/(float)symmetry;
|
||||
float thickness = 3.0f;
|
||||
Rectangle resetButtonRec = { screenWidth - 55, 5, 50, 25 };
|
||||
Rectangle backButtonRec = { screenWidth - 55, screenHeight - 30, 25, 25 };
|
||||
Rectangle nextButtonRec = { screenWidth - 30, screenHeight - 30, 25, 25 };
|
||||
Vector2 mousePos = { 0 };
|
||||
Vector2 prevMousePos = { 0 };
|
||||
Vector2 scaleVector = { 1.0f, -1.0f };
|
||||
@ -58,7 +64,11 @@ int main(void)
|
||||
camera.rotation = 0.0f;
|
||||
camera.zoom = 1.0f;
|
||||
|
||||
int lineCounter = 0;
|
||||
int currentLineCounter = 0;
|
||||
int totalLineCounter = 0;
|
||||
int resetButtonClicked = false;
|
||||
int backButtonClicked = false;
|
||||
int nextButtonClicked = false;
|
||||
|
||||
SetTargetFPS(20);
|
||||
//--------------------------------------------------------------------------------------
|
||||
@ -74,24 +84,47 @@ int main(void)
|
||||
Vector2 lineStart = Vector2Subtract(mousePos, offset);
|
||||
Vector2 lineEnd = Vector2Subtract(prevMousePos, offset);
|
||||
|
||||
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
|
||||
if (
|
||||
IsMouseButtonDown(MOUSE_LEFT_BUTTON)
|
||||
&& (CheckCollisionPointRec(mousePos, resetButtonRec) == false)
|
||||
&& (CheckCollisionPointRec(mousePos, backButtonRec) == false)
|
||||
&& (CheckCollisionPointRec(mousePos, nextButtonRec) == false)
|
||||
)
|
||||
{
|
||||
for (int s = 0; (s < symmetry) && (lineCounter < (MAX_DRAW_LINES - 1)); s++)
|
||||
for (int s = 0; (s < symmetry) && (totalLineCounter < (MAX_DRAW_LINES - 1)); s++)
|
||||
{
|
||||
lineStart = Vector2Rotate(lineStart, angle*DEG2RAD);
|
||||
lineEnd = Vector2Rotate(lineEnd, angle*DEG2RAD);
|
||||
|
||||
// Store mouse line
|
||||
lines[lineCounter].start = lineStart;
|
||||
lines[lineCounter].end = lineEnd;
|
||||
lines[totalLineCounter].start = lineStart;
|
||||
lines[totalLineCounter].end = lineEnd;
|
||||
|
||||
// Store reflective line
|
||||
lines[lineCounter + 1].start = Vector2Multiply(lineStart, scaleVector);
|
||||
lines[lineCounter + 1].end = Vector2Multiply(lineEnd, scaleVector);
|
||||
lines[totalLineCounter + 1].start = Vector2Multiply(lineStart, scaleVector);
|
||||
lines[totalLineCounter + 1].end = Vector2Multiply(lineEnd, scaleVector);
|
||||
|
||||
lineCounter += 2;
|
||||
totalLineCounter += 2;
|
||||
currentLineCounter = totalLineCounter;
|
||||
}
|
||||
}
|
||||
|
||||
if (resetButtonClicked)
|
||||
{
|
||||
memset(&lines, 0, sizeof(Line)*MAX_DRAW_LINES);
|
||||
currentLineCounter = 0;
|
||||
totalLineCounter = 0;
|
||||
}
|
||||
|
||||
if (backButtonClicked && (currentLineCounter > 0))
|
||||
{
|
||||
currentLineCounter -= 1;
|
||||
}
|
||||
|
||||
if (nextButtonClicked && (currentLineCounter < MAX_DRAW_LINES) && ((currentLineCounter + 1) <= totalLineCounter))
|
||||
{
|
||||
currentLineCounter += 1;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
@ -99,19 +132,31 @@ int main(void)
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode2D(camera);
|
||||
|
||||
for (int s = 0; s < symmetry; s++)
|
||||
{
|
||||
for (int i = 0; i < lineCounter; i += 2)
|
||||
for (int i = 0; i < currentLineCounter; i += 2)
|
||||
{
|
||||
DrawLineEx(lines[i].start, lines[i].end, thickness, BLACK);
|
||||
DrawLineEx(lines[i + 1].start, lines[i + 1].end, thickness, BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
EndMode2D();
|
||||
|
||||
DrawText(TextFormat("LINES: %i/%i", lineCounter, MAX_DRAW_LINES), 10, screenHeight - 30, 20, MAROON);
|
||||
if ((currentLineCounter - 1) < 0) GuiDisable();
|
||||
|
||||
backButtonClicked = GuiButton(backButtonRec, "<");
|
||||
GuiEnable();
|
||||
|
||||
if ((currentLineCounter + 1) > totalLineCounter) GuiDisable();
|
||||
|
||||
nextButtonClicked = GuiButton(nextButtonRec, ">");
|
||||
GuiEnable();
|
||||
resetButtonClicked = GuiButton(resetButtonRec, "Reset");
|
||||
|
||||
DrawText(TextFormat("LINES: %i/%i", currentLineCounter, MAX_DRAW_LINES), 10, screenHeight - 30, 20, MAROON);
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 81 KiB |
Loading…
x
Reference in New Issue
Block a user