From 923f4b9bbd1af4bff0037807ec0f6e6514c043cd Mon Sep 17 00:00:00 2001 From: Codecat Date: Wed, 5 Jun 2019 10:35:20 +0200 Subject: Added waving cubes example --- examples/models/models_waving_cubes.c | 105 ++++++++++++++++++++++++++++++++ examples/models/models_waving_cubes.png | Bin 0 -> 37712 bytes 2 files changed, 105 insertions(+) create mode 100644 examples/models/models_waving_cubes.c create mode 100644 examples/models/models_waving_cubes.png (limited to 'examples') diff --git a/examples/models/models_waving_cubes.c b/examples/models/models_waving_cubes.c new file mode 100644 index 00000000..0fefbcf2 --- /dev/null +++ b/examples/models/models_waving_cubes.c @@ -0,0 +1,105 @@ +/******************************************************************************************* +* +* raylib [models] example - Waving cubes +* +* This example has been created using raylib 2.5 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2019 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [models] example - waving cubes"); + + // Initialize the camera + Camera3D camera; + camera.position = (Vector3){ 30.0f, 20.0f, 30.0f }; + camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 70.0f; + camera.type = CAMERA_PERSPECTIVE; + + // Specify the amount of blocks in each direction + const int numBlocks = 15; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + double time = GetTime(); + + // Calculate time scale for cube position and size + float scale = (2.0f + (float)sin(time)) * 0.7f; + + // Move camera around the scene + double cameraTime = time * 0.3; + camera.position.x = (float)cos(cameraTime) * 40.0f; + camera.position.z = (float)sin(cameraTime) * 40.0f; + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + BeginMode3D(camera); + + DrawGrid(10, 5.0f); + + for (int x = 0; x < numBlocks; x++) { + for (int y = 0; y < numBlocks; y++) { + for (int z = 0; z < numBlocks; z++) { + // Scale of the blocks depends on x/y/z positions + float blockScale = (x + y + z) / 30.0f; + + // Scatter makes the waving effect by adding blockScale over time + float scatter = sinf(blockScale * 20.0f + (float)(time * 4.0f)); + + // Calculate the cube position + Vector3 cubePos = { + (float)(x - numBlocks / 2) * (scale * 3.0f) + scatter, + (float)(y - numBlocks / 2) * (scale * 2.0f) + scatter, + (float)(z - numBlocks / 2) * (scale * 3.0f) + scatter + }; + + // Pick a color with a hue depending on cube position for the rainbow color effect + Color cubeColor = ColorFromHSV((Vector3){ (float)(((x + y + z) * 18) % 360), 0.75f, 0.9f }); + + // Calculate cube size + float cubeSize = (2.4f - scale) * blockScale; + + // And finally, draw the cube! + DrawCube(cubePos, cubeSize, cubeSize, cubeSize, cubeColor); + } + } + } + + DrawFPS(10, 10); + + EndMode3D(); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/models/models_waving_cubes.png b/examples/models/models_waving_cubes.png new file mode 100644 index 00000000..37a1761e Binary files /dev/null and b/examples/models/models_waving_cubes.png differ -- cgit v1.2.3 From ddaa4a304d5a8fe8bf7fc6d4d94a2bcd01298119 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 5 Jun 2019 12:58:35 +0200 Subject: Review contributor info --- examples/models/models_animation.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/models/models_animation.c b/examples/models/models_animation.c index 294b07a5..7f38b7f5 100644 --- a/examples/models/models_animation.c +++ b/examples/models/models_animation.c @@ -5,7 +5,9 @@ * This example has been created using raylib 2.5 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2019 Ramon Santamaria (@raysan5) and @culacant +* Example contributed by Culacant (@culacant) and reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2019 Culacant (@culacant) and Ramon Santamaria (@raysan5) * ********************************************************************************************/ -- cgit v1.2.3 From 03720b30a135d9acab1f008c7ffb2aa46f8dbffb Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 5 Jun 2019 12:58:53 +0200 Subject: Review contributed example --- examples/models/models_waving_cubes.c | 47 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'examples') diff --git a/examples/models/models_waving_cubes.c b/examples/models/models_waving_cubes.c index 0fefbcf2..f6309bd6 100644 --- a/examples/models/models_waving_cubes.c +++ b/examples/models/models_waving_cubes.c @@ -5,7 +5,9 @@ * This example has been created using raylib 2.5 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2019 Ramon Santamaria (@raysan5) +* Example contributed by Codecat (@codecat) and reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2019 Codecat (@codecat) and Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -23,7 +25,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - waving cubes"); // Initialize the camera - Camera3D camera; + Camera3D camera = { 0 }; camera.position = (Vector3){ 30.0f, 20.0f, 30.0f }; camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; @@ -40,16 +42,18 @@ int main() while (!WindowShouldClose()) // Detect window close button or ESC key { // Update + //---------------------------------------------------------------------------------- double time = GetTime(); // Calculate time scale for cube position and size - float scale = (2.0f + (float)sin(time)) * 0.7f; + float scale = (2.0f + (float)sin(time))*0.7f; // Move camera around the scene - double cameraTime = time * 0.3; - camera.position.x = (float)cos(cameraTime) * 40.0f; - camera.position.z = (float)sin(cameraTime) * 40.0f; - + double cameraTime = time*0.3; + camera.position.x = (float)cos(cameraTime)*40.0f; + camera.position.z = (float)sin(cameraTime)*40.0f; + //---------------------------------------------------------------------------------- + // Draw //---------------------------------------------------------------------------------- BeginDrawing(); @@ -60,37 +64,40 @@ int main() DrawGrid(10, 5.0f); - for (int x = 0; x < numBlocks; x++) { - for (int y = 0; y < numBlocks; y++) { - for (int z = 0; z < numBlocks; z++) { + for (int x = 0; x < numBlocks; x++) + { + for (int y = 0; y < numBlocks; y++) + { + for (int z = 0; z < numBlocks; z++) + { // Scale of the blocks depends on x/y/z positions - float blockScale = (x + y + z) / 30.0f; + float blockScale = (x + y + z)/30.0f; // Scatter makes the waving effect by adding blockScale over time - float scatter = sinf(blockScale * 20.0f + (float)(time * 4.0f)); + float scatter = sinf(blockScale*20.0f + (float)(time*4.0f)); // Calculate the cube position Vector3 cubePos = { - (float)(x - numBlocks / 2) * (scale * 3.0f) + scatter, - (float)(y - numBlocks / 2) * (scale * 2.0f) + scatter, - (float)(z - numBlocks / 2) * (scale * 3.0f) + scatter + (float)(x - numBlocks/2)*(scale*3.0f) + scatter, + (float)(y - numBlocks/2)*(scale*2.0f) + scatter, + (float)(z - numBlocks/2)*(scale*3.0f) + scatter }; // Pick a color with a hue depending on cube position for the rainbow color effect - Color cubeColor = ColorFromHSV((Vector3){ (float)(((x + y + z) * 18) % 360), 0.75f, 0.9f }); + Color cubeColor = ColorFromHSV((Vector3){ (float)(((x + y + z)*18)%360), 0.75f, 0.9f }); // Calculate cube size - float cubeSize = (2.4f - scale) * blockScale; + float cubeSize = (2.4f - scale)*blockScale; // And finally, draw the cube! DrawCube(cubePos, cubeSize, cubeSize, cubeSize, cubeColor); } } } - - DrawFPS(10, 10); - + EndMode3D(); + + DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- -- cgit v1.2.3 From bdbc05c0dc255d36c74415b6802a58178e821943 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 5 Jun 2019 13:35:22 +0200 Subject: Review font --- examples/text/resources/pixantiqua.fnt | 2 +- examples/text/resources/pixantiqua.png | Bin 0 -> 4531 bytes examples/text/resources/pixantiqua_0.png | Bin 4531 -> 0 bytes 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 examples/text/resources/pixantiqua.png delete mode 100644 examples/text/resources/pixantiqua_0.png (limited to 'examples') diff --git a/examples/text/resources/pixantiqua.fnt b/examples/text/resources/pixantiqua.fnt index 971b9b0b..fd9f9dbb 100644 --- a/examples/text/resources/pixantiqua.fnt +++ b/examples/text/resources/pixantiqua.fnt @@ -1,6 +1,6 @@ info face="PixAntiqua" size=32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=2,2,2,2 spacing=2,2 outline=0 common lineHeight=32 base=27 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4 -page id=0 file="pixantiqua_0.png" +page id=0 file="pixantiqua.png" chars count=184 char id=32 x=9 y=304 width=7 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 char id=33 x=391 y=266 width=11 height=36 xoffset=-3 yoffset=-2 xadvance=8 page=0 chnl=15 diff --git a/examples/text/resources/pixantiqua.png b/examples/text/resources/pixantiqua.png new file mode 100644 index 00000000..2aa2870f Binary files /dev/null and b/examples/text/resources/pixantiqua.png differ diff --git a/examples/text/resources/pixantiqua_0.png b/examples/text/resources/pixantiqua_0.png deleted file mode 100644 index 2aa2870f..00000000 Binary files a/examples/text/resources/pixantiqua_0.png and /dev/null differ -- cgit v1.2.3