diff options
| author | Ray <raysan5@gmail.com> | 2019-06-06 23:52:53 +0200 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2019-06-06 23:52:53 +0200 |
| commit | dee602464bcf17d6be6e0bbe215ed79140d11a8f (patch) | |
| tree | d04d625a5cd54760f4f3bae0faea46cadb5d853e /examples | |
| parent | baf225dc01250bb5c2918b854c24c6e45ccdea4d (diff) | |
| parent | e1f3f84e84c3f3b8cb831791b8400e50340e4064 (diff) | |
| download | raylib-dee602464bcf17d6be6e0bbe215ed79140d11a8f.tar.gz raylib-dee602464bcf17d6be6e0bbe215ed79140d11a8f.zip | |
Merge branch 'master' of https://github.com/raysan5/raylib
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/models/models_animation.c | 4 | ||||
| -rw-r--r-- | examples/models/models_waving_cubes.c | 112 | ||||
| -rw-r--r-- | examples/models/models_waving_cubes.png | bin | 0 -> 37712 bytes | |||
| -rw-r--r-- | examples/text/resources/pixantiqua.fnt | 2 | ||||
| -rw-r--r-- | examples/text/resources/pixantiqua.png (renamed from examples/text/resources/pixantiqua_0.png) | bin | 4531 -> 4531 bytes |
5 files changed, 116 insertions, 2 deletions
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) * ********************************************************************************************/ diff --git a/examples/models/models_waving_cubes.c b/examples/models/models_waving_cubes.c new file mode 100644 index 00000000..f6309bd6 --- /dev/null +++ b/examples/models/models_waving_cubes.c @@ -0,0 +1,112 @@ +/******************************************************************************************* +* +* 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) +* +* Example contributed by Codecat (@codecat) and reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2019 Codecat (@codecat) and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include <math.h> + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [models] example - waving cubes"); + + // Initialize the 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 }; + 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); + } + } + } + + EndMode3D(); + + DrawFPS(10, 10); + + 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 Binary files differnew file mode 100644 index 00000000..37a1761e --- /dev/null +++ b/examples/models/models_waving_cubes.png 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_0.png b/examples/text/resources/pixantiqua.png Binary files differindex 2aa2870f..2aa2870f 100644 --- a/examples/text/resources/pixantiqua_0.png +++ b/examples/text/resources/pixantiqua.png |
