Remove trail spaces
This commit is contained in:
parent
f92ee46d86
commit
dcf52c132f
61 changed files with 558 additions and 558 deletions
|
|
@ -87,7 +87,7 @@ int main(void)
|
||||||
|
|
||||||
if (IsKeyDown(KEY_DOWN)) pitch -= 0.01f;
|
if (IsKeyDown(KEY_DOWN)) pitch -= 0.01f;
|
||||||
else if (IsKeyDown(KEY_UP)) pitch += 0.01f;
|
else if (IsKeyDown(KEY_UP)) pitch += 0.01f;
|
||||||
|
|
||||||
SetMusicPitch(music, pitch);
|
SetMusicPitch(music, pitch);
|
||||||
|
|
||||||
// Get timePlayed scaled to bar dimensions
|
// Get timePlayed scaled to bar dimensions
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ int main(void)
|
||||||
|
|
||||||
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
|
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
|
||||||
Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file
|
Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file
|
||||||
|
|
||||||
SetSoundVolume(fxWav, 0.2f);
|
SetSoundVolume(fxWav, 0.2f);
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
|
@ -46,7 +46,7 @@ int main(void)
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY);
|
DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY);
|
||||||
DrawText("Press SPACE to play new ogg instance!", 200, 120, 20, LIGHTGRAY);
|
DrawText("Press SPACE to play new ogg instance!", 200, 120, 20, LIGHTGRAY);
|
||||||
DrawText("Press ENTER to play new wav instance!", 200, 180, 20, LIGHTGRAY);
|
DrawText("Press ENTER to play new wav instance!", 200, 180, 20, LIGHTGRAY);
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Player movement
|
// Player movement
|
||||||
if (IsKeyDown(KEY_RIGHT)) player.x += 2;
|
if (IsKeyDown(KEY_RIGHT)) player.x += 2;
|
||||||
else if (IsKeyDown(KEY_LEFT)) player.x -= 2;
|
else if (IsKeyDown(KEY_LEFT)) player.x -= 2;
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");
|
||||||
|
|
||||||
Player player = { 0 };
|
Player player = { 0 };
|
||||||
|
|
@ -60,7 +60,7 @@ int main(void)
|
||||||
{{ 250, 300, 100, 10 }, 1, GRAY },
|
{{ 250, 300, 100, 10 }, 1, GRAY },
|
||||||
{{ 650, 300, 100, 10 }, 1, GRAY }
|
{{ 650, 300, 100, 10 }, 1, GRAY }
|
||||||
};
|
};
|
||||||
|
|
||||||
int envItemsLength = sizeof(envItems)/sizeof(envItems[0]);
|
int envItemsLength = sizeof(envItems)/sizeof(envItems[0]);
|
||||||
|
|
||||||
Camera2D camera = { 0 };
|
Camera2D camera = { 0 };
|
||||||
|
|
@ -77,10 +77,10 @@ int main(void)
|
||||||
UpdateCameraEvenOutOnLanding,
|
UpdateCameraEvenOutOnLanding,
|
||||||
UpdateCameraPlayerBoundsPush
|
UpdateCameraPlayerBoundsPush
|
||||||
};
|
};
|
||||||
|
|
||||||
int cameraOption = 0;
|
int cameraOption = 0;
|
||||||
int cameraUpdatersLength = sizeof(cameraUpdaters)/sizeof(cameraUpdaters[0]);
|
int cameraUpdatersLength = sizeof(cameraUpdaters)/sizeof(cameraUpdaters[0]);
|
||||||
|
|
||||||
char *cameraDescriptions[] = {
|
char *cameraDescriptions[] = {
|
||||||
"Follow player center",
|
"Follow player center",
|
||||||
"Follow player center, but clamp to map edges",
|
"Follow player center, but clamp to map edges",
|
||||||
|
|
@ -88,25 +88,25 @@ int main(void)
|
||||||
"Follow player center horizontally; updateplayer center vertically after landing",
|
"Follow player center horizontally; updateplayer center vertically after landing",
|
||||||
"Player push camera on getting too close to screen edge"
|
"Player push camera on getting too close to screen edge"
|
||||||
};
|
};
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
float deltaTime = GetFrameTime();
|
float deltaTime = GetFrameTime();
|
||||||
|
|
||||||
UpdatePlayer(&player, envItems, envItemsLength, deltaTime);
|
UpdatePlayer(&player, envItems, envItemsLength, deltaTime);
|
||||||
|
|
||||||
camera.zoom += ((float)GetMouseWheelMove()*0.05f);
|
camera.zoom += ((float)GetMouseWheelMove()*0.05f);
|
||||||
|
|
||||||
if (camera.zoom > 3.0f) camera.zoom = 3.0f;
|
if (camera.zoom > 3.0f) camera.zoom = 3.0f;
|
||||||
else if (camera.zoom < 0.25f) camera.zoom = 0.25f;
|
else if (camera.zoom < 0.25f) camera.zoom = 0.25f;
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_R))
|
if (IsKeyPressed(KEY_R))
|
||||||
{
|
{
|
||||||
camera.zoom = 1.0f;
|
camera.zoom = 1.0f;
|
||||||
player.position = (Vector2){ 400, 280 };
|
player.position = (Vector2){ 400, 280 };
|
||||||
|
|
@ -125,12 +125,12 @@ int main(void)
|
||||||
ClearBackground(LIGHTGRAY);
|
ClearBackground(LIGHTGRAY);
|
||||||
|
|
||||||
BeginMode2D(camera);
|
BeginMode2D(camera);
|
||||||
|
|
||||||
for (int i = 0; i < envItemsLength; i++) DrawRectangleRec(envItems[i].rect, envItems[i].color);
|
for (int i = 0; i < envItemsLength; i++) DrawRectangleRec(envItems[i].rect, envItems[i].color);
|
||||||
|
|
||||||
Rectangle playerRect = { player.position.x - 20, player.position.y - 40, 40, 40 };
|
Rectangle playerRect = { player.position.x - 20, player.position.y - 40, 40, 40 };
|
||||||
DrawRectangleRec(playerRect, RED);
|
DrawRectangleRec(playerRect, RED);
|
||||||
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
||||||
DrawText("Controls:", 20, 20, 10, BLACK);
|
DrawText("Controls:", 20, 20, 10, BLACK);
|
||||||
|
|
@ -140,7 +140,7 @@ int main(void)
|
||||||
DrawText("- C to change camera mode", 40, 100, 10, DARKGRAY);
|
DrawText("- C to change camera mode", 40, 100, 10, DARKGRAY);
|
||||||
DrawText("Current camera mode:", 20, 120, 10, BLACK);
|
DrawText("Current camera mode:", 20, 120, 10, BLACK);
|
||||||
DrawText(cameraDescriptions[cameraOption], 40, 140, 10, DARKGRAY);
|
DrawText(cameraDescriptions[cameraOption], 40, 140, 10, DARKGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
@ -157,35 +157,35 @@ void UpdatePlayer(Player *player, EnvItem *envItems, int envItemsLength, float d
|
||||||
{
|
{
|
||||||
if (IsKeyDown(KEY_LEFT)) player->position.x -= PLAYER_HOR_SPD*delta;
|
if (IsKeyDown(KEY_LEFT)) player->position.x -= PLAYER_HOR_SPD*delta;
|
||||||
if (IsKeyDown(KEY_RIGHT)) player->position.x += PLAYER_HOR_SPD*delta;
|
if (IsKeyDown(KEY_RIGHT)) player->position.x += PLAYER_HOR_SPD*delta;
|
||||||
if (IsKeyDown(KEY_SPACE) && player->canJump)
|
if (IsKeyDown(KEY_SPACE) && player->canJump)
|
||||||
{
|
{
|
||||||
player->speed = -PLAYER_JUMP_SPD;
|
player->speed = -PLAYER_JUMP_SPD;
|
||||||
player->canJump = false;
|
player->canJump = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hitObstacle = 0;
|
int hitObstacle = 0;
|
||||||
for (int i = 0; i < envItemsLength; i++)
|
for (int i = 0; i < envItemsLength; i++)
|
||||||
{
|
{
|
||||||
EnvItem *ei = envItems + i;
|
EnvItem *ei = envItems + i;
|
||||||
Vector2 *p = &(player->position);
|
Vector2 *p = &(player->position);
|
||||||
if (ei->blocking &&
|
if (ei->blocking &&
|
||||||
ei->rect.x <= p->x &&
|
ei->rect.x <= p->x &&
|
||||||
ei->rect.x + ei->rect.width >= p->x &&
|
ei->rect.x + ei->rect.width >= p->x &&
|
||||||
ei->rect.y >= p->y &&
|
ei->rect.y >= p->y &&
|
||||||
ei->rect.y < p->y + player->speed*delta)
|
ei->rect.y < p->y + player->speed*delta)
|
||||||
{
|
{
|
||||||
hitObstacle = 1;
|
hitObstacle = 1;
|
||||||
player->speed = 0.0f;
|
player->speed = 0.0f;
|
||||||
p->y = ei->rect.y;
|
p->y = ei->rect.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hitObstacle)
|
if (!hitObstacle)
|
||||||
{
|
{
|
||||||
player->position.y += player->speed*delta;
|
player->position.y += player->speed*delta;
|
||||||
player->speed += G*delta;
|
player->speed += G*delta;
|
||||||
player->canJump = false;
|
player->canJump = false;
|
||||||
}
|
}
|
||||||
else player->canJump = true;
|
else player->canJump = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,7 +200,7 @@ void UpdateCameraCenterInsideMap(Camera2D *camera, Player *player, EnvItem *envI
|
||||||
camera->target = player->position;
|
camera->target = player->position;
|
||||||
camera->offset = (Vector2){ width/2.0f, height/2.0f };
|
camera->offset = (Vector2){ width/2.0f, height/2.0f };
|
||||||
float minX = 1000, minY = 1000, maxX = -1000, maxY = -1000;
|
float minX = 1000, minY = 1000, maxX = -1000, maxY = -1000;
|
||||||
|
|
||||||
for (int i = 0; i < envItemsLength; i++)
|
for (int i = 0; i < envItemsLength; i++)
|
||||||
{
|
{
|
||||||
EnvItem *ei = envItems + i;
|
EnvItem *ei = envItems + i;
|
||||||
|
|
@ -209,10 +209,10 @@ void UpdateCameraCenterInsideMap(Camera2D *camera, Player *player, EnvItem *envI
|
||||||
minY = fminf(ei->rect.y, minY);
|
minY = fminf(ei->rect.y, minY);
|
||||||
maxY = fmaxf(ei->rect.y + ei->rect.height, maxY);
|
maxY = fmaxf(ei->rect.y + ei->rect.height, maxY);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 max = GetWorldToScreen2D((Vector2){ maxX, maxY }, *camera);
|
Vector2 max = GetWorldToScreen2D((Vector2){ maxX, maxY }, *camera);
|
||||||
Vector2 min = GetWorldToScreen2D((Vector2){ minX, minY }, *camera);
|
Vector2 min = GetWorldToScreen2D((Vector2){ minX, minY }, *camera);
|
||||||
|
|
||||||
if (max.x < width) camera->offset.x = width - (max.x - width/2);
|
if (max.x < width) camera->offset.x = width - (max.x - width/2);
|
||||||
if (max.y < height) camera->offset.y = height - (max.y - height/2);
|
if (max.y < height) camera->offset.y = height - (max.y - height/2);
|
||||||
if (min.x > 0) camera->offset.x = width/2 - min.x;
|
if (min.x > 0) camera->offset.x = width/2 - min.x;
|
||||||
|
|
@ -224,11 +224,11 @@ void UpdateCameraCenterSmoothFollow(Camera2D *camera, Player *player, EnvItem *e
|
||||||
static float minSpeed = 30;
|
static float minSpeed = 30;
|
||||||
static float minEffectLength = 10;
|
static float minEffectLength = 10;
|
||||||
static float fractionSpeed = 0.8f;
|
static float fractionSpeed = 0.8f;
|
||||||
|
|
||||||
camera->offset = (Vector2){ width/2.0f, height/2.0f };
|
camera->offset = (Vector2){ width/2.0f, height/2.0f };
|
||||||
Vector2 diff = Vector2Subtract(player->position, camera->target);
|
Vector2 diff = Vector2Subtract(player->position, camera->target);
|
||||||
float length = Vector2Length(diff);
|
float length = Vector2Length(diff);
|
||||||
|
|
||||||
if (length > minEffectLength)
|
if (length > minEffectLength)
|
||||||
{
|
{
|
||||||
float speed = fmaxf(fractionSpeed*length, minSpeed);
|
float speed = fmaxf(fractionSpeed*length, minSpeed);
|
||||||
|
|
@ -241,34 +241,34 @@ void UpdateCameraEvenOutOnLanding(Camera2D *camera, Player *player, EnvItem *env
|
||||||
static float evenOutSpeed = 700;
|
static float evenOutSpeed = 700;
|
||||||
static int eveningOut = false;
|
static int eveningOut = false;
|
||||||
static float evenOutTarget;
|
static float evenOutTarget;
|
||||||
|
|
||||||
camera->offset = (Vector2){ width/2.0f, height/2.0f };
|
camera->offset = (Vector2){ width/2.0f, height/2.0f };
|
||||||
camera->target.x = player->position.x;
|
camera->target.x = player->position.x;
|
||||||
|
|
||||||
if (eveningOut)
|
if (eveningOut)
|
||||||
{
|
{
|
||||||
if (evenOutTarget > camera->target.y)
|
if (evenOutTarget > camera->target.y)
|
||||||
{
|
{
|
||||||
camera->target.y += evenOutSpeed*delta;
|
camera->target.y += evenOutSpeed*delta;
|
||||||
|
|
||||||
if (camera->target.y > evenOutTarget)
|
if (camera->target.y > evenOutTarget)
|
||||||
{
|
|
||||||
camera->target.y = evenOutTarget;
|
|
||||||
eveningOut = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
camera->target.y -= evenOutSpeed*delta;
|
|
||||||
|
|
||||||
if (camera->target.y < evenOutTarget)
|
|
||||||
{
|
{
|
||||||
camera->target.y = evenOutTarget;
|
camera->target.y = evenOutTarget;
|
||||||
eveningOut = 0;
|
eveningOut = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
|
camera->target.y -= evenOutSpeed*delta;
|
||||||
|
|
||||||
|
if (camera->target.y < evenOutTarget)
|
||||||
|
{
|
||||||
|
camera->target.y = evenOutTarget;
|
||||||
|
eveningOut = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (player->canJump && (player->speed == 0) && (player->position.y != camera->target.y))
|
if (player->canJump && (player->speed == 0) && (player->position.y != camera->target.y))
|
||||||
{
|
{
|
||||||
|
|
@ -278,7 +278,7 @@ void UpdateCameraEvenOutOnLanding(Camera2D *camera, Player *player, EnvItem *env
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateCameraPlayerBoundsPush(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height)
|
void UpdateCameraPlayerBoundsPush(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height)
|
||||||
{
|
{
|
||||||
static Vector2 bbox = { 0.2f, 0.2f };
|
static Vector2 bbox = { 0.2f, 0.2f };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ int main()
|
||||||
#else
|
#else
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ int main(void)
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - quat conversions");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - quat conversions");
|
||||||
|
|
||||||
Camera3D camera = { 0 };
|
Camera3D camera = { 0 };
|
||||||
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
|
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
|
|
@ -34,9 +34,9 @@ int main(void)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
||||||
|
|
||||||
Mesh mesh = GenMeshCylinder(0.2f, 1.0f, 32);
|
Mesh mesh = GenMeshCylinder(0.2f, 1.0f, 32);
|
||||||
Model model = LoadModelFromMesh(mesh);
|
Model model = LoadModelFromMesh(mesh);
|
||||||
|
|
||||||
// Some required variables
|
// Some required variables
|
||||||
Quaternion q1 = { 0 };
|
Quaternion q1 = { 0 };
|
||||||
Matrix m1 = { 0 }, m2 = { 0 }, m3 = { 0 }, m4 = { 0 };
|
Matrix m1 = { 0 }, m2 = { 0 }, m3 = { 0 }, m4 = { 0 };
|
||||||
|
|
@ -44,7 +44,7 @@ int main(void)
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
|
|
@ -60,28 +60,28 @@ int main(void)
|
||||||
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;
|
||||||
|
|
||||||
q1 = QuaternionFromEuler(v1.x, v1.y, v1.z);
|
q1 = QuaternionFromEuler(v1.x, v1.y, v1.z);
|
||||||
m1 = MatrixRotateZYX(v1);
|
m1 = MatrixRotateZYX(v1);
|
||||||
m2 = QuaternionToMatrix(q1);
|
m2 = QuaternionToMatrix(q1);
|
||||||
|
|
||||||
q1 = QuaternionFromMatrix(m1);
|
q1 = QuaternionFromMatrix(m1);
|
||||||
m3 = QuaternionToMatrix(q1);
|
m3 = QuaternionToMatrix(q1);
|
||||||
|
|
||||||
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);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
model.transform = m1;
|
model.transform = m1;
|
||||||
|
|
@ -94,19 +94,19 @@ int main(void)
|
||||||
DrawModel(model, (Vector3){ 0, 0, -1 }, 1.0f, RED);
|
DrawModel(model, (Vector3){ 0, 0, -1 }, 1.0f, RED);
|
||||||
|
|
||||||
DrawGrid(10, 1.0f);
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
if (v2.x < 0) v2.x += PI*2;
|
if (v2.x < 0) v2.x += PI*2;
|
||||||
if (v2.y < 0) v2.y += PI*2;
|
if (v2.y < 0) v2.y += PI*2;
|
||||||
if (v2.z < 0) v2.z += PI*2;
|
if (v2.z < 0) v2.z += PI*2;
|
||||||
|
|
||||||
Color cx,cy,cz;
|
Color cx,cy,cz;
|
||||||
cx = cy = cz = BLACK;
|
cx = cy = cz = BLACK;
|
||||||
if (v1.x == v2.x) cx = GREEN;
|
if (v1.x == v2.x) cx = GREEN;
|
||||||
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);
|
||||||
|
|
@ -122,7 +122,7 @@ int main(void)
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadModel(model); // Unload model data (mesh and materials)
|
UnloadModel(model); // Unload model data (mesh and materials)
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,9 @@ int main(void)
|
||||||
.eyeToScreenDistance = 0.041f, // Distance between eye and display in meters
|
.eyeToScreenDistance = 0.041f, // Distance between eye and display in meters
|
||||||
.lensSeparationDistance = 0.07f, // Lens separation distance in meters
|
.lensSeparationDistance = 0.07f, // Lens separation distance in meters
|
||||||
.interpupillaryDistance = 0.07f, // IPD (distance between pupils) in meters
|
.interpupillaryDistance = 0.07f, // IPD (distance between pupils) in meters
|
||||||
|
|
||||||
// NOTE: CV1 uses fresnel-hybrid-asymmetric lenses with specific compute shaders
|
// NOTE: CV1 uses fresnel-hybrid-asymmetric lenses with specific compute shaders
|
||||||
// Following parameters are just an approximation to CV1 distortion stereo rendering
|
// Following parameters are just an approximation to CV1 distortion stereo rendering
|
||||||
.lensDistortionValues[0] = 1.0f, // Lens distortion constant parameter 0
|
.lensDistortionValues[0] = 1.0f, // Lens distortion constant parameter 0
|
||||||
.lensDistortionValues[1] = 0.22f, // Lens distortion constant parameter 1
|
.lensDistortionValues[1] = 0.22f, // Lens distortion constant parameter 1
|
||||||
.lensDistortionValues[2] = 0.24f, // Lens distortion constant parameter 2
|
.lensDistortionValues[2] = 0.24f, // Lens distortion constant parameter 2
|
||||||
|
|
@ -50,32 +50,32 @@ int main(void)
|
||||||
.chromaAbCorrection[2] = 1.014f, // Chromatic aberration correction parameter 2
|
.chromaAbCorrection[2] = 1.014f, // Chromatic aberration correction parameter 2
|
||||||
.chromaAbCorrection[3] = 0.0f, // Chromatic aberration correction parameter 3
|
.chromaAbCorrection[3] = 0.0f, // Chromatic aberration correction parameter 3
|
||||||
};
|
};
|
||||||
|
|
||||||
// Load VR stereo config for VR device parameteres (Oculus Rift CV1 parameters)
|
// Load VR stereo config for VR device parameteres (Oculus Rift CV1 parameters)
|
||||||
VrStereoConfig config = LoadVrStereoConfig(device);
|
VrStereoConfig config = LoadVrStereoConfig(device);
|
||||||
|
|
||||||
// Distortion shader (uses device lens distortion and chroma)
|
// Distortion shader (uses device lens distortion and chroma)
|
||||||
Shader distortion = LoadShader(0, TextFormat("resources/distortion%i.fs", GLSL_VERSION));
|
Shader distortion = LoadShader(0, TextFormat("resources/distortion%i.fs", GLSL_VERSION));
|
||||||
|
|
||||||
// Update distortion shader with lens and distortion-scale parameters
|
// Update distortion shader with lens and distortion-scale parameters
|
||||||
SetShaderValue(distortion, GetShaderLocation(distortion, "leftLensCenter"),
|
SetShaderValue(distortion, GetShaderLocation(distortion, "leftLensCenter"),
|
||||||
config.leftLensCenter, SHADER_UNIFORM_VEC2);
|
config.leftLensCenter, SHADER_UNIFORM_VEC2);
|
||||||
SetShaderValue(distortion, GetShaderLocation(distortion, "rightLensCenter"),
|
SetShaderValue(distortion, GetShaderLocation(distortion, "rightLensCenter"),
|
||||||
config.rightLensCenter, SHADER_UNIFORM_VEC2);
|
config.rightLensCenter, SHADER_UNIFORM_VEC2);
|
||||||
SetShaderValue(distortion, GetShaderLocation(distortion, "leftScreenCenter"),
|
SetShaderValue(distortion, GetShaderLocation(distortion, "leftScreenCenter"),
|
||||||
config.leftScreenCenter, SHADER_UNIFORM_VEC2);
|
config.leftScreenCenter, SHADER_UNIFORM_VEC2);
|
||||||
SetShaderValue(distortion, GetShaderLocation(distortion, "rightScreenCenter"),
|
SetShaderValue(distortion, GetShaderLocation(distortion, "rightScreenCenter"),
|
||||||
config.rightScreenCenter, SHADER_UNIFORM_VEC2);
|
config.rightScreenCenter, SHADER_UNIFORM_VEC2);
|
||||||
|
|
||||||
SetShaderValue(distortion, GetShaderLocation(distortion, "scale"),
|
SetShaderValue(distortion, GetShaderLocation(distortion, "scale"),
|
||||||
config.scale, SHADER_UNIFORM_VEC2);
|
config.scale, SHADER_UNIFORM_VEC2);
|
||||||
SetShaderValue(distortion, GetShaderLocation(distortion, "scaleIn"),
|
SetShaderValue(distortion, GetShaderLocation(distortion, "scaleIn"),
|
||||||
config.scaleIn, SHADER_UNIFORM_VEC2);
|
config.scaleIn, SHADER_UNIFORM_VEC2);
|
||||||
SetShaderValue(distortion, GetShaderLocation(distortion, "deviceWarpParam"),
|
SetShaderValue(distortion, GetShaderLocation(distortion, "deviceWarpParam"),
|
||||||
device.lensDistortionValues, SHADER_UNIFORM_VEC4);
|
device.lensDistortionValues, SHADER_UNIFORM_VEC4);
|
||||||
SetShaderValue(distortion, GetShaderLocation(distortion, "chromaAbParam"),
|
SetShaderValue(distortion, GetShaderLocation(distortion, "chromaAbParam"),
|
||||||
device.chromaAbCorrection, SHADER_UNIFORM_VEC4);
|
device.chromaAbCorrection, SHADER_UNIFORM_VEC4);
|
||||||
|
|
||||||
// Initialize framebuffer for stereo rendering
|
// Initialize framebuffer for stereo rendering
|
||||||
// NOTE: Screen size should match HMD aspect ratio
|
// NOTE: Screen size should match HMD aspect ratio
|
||||||
RenderTexture2D target = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
|
RenderTexture2D target = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
|
||||||
|
|
@ -121,9 +121,9 @@ int main(void)
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
EndVrStereoMode();
|
EndVrStereoMode();
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
BeginShaderMode(distortion);
|
BeginShaderMode(distortion);
|
||||||
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width,
|
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width,
|
||||||
(float)-target.texture.height }, (Vector2){ 0.0f, 0.0f }, WHITE);
|
(float)-target.texture.height }, (Vector2){ 0.0f, 0.0f }, WHITE);
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ int main(void)
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadVrStereoConfig(config); // Unload stereo config
|
UnloadVrStereoConfig(config); // Unload stereo config
|
||||||
|
|
||||||
UnloadRenderTexture(target); // Unload stereo render fbo
|
UnloadRenderTexture(target); // Unload stereo render fbo
|
||||||
UnloadShader(distortion); // Unload distortion shader
|
UnloadShader(distortion); // Unload distortion shader
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,13 +64,13 @@ int main(void)
|
||||||
// Recalculate random colors for the bars
|
// Recalculate random colors for the bars
|
||||||
for (int i = 0; i < 10; i++) colors[i] = (Color){ GetRandomValue(100, 250), GetRandomValue(50, 150), GetRandomValue(10, 100), 255 };
|
for (int i = 0; i < 10; i++) colors[i] = (Color){ GetRandomValue(100, 250), GetRandomValue(50, 150), GetRandomValue(10, 100), 255 };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update virtual mouse (clamped mouse value behind game screen)
|
// Update virtual mouse (clamped mouse value behind game screen)
|
||||||
Vector2 mouse = GetMousePosition();
|
Vector2 mouse = GetMousePosition();
|
||||||
Vector2 virtualMouse = { 0 };
|
Vector2 virtualMouse = { 0 };
|
||||||
virtualMouse.x = (mouse.x - (GetScreenWidth() - (gameScreenWidth*scale))*0.5f)/scale;
|
virtualMouse.x = (mouse.x - (GetScreenWidth() - (gameScreenWidth*scale))*0.5f)/scale;
|
||||||
virtualMouse.y = (mouse.y - (GetScreenHeight() - (gameScreenHeight*scale))*0.5f)/scale;
|
virtualMouse.y = (mouse.y - (GetScreenHeight() - (gameScreenHeight*scale))*0.5f)/scale;
|
||||||
virtualMouse = ClampValue(virtualMouse, (Vector2){ 0, 0 }, (Vector2){ gameScreenWidth, gameScreenHeight });
|
virtualMouse = ClampValue(virtualMouse, (Vector2){ 0, 0 }, (Vector2){ gameScreenWidth, gameScreenHeight });
|
||||||
|
|
||||||
// Apply the same transformation as the virtual mouse to the real mouse (i.e. to work with raygui)
|
// Apply the same transformation as the virtual mouse to the real mouse (i.e. to work with raygui)
|
||||||
//SetMouseOffset(-(GetScreenWidth() - (gameScreenWidth*scale))*0.5f, -(GetScreenHeight() - (gameScreenHeight*scale))*0.5f);
|
//SetMouseOffset(-(GetScreenWidth() - (gameScreenWidth*scale))*0.5f, -(GetScreenHeight() - (gameScreenHeight*scale))*0.5f);
|
||||||
|
|
@ -90,7 +90,7 @@ int main(void)
|
||||||
for (int i = 0; i < 10; i++) DrawRectangle(0, (gameScreenHeight/10)*i, gameScreenWidth, gameScreenHeight/10, colors[i]);
|
for (int i = 0; i < 10; i++) DrawRectangle(0, (gameScreenHeight/10)*i, gameScreenWidth, gameScreenHeight/10, colors[i]);
|
||||||
|
|
||||||
DrawText("If executed inside a window,\nyou can resize the window,\nand see the screen scaling!", 10, 25, 20, WHITE);
|
DrawText("If executed inside a window,\nyou can resize the window,\nand see the screen scaling!", 10, 25, 20, WHITE);
|
||||||
|
|
||||||
DrawText(TextFormat("Default Mouse: [%i , %i]", (int)mouse.x, (int)mouse.y), 350, 25, 20, GREEN);
|
DrawText(TextFormat("Default Mouse: [%i , %i]", (int)mouse.x, (int)mouse.y), 350, 25, 20, GREEN);
|
||||||
DrawText(TextFormat("Virtual Mouse: [%i , %i]", (int)virtualMouse.x, (int)virtualMouse.y), 350, 55, 20, YELLOW);
|
DrawText(TextFormat("Virtual Mouse: [%i , %i]", (int)virtualMouse.x, (int)virtualMouse.y), 350, 55, 20, YELLOW);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
WELCOME raylib EXAMPLES CONTRIBUTOR!
|
WELCOME raylib EXAMPLES CONTRIBUTOR!
|
||||||
|
|
||||||
This is a bsasic template to anyone ready to contribute with some code example for the library,
|
This is a bsasic template to anyone ready to contribute with some code example for the library,
|
||||||
here there are some guidelines on how to create an example to be included in raylib
|
here there are some guidelines on how to create an example to be included in raylib
|
||||||
|
|
||||||
|
|
@ -8,32 +8,32 @@
|
||||||
no more than 3-4 words in total to describe the example. <module> referes to the primary
|
no more than 3-4 words in total to describe the example. <module> referes to the primary
|
||||||
raylib module the example is more related with (code, shapes, textures, models, shaders, raudio).
|
raylib module the example is more related with (code, shapes, textures, models, shaders, raudio).
|
||||||
i.e: core_input_multitouch, shapes_lines_bezier, shaders_palette_switch
|
i.e: core_input_multitouch, shapes_lines_bezier, shaders_palette_switch
|
||||||
|
|
||||||
2. Follow below template structure, example info should list the module, the short description
|
2. Follow below template structure, example info should list the module, the short description
|
||||||
and the author of the example, twitter or github info could be also provided for the author.
|
and the author of the example, twitter or github info could be also provided for the author.
|
||||||
Short description should also be used on the title of the window.
|
Short description should also be used on the title of the window.
|
||||||
|
|
||||||
3. Code should be organized by sections:[Initialization]- [Update] - [Draw] - [De-Initialization]
|
3. Code should be organized by sections:[Initialization]- [Update] - [Draw] - [De-Initialization]
|
||||||
Place your code between the dotted lines for every section, please don't mix update logic with drawing
|
Place your code between the dotted lines for every section, please don't mix update logic with drawing
|
||||||
and remember to unload all loaded resources.
|
and remember to unload all loaded resources.
|
||||||
|
|
||||||
4. Code should follow raylib conventions: https://github.com/raysan5/raylib/wiki/raylib-coding-conventions
|
4. Code should follow raylib conventions: https://github.com/raysan5/raylib/wiki/raylib-coding-conventions
|
||||||
Try to be very organized, using line-breaks appropiately.
|
Try to be very organized, using line-breaks appropiately.
|
||||||
|
|
||||||
5. Add comments to the specific parts of code the example is focus on.
|
5. Add comments to the specific parts of code the example is focus on.
|
||||||
Don't abuse with comments, try to be clear and impersonal on the comments.
|
Don't abuse with comments, try to be clear and impersonal on the comments.
|
||||||
|
|
||||||
6. Try to keep the example simple, under 300 code lines if possible. Try to avoid external dependencies.
|
6. Try to keep the example simple, under 300 code lines if possible. Try to avoid external dependencies.
|
||||||
Try to avoid defining functions outside the main(). Example should be as self-contained as possible.
|
Try to avoid defining functions outside the main(). Example should be as self-contained as possible.
|
||||||
|
|
||||||
7. About external resources, they should be placed in a [resources] folder and those resources
|
7. About external resources, they should be placed in a [resources] folder and those resources
|
||||||
should be open and free for use and distribution. Avoid propietary content.
|
should be open and free for use and distribution. Avoid propietary content.
|
||||||
|
|
||||||
8. Try to keep the example simple but with a creative touch.
|
8. Try to keep the example simple but with a creative touch.
|
||||||
Simple but beautiful examples are more appealing to users!
|
Simple but beautiful examples are more appealing to users!
|
||||||
|
|
||||||
9. In case of additional information is required, just come to raylib Discord channel: example-contributions
|
9. In case of additional information is required, just come to raylib Discord channel: example-contributions
|
||||||
|
|
||||||
10. Have fun!
|
10. Have fun!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -58,9 +58,9 @@ int main()
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
|
|
||||||
// TODO: Load resources / Initialize variables at this point
|
// TODO: Load resources / Initialize variables at this point
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -79,7 +79,7 @@ int main()
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
// TODO: Draw everything that requires to be drawn at this point:
|
// TODO: Draw everything that requires to be drawn at this point:
|
||||||
|
|
||||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); // Example
|
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); // Example
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
@ -88,9 +88,9 @@ int main()
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// TODO: Unload all loaded resources at this point
|
// TODO: Unload all loaded resources at this point
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
*
|
*
|
||||||
********************************************************************************************
|
********************************************************************************************
|
||||||
*
|
*
|
||||||
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
||||||
* same position as they would be in edit mode.
|
* same position as they would be in edit mode.
|
||||||
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
|
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
|
||||||
*
|
*
|
||||||
|
|
@ -100,7 +100,7 @@ int main(void)
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadTexture(texture); // Unload texture
|
UnloadTexture(texture); // Unload texture
|
||||||
|
|
||||||
// Unload model animations data
|
// Unload model animations data
|
||||||
for (int i = 0; i < animsCount; i++) UnloadModelAnimation(anims[i]);
|
for (int i = 0; i < animsCount; i++) UnloadModelAnimation(anims[i]);
|
||||||
RL_FREE(anims);
|
RL_FREE(anims);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
*
|
*
|
||||||
********************************************************************************************
|
********************************************************************************************
|
||||||
*
|
*
|
||||||
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
||||||
* same position as they would be in edit mode.
|
* same position as they would be in edit mode.
|
||||||
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
|
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
|
||||||
*
|
*
|
||||||
|
|
@ -68,13 +68,13 @@ int main(void)
|
||||||
if (IsKeyDown(KEY_SPACE))
|
if (IsKeyDown(KEY_SPACE))
|
||||||
{
|
{
|
||||||
animFrameCounter += animationDirection;
|
animFrameCounter += animationDirection;
|
||||||
|
|
||||||
if (animFrameCounter >= anims[0].frameCount || animFrameCounter <= 0)
|
if (animFrameCounter >= anims[0].frameCount || animFrameCounter <= 0)
|
||||||
{
|
{
|
||||||
animationDirection *= -1;
|
animationDirection *= -1;
|
||||||
animFrameCounter += animationDirection;
|
animFrameCounter += animationDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateModelAnimation(model, anims[0], animFrameCounter);
|
UpdateModelAnimation(model, anims[0], animFrameCounter);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -108,7 +108,7 @@ int main(void)
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
// UnloadTexture(texture); // Unload texture
|
// UnloadTexture(texture); // Unload texture
|
||||||
|
|
||||||
// Unload model animations data
|
// Unload model animations data
|
||||||
for (int i = 0; i < animsCount; i++) UnloadModelAnimation(anims[i]);
|
for (int i = 0; i < animsCount; i++) UnloadModelAnimation(anims[i]);
|
||||||
RL_FREE(anims);
|
RL_FREE(anims);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
*
|
*
|
||||||
********************************************************************************************
|
********************************************************************************************
|
||||||
*
|
*
|
||||||
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
||||||
* same position as they would be in edit mode.
|
* same position as they would be in edit mode.
|
||||||
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
|
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
|
||||||
*
|
*
|
||||||
|
|
@ -41,14 +41,14 @@ int main(void)
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
||||||
|
|
||||||
Model model[MAX_MODELS] = { 0 };
|
Model model[MAX_MODELS] = { 0 };
|
||||||
|
|
||||||
model[0] = LoadModel("resources/gltf/raylib_32x32.glb");
|
model[0] = LoadModel("resources/gltf/raylib_32x32.glb");
|
||||||
model[1] = LoadModel("resources/gltf/rigged_figure.glb");
|
model[1] = LoadModel("resources/gltf/rigged_figure.glb");
|
||||||
model[2] = LoadModel("resources/gltf/GearboxAssy.glb");
|
model[2] = LoadModel("resources/gltf/GearboxAssy.glb");
|
||||||
model[3] = LoadModel("resources/gltf/BoxAnimated.glb");
|
model[3] = LoadModel("resources/gltf/BoxAnimated.glb");
|
||||||
model[4] = LoadModel("resources/gltf/AnimatedTriangle.gltf");
|
model[4] = LoadModel("resources/gltf/AnimatedTriangle.gltf");
|
||||||
model[5] = LoadModel("resources/gltf/AnimatedMorphCube.glb");
|
model[5] = LoadModel("resources/gltf/AnimatedMorphCube.glb");
|
||||||
|
|
||||||
int currentModel = 0;
|
int currentModel = 0;
|
||||||
|
|
||||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
@ -64,13 +64,13 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera);
|
UpdateCamera(&camera);
|
||||||
|
|
||||||
if (IsKeyReleased(KEY_RIGHT))
|
if (IsKeyReleased(KEY_RIGHT))
|
||||||
{
|
{
|
||||||
currentModel++;
|
currentModel++;
|
||||||
if (currentModel == MAX_MODELS) currentModel = 0;
|
if (currentModel == MAX_MODELS) currentModel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsKeyReleased(KEY_LEFT))
|
if (IsKeyReleased(KEY_LEFT))
|
||||||
{
|
{
|
||||||
currentModel--;
|
currentModel--;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
* - GLTF > Modern text/binary file format, includes lot of information and it could
|
* - GLTF > Modern text/binary file format, includes lot of information and it could
|
||||||
* also reference external files, raylib will try loading mesh and materials data
|
* also reference external files, raylib will try loading mesh and materials data
|
||||||
* - IQM > Binary file format including mesh vertex data but also animation data,
|
* - IQM > Binary file format including mesh vertex data but also animation data,
|
||||||
* raylib can load .iqm animations.
|
* raylib can load .iqm animations.
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 2.6 (www.raylib.com)
|
* This example has been created using raylib 2.6 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
|
@ -42,7 +42,7 @@ int main(void)
|
||||||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
||||||
|
|
||||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
BoundingBox bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds
|
BoundingBox bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds
|
||||||
|
|
||||||
// NOTE: bounds are calculated from the original size of the model,
|
// NOTE: bounds are calculated from the original size of the model,
|
||||||
|
|
@ -61,7 +61,7 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera);
|
UpdateCamera(&camera);
|
||||||
|
|
||||||
// Load new models/textures on drag&drop
|
// Load new models/textures on drag&drop
|
||||||
if (IsFileDropped())
|
if (IsFileDropped())
|
||||||
{
|
{
|
||||||
|
|
@ -79,7 +79,7 @@ int main(void)
|
||||||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set current map diffuse texture
|
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set current map diffuse texture
|
||||||
|
|
||||||
bounds = MeshBoundingBox(model.meshes[0]);
|
bounds = MeshBoundingBox(model.meshes[0]);
|
||||||
|
|
||||||
// TODO: Move camera position from target enough distance to visualize model properly
|
// TODO: Move camera position from target enough distance to visualize model properly
|
||||||
}
|
}
|
||||||
else if (IsFileExtension(droppedFiles[0], ".png")) // Texture file formats supported
|
else if (IsFileExtension(droppedFiles[0], ".png")) // Texture file formats supported
|
||||||
|
|
@ -118,7 +118,7 @@ int main(void)
|
||||||
if (selected) DrawBoundingBox(bounds, GREEN); // Draw selection box
|
if (selected) DrawBoundingBox(bounds, GREEN); // Draw selection box
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawText("Drag & drop model to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
|
DrawText("Drag & drop model to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
|
||||||
if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);
|
if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||||
Material mat = LoadMaterialDefault(); // Initialize material to default
|
Material mat = LoadMaterialDefault(); // Initialize material to default
|
||||||
|
|
||||||
// Load PBR shader (requires several maps)
|
// Load PBR shader (requires several maps)
|
||||||
mat.shader = LoadShader(TextFormat("resources/shaders/glsl%i/pbr.vs", GLSL_VERSION),
|
mat.shader = LoadShader(TextFormat("resources/shaders/glsl%i/pbr.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/pbr.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/pbr.fs", GLSL_VERSION));
|
||||||
|
|
||||||
// Get required locations points for PBR material
|
// Get required locations points for PBR material
|
||||||
|
|
@ -160,14 +160,14 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||||
mat.maps[MATERIAL_MAP_METALNESS].texture = LoadTexture("resources/pbr/trooper_metalness.png");
|
mat.maps[MATERIAL_MAP_METALNESS].texture = LoadTexture("resources/pbr/trooper_metalness.png");
|
||||||
mat.maps[MATERIAL_MAP_ROUGHNESS].texture = LoadTexture("resources/pbr/trooper_roughness.png");
|
mat.maps[MATERIAL_MAP_ROUGHNESS].texture = LoadTexture("resources/pbr/trooper_roughness.png");
|
||||||
mat.maps[MATERIAL_MAP_OCCLUSION].texture = LoadTexture("resources/pbr/trooper_ao.png");
|
mat.maps[MATERIAL_MAP_OCCLUSION].texture = LoadTexture("resources/pbr/trooper_ao.png");
|
||||||
|
|
||||||
// Set textures filtering for better quality
|
// Set textures filtering for better quality
|
||||||
SetTextureFilter(mat.maps[MATERIAL_MAP_ALBEDO].texture, FILTER_BILINEAR);
|
SetTextureFilter(mat.maps[MATERIAL_MAP_ALBEDO].texture, FILTER_BILINEAR);
|
||||||
SetTextureFilter(mat.maps[MATERIAL_MAP_NORMAL].texture, FILTER_BILINEAR);
|
SetTextureFilter(mat.maps[MATERIAL_MAP_NORMAL].texture, FILTER_BILINEAR);
|
||||||
SetTextureFilter(mat.maps[MATERIAL_MAP_METALNESS].texture, FILTER_BILINEAR);
|
SetTextureFilter(mat.maps[MATERIAL_MAP_METALNESS].texture, FILTER_BILINEAR);
|
||||||
SetTextureFilter(mat.maps[MATERIAL_MAP_ROUGHNESS].texture, FILTER_BILINEAR);
|
SetTextureFilter(mat.maps[MATERIAL_MAP_ROUGHNESS].texture, FILTER_BILINEAR);
|
||||||
SetTextureFilter(mat.maps[MATERIAL_MAP_OCCLUSION].texture, FILTER_BILINEAR);
|
SetTextureFilter(mat.maps[MATERIAL_MAP_OCCLUSION].texture, FILTER_BILINEAR);
|
||||||
|
|
||||||
// Enable sample usage in shader for assigned textures
|
// Enable sample usage in shader for assigned textures
|
||||||
SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, SHADER_UNIFORM_INT);
|
SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, SHADER_UNIFORM_INT);
|
||||||
SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, SHADER_UNIFORM_INT);
|
SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, SHADER_UNIFORM_INT);
|
||||||
|
|
@ -186,13 +186,13 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||||
mat.maps[MATERIAL_MAP_OCCLUSION].value = 1.0f;
|
mat.maps[MATERIAL_MAP_OCCLUSION].value = 1.0f;
|
||||||
mat.maps[MATERIAL_MAP_EMISSION].value = 0.5f;
|
mat.maps[MATERIAL_MAP_EMISSION].value = 0.5f;
|
||||||
mat.maps[MATERIAL_MAP_HEIGHT].value = 0.5f;
|
mat.maps[MATERIAL_MAP_HEIGHT].value = 0.5f;
|
||||||
|
|
||||||
// Generate cubemap from panorama texture
|
// Generate cubemap from panorama texture
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
Texture2D panorama = LoadTexture("resources/dresden_square_2k.hdr");
|
Texture2D panorama = LoadTexture("resources/dresden_square_2k.hdr");
|
||||||
|
|
||||||
// Load equirectangular to cubemap shader
|
// Load equirectangular to cubemap shader
|
||||||
Shader shdrCubemap = LoadShader(TextFormat("resources/shaders/glsl%i/pbr.vs", GLSL_VERSION),
|
Shader shdrCubemap = LoadShader(TextFormat("resources/shaders/glsl%i/pbr.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/pbr.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/pbr.fs", GLSL_VERSION));
|
||||||
|
|
||||||
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
||||||
|
|
@ -200,33 +200,33 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||||
UnloadTexture(panorama);
|
UnloadTexture(panorama);
|
||||||
UnloadShader(shdrCubemap);
|
UnloadShader(shdrCubemap);
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Generate irradiance map from cubemap texture
|
// Generate irradiance map from cubemap texture
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
// Load irradiance (GI) calculation shader
|
// Load irradiance (GI) calculation shader
|
||||||
Shader shdrIrradiance = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
Shader shdrIrradiance = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/irradiance.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/irradiance.fs", GLSL_VERSION));
|
||||||
|
|
||||||
SetShaderValue(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
SetShaderValue(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
||||||
mat.maps[MATERIAL_MAP_IRRADIANCE].texture = GenTextureIrradiance(shdrIrradiance, cubemap, IRRADIANCE_SIZE);
|
mat.maps[MATERIAL_MAP_IRRADIANCE].texture = GenTextureIrradiance(shdrIrradiance, cubemap, IRRADIANCE_SIZE);
|
||||||
UnloadShader(shdrIrradiance);
|
UnloadShader(shdrIrradiance);
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Generate prefilter map from cubemap texture
|
// Generate prefilter map from cubemap texture
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
// Load reflection prefilter calculation shader
|
// Load reflection prefilter calculation shader
|
||||||
Shader shdrPrefilter = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
Shader shdrPrefilter = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/prefilter.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/prefilter.fs", GLSL_VERSION));
|
||||||
|
|
||||||
SetShaderValue(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
SetShaderValue(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
||||||
mat.maps[MATERIAL_MAP_PREFILTER].texture = GenTexturePrefilter(shdrPrefilter, cubemap, PREFILTERED_SIZE);
|
mat.maps[MATERIAL_MAP_PREFILTER].texture = GenTexturePrefilter(shdrPrefilter, cubemap, PREFILTERED_SIZE);
|
||||||
UnloadTexture(cubemap);
|
UnloadTexture(cubemap);
|
||||||
UnloadShader(shdrPrefilter);
|
UnloadShader(shdrPrefilter);
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Generate BRDF (bidirectional reflectance distribution function) texture (using shader)
|
// Generate BRDF (bidirectional reflectance distribution function) texture (using shader)
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
Shader shdrBRDF = LoadShader(TextFormat("resources/shaders/glsl%i/brdf.vs", GLSL_VERSION),
|
Shader shdrBRDF = LoadShader(TextFormat("resources/shaders/glsl%i/brdf.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/brdf.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/brdf.fs", GLSL_VERSION));
|
||||||
|
|
||||||
mat.maps[MATERIAL_MAP_BRDG].texture = GenTextureBRDF(shdrBRDF, BRDF_SIZE);
|
mat.maps[MATERIAL_MAP_BRDG].texture = GenTextureBRDF(shdrBRDF, BRDF_SIZE);
|
||||||
|
|
@ -453,7 +453,7 @@ static TextureCubemap GenTexturePrefilter(Shader shader, TextureCubemap cubemap,
|
||||||
{
|
{
|
||||||
rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
|
rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
|
||||||
rlFramebufferAttach(fbo, prefilter.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i, mip);
|
rlFramebufferAttach(fbo, prefilter.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i, mip);
|
||||||
|
|
||||||
rlClearScreenBuffers();
|
rlClearScreenBuffers();
|
||||||
rlLoadDrawCube();
|
rlLoadDrawCube();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ void DrawSphereBasic(Color color)
|
||||||
{
|
{
|
||||||
int rings = 16;
|
int rings = 16;
|
||||||
int slices = 16;
|
int slices = 16;
|
||||||
|
|
||||||
// Make sure there is enough space in the internal render batch
|
// Make sure there is enough space in the internal render batch
|
||||||
// buffer to store all required vertex, batch is reseted if required
|
// buffer to store all required vertex, batch is reseted if required
|
||||||
rlCheckRenderBatchLimit((rings + 2)*slices*6);
|
rlCheckRenderBatchLimit((rings + 2)*slices*6);
|
||||||
|
|
|
||||||
|
|
@ -36,12 +36,12 @@ int main(void)
|
||||||
// Load skybox model
|
// Load skybox model
|
||||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||||
Model skybox = LoadModelFromMesh(cube);
|
Model skybox = LoadModelFromMesh(cube);
|
||||||
|
|
||||||
bool useHDR = false;
|
bool useHDR = false;
|
||||||
|
|
||||||
// Load skybox shader and set required locations
|
// Load skybox shader and set required locations
|
||||||
// NOTE: Some locations are automatically set at shader loading
|
// NOTE: Some locations are automatically set at shader loading
|
||||||
skybox.materials[0].shader = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
skybox.materials[0].shader = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/skybox.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/skybox.fs", GLSL_VERSION));
|
||||||
|
|
||||||
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "environmentMap"), (int[1]){ MATERIAL_MAP_CUBEMAP }, SHADER_UNIFORM_INT);
|
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "environmentMap"), (int[1]){ MATERIAL_MAP_CUBEMAP }, SHADER_UNIFORM_INT);
|
||||||
|
|
@ -49,7 +49,7 @@ int main(void)
|
||||||
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "vflipped"), (int[1]){ useHDR ? 1 : 0 }, SHADER_UNIFORM_INT);
|
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "vflipped"), (int[1]){ useHDR ? 1 : 0 }, SHADER_UNIFORM_INT);
|
||||||
|
|
||||||
// Load cubemap shader and setup required shader locations
|
// Load cubemap shader and setup required shader locations
|
||||||
Shader shdrCubemap = LoadShader(TextFormat("resources/shaders/glsl%i/cubemap.vs", GLSL_VERSION),
|
Shader shdrCubemap = LoadShader(TextFormat("resources/shaders/glsl%i/cubemap.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/cubemap.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/cubemap.fs", GLSL_VERSION));
|
||||||
|
|
||||||
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
||||||
|
|
@ -89,7 +89,7 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update camera
|
UpdateCamera(&camera); // Update camera
|
||||||
|
|
||||||
// Load new cubemap texture on drag&drop
|
// Load new cubemap texture on drag&drop
|
||||||
if (IsFileDropped())
|
if (IsFileDropped())
|
||||||
{
|
{
|
||||||
|
|
@ -105,7 +105,7 @@ int main(void)
|
||||||
if (useHDR)
|
if (useHDR)
|
||||||
{
|
{
|
||||||
Texture2D panorama = LoadTexture(droppedFiles[0]);
|
Texture2D panorama = LoadTexture(droppedFiles[0]);
|
||||||
|
|
||||||
// Generate cubemap from panorama texture
|
// Generate cubemap from panorama texture
|
||||||
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
|
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
|
||||||
UnloadTexture(panorama);
|
UnloadTexture(panorama);
|
||||||
|
|
@ -132,16 +132,16 @@ int main(void)
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
// We are inside the cube, we need to disable backface culling!
|
// We are inside the cube, we need to disable backface culling!
|
||||||
rlDisableBackfaceCulling();
|
rlDisableBackfaceCulling();
|
||||||
rlDisableDepthMask();
|
rlDisableDepthMask();
|
||||||
DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE);
|
DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE);
|
||||||
rlEnableBackfaceCulling();
|
rlEnableBackfaceCulling();
|
||||||
rlEnableDepthMask();
|
rlEnableDepthMask();
|
||||||
|
|
||||||
DrawGrid(10, 1.0f);
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
if (useHDR)
|
if (useHDR)
|
||||||
|
|
@ -159,7 +159,7 @@ int main(void)
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadShader(skybox.materials[0].shader);
|
UnloadShader(skybox.materials[0].shader);
|
||||||
UnloadTexture(skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture);
|
UnloadTexture(skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture);
|
||||||
|
|
||||||
UnloadModel(skybox); // Unload skybox model
|
UnloadModel(skybox); // Unload skybox model
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ int main()
|
||||||
camera.position.x = (float)cos(cameraTime)*40.0f;
|
camera.position.x = (float)cos(cameraTime)*40.0f;
|
||||||
camera.position.z = (float)sin(cameraTime)*40.0f;
|
camera.position.z = (float)sin(cameraTime)*40.0f;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
@ -64,11 +64,11 @@ int main()
|
||||||
|
|
||||||
DrawGrid(10, 5.0f);
|
DrawGrid(10, 5.0f);
|
||||||
|
|
||||||
for (int x = 0; x < numBlocks; x++)
|
for (int x = 0; x < numBlocks; x++)
|
||||||
{
|
{
|
||||||
for (int y = 0; y < numBlocks; y++)
|
for (int y = 0; y < numBlocks; y++)
|
||||||
{
|
{
|
||||||
for (int z = 0; z < numBlocks; z++)
|
for (int z = 0; z < numBlocks; z++)
|
||||||
{
|
{
|
||||||
// Scale of the blocks depends on x/y/z positions
|
// Scale of the blocks depends on x/y/z positions
|
||||||
float blockScale = (x + y + z)/30.0f;
|
float blockScale = (x + y + z)/30.0f;
|
||||||
|
|
@ -94,9 +94,9 @@ int main()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ int main(void)
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 30.0f; // Camera field-of-view Y
|
camera.fovy = 30.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera type
|
||||||
|
|
||||||
// Model loading
|
// Model loading
|
||||||
// NOTE: Diffuse map loaded automatically
|
// NOTE: Diffuse map loaded automatically
|
||||||
Model model = LoadModel("resources/plane/plane.gltf");
|
Model model = LoadModel("resources/plane/plane.gltf");
|
||||||
|
|
@ -77,8 +77,8 @@ int main(void)
|
||||||
// Tranformation matrix for rotations
|
// Tranformation matrix for rotations
|
||||||
model.transform = MatrixRotateXYZ((Vector3){ DEG2RAD*pitch, DEG2RAD*yaw, DEG2RAD*roll });
|
model.transform = MatrixRotateXYZ((Vector3){ DEG2RAD*pitch, DEG2RAD*yaw, DEG2RAD*roll });
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
@ -92,7 +92,7 @@ int main(void)
|
||||||
DrawGrid(10, 10.0f);
|
DrawGrid(10, 10.0f);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
// Draw controls info
|
// Draw controls info
|
||||||
DrawRectangle(30, 370, 260, 70, Fade(GREEN, 0.5f));
|
DrawRectangle(30, 370, 260, 70, Fade(GREEN, 0.5f));
|
||||||
DrawRectangleLines(30, 370, 260, 70, Fade(DARKGREEN, 0.5f));
|
DrawRectangleLines(30, 370, 260, 70, Fade(DARKGREEN, 0.5f));
|
||||||
|
|
@ -107,7 +107,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadModel(model); // Unload model data
|
UnloadModel(model); // Unload model data
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
|
|
||||||
|
|
@ -40,16 +40,16 @@ static void NetworkConnect(void)
|
||||||
{
|
{
|
||||||
ping = true;
|
ping = true;
|
||||||
connected = true;
|
connected = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If the client is connected, run the server code to check for a connection
|
// If the client is connected, run the server code to check for a connection
|
||||||
if (clientConnected)
|
if (clientConnected)
|
||||||
{
|
{
|
||||||
int active = CheckSockets(socketSet, 0);
|
int active = CheckSockets(socketSet, 0);
|
||||||
if (active != 0) TraceLog(LOG_INFO, "There are currently %d socket(s) with data to be processed.", active);
|
if (active != 0) TraceLog(LOG_INFO, "There are currently %d socket(s) with data to be processed.", active);
|
||||||
|
|
||||||
if (active > 0)
|
if (active > 0)
|
||||||
{
|
{
|
||||||
if ((connection = SocketAccept(serverResult->socket, &connectionConfig)) != NULL)
|
if ((connection = SocketAccept(serverResult->socket, &connectionConfig)) != NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -58,7 +58,7 @@ static void NetworkConnect(void)
|
||||||
ping = true;
|
ping = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Check if we're connected every _delay_ seconds
|
// Check if we're connected every _delay_ seconds
|
||||||
|
|
@ -66,7 +66,7 @@ static void NetworkConnect(void)
|
||||||
if (elapsed > delay)
|
if (elapsed > delay)
|
||||||
{
|
{
|
||||||
if (IsSocketConnected(clientResult->socket)) clientConnected = true;
|
if (IsSocketConnected(clientResult->socket)) clientConnected = true;
|
||||||
|
|
||||||
elapsed = 0.0f;
|
elapsed = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +88,7 @@ static void UpdateNetwork(void)
|
||||||
{
|
{
|
||||||
if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, msglen);
|
if (IsSocketReady(clientResult->socket)) bytesRecv = SocketReceive(clientResult->socket, receiveBuffer, msglen);
|
||||||
if (IsSocketReady(serverResult->socket)) bytesRecv = SocketReceive(serverResult->socket, receiveBuffer, msglen);
|
if (IsSocketReady(serverResult->socket)) bytesRecv = SocketReceive(serverResult->socket, receiveBuffer, msglen);
|
||||||
}
|
}
|
||||||
else if (IsSocketReady(connection)) bytesRecv = SocketReceive(connection, receiveBuffer, msglen);
|
else if (IsSocketReady(connection)) bytesRecv = SocketReceive(connection, receiveBuffer, msglen);
|
||||||
|
|
||||||
// If we received data, was that data a "Ping!" or a "Pong!"
|
// If we received data, was that data a "Ping!" or a "Pong!"
|
||||||
|
|
@ -107,14 +107,14 @@ static void UpdateNetwork(void)
|
||||||
ping = false;
|
ping = false;
|
||||||
if (serverConfig.type == SOCKET_UDP && clientConfig.type == SOCKET_UDP) SocketSend(clientResult->socket, pingmsg, msglen);
|
if (serverConfig.type == SOCKET_UDP && clientConfig.type == SOCKET_UDP) SocketSend(clientResult->socket, pingmsg, msglen);
|
||||||
else SocketSend(clientResult->socket, pingmsg, msglen);
|
else SocketSend(clientResult->socket, pingmsg, msglen);
|
||||||
}
|
}
|
||||||
else if (pong)
|
else if (pong)
|
||||||
{
|
{
|
||||||
pong = false;
|
pong = false;
|
||||||
if (serverConfig.type == SOCKET_UDP && clientConfig.type == SOCKET_UDP) SocketSend(clientResult->socket, pongmsg, msglen);
|
if (serverConfig.type == SOCKET_UDP && clientConfig.type == SOCKET_UDP) SocketSend(clientResult->socket, pongmsg, msglen);
|
||||||
else SocketSend(clientResult->socket, pongmsg, msglen);
|
else SocketSend(clientResult->socket, pongmsg, msglen);
|
||||||
}
|
}
|
||||||
|
|
||||||
elapsed = 0.0f;
|
elapsed = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +132,7 @@ int main(void)
|
||||||
|
|
||||||
// Create the server: getaddrinfo + socket + setsockopt + bind + listen
|
// Create the server: getaddrinfo + socket + setsockopt + bind + listen
|
||||||
serverResult = LoadSocketResult();
|
serverResult = LoadSocketResult();
|
||||||
if (!SocketCreate(&serverConfig, serverResult))
|
if (!SocketCreate(&serverConfig, serverResult))
|
||||||
{
|
{
|
||||||
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
TraceLog(LOG_WARNING, "Failed to open server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||||
}
|
}
|
||||||
|
|
@ -141,7 +141,7 @@ int main(void)
|
||||||
if (!SocketBind(&serverConfig, serverResult))
|
if (!SocketBind(&serverConfig, serverResult))
|
||||||
{
|
{
|
||||||
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
TraceLog(LOG_WARNING, "Failed to bind server: status %d, errno %d", serverResult->status, serverResult->socket->status);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!(serverConfig.type == SOCKET_UDP))
|
if (!(serverConfig.type == SOCKET_UDP))
|
||||||
|
|
@ -156,7 +156,7 @@ int main(void)
|
||||||
|
|
||||||
// Create the client: getaddrinfo + socket + setsockopt + connect (TCP only)
|
// Create the client: getaddrinfo + socket + setsockopt + connect (TCP only)
|
||||||
clientResult = LoadSocketResult();
|
clientResult = LoadSocketResult();
|
||||||
if (!SocketCreate(&clientConfig, clientResult))
|
if (!SocketCreate(&clientConfig, clientResult))
|
||||||
{
|
{
|
||||||
TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d", clientResult->status, clientResult->socket->status);
|
TraceLog(LOG_WARNING, "Failed to open client: status %d, errno %d", clientResult->status, clientResult->socket->status);
|
||||||
}
|
}
|
||||||
|
|
@ -194,7 +194,7 @@ int main(void)
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
// TODO: Draw relevant connection info
|
// TODO: Draw relevant connection info
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
@ -204,7 +204,7 @@ int main(void)
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
CloseNetworkDevice(); // Close network communication
|
CloseNetworkDevice(); // Close network communication
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,17 +22,17 @@ int main(void)
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [network] example - resolve host");
|
InitWindow(screenWidth, screenHeight, "raylib [network] example - resolve host");
|
||||||
|
|
||||||
InitNetworkDevice(); // Init network communications
|
InitNetworkDevice(); // Init network communications
|
||||||
|
|
||||||
char buffer[ADDRESS_IPV6_ADDRSTRLEN];
|
char buffer[ADDRESS_IPV6_ADDRSTRLEN];
|
||||||
unsigned short port = 0;
|
unsigned short port = 0;
|
||||||
|
|
||||||
AddressInformation *address = LoadAddressList(1);
|
AddressInformation *address = LoadAddressList(1);
|
||||||
|
|
||||||
// Address info flags
|
// Address info flags
|
||||||
// ADDRESS_INFO_NUMERICHOST // or try them in conjunction to
|
// ADDRESS_INFO_NUMERICHOST // or try them in conjunction to
|
||||||
// ADDRESS_INFO_NUMERICSERV // specify custom behaviour from
|
// ADDRESS_INFO_NUMERICSERV // specify custom behaviour from
|
||||||
// ADDRESS_INFO_DNS_ONLY // the function getaddrinfo()
|
// ADDRESS_INFO_DNS_ONLY // the function getaddrinfo()
|
||||||
// ADDRESS_INFO_ALL //
|
// ADDRESS_INFO_ALL //
|
||||||
// ADDRESS_INFO_FQDN // e.g. ADDRESS_INFO_CANONNAME | ADDRESS_INFO_NUMERICSERV
|
// ADDRESS_INFO_FQDN // e.g. ADDRESS_INFO_CANONNAME | ADDRESS_INFO_NUMERICSERV
|
||||||
|
|
@ -70,7 +70,7 @@ int main(void)
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
CloseNetworkDevice(); // Close network communication
|
CloseNetworkDevice(); // Close network communication
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue