aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay San <raysan5@gmail.com>2018-04-11 10:13:00 +0200
committerRay San <raysan5@gmail.com>2018-04-11 10:13:00 +0200
commit4cc12ef2b32f66f160e4e401e5cd76d1740eaf61 (patch)
treef9a43a0d3e69aa430e3a8152bb6b5b9268c3b1be
parentcc3b8645df23ed9aeb9d6efc806ab91170a29a89 (diff)
downloadraylib-4cc12ef2b32f66f160e4e401e5cd76d1740eaf61.tar.gz
raylib-4cc12ef2b32f66f160e4e401e5cd76d1740eaf61.zip
Review camera definition on examples
-rw-r--r--examples/core/core_3d_camera_first_person.c7
-rw-r--r--examples/core/core_world_screen.c7
-rw-r--r--examples/models/models_billboard.c8
-rw-r--r--examples/models/models_box_collisions.c2
-rw-r--r--examples/models/models_cubicmap.c2
-rw-r--r--examples/models/models_geometric_shapes.c7
-rw-r--r--examples/models/models_heightmap.c2
-rw-r--r--examples/models/models_material_pbr.c2
-rw-r--r--examples/models/models_mesh_generation.c2
-rw-r--r--examples/models/models_obj_loading.c7
-rw-r--r--examples/models/models_orthographic_projection.c37
-rw-r--r--examples/models/models_skybox.c2
-rw-r--r--examples/models/models_yaw_pitch_roll.c1
-rw-r--r--examples/shaders/shaders_custom_uniform.c7
-rw-r--r--examples/shaders/shaders_model_shader.c7
-rw-r--r--examples/shaders/shaders_postprocessing.c2
-rw-r--r--src/raylib.h14
17 files changed, 69 insertions, 47 deletions
diff --git a/examples/core/core_3d_camera_first_person.c b/examples/core/core_3d_camera_first_person.c
index 3998af81..775e6c57 100644
--- a/examples/core/core_3d_camera_first_person.c
+++ b/examples/core/core_3d_camera_first_person.c
@@ -23,7 +23,12 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
// Define the camera to look into our 3d world (position, target, up vector)
- Camera camera = {{ 4.0f, 2.0f, 4.0f }, { 0.0f, 1.8f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 60.0f };
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 4.0f, 2.0f, 4.0f };
+ camera.target = (Vector3){ 0.0f, 1.8f, 0.0f };
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
+ camera.fovy = 60.0f;
+ camera.type = CAMERA_PERSPECTIVE;
// Generates some random columns
float heights[MAX_COLUMNS];
diff --git a/examples/core/core_world_screen.c b/examples/core/core_world_screen.c
index f8c53c70..78ca6eb4 100644
--- a/examples/core/core_world_screen.c
+++ b/examples/core/core_world_screen.c
@@ -21,7 +21,12 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
// Define the camera to look into our 3d world
- Camera camera = {{ 10.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 10.0f, 10.0f, 10.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;
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
diff --git a/examples/models/models_billboard.c b/examples/models/models_billboard.c
index bca9faf8..3b3efc47 100644
--- a/examples/models/models_billboard.c
+++ b/examples/models/models_billboard.c
@@ -21,7 +21,13 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
// Define the camera to look into our 3d world
- Camera camera = {{ 5.0f, 4.0f, 5.0f }, { 0.0f, 2.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 5.0f, 4.0f, 5.0f };
+ camera.target = (Vector3){ 0.0f, 2.0f, 0.0f };
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
+ 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
diff --git a/examples/models/models_box_collisions.c b/examples/models/models_box_collisions.c
index 69cec418..eb72c54c 100644
--- a/examples/models/models_box_collisions.c
+++ b/examples/models/models_box_collisions.c
@@ -21,7 +21,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions");
// 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 }, 45.0f };
+ Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
Vector3 playerPosition = { 0.0f, 1.0f, 2.0f };
Vector3 playerSize = { 1.0f, 2.0f, 1.0f };
diff --git a/examples/models/models_cubicmap.c b/examples/models/models_cubicmap.c
index d8be9329..47b88748 100644
--- a/examples/models/models_cubicmap.c
+++ b/examples/models/models_cubicmap.c
@@ -21,7 +21,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
// Define the camera to look into our 3d world
- Camera camera = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
+ Camera camera = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
diff --git a/examples/models/models_geometric_shapes.c b/examples/models/models_geometric_shapes.c
index a13a1f3b..7a1e7e48 100644
--- a/examples/models/models_geometric_shapes.c
+++ b/examples/models/models_geometric_shapes.c
@@ -21,7 +21,12 @@ int main()
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 }, 45.0f };
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 0.0f, 10.0f, 10.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;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
diff --git a/examples/models/models_heightmap.c b/examples/models/models_heightmap.c
index e476d1b7..55474185 100644
--- a/examples/models/models_heightmap.c
+++ b/examples/models/models_heightmap.c
@@ -21,7 +21,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
// Define our custom camera to look into our 3d world
- Camera camera = {{ 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
+ Camera camera = {{ 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c
index d98d7eac..4ad2c9e7 100644
--- a/examples/models/models_material_pbr.c
+++ b/examples/models/models_material_pbr.c
@@ -34,7 +34,7 @@ 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 = {{ 4.0f, 4.0f, 4.0f }, { 0.0f, 0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
// Load model and PBR material
Model model = LoadModel("resources/pbr/trooper.obj");
diff --git a/examples/models/models_mesh_generation.c b/examples/models/models_mesh_generation.c
index 72222156..d9c28ac2 100644
--- a/examples/models/models_mesh_generation.c
+++ b/examples/models/models_mesh_generation.c
@@ -41,7 +41,7 @@ int main()
for (int i = 0; i < NUM_MODELS; i++) models[i].material.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 };
+ Camera camera = {{ 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
// Model drawing position
Vector3 position = { 0.0f, 0.0f, 0.0f };
diff --git a/examples/models/models_obj_loading.c b/examples/models/models_obj_loading.c
index 70f92168..4f89130f 100644
--- a/examples/models/models_obj_loading.c
+++ b/examples/models/models_obj_loading.c
@@ -21,7 +21,12 @@ 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 };
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 3.0f, 3.0f, 3.0f };
+ camera.target = (Vector3){ 0.0f, 1.5f, 0.0f };
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
+ camera.fovy = 45.0f;
+ camera.type = CAMERA_PERSPECTIVE;
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
diff --git a/examples/models/models_orthographic_projection.c b/examples/models/models_orthographic_projection.c
index 2c2a89d1..cb5ea053 100644
--- a/examples/models/models_orthographic_projection.c
+++ b/examples/models/models_orthographic_projection.c
@@ -4,17 +4,17 @@
*
* This program is heavily based on the geometric objects example
*
-* This example has been created using raylib 1.0 (www.raylib.com)
+* This example has been created using raylib 1.9.7 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2014 Ramon Santamaria (@raysan5)
+* Copyright (c) 2018 Max Danielsson & Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
-#define FOVY_PERSPECTIVE 45.0f
-#define WIDTH_ORTHOGRAPHIC 10.0f
+#define FOVY_PERSPECTIVE 45.0f
+#define WIDTH_ORTHOGRAPHIC 10.0f
int main()
{
@@ -36,15 +36,9 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- // TODO: Update your variables here
- //----------------------------------------------------------------------------------
- //
-
- // Input
- //----------------------------------------------------------------------------------
- if(IsKeyPressed(KEY_SPACE))
+ if (IsKeyPressed(KEY_SPACE))
{
- if(camera.type == CAMERA_PERSPECTIVE)
+ if (camera.type == CAMERA_PERSPECTIVE)
{
camera.fovy = WIDTH_ORTHOGRAPHIC;
camera.type = CAMERA_ORTHOGRAPHIC;
@@ -55,12 +49,10 @@ int main()
camera.type = CAMERA_PERSPECTIVE;
}
}
-
+ //----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
-
-
BeginDrawing();
ClearBackground(RAYWHITE);
@@ -85,19 +77,12 @@ int main()
End3dMode();
- DrawFPS(10, 10);
+ DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY);
- DrawText("Press Spacebar to switch camera type", 10, 40, 24, BLACK);
-
- if(camera.type == CAMERA_ORTHOGRAPHIC)
- {
- DrawText("Orthographic", 10, 65, 24, BLACK);
- }
- else if(camera.type == CAMERA_PERSPECTIVE)
- {
- DrawText("Perspective", 10, 65, 24, BLACK);
- }
+ 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();
//----------------------------------------------------------------------------------
diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c
index 9f0d8c17..700824d3 100644
--- a/examples/models/models_skybox.c
+++ b/examples/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 };
+ Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
// Load skybox model
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
diff --git a/examples/models/models_yaw_pitch_roll.c b/examples/models/models_yaw_pitch_roll.c
index 4fdbd4d7..c559e67b 100644
--- a/examples/models/models_yaw_pitch_roll.c
+++ b/examples/models/models_yaw_pitch_roll.c
@@ -48,6 +48,7 @@ int main()
camera.target = (Vector3){ 0.0f, 12.0f, 0.0f }; // Camera looking at point
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.type = CAMERA_PERSPECTIVE; // Camera type
float pitch = 0.0f;
float roll = 0.0f;
diff --git a/examples/shaders/shaders_custom_uniform.c b/examples/shaders/shaders_custom_uniform.c
index a0f6fd22..4e160455 100644
--- a/examples/shaders/shaders_custom_uniform.c
+++ b/examples/shaders/shaders_custom_uniform.c
@@ -30,7 +30,12 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable");
// 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 };
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 3.0f, 3.0f, 3.0f };
+ camera.target = (Vector3){ 0.0f, 1.5f, 0.0f };
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
+ camera.fovy = 45.0f;
+ camera.type = CAMERA_PERSPECTIVE;
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture (diffuse map)
diff --git a/examples/shaders/shaders_model_shader.c b/examples/shaders/shaders_model_shader.c
index f1a349c6..51acc836 100644
--- a/examples/shaders/shaders_model_shader.c
+++ b/examples/shaders/shaders_model_shader.c
@@ -30,7 +30,12 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader");
// 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 };
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 3.0f, 3.0f, 3.0f };
+ camera.target = (Vector3){ 0.0f, 1.5f, 0.0f };
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
+ camera.fovy = 45.0f;
+ camera.type = CAMERA_PERSPECTIVE;
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
diff --git a/examples/shaders/shaders_postprocessing.c b/examples/shaders/shaders_postprocessing.c
index b8b5f6ae..5eeda896 100644
--- a/examples/shaders/shaders_postprocessing.c
+++ b/examples/shaders/shaders_postprocessing.c
@@ -70,7 +70,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader");
// 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 };
+ Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture (diffuse map)
diff --git a/src/raylib.h b/src/raylib.h
index fd4b9b21..9c50ecf7 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -396,19 +396,13 @@ typedef struct SpriteFont {
CharInfo *chars; // Characters info data
} SpriteFont;
-// Camera projection modes
-typedef enum {
- CAMERA_PERSPECTIVE = 0,
- CAMERA_ORTHOGRAPHIC
-} CameraType;
-
// Camera type, defines a camera position/orientation in 3d space
typedef struct Camera {
Vector3 position; // Camera position
Vector3 target; // Camera target it looks-at
Vector3 up; // Camera up vector (rotation over its axis)
float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
- CameraType type; // Camera type, controlling projection type, either CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC.
+ int type; // Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
} Camera;
// Camera2D type, defines a 2d camera
@@ -673,6 +667,12 @@ typedef enum {
CAMERA_THIRD_PERSON
} CameraMode;
+// Camera projection modes
+typedef enum {
+ CAMERA_PERSPECTIVE = 0,
+ CAMERA_ORTHOGRAPHIC
+} CameraType;
+
// Head Mounted Display devices
typedef enum {
HMD_DEFAULT_DEVICE = 0,