mirror of
https://github.com/raysan5/raylib.git
synced 2026-08-25 13:48:27 -04:00
Compare commits
4 Commits
1c3a7748ea
...
aa4cf20eae
| Author | SHA1 | Date | |
|---|---|---|---|
| aa4cf20eae | |||
| 78535d2343 | |||
| e809face7b | |||
| 9fd4726c31 |
1516
src/external/rlsw.h
vendored
1516
src/external/rlsw.h
vendored
File diff suppressed because it is too large
Load Diff
11
src/rcore.c
11
src/rcore.c
@ -110,7 +110,12 @@
|
|||||||
#include <stdio.h> // Required for: FILE, fopen(), fseek(), ftell(), fread(), fwrite(), fprintf(), vprintf(), fclose(), sprintf() [Used in OpenURL()]
|
#include <stdio.h> // Required for: FILE, fopen(), fseek(), ftell(), fread(), fwrite(), fprintf(), vprintf(), fclose(), sprintf() [Used in OpenURL()]
|
||||||
#include <string.h> // Required for: strlen(), strcmp(), strrchr(), memset(), memcpy(), strcat()
|
#include <string.h> // Required for: strlen(), strcmp(), strrchr(), memset(), memcpy(), strcat()
|
||||||
#include <stdarg.h> // Required for: va_list, va_start(), va_end() [Used in TraceLog()]
|
#include <stdarg.h> // Required for: va_list, va_start(), va_end() [Used in TraceLog()]
|
||||||
|
|
||||||
|
#ifndef PICO_RP2350
|
||||||
#include <time.h> // Required for: time() [Used in InitTimer()]
|
#include <time.h> // Required for: time() [Used in InitTimer()]
|
||||||
|
#else
|
||||||
|
#include "pico/rand.h" // Pico doesn't implement time, and will implement its own hardware timer elsewhere. However, we need something to get a random seed from...
|
||||||
|
#endif
|
||||||
#include <math.h> // Required for: tan() [Used in BeginMode3D()], atan2f() [Used in LoadVrStereoConfig()]
|
#include <math.h> // Required for: tan() [Used in BeginMode3D()], atan2f() [Used in LoadVrStereoConfig()]
|
||||||
|
|
||||||
#if defined(PLATFORM_MEMORY) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_MEMORY) || defined(PLATFORM_WEB)
|
||||||
@ -713,8 +718,12 @@ void InitWindow(int width, int height, const char *title)
|
|||||||
CORE.Time.frameCounter = 0;
|
CORE.Time.frameCounter = 0;
|
||||||
CORE.Window.shouldClose = false;
|
CORE.Window.shouldClose = false;
|
||||||
|
|
||||||
// Initialize random seed
|
// Initialize random seed using available timer source instead of standard time() on embedded platforms
|
||||||
|
#ifndef PICO_RP2350
|
||||||
SetRandomSeed((unsigned int)time(NULL));
|
SetRandomSeed((unsigned int)time(NULL));
|
||||||
|
#else
|
||||||
|
SetRandomSeed(get_rand_32());
|
||||||
|
#endif
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "SYSTEM: Working Directory: %s", GetWorkingDirectory());
|
TRACELOG(LOG_INFO, "SYSTEM: Working Directory: %s", GetWorkingDirectory());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -488,7 +488,7 @@ void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color
|
|||||||
rlBegin(RL_TRIANGLES);
|
rlBegin(RL_TRIANGLES);
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
float ringangle = DEG2RAD*(180.0f/(rings + 1)); // Angle between latitudinal parallels
|
float ringangle = DEG2RAD*(180.0f/rings); // Angle between latitudinal parallels
|
||||||
float sliceangle = DEG2RAD*(360.0f/slices); // Angle between longitudinal meridians
|
float sliceangle = DEG2RAD*(360.0f/slices); // Angle between longitudinal meridians
|
||||||
|
|
||||||
float cosring = cosf(ringangle);
|
float cosring = cosf(ringangle);
|
||||||
@ -500,7 +500,7 @@ void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color
|
|||||||
vertices[2] = (Vector3){ 0, 1, 0 };
|
vertices[2] = (Vector3){ 0, 1, 0 };
|
||||||
vertices[3] = (Vector3){ sinring, cosring, 0 };
|
vertices[3] = (Vector3){ sinring, cosring, 0 };
|
||||||
|
|
||||||
for (int i = 0; i < rings + 1; i++)
|
for (int i = 0; i < rings; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < slices; j++)
|
for (int j = 0; j < slices; j++)
|
||||||
{
|
{
|
||||||
@ -542,31 +542,42 @@ void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Col
|
|||||||
rlBegin(RL_LINES);
|
rlBegin(RL_LINES);
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
for (int i = 0; i < (rings + 2); i++)
|
float ringangle = DEG2RAD*(180.0f/rings); // Angle between latitudinal parallels
|
||||||
|
float sliceangle = DEG2RAD*(360.0f/slices); // Angle between longitudinal meridians
|
||||||
|
|
||||||
|
float cosring = cosf(ringangle);
|
||||||
|
float sinring = sinf(ringangle);
|
||||||
|
float cosslice = cosf(sliceangle);
|
||||||
|
float sinslice = sinf(sliceangle);
|
||||||
|
|
||||||
|
Vector3 vertices[4] = { 0 }; // Required to store face vertices
|
||||||
|
vertices[2] = (Vector3){ 0, 1, 0 };
|
||||||
|
vertices[3] = (Vector3){ sinring, cosring, 0 };
|
||||||
|
|
||||||
|
for (int i = 0; i < rings; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < slices; j++)
|
for (int j = 0; j < slices; j++)
|
||||||
{
|
{
|
||||||
rlVertex3f(cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*i))*sinf(DEG2RAD*(360.0f*j/slices)),
|
vertices[0] = vertices[2]; // Rotate around y axis to set up vertices for next face
|
||||||
sinf(DEG2RAD*(270 + (180.0f/(rings + 1))*i)),
|
vertices[1] = vertices[3];
|
||||||
cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*i))*cosf(DEG2RAD*(360.0f*j/slices)));
|
vertices[2] = (Vector3){ cosslice*vertices[2].x - sinslice*vertices[2].z, vertices[2].y, sinslice*vertices[2].x + cosslice*vertices[2].z }; // Rotation matrix around y axis
|
||||||
rlVertex3f(cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*sinf(DEG2RAD*(360.0f*(j + 1)/slices)),
|
vertices[3] = (Vector3){ cosslice*vertices[3].x - sinslice*vertices[3].z, vertices[3].y, sinslice*vertices[3].x + cosslice*vertices[3].z };
|
||||||
sinf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1))),
|
|
||||||
cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*cosf(DEG2RAD*(360.0f*(j + 1)/slices)));
|
|
||||||
|
|
||||||
rlVertex3f(cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*sinf(DEG2RAD*(360.0f*(j + 1)/slices)),
|
// Longitude Lines
|
||||||
sinf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1))),
|
rlVertex3f(vertices[0].x, vertices[0].y, vertices[0].z);
|
||||||
cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*cosf(DEG2RAD*(360.0f*(j + 1)/slices)));
|
rlVertex3f(vertices[1].x, vertices[1].y, vertices[1].z);
|
||||||
rlVertex3f(cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*sinf(DEG2RAD*(360.0f*j/slices)),
|
|
||||||
sinf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1))),
|
|
||||||
cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*cosf(DEG2RAD*(360.0f*j/slices)));
|
|
||||||
|
|
||||||
rlVertex3f(cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*sinf(DEG2RAD*(360.0f*j/slices)),
|
// Latitude Lines
|
||||||
sinf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1))),
|
rlVertex3f(vertices[0].x, vertices[0].y, vertices[0].z);
|
||||||
cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*cosf(DEG2RAD*(360.0f*j/slices)));
|
rlVertex3f(vertices[2].x, vertices[2].y, vertices[2].z);
|
||||||
rlVertex3f(cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*i))*sinf(DEG2RAD*(360.0f*j/slices)),
|
|
||||||
sinf(DEG2RAD*(270 + (180.0f/(rings + 1))*i)),
|
// Diagonal Lines
|
||||||
cosf(DEG2RAD*(270 + (180.0f/(rings + 1))*i))*cosf(DEG2RAD*(360.0f*j/slices)));
|
rlVertex3f(vertices[0].x, vertices[0].y, vertices[0].z);
|
||||||
|
rlVertex3f(vertices[3].x, vertices[3].y, vertices[3].z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vertices[2] = vertices[3]; // Rotate around z axis to set up starting vertices for next ring
|
||||||
|
vertices[3] = (Vector3){ cosring*vertices[3].x + sinring*vertices[3].y, -sinring*vertices[3].x + cosring*vertices[3].y, vertices[3].z }; // Rotation matrix around z axis
|
||||||
}
|
}
|
||||||
rlEnd();
|
rlEnd();
|
||||||
rlPopMatrix();
|
rlPopMatrix();
|
||||||
|
|||||||
@ -888,7 +888,90 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co
|
|||||||
// Draw rectangle with rounded edges
|
// Draw rectangle with rounded edges
|
||||||
void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, Color color)
|
void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, Color color)
|
||||||
{
|
{
|
||||||
DrawRectangleRoundedLinesEx(rec, roundness, segments, 1.0f, color);
|
// Not a rounded rectangle
|
||||||
|
if (roundness <= 0.0f)
|
||||||
|
{
|
||||||
|
DrawRectangleLines((int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height, color);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (roundness >= 1.0f) roundness = 1.0f;
|
||||||
|
|
||||||
|
// Calculate corner radius
|
||||||
|
float radius = (rec.width > rec.height)? (rec.height*roundness)/2 : (rec.width*roundness)/2;
|
||||||
|
if (radius <= 0.0f) return;
|
||||||
|
|
||||||
|
// Calculate number of segments to use for the corners
|
||||||
|
if (segments < 4)
|
||||||
|
{
|
||||||
|
// Calculate the maximum angle between segments based on the error rate (usually 0.5f)
|
||||||
|
float th = acosf(2*powf(1 - SMOOTH_CIRCLE_ERROR_RATE/radius, 2) - 1);
|
||||||
|
segments = (int)ceilf((2*PI/th)/4.0f);
|
||||||
|
if (segments <= 0) segments = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
float stepLength = 90.0f/(float)segments;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Quick sketch to make sense of all of this,
|
||||||
|
marks the 8 + 4 (corner centers P8-11) points used
|
||||||
|
|
||||||
|
P0 ------------------ P1
|
||||||
|
/ \
|
||||||
|
/ \
|
||||||
|
P7 / \ P2
|
||||||
|
| *P8 P9* |
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
P6 \ *P11 P10* / P3
|
||||||
|
\ /
|
||||||
|
\ /
|
||||||
|
P5 ------------------ P4
|
||||||
|
*/
|
||||||
|
const Vector2 point[8] = {
|
||||||
|
{(float)rec.x + radius + 0.5f, rec.y + 0.5f},
|
||||||
|
{(float)(rec.x + rec.width) - radius - 0.5f, rec.y + 0.5f},
|
||||||
|
{rec.x + rec.width - 0.5f, (float)rec.y + radius + 0.5f}, // PO, P1, P2
|
||||||
|
{rec.x + rec.width - 0.5f, (float)(rec.y + rec.height) - radius - 0.5f},
|
||||||
|
{(float)(rec.x + rec.width) - radius - 0.5f, rec.y + rec.height - 0.5f}, // P3, P4
|
||||||
|
{(float)rec.x + radius + 0.5f, rec.y + rec.height - 0.5f},
|
||||||
|
{rec.x + 0.5f, (float)(rec.y + rec.height) - radius - 0.5f},
|
||||||
|
{rec.x + 0.5f, (float)rec.y + radius + 0.5f}, // P5, P6, P7
|
||||||
|
};
|
||||||
|
|
||||||
|
const Vector2 centers[4] = {
|
||||||
|
{(float)rec.x + radius + 0.5f, (float)rec.y + radius + 0.5f},
|
||||||
|
{(float)(rec.x + rec.width) - radius - 0.5f, (float)rec.y + radius + 0.5f}, // P16, P17
|
||||||
|
{(float)(rec.x + rec.width) - radius - 0.5f, (float)(rec.y + rec.height) - radius - 0.5f},
|
||||||
|
{(float)rec.x + radius + 0.5f, (float)(rec.y + rec.height) - radius - 0.5f} // P18, P19
|
||||||
|
};
|
||||||
|
|
||||||
|
const float angles[4] = { 180.0f, 270.0f, 0.0f, 90.0f };
|
||||||
|
|
||||||
|
rlBegin(RL_LINES);
|
||||||
|
// Draw all the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner
|
||||||
|
for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop
|
||||||
|
{
|
||||||
|
float angle = angles[k];
|
||||||
|
const Vector2 center = centers[k];
|
||||||
|
|
||||||
|
for (int i = 0; i < segments; i++)
|
||||||
|
{
|
||||||
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
rlVertex2f(center.x + cosf(DEG2RAD*angle)*radius, center.y + sinf(DEG2RAD*angle)*radius);
|
||||||
|
rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*radius, center.y + sinf(DEG2RAD*(angle + stepLength))*radius);
|
||||||
|
angle += stepLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// And now the remaining 4 lines
|
||||||
|
for (int i = 0; i < 8; i += 2)
|
||||||
|
{
|
||||||
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
rlVertex2f(point[i].x, point[i].y);
|
||||||
|
rlVertex2f(point[i + 1].x, point[i + 1].y);
|
||||||
|
}
|
||||||
|
rlEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw rectangle with rounded edges outline with line thickness
|
// Draw rectangle with rounded edges outline with line thickness
|
||||||
|
|||||||
Reference in New Issue
Block a user