summaryrefslogtreecommitdiffhomepage
path: root/examples/src/models
diff options
context:
space:
mode:
authorRay <[email protected]>2019-05-14 17:57:45 +0200
committerRay <[email protected]>2019-05-14 17:57:45 +0200
commit5a27bcaf7115e46a5123e9857007d940998f0650 (patch)
tree7179c6a1b4d700c9685dd51cc76cb2b2c90b9609 /examples/src/models
parent423fdd699225ee9686c44a606bf83272b4c77802 (diff)
downloadraylib.com-5a27bcaf7115e46a5123e9857007d940998f0650.tar.gz
raylib.com-5a27bcaf7115e46a5123e9857007d940998f0650.zip
Review examples collection -WIP-
WARNING: Examples list has been reviewed but examples haven't been recompiled yet... that's not trivial...
Diffstat (limited to 'examples/src/models')
-rw-r--r--examples/src/models/models_animation.c101
-rw-r--r--examples/src/models/models_billboard.c7
-rw-r--r--examples/src/models/models_cubicmap.c2
-rw-r--r--examples/src/models/models_first_person_maze.c126
-rw-r--r--examples/src/models/models_heightmap.c2
-rw-r--r--examples/src/models/models_material_pbr.c62
-rw-r--r--examples/src/models/models_mesh_generation.c17
-rw-r--r--examples/src/models/models_mesh_picking.c44
-rw-r--r--examples/src/models/models_obj_loading.c27
-rw-r--r--examples/src/models/models_obj_viewer.c127
-rw-r--r--examples/src/models/models_orthographic_projection.c99
-rw-r--r--examples/src/models/models_rlgl_solar_system.c168
-rw-r--r--examples/src/models/models_skybox.c10
-rw-r--r--examples/src/models/models_yaw_pitch_roll.c10
14 files changed, 732 insertions, 70 deletions
diff --git a/examples/src/models/models_animation.c b/examples/src/models/models_animation.c
new file mode 100644
index 0000000..a75241b
--- /dev/null
+++ b/examples/src/models/models_animation.c
@@ -0,0 +1,101 @@
+/*******************************************************************************************
+*
+* raylib [models] example - Load 3d model with animations and play them
+*
+* 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
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - model animation");
+
+ // Define the camera to look into our 3d world
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
+ camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
+ camera.fovy = 45.0f; // Camera field-of-view Y
+ camera.type = CAMERA_PERSPECTIVE; // Camera mode type
+
+
+ Model model = LoadModel("resources/guy/guy.iqm"); // Load the animated model mesh and basic data
+ Texture2D texture = LoadTexture("resources/guy/guytex.png"); // Load model texture and set material
+ SetMaterialTexture(&model.materials[0], MAP_DIFFUSE, texture); // Set model material map texture
+
+ Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
+
+ // Load animation data
+ int animsCount = 0;
+ ModelAnimation *anims = LoadModelAnimations("resources/guy/guyanim.iqm", &animsCount);
+ int animFrameCounter = 0;
+
+ SetCameraMode(camera, CAMERA_FREE); // Set free camera mode
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ UpdateCamera(&camera);
+
+ // Play animation when spacebar is held down
+ if (IsKeyDown(KEY_SPACE))
+ {
+ animFrameCounter++;
+ UpdateModelAnimation(model, anims[0], animFrameCounter);
+ if (animFrameCounter >= anims[0].frameCount) animFrameCounter = 0;
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ BeginMode3D(camera);
+
+ DrawModelEx(model, position, (Vector3){ 1.0f, 0.0f, 0.0f }, -90.0f, (Vector3){ 1.0f, 1.0f, 1.0f }, WHITE);
+
+ for (int i = 0; i < model.boneCount; i++)
+ {
+ DrawCube(anims[0].framePoses[animFrameCounter][i].translation, 0.2f, 0.2f, 0.2f, RED);
+ }
+
+ DrawGrid(10, 1.0f); // Draw a grid
+
+ EndMode3D();
+
+ DrawText("PRESS SPACE to PLAY MODEL ANIMATION", 10, 10, 20, MAROON);
+ DrawText("(c) Guy IQM 3D model by @culacant", screenWidth - 200, screenHeight - 20, 10, GRAY);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ // Unload model animations data
+ for (int i = 0; i < animsCount; i++) UnloadModelAnimation(anims[i]);
+
+ UnloadModel(model); // Unload model
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/examples/src/models/models_billboard.c b/examples/src/models/models_billboard.c
index 8ce6a44..5965571 100644
--- a/examples/src/models/models_billboard.c
+++ b/examples/src/models/models_billboard.c
@@ -28,7 +28,6 @@ int main()
camera.fovy = 45.0f;
camera.type = CAMERA_PERSPECTIVE;
-
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
@@ -52,11 +51,11 @@ int main()
ClearBackground(RAYWHITE);
BeginMode3D(camera);
-
- DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
DrawGrid(10, 1.0f); // Draw a grid
-
+
+ DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
+
EndMode3D();
DrawFPS(10, 10);
diff --git a/examples/src/models/models_cubicmap.c b/examples/src/models/models_cubicmap.c
index c8d62c4..ac24188 100644
--- a/examples/src/models/models_cubicmap.c
+++ b/examples/src/models/models_cubicmap.c
@@ -31,7 +31,7 @@ int main()
// NOTE: By default each cube is mapped to one part of texture atlas
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
- model.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
+ model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
diff --git a/examples/src/models/models_first_person_maze.c b/examples/src/models/models_first_person_maze.c
new file mode 100644
index 0000000..093334b
--- /dev/null
+++ b/examples/src/models/models_first_person_maze.c
@@ -0,0 +1,126 @@
+/*******************************************************************************************
+*
+* raylib [models] example - first person maze
+*
+* 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 <stdlib.h> // Required for: free()
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - first person maze");
+
+ // Define the camera to look into our 3d world
+ Camera camera = {{ 0.2f, 0.4f, 0.2f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
+
+ Image imMap = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
+ Texture2D cubicmap = LoadTextureFromImage(imMap); // Convert image to texture to display (VRAM)
+ Mesh mesh = GenMeshCubicmap(imMap, (Vector3){ 1.0f, 1.0f, 1.0f });
+ Model model = LoadModelFromMesh(mesh);
+
+ // NOTE: By default each cube is mapped to one part of texture atlas
+ Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
+ model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
+
+ // Get map image data to be used for collision detection
+ Color *mapPixels = GetImageData(imMap);
+ UnloadImage(imMap); // Unload image from RAM
+
+ Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
+ Vector3 playerPosition = camera.position; // Set player position
+
+ SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set camera mode
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ Vector3 oldCamPos = camera.position; // Store old camera position
+
+ UpdateCamera(&camera); // Update camera
+
+ // Check player collision (we simplify to 2D collision detection)
+ Vector2 playerPos = { camera.position.x, camera.position.z };
+ float playerRadius = 0.1f; // Collision radius (player is modelled as a cilinder for collision)
+
+ int playerCellX = (int)(playerPos.x - mapPosition.x + 0.5f);
+ int playerCellY = (int)(playerPos.y - mapPosition.z + 0.5f);
+
+ // Out-of-limits security check
+ if (playerCellX < 0) playerCellX = 0;
+ else if (playerCellX >= cubicmap.width) playerCellX = cubicmap.width - 1;
+
+ if (playerCellY < 0) playerCellY = 0;
+ else if (playerCellY >= cubicmap.height) playerCellY = cubicmap.height - 1;
+
+ // Check map collisions using image data and player position
+ // TODO: Improvement: Just check player surrounding cells for collision
+ for (int y = 0; y < cubicmap.height; y++)
+ {
+ for (int x = 0; x < cubicmap.width; x++)
+ {
+ if ((mapPixels[y*cubicmap.width + x].r == 255) && // Collision: white pixel, only check R channel
+ (CheckCollisionCircleRec(playerPos, playerRadius,
+ (Rectangle){ mapPosition.x - 0.5f + x*1.0f, mapPosition.z - 0.5f + y*1.0f, 1.0f, 1.0f })))
+ {
+ // Collision detected, reset camera position
+ camera.position = oldCamPos;
+ }
+ }
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ BeginMode3D(camera);
+
+ DrawModel(model, mapPosition, 1.0f, WHITE); // Draw maze map
+ //DrawCubeV(playerPosition, (Vector3){ 0.2f, 0.4f, 0.2f }, RED); // Draw player
+
+ EndMode3D();
+
+ DrawTextureEx(cubicmap, (Vector2){ GetScreenWidth() - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE);
+ DrawRectangleLines(GetScreenWidth() - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);
+
+ // Draw player position radar
+ DrawRectangle(GetScreenWidth() - cubicmap.width*4 - 20 + playerCellX*4, 20 + playerCellY*4, 4, 4, RED);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ free(mapPixels); // Unload color array
+
+ UnloadTexture(cubicmap); // Unload cubicmap texture
+ UnloadTexture(texture); // Unload map texture
+ UnloadModel(model); // Unload map model
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/examples/src/models/models_heightmap.c b/examples/src/models/models_heightmap.c
index d131b12..e0475f1 100644
--- a/examples/src/models/models_heightmap.c
+++ b/examples/src/models/models_heightmap.c
@@ -29,7 +29,7 @@ int main()
Mesh mesh = GenMeshHeightmap(image, (Vector3){ 16, 8, 16 }); // Generate heightmap mesh (RAM and VRAM)
Model model = LoadModelFromMesh(mesh); // Load model from generated mesh
- model.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
+ model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Define model position
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
diff --git a/examples/src/models/models_material_pbr.c b/examples/src/models/models_material_pbr.c
index 9f57634..5c308cf 100644
--- a/examples/src/models/models_material_pbr.c
+++ b/examples/src/models/models_material_pbr.c
@@ -12,6 +12,8 @@
#include "raylib.h"
#include "raymath.h"
+#include <stdio.h>
+
#define RLIGHTS_IMPLEMENTATION
#include "rlights.h"
@@ -34,19 +36,29 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - pbr material");
// Define the camera to look into our 3d world
- Camera camera = {{ 4.0f, 4.0f, 4.0f }, { 0.0f, 0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 4.0f, 4.0f, 4.0f }; // Camera position
+ camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
+ camera.fovy = 45.0f; // Camera field-of-view Y
+ camera.type = CAMERA_PERSPECTIVE; // Camera mode type
// Load model and PBR material
Model model = LoadModel("resources/pbr/trooper.obj");
- model.material = LoadMaterialPBR((Color){ 255, 255, 255, 255 }, 1.0f, 1.0f);
+
+ // Mesh tangents are generated... and uploaded to GPU
+ // NOTE: New VBO for tangents is generated at default location and also binded to mesh VAO
+ MeshTangents(&model.meshes[0]);
+
+ model.materials[0] = LoadMaterialPBR((Color){ 255, 255, 255, 255 }, 1.0f, 1.0f);
// Define lights attributes
// NOTE: Shader is passed to every light on creation to define shader bindings internally
Light lights[MAX_LIGHTS] = {
- CreateLight(LIGHT_POINT, (Vector3){ LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 0, 255 }, model.material.shader),
- CreateLight(LIGHT_POINT, (Vector3){ 0.0f, LIGHT_HEIGHT, LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 255, 0, 255 }, model.material.shader),
- CreateLight(LIGHT_POINT, (Vector3){ -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 0, 255, 255 }, model.material.shader),
- CreateLight(LIGHT_DIRECTIONAL, (Vector3){ 0.0f, LIGHT_HEIGHT*2.0f, -LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 255, 255 }, model.material.shader)
+ CreateLight(LIGHT_POINT, (Vector3){ LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 0, 255 }, model.materials[0].shader),
+ CreateLight(LIGHT_POINT, (Vector3){ 0.0f, LIGHT_HEIGHT, LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 255, 0, 255 }, model.materials[0].shader),
+ CreateLight(LIGHT_POINT, (Vector3){ -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 0, 255, 255 }, model.materials[0].shader),
+ CreateLight(LIGHT_DIRECTIONAL, (Vector3){ 0.0f, LIGHT_HEIGHT*2.0f, -LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 255, 255 }, model.materials[0].shader)
};
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
@@ -63,7 +75,7 @@ int main()
// Send to material PBR shader camera view position
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
- SetShaderValue(model.material.shader, model.material.shader.locs[LOC_VECTOR_VIEW], cameraPos, 3);
+ SetShaderValue(model.materials[0].shader, model.materials[0].shader.locs[LOC_VECTOR_VIEW], cameraPos, UNIFORM_VEC3);
//----------------------------------------------------------------------------------
// Draw
@@ -72,13 +84,13 @@ int main()
ClearBackground(RAYWHITE);
- Begin3dMode(camera);
+ BeginMode3D(camera);
DrawModel(model, Vector3Zero(), 1.0f, WHITE);
DrawGrid(10, 1.0f);
- End3dMode();
+ EndMode3D();
DrawFPS(10, 10);
@@ -113,7 +125,7 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
mat.shader.locs[LOC_MAP_METALNESS] = GetShaderLocation(mat.shader, "metalness.sampler");
mat.shader.locs[LOC_MAP_NORMAL] = GetShaderLocation(mat.shader, "normals.sampler");
mat.shader.locs[LOC_MAP_ROUGHNESS] = GetShaderLocation(mat.shader, "roughness.sampler");
- mat.shader.locs[LOC_MAP_OCCUSION] = GetShaderLocation(mat.shader, "occlusion.sampler");
+ mat.shader.locs[LOC_MAP_OCCLUSION] = GetShaderLocation(mat.shader, "occlusion.sampler");
//mat.shader.locs[LOC_MAP_EMISSION] = GetShaderLocation(mat.shader, "emission.sampler");
//mat.shader.locs[LOC_MAP_HEIGHT] = GetShaderLocation(mat.shader, "height.sampler");
mat.shader.locs[LOC_MAP_IRRADIANCE] = GetShaderLocation(mat.shader, "irradianceMap");
@@ -121,7 +133,7 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
mat.shader.locs[LOC_MAP_BRDF] = GetShaderLocation(mat.shader, "brdfLUT");
// Set view matrix location
- mat.shader.locs[LOC_MATRIX_MODEL] = GetShaderLocation(mat.shader, "mMatrix");
+ mat.shader.locs[LOC_MATRIX_MODEL] = GetShaderLocation(mat.shader, "matModel");
mat.shader.locs[LOC_MATRIX_VIEW] = GetShaderLocation(mat.shader, "view");
mat.shader.locs[LOC_VECTOR_VIEW] = GetShaderLocation(mat.shader, "viewPos");
@@ -142,20 +154,24 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
#define PATH_BRDF_FS "resources/shaders/brdf.fs" // Path to bidirectional reflectance distribution function fragment shader
Shader shdrCubemap = LoadShader(PATH_CUBEMAP_VS, PATH_CUBEMAP_FS);
+ printf("Loaded shader: cubemap\n");
Shader shdrIrradiance = LoadShader(PATH_SKYBOX_VS, PATH_IRRADIANCE_FS);
+ printf("Loaded shader: irradiance\n");
Shader shdrPrefilter = LoadShader(PATH_SKYBOX_VS, PATH_PREFILTER_FS);
+ printf("Loaded shader: prefilter\n");
Shader shdrBRDF = LoadShader(PATH_BRDF_VS, PATH_BRDF_FS);
+ printf("Loaded shader: brdf\n");
// Setup required shader locations
- SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1);
- SetShaderValuei(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, 1);
- SetShaderValuei(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, 1);
+ SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
+ SetShaderValue(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT);
+ SetShaderValue(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT);
- Texture2D texHDR = LoadTexture("resources/pinetree.hdr");
+ Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
Texture2D cubemap = GenTextureCubemap(shdrCubemap, texHDR, CUBEMAP_SIZE);
mat.maps[MAP_IRRADIANCE].texture = GenTextureIrradiance(shdrIrradiance, cubemap, IRRADIANCE_SIZE);
mat.maps[MAP_PREFILTER].texture = GenTexturePrefilter(shdrPrefilter, cubemap, PREFILTERED_SIZE);
- mat.maps[MAP_BRDF].texture = GenTextureBRDF(shdrBRDF, cubemap, BRDF_SIZE);
+ mat.maps[MAP_BRDF].texture = GenTextureBRDF(shdrBRDF, BRDF_SIZE);
UnloadTexture(cubemap);
UnloadTexture(texHDR);
@@ -173,14 +189,14 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
SetTextureFilter(mat.maps[MAP_OCCLUSION].texture, FILTER_BILINEAR);
// Enable sample usage in shader for assigned textures
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1]){ 1 }, 1);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
int renderModeLoc = GetShaderLocation(mat.shader, "renderMode");
- SetShaderValuei(mat.shader, renderModeLoc, (int[1]){ 0 }, 1);
+ SetShaderValue(mat.shader, renderModeLoc, (int[1]){ 0 }, UNIFORM_INT);
// Set up material properties color
mat.maps[MAP_ALBEDO].color = albedo;
@@ -192,4 +208,4 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
mat.maps[MAP_HEIGHT].value = 0.5f;
return mat;
-} \ No newline at end of file
+}
diff --git a/examples/src/models/models_mesh_generation.c b/examples/src/models/models_mesh_generation.c
index c02bd91..2b4b75a 100644
--- a/examples/src/models/models_mesh_generation.c
+++ b/examples/src/models/models_mesh_generation.c
@@ -11,7 +11,7 @@
#include "raylib.h"
-#define NUM_MODELS 7 // We generate 7 parametric 3d shapes
+#define NUM_MODELS 8 // We generate 8 parametric 3d shapes
int main()
{
@@ -36,9 +36,10 @@ int main()
models[4] = LoadModelFromMesh(GenMeshCylinder(1, 2, 16));
models[5] = LoadModelFromMesh(GenMeshTorus(0.25f, 4.0f, 16, 32));
models[6] = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128));
+ models[7] = LoadModelFromMesh(GenMeshPoly(5, 2.0f));
// Set checked texture as default diffuse component for all models material
- for (int i = 0; i < NUM_MODELS; i++) models[i].material.maps[MAP_DIFFUSE].texture = texture;
+ for (int i = 0; i < NUM_MODELS; i++) models[i].materials[0].maps[MAP_DIFFUSE].texture = texture;
// Define the camera to look into our 3d world
Camera camera = {{ 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
@@ -64,6 +65,17 @@ int main()
{
currentModel = (currentModel + 1)%NUM_MODELS; // Cycle between the textures
}
+
+ if (IsKeyPressed(KEY_RIGHT))
+ {
+ currentModel++;
+ if (currentModel >= NUM_MODELS) currentModel = 0;
+ }
+ else if (IsKeyPressed(KEY_LEFT))
+ {
+ currentModel--;
+ if (currentModel < 0) currentModel = NUM_MODELS - 1;
+ }
//----------------------------------------------------------------------------------
// Draw
@@ -93,6 +105,7 @@ int main()
case 4: DrawText("CYLINDER", 680, 10, 20, DARKBLUE); break;
case 5: DrawText("TORUS", 680, 10, 20, DARKBLUE); break;
case 6: DrawText("KNOT", 680, 10, 20, DARKBLUE); break;
+ case 7: DrawText("POLY", 680, 10, 20, DARKBLUE); break;
default: break;
}
diff --git a/examples/src/models/models_mesh_picking.c b/examples/src/models/models_mesh_picking.c
index e150fe9..4202882 100644
--- a/examples/src/models/models_mesh_picking.c
+++ b/examples/src/models/models_mesh_picking.c
@@ -13,7 +13,7 @@
#include "raylib.h"
#include "raymath.h"
-#define FLT_MAX 3.40282347E+38F // Maximum value of a float, defined in <float.h>
+#define FLT_MAX 340282346638528859811704183484516925440.0f // Maximum value of a float, from bit pattern 01111111011111111111111111111111
int main()
{
@@ -25,20 +25,21 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh picking");
// Define the camera to look into our 3d world
- Camera camera;
- camera.position = (Vector3){ 10.0f, 8.0f, 10.0f }; // Camera position
- camera.target = (Vector3){ 0.0f, 2.3f, 0.0f }; // Camera looking at point
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 20.0f, 20.0f, 20.0f }; // Camera position
+ camera.target = (Vector3){ 0.0f, 8.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.6f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y
+ camera.type = CAMERA_PERSPECTIVE; // Camera mode type
- Ray ray; // Picking ray
+ Ray ray = { 0 }; // Picking ray
- Model tower = LoadModel("resources/tower.obj"); // Load OBJ model
- Texture2D texture = LoadTexture("resources/tower.png"); // Load model texture
- tower.material.maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture
+ Model tower = LoadModel("resources/models/turret.obj"); // Load OBJ model
+ Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load model texture
+ tower.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture
Vector3 towerPos = { 0.0f, 0.0f, 0.0f }; // Set model position
- BoundingBox towerBBox = CalculateBoundingBox(tower.mesh);
+ BoundingBox towerBBox = MeshBoundingBox(tower.meshes[0]); // Get mesh bounding box
bool hitMeshBBox = false;
bool hitTriangle = false;
@@ -61,7 +62,7 @@ int main()
UpdateCamera(&camera); // Update camera
// Display information about closest hit
- RayHitInfo nearestHit;
+ RayHitInfo nearestHit = { 0 };
char *hitObjectName = "None";
nearestHit.distance = FLT_MAX;
nearestHit.hit = false;
@@ -94,15 +95,16 @@ int main()
}
else hitTriangle = false;
- RayHitInfo meshHitInfo;
+ RayHitInfo meshHitInfo = { 0 };
// Check ray collision against bounding box first, before trying the full ray-mesh test
if (CheckCollisionRayBox(ray, towerBBox))
{
hitMeshBBox = true;
- // Check ray collision against mesh
- meshHitInfo = GetCollisionRayMesh(ray, &tower.mesh);
+ // Check ray collision against model
+ // NOTE: It considers model.transform matrix!
+ meshHitInfo = GetCollisionRayModel(ray, &tower);
if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance))
{
@@ -111,7 +113,9 @@ int main()
hitObjectName = "Mesh";
}
- } hitMeshBBox = false;
+ }
+
+ hitMeshBBox = false;
//----------------------------------------------------------------------------------
// Draw
@@ -120,10 +124,12 @@ int main()
ClearBackground(RAYWHITE);
- Begin3dMode(camera);
+ BeginMode3D(camera);
// Draw the tower
- DrawModel(tower, towerPos, 1.0, WHITE);
+ // WARNING: If scale is different than 1.0f,
+ // not considered by GetCollisionRayModel()
+ DrawModel(tower, towerPos, 1.0f, WHITE);
// Draw the test triangle
DrawLine3D(ta, tb, PURPLE);
@@ -149,9 +155,9 @@ int main()
DrawRay(ray, MAROON);
- DrawGrid(100, 1.0f);
+ DrawGrid(10, 10.0f);
- End3dMode();
+ EndMode3D();
// Draw some debug GUI text
DrawText(FormatText("Hit Object: %s", hitObjectName), 10, 50, 10, BLACK);
@@ -176,6 +182,8 @@ int main()
}
DrawText("Use Mouse to Move Camera", 10, 430, 10, GRAY);
+
+ DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawFPS(10, 10);
diff --git a/examples/src/models/models_obj_loading.c b/examples/src/models/models_obj_loading.c
index 70f9216..74e7d08 100644
--- a/examples/src/models/models_obj_loading.c
+++ b/examples/src/models/models_obj_loading.c
@@ -21,11 +21,16 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading");
// Define the camera to look into our 3d world
- Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
-
- Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
- Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
- dwarf.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 8.0f, 8.0f, 8.0f }; // Camera position
+ camera.target = (Vector3){ 0.0f, 2.5f, 0.0f }; // Camera looking at point
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
+ camera.fovy = 45.0f; // Camera field-of-view Y
+ camera.type = CAMERA_PERSPECTIVE; // Camera mode type
+
+ Model model = LoadModel("resources/models/castle.obj"); // Load OBJ model
+ Texture2D texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture
+ model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
@@ -45,17 +50,17 @@ int main()
ClearBackground(RAYWHITE);
- Begin3dMode(camera);
+ BeginMode3D(camera);
- DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
+ DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture
DrawGrid(10, 1.0f); // Draw a grid
DrawGizmo(position); // Draw gizmo
- End3dMode();
-
- DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
+ EndMode3D();
+
+ DrawText("(c) Castle 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawFPS(10, 10);
@@ -66,7 +71,7 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Unload texture
- UnloadModel(dwarf); // Unload model
+ UnloadModel(model); // Unload model
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
diff --git a/examples/src/models/models_obj_viewer.c b/examples/src/models/models_obj_viewer.c
new file mode 100644
index 0000000..7d38744
--- /dev/null
+++ b/examples/src/models/models_obj_viewer.c
@@ -0,0 +1,127 @@
+/*******************************************************************************************
+*
+* raylib [models] example - OBJ models viewer
+*
+* This example has been created using raylib 2.0 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#include <string.h> // Required for: strcpy()
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib example - obj viewer");
+
+ // Define the camera to look into our 3d world
+ Camera camera = {{ 30.0f, 30.0f, 30.0f }, { 0.0f, 10.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
+
+ Model model = LoadModel("resources/models/turret.obj"); // Load default model obj
+ Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load default model texture
+ model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Bind texture to model
+
+ Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
+ BoundingBox bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds
+ bool selected = false; // Selected object flag
+
+ SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
+
+ char objFilename[64] = "turret.obj";
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ if (IsFileDropped())
+ {
+ int count = 0;
+ char **droppedFiles = GetDroppedFiles(&count);
+
+ if (count == 1)
+ {
+ if (IsFileExtension(droppedFiles[0], ".obj"))
+ {
+ for (int i = 0; i < model.meshCount; i++) UnloadMesh(&model.meshes[i]);
+ model.meshes = LoadMeshes(droppedFiles[0], &model.meshCount);
+ bounds = MeshBoundingBox(model.meshes[0]);
+ }
+ else if (IsFileExtension(droppedFiles[0], ".png"))
+ {
+ UnloadTexture(texture);
+ texture = LoadTexture(droppedFiles[0]);
+ model.materials[0].maps[MAP_DIFFUSE].texture = texture;
+ }
+
+ strcpy(objFilename, GetFileName(droppedFiles[0]));
+ }
+
+ ClearDroppedFiles(); // Clear internal buffers
+ }
+
+ UpdateCamera(&camera);
+
+ // Select model on mouse click
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
+ {
+ // Check collision between ray and box
+ if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) selected = !selected;
+ else selected = false;
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ BeginMode3D(camera);
+
+ DrawModel(model, position, 1.0f, WHITE); // Draw 3d model with texture
+
+ DrawGrid(20.0, 10.0); // Draw a grid
+
+ if (selected) DrawBoundingBox(bounds, GREEN);
+
+ EndMode3D();
+
+ DrawText("Free camera default controls:", 10, 20, 10, DARKGRAY);
+ DrawText("- Mouse Wheel to Zoom in-out", 20, 40, 10, GRAY);
+ DrawText("- Mouse Wheel Pressed to Pan", 20, 60, 10, GRAY);
+ DrawText("- Alt + Mouse Wheel Pressed to Rotate", 20, 80, 10, GRAY);
+ DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 20, 100, 10, GRAY);
+
+ DrawText("Drag & drop .obj/.png to load mesh/texture.", 10, GetScreenHeight() - 20, 10, DARKGRAY);
+ DrawText(FormatText("Current file: %s", objFilename), 250, GetScreenHeight() - 20, 10, GRAY);
+ if (selected) DrawText("MODEL SELECTED", GetScreenWidth() - 110, 10, 10, GREEN);
+
+ DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadModel(model); // Unload model
+
+ ClearDroppedFiles(); // Clear internal buffers
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/src/models/models_orthographic_projection.c b/examples/src/models/models_orthographic_projection.c
new file mode 100644
index 0000000..3ad32b6
--- /dev/null
+++ b/examples/src/models/models_orthographic_projection.c
@@ -0,0 +1,99 @@
+/*******************************************************************************************
+*
+* raylib [models] example - Show the difference between perspective and orthographic projection
+*
+* This program is heavily based on the geometric objects example
+*
+* This example has been created using raylib 2.0 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Example contributed by Max Danielsson (@autious) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Max Danielsson (@autious) and Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#define FOVY_PERSPECTIVE 45.0f
+#define WIDTH_ORTHOGRAPHIC 10.0f
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
+
+ // Define the camera to look into our 3d world
+ Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, FOVY_PERSPECTIVE, CAMERA_PERSPECTIVE };
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ if (IsKeyPressed(KEY_SPACE))
+ {
+ if (camera.type == CAMERA_PERSPECTIVE)
+ {
+ camera.fovy = WIDTH_ORTHOGRAPHIC;
+ camera.type = CAMERA_ORTHOGRAPHIC;
+ }
+ else
+ {
+ camera.fovy = FOVY_PERSPECTIVE;
+ camera.type = CAMERA_PERSPECTIVE;
+ }
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ BeginMode3D(camera);
+
+ DrawCube((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, RED);
+ DrawCubeWires((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, GOLD);
+ DrawCubeWires((Vector3){-4.0f, 0.0f, -2.0f}, 3.0f, 6.0f, 2.0f, MAROON);
+
+ DrawSphere((Vector3){-1.0f, 0.0f, -2.0f}, 1.0f, GREEN);
+ DrawSphereWires((Vector3){1.0f, 0.0f, 2.0f}, 2.0f, 16, 16, LIME);
+
+ DrawCylinder((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
+ DrawCylinderWires((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
+ DrawCylinderWires((Vector3){4.5f, -1.0f, 2.0f}, 1.0f, 1.0f, 2.0f, 6, BROWN);
+
+ DrawCylinder((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, GOLD);
+ DrawCylinderWires((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, PINK);
+
+ DrawGrid(10, 1.0f); // Draw a grid
+
+ EndMode3D();
+
+ DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY);
+
+ if (camera.type == CAMERA_ORTHOGRAPHIC) DrawText("ORTHOGRAPHIC", 10, 40, 20, BLACK);
+ else if (camera.type == CAMERA_PERSPECTIVE) DrawText("PERSPECTIVE", 10, 40, 20, BLACK);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/examples/src/models/models_rlgl_solar_system.c b/examples/src/models/models_rlgl_solar_system.c
new file mode 100644
index 0000000..7193d6f
--- /dev/null
+++ b/examples/src/models/models_rlgl_solar_system.c
@@ -0,0 +1,168 @@
+/*******************************************************************************************
+*
+* raylib [models] example - rlgl module usage with push/pop matrix transformations
+*
+* This example uses [rlgl] module funtionality (pseudo-OpenGL 1.1 style coding)
+*
+* This example has been created using raylib 2.2 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2018 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+#include "rlgl.h"
+
+//------------------------------------------------------------------------------------
+// Module Functions Declaration
+//------------------------------------------------------------------------------------
+void DrawSphereBasic(Color color); // Draw sphere without any matrix transformation
+
+//------------------------------------------------------------------------------------
+// Program main entry point
+//------------------------------------------------------------------------------------
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ const float sunRadius = 4.0f;
+ const float earthRadius = 0.6f;
+ const float earthOrbitRadius = 8.0f;
+ const float moonRadius = 0.16f;
+ const float moonOrbitRadius = 1.5f;
+
+ InitWindow(screenWidth, screenHeight, "raylib [models] example - rlgl module usage with push/pop matrix transformations");
+
+ // Define the camera to look into our 3d world
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 16.0f, 16.0f, 16.0f };
+ camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
+ camera.fovy = 45.0f;
+ camera.type = CAMERA_PERSPECTIVE;
+
+ SetCameraMode(camera, CAMERA_FREE);
+
+ float rotationSpeed = 0.2f; // General system rotation speed
+
+ float earthRotation = 0.0f; // Rotation of earth around itself (days) in degrees
+ float earthOrbitRotation = 0.0f; // Rotation of earth around the Sun (years) in degrees
+ float moonRotation = 0.0f; // Rotation of moon around itself
+ float moonOrbitRotation = 0.0f; // Rotation of moon around earth in degrees
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ UpdateCamera(&camera);
+
+ earthRotation += (5.0f*rotationSpeed);
+ earthOrbitRotation += (365/360.0f*(5.0f*rotationSpeed)*rotationSpeed);
+ moonRotation += (2.0f*rotationSpeed);
+ moonOrbitRotation += (8.0f*rotationSpeed);
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ BeginMode3D(camera);
+
+ rlPushMatrix();
+ rlScalef(sunRadius, sunRadius, sunRadius); // Scale Sun
+ DrawSphereBasic(GOLD); // Draw the Sun
+ rlPopMatrix();
+
+ rlPushMatrix();
+ rlRotatef(earthOrbitRotation, 0.0f, 1.0f, 0.0f); // Rotation for Earth orbit around Sun
+ rlTranslatef(earthOrbitRadius, 0.0f, 0.0f); // Translation for Earth orbit
+ rlRotatef(-earthOrbitRotation, 0.0f, 1.0f, 0.0f); // Rotation for Earth orbit around Sun inverted
+
+ rlPushMatrix();
+ rlRotatef(earthRotation, 0.25, 1.0, 0.0); // Rotation for Earth itself
+ rlScalef(earthRadius, earthRadius, earthRadius);// Scale Earth
+
+ DrawSphereBasic(BLUE); // Draw the Earth
+ rlPopMatrix();
+
+ rlRotatef(moonOrbitRotation, 0.0f, 1.0f, 0.0f); // Rotation for Moon orbit around Earth
+ rlTranslatef(moonOrbitRadius, 0.0f, 0.0f); // Translation for Moon orbit
+ rlRotatef(-moonOrbitRotation, 0.0f, 1.0f, 0.0f); // Rotation for Moon orbit around Earth inverted
+ rlRotatef(moonRotation, 0.0f, 1.0f, 0.0f); // Rotation for Moon itself
+ rlScalef(moonRadius, moonRadius, moonRadius); // Scale Moon
+
+ DrawSphereBasic(LIGHTGRAY); // Draw the Moon
+ rlPopMatrix();
+
+ // Some reference elements (not affected by previous matrix transformations)
+ DrawCircle3D((Vector3){ 0.0f, 0.0f, 0.0f }, earthOrbitRadius, (Vector3){ 1, 0, 0 }, 90.0f, Fade(RED, 0.5f));
+ DrawGrid(20, 1.0f);
+
+ EndMode3D();
+
+ DrawText("EARTH ORBITING AROUND THE SUN!", 400, 10, 20, MAROON);
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
+
+//--------------------------------------------------------------------------------------------
+// Module Functions Definitions (local)
+//--------------------------------------------------------------------------------------------
+
+// Draw sphere without any matrix transformation
+// NOTE: Sphere is drawn in world position ( 0, 0, 0 ) with radius 1.0f
+void DrawSphereBasic(Color color)
+{
+ int rings = 16;
+ int slices = 16;
+
+ rlBegin(RL_TRIANGLES);
+ rlColor4ub(color.r, color.g, color.b, color.a);
+
+ for (int i = 0; i < (rings + 2); i++)
+ {
+ for (int j = 0; j < slices; j++)
+ {
+ rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*i))*sinf(DEG2RAD*(j*360/slices)),
+ sinf(DEG2RAD*(270+(180/(rings + 1))*i)),
+ cosf(DEG2RAD*(270+(180/(rings + 1))*i))*cosf(DEG2RAD*(j*360/slices)));
+ rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*sinf(DEG2RAD*((j+1)*360/slices)),
+ sinf(DEG2RAD*(270+(180/(rings + 1))*(i+1))),
+ cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*cosf(DEG2RAD*((j+1)*360/slices)));
+ rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*sinf(DEG2RAD*(j*360/slices)),
+ sinf(DEG2RAD*(270+(180/(rings + 1))*(i+1))),
+ cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*cosf(DEG2RAD*(j*360/slices)));
+
+ rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*i))*sinf(DEG2RAD*(j*360/slices)),
+ sinf(DEG2RAD*(270+(180/(rings + 1))*i)),
+ cosf(DEG2RAD*(270+(180/(rings + 1))*i))*cosf(DEG2RAD*(j*360/slices)));
+ rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i)))*sinf(DEG2RAD*((j+1)*360/slices)),
+ sinf(DEG2RAD*(270+(180/(rings + 1))*(i))),
+ cosf(DEG2RAD*(270+(180/(rings + 1))*(i)))*cosf(DEG2RAD*((j+1)*360/slices)));
+ rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*sinf(DEG2RAD*((j+1)*360/slices)),
+ sinf(DEG2RAD*(270+(180/(rings + 1))*(i+1))),
+ cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*cosf(DEG2RAD*((j+1)*360/slices)));
+ }
+ }
+ rlEnd();
+}
diff --git a/examples/src/models/models_skybox.c b/examples/src/models/models_skybox.c
index 6f6002b..759c79c 100644
--- a/examples/src/models/models_skybox.c
+++ b/examples/src/models/models_skybox.c
@@ -21,7 +21,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
// Define the camera to look into our 3d world
- Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
+ Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 4.0f, 1.0f, 4.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
// Load skybox model
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
@@ -29,19 +29,19 @@ int main()
// Load skybox shader and set required locations
// NOTE: Some locations are automatically set at shader loading
- skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
- SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, 1);
+ skybox.materials[0].shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
+ SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, UNIFORM_INT);
// Load cubemap shader and setup required shader locations
Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs");
- SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1);
+ SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
// Load HDR panorama (sphere) texture
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
// Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture
// NOTE: New texture is generated rendering to texture, shader computes the sphre->cube coordinates mapping
- skybox.material.maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512);
+ skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512);
UnloadTexture(texHDR); // Texture not required anymore, cubemap already generated
UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore
diff --git a/examples/src/models/models_yaw_pitch_roll.c b/examples/src/models/models_yaw_pitch_roll.c
index 652f168..658be08 100644
--- a/examples/src/models/models_yaw_pitch_roll.c
+++ b/examples/src/models/models_yaw_pitch_roll.c
@@ -5,9 +5,9 @@
* This example has been created using raylib 1.8 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Example based on Berni work on Raspberry Pi
+* Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5)
*
-* Copyright (c) 2017 Ramon Santamaria (@raysan5)
+* Copyright (c) 2017 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@@ -37,10 +37,10 @@ int main()
RenderTexture2D framebuffer = LoadRenderTexture(192, 192);
// Model loading
- Model model = LoadModel("resources/plane.obj"); // Load OBJ model
- model.material.maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture
+ Model model = LoadModel("resources/plane.obj"); // Load OBJ model
+ model.materials[0].maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture
- GenTextureMipmaps(&model.material.maps[MAP_DIFFUSE].texture);
+ GenTextureMipmaps(&model.materials[0].maps[MAP_DIFFUSE].texture);
Camera camera = { 0 };
camera.position = (Vector3){ 0.0f, 60.0f, -120.0f };// Camera position perspective