Review formatting
This commit is contained in:
parent
10a57f297e
commit
d9a9bacb48
3 changed files with 122 additions and 126 deletions
|
@ -34,16 +34,17 @@ int main(void)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.type = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.type = CAMERA_PERSPECTIVE; // Camera mode type
|
||||||
|
|
||||||
Mesh msh = GenMeshCylinder(.2, 1, 32);
|
Mesh mesh = GenMeshCylinder(0.2f, 1.0f, 32);
|
||||||
Model mod = LoadModelFromMesh(msh);
|
Model model = LoadModelFromMesh(mesh);
|
||||||
|
|
||||||
|
// Some required variables
|
||||||
|
Quaternion q1 = { 0 };
|
||||||
|
Matrix m1 = { 0 }, m2 = { 0 }, m3 = { 0 }, m4 = { 0 };
|
||||||
|
Vector3 v1 = { 0 }, v2 = { 0 };
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
Quaternion q1;
|
|
||||||
Matrix m1,m2,m3,m4;
|
|
||||||
Vector3 v1,v2;
|
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
|
@ -51,11 +52,11 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
if (!IsKeyDown(KEY_SPACE))
|
if (!IsKeyDown(KEY_SPACE))
|
||||||
{
|
{
|
||||||
v1.x += 0.01;
|
v1.x += 0.01f;
|
||||||
v1.y += 0.03;
|
v1.y += 0.03f;
|
||||||
v1.z += 0.05;
|
v1.z += 0.05f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v1.x > PI*2) v1.x -= PI*2;
|
if (v1.x > PI*2) v1.x -= PI*2;
|
||||||
if (v1.y > PI*2) v1.y -= PI*2;
|
if (v1.y > PI*2) v1.y -= PI*2;
|
||||||
if (v1.z > PI*2) v1.z -= PI*2;
|
if (v1.z > PI*2) v1.z -= PI*2;
|
||||||
|
@ -70,7 +71,7 @@ int main(void)
|
||||||
v2 = QuaternionToEuler(q1);
|
v2 = QuaternionToEuler(q1);
|
||||||
v2.x *= DEG2RAD;
|
v2.x *= DEG2RAD;
|
||||||
v2.y *= DEG2RAD;
|
v2.y *= DEG2RAD;
|
||||||
v2.z *=DEG2RAD;
|
v2.z *= DEG2RAD;
|
||||||
|
|
||||||
m4 = MatrixRotateZYX(v2);
|
m4 = MatrixRotateZYX(v2);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
@ -80,16 +81,17 @@ int main(void)
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
mod.transform = m1;
|
model.transform = m1;
|
||||||
DrawModel(mod, (Vector3){-1,0,0},1.0,RED);
|
DrawModel(model, (Vector3){ -1, 0, 0 }, 1.0f, RED);
|
||||||
mod.transform = m2;
|
model.transform = m2;
|
||||||
DrawModel(mod, (Vector3){1,0,0},1.0,RED);
|
DrawModel(model, (Vector3){ 1, 0, 0 }, 1.0f, RED);
|
||||||
mod.transform = m3;
|
model.transform = m3;
|
||||||
DrawModel(mod, (Vector3){0,0,0},1.0,RED);
|
DrawModel(model, (Vector3){ 0, 0, 0 }, 1.0f, RED);
|
||||||
mod.transform = m4;
|
model.transform = m4;
|
||||||
DrawModel(mod, (Vector3){0,0,-1},1.0,RED);
|
DrawModel(model, (Vector3){ 0, 0, -1 }, 1.0f, RED);
|
||||||
|
|
||||||
DrawGrid(10, 1.0f);
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
|
@ -105,13 +107,13 @@ int main(void)
|
||||||
if (v1.y == v2.y) cy = GREEN;
|
if (v1.y == v2.y) cy = GREEN;
|
||||||
if (v1.z == v2.z) cz = GREEN;
|
if (v1.z == v2.z) cz = GREEN;
|
||||||
|
|
||||||
DrawText(TextFormat("%2.3f",v1.x),20,20,20,cx);
|
DrawText(TextFormat("%2.3f", v1.x), 20, 20, 20, cx);
|
||||||
DrawText(TextFormat("%2.3f",v1.y),20,40,20,cy);
|
DrawText(TextFormat("%2.3f", v1.y), 20, 40, 20, cy);
|
||||||
DrawText(TextFormat("%2.3f",v1.z),20,60,20,cz);
|
DrawText(TextFormat("%2.3f", v1.z), 20, 60, 20, cz);
|
||||||
|
|
||||||
DrawText(TextFormat("%2.3f",v2.x),200,20,20,cx);
|
DrawText(TextFormat("%2.3f", v2.x), 200, 20, 20, cx);
|
||||||
DrawText(TextFormat("%2.3f",v2.y),200,40,20,cy);
|
DrawText(TextFormat("%2.3f", v2.y), 200, 40, 20, cy);
|
||||||
DrawText(TextFormat("%2.3f",v2.z),200,60,20,cz);
|
DrawText(TextFormat("%2.3f", v2.z), 200, 60, 20, cz);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -119,6 +121,8 @@ int main(void)
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadModel(model); // Unload model data (mesh and materials)
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,8 @@
|
||||||
#define GLSL_VERSION 100
|
#define GLSL_VERSION 100
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MAX_SPOTS 3 // NOTE: It must be the same as define in shader
|
||||||
#define MAXSPOT 3 // NB must be the same as define in shader
|
#define MAX_STARS 400
|
||||||
#define numStars 400
|
|
||||||
|
|
||||||
|
|
||||||
// Spot data
|
// Spot data
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -78,76 +76,67 @@ int main(void)
|
||||||
|
|
||||||
Texture texRay = LoadTexture("resources/raysan.png");
|
Texture texRay = LoadTexture("resources/raysan.png");
|
||||||
|
|
||||||
Star stars[numStars] = { 0 };
|
Star stars[MAX_STARS] = { 0 };
|
||||||
|
|
||||||
for (int n = 0; n < numStars; n++) ResetStar(&stars[n]);
|
for (int n = 0; n < MAX_STARS; n++) ResetStar(&stars[n]);
|
||||||
|
|
||||||
// Progress all the stars on, so they don't all start in the centre
|
// Progress all the stars on, so they don't all start in the centre
|
||||||
for (int m = 0; m < screenWidth/2.0; m++)
|
for (int m = 0; m < screenWidth/2.0; m++)
|
||||||
{
|
{
|
||||||
for (int n = 0; n < numStars; n++) UpdateStar(&stars[n]);
|
for (int n = 0; n < MAX_STARS; n++) UpdateStar(&stars[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int frameCounter = 0;
|
int frameCounter = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Use default vert shader
|
// Use default vert shader
|
||||||
Shader spotShader = LoadShader(0, TextFormat("resources/shaders/glsl%i/spotlight.fs", GLSL_VERSION));
|
Shader shdrSpot = LoadShader(0, TextFormat("resources/shaders/glsl%i/spotlight.fs", GLSL_VERSION));
|
||||||
|
|
||||||
// Get the locations of spots in the shader
|
// Get the locations of spots in the shader
|
||||||
Spot spots[MAXSPOT];
|
Spot spots[MAX_SPOTS];
|
||||||
/*
|
|
||||||
unsigned int posLoc;
|
|
||||||
unsigned int innerLoc;
|
|
||||||
unsigned int radiusLoc;
|
|
||||||
*/
|
|
||||||
for (int i = 0; i < MAXSPOT; i++)
|
|
||||||
{
|
|
||||||
char posName[32] = "spots[x].pos\0";
|
|
||||||
char innerName[32] = "spots[x].inner\0";
|
|
||||||
char radiusName[32] = "spots[x].radius\0";
|
|
||||||
|
|
||||||
posName[6] = '0' + i;
|
for (int i = 0; i < MAX_SPOTS; i++)
|
||||||
innerName[6] = '0' + i;
|
|
||||||
radiusName[6] = '0' + i;
|
|
||||||
|
|
||||||
spots[i].posLoc = GetShaderLocation(spotShader, posName);
|
|
||||||
spots[i].innerLoc = GetShaderLocation(spotShader, innerName);
|
|
||||||
spots[i].radiusLoc = GetShaderLocation(spotShader, radiusName);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// tell the shader how wide the screen is so we can have
|
|
||||||
// a pitch black half and a dimly lit half.
|
|
||||||
{
|
|
||||||
unsigned int wLoc = GetShaderLocation(spotShader, "screenWidth");
|
|
||||||
float sw = (float)GetScreenWidth();
|
|
||||||
SetShaderValue(spotShader, wLoc, &sw, UNIFORM_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// randomise the locations and velocities of the spotlights
|
|
||||||
// and initialise the shader locations
|
|
||||||
for (int i = 0; i < MAXSPOT; i++)
|
|
||||||
{
|
{
|
||||||
|
char posName[32] = "spots[x].pos\0";
|
||||||
spots[i].pos.x = GetRandomValue(64, screenWidth - 64);
|
char innerName[32] = "spots[x].inner\0";
|
||||||
spots[i].pos.y = GetRandomValue(64, screenHeight - 64);
|
char radiusName[32] = "spots[x].radius\0";
|
||||||
spots[i].vel = (Vector2){ 0, 0 };
|
|
||||||
|
posName[6] = '0' + i;
|
||||||
|
innerName[6] = '0' + i;
|
||||||
|
radiusName[6] = '0' + i;
|
||||||
|
|
||||||
while ((fabs(spots[i].vel.x) + fabs(spots[i].vel.y)) < 2)
|
spots[i].posLoc = GetShaderLocation(shdrSpot, posName);
|
||||||
|
spots[i].innerLoc = GetShaderLocation(shdrSpot, innerName);
|
||||||
|
spots[i].radiusLoc = GetShaderLocation(shdrSpot, radiusName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tell the shader how wide the screen is so we can have
|
||||||
|
// a pitch black half and a dimly lit half.
|
||||||
|
unsigned int wLoc = GetShaderLocation(shdrSpot, "screenWidth");
|
||||||
|
float sw = (float)GetScreenWidth();
|
||||||
|
SetShaderValue(shdrSpot, wLoc, &sw, UNIFORM_FLOAT);
|
||||||
|
|
||||||
|
// Randomise the locations and velocities of the spotlights
|
||||||
|
// and initialise the shader locations
|
||||||
|
for (int i = 0; i < MAX_SPOTS; i++)
|
||||||
|
{
|
||||||
|
spots[i].pos.x = GetRandomValue(64, screenWidth - 64);
|
||||||
|
spots[i].pos.y = GetRandomValue(64, screenHeight - 64);
|
||||||
|
spots[i].vel = (Vector2){ 0, 0 };
|
||||||
|
|
||||||
|
while ((fabs(spots[i].vel.x) + fabs(spots[i].vel.y)) < 2)
|
||||||
{
|
{
|
||||||
spots[i].vel.x = GetRandomValue(-40, 40)/10.0;
|
spots[i].vel.x = GetRandomValue(-40, 40)/10.0;
|
||||||
spots[i].vel.y = GetRandomValue(-40, 40)/10.0;
|
spots[i].vel.y = GetRandomValue(-40, 40)/10.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
spots[i].inner = 28 * (i + 1);
|
spots[i].inner = 28 * (i + 1);
|
||||||
spots[i].radius = 48 * (i + 1);
|
spots[i].radius = 48 * (i + 1);
|
||||||
|
|
||||||
SetShaderValue(spotShader, spots[i].posLoc, &spots[i].pos.x, UNIFORM_VEC2);
|
SetShaderValue(shdrSpot, spots[i].posLoc, &spots[i].pos.x, UNIFORM_VEC2);
|
||||||
SetShaderValue(spotShader, spots[i].innerLoc, &spots[i].inner, UNIFORM_FLOAT);
|
SetShaderValue(shdrSpot, spots[i].innerLoc, &spots[i].inner, UNIFORM_FLOAT);
|
||||||
SetShaderValue(spotShader, spots[i].radiusLoc, &spots[i].radius, UNIFORM_FLOAT);
|
SetShaderValue(shdrSpot, spots[i].radiusLoc, &spots[i].radius, UNIFORM_FLOAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetTargetFPS(60); // Set to run at 60 frames-per-second
|
SetTargetFPS(60); // Set to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
@ -159,39 +148,42 @@ int main(void)
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
frameCounter++;
|
frameCounter++;
|
||||||
|
|
||||||
// Move the stars, resetting them if the go offscreen
|
// Move the stars, resetting them if the go offscreen
|
||||||
for (int n = 0; n < numStars; n++) UpdateStar(&stars[n]);
|
for (int n = 0; n < MAX_STARS; n++) UpdateStar(&stars[n]);
|
||||||
|
|
||||||
// Update the spots, send them to the shader
|
// Update the spots, send them to the shader
|
||||||
for (int i = 0; i < MAXSPOT; i++)
|
for (int i = 0; i < MAX_SPOTS; i++)
|
||||||
{
|
{
|
||||||
if ( i == 0 ) {
|
if (i == 0)
|
||||||
Vector2 mp = GetMousePosition();
|
{
|
||||||
spots[i].pos.x = mp.x;
|
Vector2 mp = GetMousePosition();
|
||||||
spots[i].pos.y = screenHeight - mp.y;
|
spots[i].pos.x = mp.x;
|
||||||
} else {
|
spots[i].pos.y = screenHeight - mp.y;
|
||||||
spots[i].pos.x += spots[i].vel.x;
|
}
|
||||||
spots[i].pos.y += spots[i].vel.y;
|
else
|
||||||
|
{
|
||||||
if (spots[i].pos.x < 64) spots[i].vel.x = -spots[i].vel.x;
|
spots[i].pos.x += spots[i].vel.x;
|
||||||
if (spots[i].pos.x > screenWidth - 64) spots[i].vel.x = -spots[i].vel.x;
|
spots[i].pos.y += spots[i].vel.y;
|
||||||
if (spots[i].pos.y < 64) spots[i].vel.y = -spots[i].vel.y;
|
|
||||||
if (spots[i].pos.y > screenHeight - 64) spots[i].vel.y = -spots[i].vel.y;
|
if (spots[i].pos.x < 64) spots[i].vel.x = -spots[i].vel.x;
|
||||||
}
|
if (spots[i].pos.x > (screenWidth - 64)) spots[i].vel.x = -spots[i].vel.x;
|
||||||
|
if (spots[i].pos.y < 64) spots[i].vel.y = -spots[i].vel.y;
|
||||||
SetShaderValue(spotShader, spots[i].posLoc, &spots[i].pos.x, UNIFORM_VEC2);
|
if (spots[i].pos.y > (screenHeight - 64)) spots[i].vel.y = -spots[i].vel.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetShaderValue(shdrSpot, spots[i].posLoc, &spots[i].pos.x, UNIFORM_VEC2);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(DARKBLUE);
|
ClearBackground(DARKBLUE);
|
||||||
|
|
||||||
// Draw stars and bobs
|
// Draw stars and bobs
|
||||||
for (int n = 0; n < numStars; n++)
|
for (int n = 0; n < MAX_STARS; n++)
|
||||||
{
|
{
|
||||||
// Single pixel is just too small these days!
|
// Single pixel is just too small these days!
|
||||||
DrawRectangle(stars[n].pos.x, stars[n].pos.y, 2, 2, WHITE);
|
DrawRectangle(stars[n].pos.x, stars[n].pos.y, 2, 2, WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,24 +191,23 @@ int main(void)
|
||||||
{
|
{
|
||||||
DrawTexture(texRay,
|
DrawTexture(texRay,
|
||||||
(screenWidth/2.0) + cos((frameCounter + i*8)/51.45f)*(screenWidth/2.2) - 32,
|
(screenWidth/2.0) + cos((frameCounter + i*8)/51.45f)*(screenWidth/2.2) - 32,
|
||||||
(screenHeight/2.0) + sin((frameCounter + i*8)/17.87f)*(screenHeight/4.2),
|
(screenHeight/2.0) + sin((frameCounter + i*8)/17.87f)*(screenHeight/4.2), WHITE);
|
||||||
WHITE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw spot lights
|
// Draw spot lights
|
||||||
BeginShaderMode(spotShader);
|
BeginShaderMode(shdrSpot);
|
||||||
// instead of a blank rectangle you could render here
|
// Instead of a blank rectangle you could render here
|
||||||
// a render texture of the full screen used to do screen
|
// a render texture of the full screen used to do screen
|
||||||
// scaling (slight adjustment to shader would be required
|
// scaling (slight adjustment to shader would be required
|
||||||
// to actually pay attention to the colour!)
|
// to actually pay attention to the colour!)
|
||||||
DrawRectangle(0,0,screenWidth,screenHeight,WHITE);
|
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
DrawText("Move the mouse!", 10, 30, 20, GREEN);
|
DrawText("Move the mouse!", 10, 30, 20, GREEN);
|
||||||
DrawText("Pitch Black", screenWidth * .2, screenHeight / 2, 20, GREEN);
|
DrawText("Pitch Black", screenWidth*0.2f, screenHeight/2, 20, GREEN);
|
||||||
DrawText("Dark", screenWidth * .66, screenHeight / 2, 20, GREEN);
|
DrawText("Dark", screenWidth*.66f, screenHeight/2, 20, GREEN);
|
||||||
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
@ -226,6 +217,7 @@ int main(void)
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadTexture(texRay);
|
UnloadTexture(texRay);
|
||||||
|
UnloadShader(shdrSpot);
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
@ -243,17 +235,17 @@ void ResetStar(Star *s)
|
||||||
s->vel.x = (float)GetRandomValue(-1000, 1000)/100.0f;
|
s->vel.x = (float)GetRandomValue(-1000, 1000)/100.0f;
|
||||||
s->vel.y = (float)GetRandomValue(-1000, 1000)/100.0f;
|
s->vel.y = (float)GetRandomValue(-1000, 1000)/100.0f;
|
||||||
|
|
||||||
} while (!(fabs(s->vel.x) + fabs(s->vel.y) > 1));
|
} while (!(fabs(s->vel.x) + (fabs(s->vel.y) > 1)));
|
||||||
|
|
||||||
s->pos = Vector2Add(s->pos, Vector2Multiply(s->vel, (Vector2){ 8, 8 }));
|
s->pos = Vector2Add(s->pos, Vector2Multiply(s->vel, (Vector2){ 8.0f, 8.0f }));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateStar(Star *s)
|
void UpdateStar(Star *s)
|
||||||
{
|
{
|
||||||
s->pos = Vector2Add(s->pos, s->vel);
|
s->pos = Vector2Add(s->pos, s->vel);
|
||||||
|
|
||||||
if (s->pos.x < 0 || s->pos.x > GetScreenWidth() ||
|
if ((s->pos.x < 0) || (s->pos.x > GetScreenWidth()) ||
|
||||||
s->pos.y < 0 || s->pos.y > GetScreenHeight())
|
(s->pos.y < 0) || (s->pos.y > GetScreenHeight()))
|
||||||
{
|
{
|
||||||
ResetStar(s);
|
ResetStar(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1509,7 +1509,7 @@ void rlEnableSmoothLines(void)
|
||||||
void rlDisableSmoothLines(void)
|
void rlDisableSmoothLines(void)
|
||||||
{
|
{
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_21) || defined(GRAPHICS_API_OPENGL_11)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_21) || defined(GRAPHICS_API_OPENGL_11)
|
||||||
glDisable(GL_LINE_SMOOTH);
|
glDisable(GL_LINE_SMOOTH);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue