Review camera definition on examples
This commit is contained in:
parent
cc3b8645df
commit
4cc12ef2b3
17 changed files with 70 additions and 48 deletions
|
@ -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];
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
*
|
||||
* 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)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
@ -36,12 +36,6 @@ int main()
|
|||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
// Input
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
if (camera.type == CAMERA_PERSPECTIVE)
|
||||
|
@ -55,12 +49,10 @@ int main()
|
|||
camera.type = CAMERA_PERSPECTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
@ -85,20 +77,13 @@ int main()
|
|||
|
||||
End3dMode();
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
14
src/raylib.h
14
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue