mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-21 04:59:17 -05:00
Compare commits
2 Commits
d4f636151b
...
3881d2aac2
| Author | SHA1 | Date | |
|---|---|---|---|
| 3881d2aac2 | |||
| f43e049444 |
@ -4,7 +4,7 @@ Hello contributors! Welcome to raylib!
|
|||||||
|
|
||||||
Do you enjoy raylib and want to contribute? Nice! You can help with the following points:
|
Do you enjoy raylib and want to contribute? Nice! You can help with the following points:
|
||||||
|
|
||||||
- `C programming` - Can you write/review/test/improve the code?
|
- `C programming` - Can you write/review/test/improve the code?
|
||||||
- `Documentation/Tutorials/Example` - Can you write some tutorials/examples?
|
- `Documentation/Tutorials/Example` - Can you write some tutorials/examples?
|
||||||
- `Porting to other platforms` - Can you port/adapt/compile raylib on other systems?
|
- `Porting to other platforms` - Can you port/adapt/compile raylib on other systems?
|
||||||
- `Web Development` - Can you help [with the website](https://github.com/raysan5/raylib.com)?
|
- `Web Development` - Can you help [with the website](https://github.com/raysan5/raylib.com)?
|
||||||
|
|||||||
@ -44,7 +44,7 @@ float GetCharacter(float n, vec2 p)
|
|||||||
// Main shader logic
|
// Main shader logic
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 charPixelSize = vec2(fontSize, fontSize);
|
vec2 charPixelSize = vec2(fontSize, fontSize);
|
||||||
vec2 uvCellSize = charPixelSize/resolution;
|
vec2 uvCellSize = charPixelSize/resolution;
|
||||||
|
|||||||
@ -63,7 +63,7 @@ float sdSixWayCutHollowSphere(vec3 p, float r, float h, float t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SRC: https://iquilezles.org/articles/boxfunctions
|
// SRC: https://iquilezles.org/articles/boxfunctions
|
||||||
vec2 iBox(in vec3 ro, in vec3 rd, in vec3 rad)
|
vec2 iBox(in vec3 ro, in vec3 rd, in vec3 rad)
|
||||||
{
|
{
|
||||||
vec3 m = 1.0/rd;
|
vec3 m = 1.0/rd;
|
||||||
vec3 n = m*ro;
|
vec3 n = m*ro;
|
||||||
|
|||||||
@ -19,7 +19,8 @@ uniform float ampY;
|
|||||||
uniform float speedX;
|
uniform float speedX;
|
||||||
uniform float speedY;
|
uniform float speedY;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
float pixelWidth = 1.0/size.x;
|
float pixelWidth = 1.0/size.x;
|
||||||
float pixelHeight = 1.0/size.y;
|
float pixelHeight = 1.0/size.y;
|
||||||
float aspect = pixelHeight/pixelWidth;
|
float aspect = pixelHeight/pixelWidth;
|
||||||
|
|||||||
@ -42,7 +42,7 @@ float GetCharacter(float n, vec2 p)
|
|||||||
// Main shader logic
|
// Main shader logic
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 charPixelSize = vec2(fontSize, fontSize);
|
vec2 charPixelSize = vec2(fontSize, fontSize);
|
||||||
vec2 uvCellSize = charPixelSize / resolution;
|
vec2 uvCellSize = charPixelSize / resolution;
|
||||||
|
|||||||
@ -61,7 +61,7 @@ float sdSixWayCutHollowSphere(vec3 p, float r, float h, float t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SRC: https://iquilezles.org/articles/boxfunctions
|
// SRC: https://iquilezles.org/articles/boxfunctions
|
||||||
vec2 iBox(in vec3 ro, in vec3 rd, in vec3 rad)
|
vec2 iBox(in vec3 ro, in vec3 rd, in vec3 rad)
|
||||||
{
|
{
|
||||||
vec3 m = 1.0/rd;
|
vec3 m = 1.0/rd;
|
||||||
vec3 n = m*ro;
|
vec3 n = m*ro;
|
||||||
|
|||||||
@ -17,7 +17,8 @@ uniform float ampY;
|
|||||||
uniform float speedX;
|
uniform float speedX;
|
||||||
uniform float speedY;
|
uniform float speedY;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
float pixelWidth = 1.0/size.x;
|
float pixelWidth = 1.0/size.x;
|
||||||
float pixelHeight = 1.0/size.y;
|
float pixelHeight = 1.0/size.y;
|
||||||
float aspect = pixelHeight/pixelWidth;
|
float aspect = pixelHeight/pixelWidth;
|
||||||
|
|||||||
@ -38,7 +38,7 @@ float GetCharacter(int n, vec2 p)
|
|||||||
// Main shader logic
|
// Main shader logic
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 charPixelSize = vec2(fontSize, fontSize);
|
vec2 charPixelSize = vec2(fontSize, fontSize);
|
||||||
vec2 uvCellSize = charPixelSize/resolution;
|
vec2 uvCellSize = charPixelSize/resolution;
|
||||||
|
|||||||
@ -23,7 +23,8 @@ uniform vec3 viewPosition;
|
|||||||
const float QUADRATIC = 0.032;
|
const float QUADRATIC = 0.032;
|
||||||
const float LINEAR = 0.09;
|
const float LINEAR = 0.09;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
vec3 fragPosition = texture(gPosition, texCoord).rgb;
|
vec3 fragPosition = texture(gPosition, texCoord).rgb;
|
||||||
vec3 normal = texture(gNormal, texCoord).rgb;
|
vec3 normal = texture(gNormal, texCoord).rgb;
|
||||||
vec3 albedo = texture(gAlbedoSpec, texCoord).rgb;
|
vec3 albedo = texture(gAlbedoSpec, texCoord).rgb;
|
||||||
|
|||||||
@ -5,7 +5,8 @@ layout (location = 1) in vec2 vertexTexCoord;
|
|||||||
|
|
||||||
out vec2 texCoord;
|
out vec2 texCoord;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
gl_Position = vec4(vertexPosition, 1.0);
|
gl_Position = vec4(vertexPosition, 1.0);
|
||||||
texCoord = vertexTexCoord;
|
texCoord = vertexTexCoord;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,8 @@ in vec3 fragNormal;
|
|||||||
uniform sampler2D diffuseTexture;
|
uniform sampler2D diffuseTexture;
|
||||||
uniform sampler2D specularTexture;
|
uniform sampler2D specularTexture;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
// store the fragment position vector in the first gbuffer texture
|
// store the fragment position vector in the first gbuffer texture
|
||||||
gPosition = fragPosition;
|
gPosition = fragPosition;
|
||||||
// also store the per-fragment normals into the gbuffer
|
// also store the per-fragment normals into the gbuffer
|
||||||
|
|||||||
@ -59,7 +59,7 @@ float sdSixWayCutHollowSphere(vec3 p, float r, float h, float t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://iquilezles.org/articles/boxfunctions
|
// https://iquilezles.org/articles/boxfunctions
|
||||||
vec2 iBox(in vec3 ro, in vec3 rd, in vec3 rad)
|
vec2 iBox(in vec3 ro, in vec3 rd, in vec3 rad)
|
||||||
{
|
{
|
||||||
vec3 m = 1.0/rd;
|
vec3 m = 1.0/rd;
|
||||||
vec3 n = m*ro;
|
vec3 n = m*ro;
|
||||||
|
|||||||
@ -22,7 +22,8 @@ uniform float ampY;
|
|||||||
uniform float speedX;
|
uniform float speedX;
|
||||||
uniform float speedY;
|
uniform float speedY;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
float pixelWidth = 1.0/size.x;
|
float pixelWidth = 1.0/size.x;
|
||||||
float pixelHeight = 1.0/size.y;
|
float pixelHeight = 1.0/size.y;
|
||||||
float aspect = pixelHeight/pixelWidth;
|
float aspect = pixelHeight/pixelWidth;
|
||||||
|
|||||||
@ -139,14 +139,14 @@ int main(void)
|
|||||||
Ball *ball = &balls[i];
|
Ball *ball = &balls[i];
|
||||||
|
|
||||||
// The ball is not grabbed
|
// The ball is not grabbed
|
||||||
if (!ball->grabbed)
|
if (!ball->grabbed)
|
||||||
{
|
{
|
||||||
// Ball repositioning using the velocity
|
// Ball repositioning using the velocity
|
||||||
ball->pos.x += ball->vel.x * delta;
|
ball->pos.x += ball->vel.x * delta;
|
||||||
ball->pos.y += ball->vel.y * delta;
|
ball->pos.y += ball->vel.y * delta;
|
||||||
|
|
||||||
// Does the ball hit the screen right boundary?
|
// Does the ball hit the screen right boundary?
|
||||||
if ((ball->pos.x + ball->radius) >= screenWidth)
|
if ((ball->pos.x + ball->radius) >= screenWidth)
|
||||||
{
|
{
|
||||||
ball->pos.x = screenWidth - ball->radius; // Ball repositioning
|
ball->pos.x = screenWidth - ball->radius; // Ball repositioning
|
||||||
ball->vel.x = -ball->vel.x*ball->elasticity; // Elasticity makes the ball lose 10% of its velocity on hit
|
ball->vel.x = -ball->vel.x*ball->elasticity; // Elasticity makes the ball lose 10% of its velocity on hit
|
||||||
@ -159,12 +159,12 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The same for y axis
|
// The same for y axis
|
||||||
if ((ball->pos.y + ball->radius) >= screenHeight)
|
if ((ball->pos.y + ball->radius) >= screenHeight)
|
||||||
{
|
{
|
||||||
ball->pos.y = screenHeight - ball->radius;
|
ball->pos.y = screenHeight - ball->radius;
|
||||||
ball->vel.y = -ball->vel.y*ball->elasticity;
|
ball->vel.y = -ball->vel.y*ball->elasticity;
|
||||||
}
|
}
|
||||||
else if ((ball->pos.y - ball->radius) <= 0)
|
else if ((ball->pos.y - ball->radius) <= 0)
|
||||||
{
|
{
|
||||||
ball->pos.y = ball->radius;
|
ball->pos.y = ball->radius;
|
||||||
ball->vel.y = -ball->vel.y*ball->elasticity;
|
ball->vel.y = -ball->vel.y*ball->elasticity;
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
|
|
||||||
@ -17,7 +18,8 @@ int main() {
|
|||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
cam.position.x = sin(GetTime())*10.0f;
|
cam.position.x = sin(GetTime())*10.0f;
|
||||||
cam.position.z = cos(GetTime())*10.0f;
|
cam.position.z = cos(GetTime())*10.0f;
|
||||||
|
|
||||||
|
|||||||
@ -894,7 +894,8 @@ void SwapScreenBuffer(void)
|
|||||||
const canvas = Module.canvas;
|
const canvas = Module.canvas;
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
if (!Module.__img || (Module.__img.width !== width) || (Module.__img.height !== height)) {
|
if (!Module.__img || (Module.__img.width !== width) || (Module.__img.height !== height))
|
||||||
|
{
|
||||||
Module.__img = ctx.createImageData(width, height);
|
Module.__img = ctx.createImageData(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -875,7 +875,8 @@ void SwapScreenBuffer(void)
|
|||||||
//const canvas = Module['canvas'];
|
//const canvas = Module['canvas'];
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
if (!Module.__img || (Module.__img.width !== width) || (Module.__img.height !== height)) {
|
if (!Module.__img || (Module.__img.width !== width) || (Module.__img.height !== height))
|
||||||
|
{
|
||||||
Module.__img = ctx.createImageData(width, height);
|
Module.__img = ctx.createImageData(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2365,30 +2365,30 @@ bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec)
|
|||||||
// Check the collision between two lines defined by two points each, returns collision point by reference
|
// Check the collision between two lines defined by two points each, returns collision point by reference
|
||||||
bool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, Vector2 *collisionPoint)
|
bool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, Vector2 *collisionPoint)
|
||||||
{
|
{
|
||||||
bool collision = false;
|
// According to https://en.wikipedia.org/wiki/Line–line_intersection#Given_two_points_on_each_line_segment
|
||||||
|
float rx = endPos1.x - startPos1.x;
|
||||||
|
float ry = endPos1.y - startPos1.y;
|
||||||
|
float sx = endPos2.x - startPos2.x;
|
||||||
|
float sy = endPos2.y - startPos2.y;
|
||||||
|
|
||||||
float div = (endPos2.y - startPos2.y)*(endPos1.x - startPos1.x) - (endPos2.x - startPos2.x)*(endPos1.y - startPos1.y);
|
float div = rx * sy - ry * sx;
|
||||||
|
|
||||||
if (fabsf(div) >= FLT_EPSILON)
|
if (fabsf(div) < FLT_EPSILON) {
|
||||||
{
|
return false;
|
||||||
collision = true;
|
|
||||||
|
|
||||||
float xi = ((startPos2.x - endPos2.x)*(startPos1.x*endPos1.y - startPos1.y*endPos1.x) - (startPos1.x - endPos1.x)*(startPos2.x*endPos2.y - startPos2.y*endPos2.x))/div;
|
|
||||||
float yi = ((startPos2.y - endPos2.y)*(startPos1.x*endPos1.y - startPos1.y*endPos1.x) - (startPos1.y - endPos1.y)*(startPos2.x*endPos2.y - startPos2.y*endPos2.x))/div;
|
|
||||||
|
|
||||||
if (((fabsf(startPos1.x - endPos1.x) > FLT_EPSILON) && (xi < fminf(startPos1.x, endPos1.x) || (xi > fmaxf(startPos1.x, endPos1.x)))) ||
|
|
||||||
((fabsf(startPos2.x - endPos2.x) > FLT_EPSILON) && (xi < fminf(startPos2.x, endPos2.x) || (xi > fmaxf(startPos2.x, endPos2.x)))) ||
|
|
||||||
((fabsf(startPos1.y - endPos1.y) > FLT_EPSILON) && (yi < fminf(startPos1.y, endPos1.y) || (yi > fmaxf(startPos1.y, endPos1.y)))) ||
|
|
||||||
((fabsf(startPos2.y - endPos2.y) > FLT_EPSILON) && (yi < fminf(startPos2.y, endPos2.y) || (yi > fmaxf(startPos2.y, endPos2.y))))) collision = false;
|
|
||||||
|
|
||||||
if (collision && (collisionPoint != 0))
|
|
||||||
{
|
|
||||||
collisionPoint->x = xi;
|
|
||||||
collisionPoint->y = yi;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return collision;
|
float s12x = startPos2.x - startPos1.x;
|
||||||
|
float s12y = startPos2.y - startPos1.y;
|
||||||
|
|
||||||
|
float t = (s12x * sy - s12y * sx) / div;
|
||||||
|
float u = (s12x * ry - s12y * rx) / div;
|
||||||
|
|
||||||
|
if (0.0f <= t && t <= 1.0f && 0.0f <= u && u <= 1.0f) {
|
||||||
|
collisionPoint->x = startPos1.x + t * rx;
|
||||||
|
collisionPoint->y = startPos1.y + t * ry;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold]
|
// Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold]
|
||||||
|
|||||||
@ -721,7 +721,8 @@ int main(int argc, char *argv[])
|
|||||||
char v = structs[i].fieldType[originalIndex][k];
|
char v = structs[i].fieldType[originalIndex][k];
|
||||||
if ((v == '*') || (v == ' ') || (v == ','))
|
if ((v == '*') || (v == ' ') || (v == ','))
|
||||||
{
|
{
|
||||||
if (nameEnd != -1) {
|
if (nameEnd != -1)
|
||||||
|
{
|
||||||
// Don't copy to last additional field
|
// Don't copy to last additional field
|
||||||
if (fieldsRemaining != additionalFields)
|
if (fieldsRemaining != additionalFields)
|
||||||
{
|
{
|
||||||
@ -1011,7 +1012,8 @@ int main(int argc, char *argv[])
|
|||||||
((linePtr[c - 4] == 'v') &&
|
((linePtr[c - 4] == 'v') &&
|
||||||
(linePtr[c - 3] == 'o') &&
|
(linePtr[c - 3] == 'o') &&
|
||||||
(linePtr[c - 2] == 'i') &&
|
(linePtr[c - 2] == 'i') &&
|
||||||
(linePtr[c - 1] == 'd'))) {
|
(linePtr[c - 1] == 'd')))
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user