summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorCrydsch Cube <[email protected]>2023-02-14 17:47:21 +0100
committerGitHub <[email protected]>2023-02-14 17:47:21 +0100
commit73989a49817225f11f547d270598e93745bf7df0 (patch)
treec5ab826343e7b131c1e3733924156add0d445dbc /examples
parentf1bcabcc3799df741d54593980ac06afe2e0f081 (diff)
downloadraylib-73989a49817225f11f547d270598e93745bf7df0.tar.gz
raylib-73989a49817225f11f547d270598e93745bf7df0.zip
WIP rcamera redesign vector (#2563)
* core functionality CAMERA_FREE * fix example * add remaining camera modes * add view bobbing * view bobbing * catch curser in SetCameraMode * adjust examples * fix compilation on linux * fix example text_draw_3d * actually fix text_draw_3d * Updated camera API * Improve Vector3RotateByAxisAngle() function * remove camera.mode dependency from low-level functions * remove camera.mode from struct * fixes after rebase * adjust examples for new UpdateCamera function * adjust example models_loading_m3d --------- Co-authored-by: Ray <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/core/core_3d_camera_first_person.c94
-rw-r--r--examples/core/core_3d_camera_free.c4
-rw-r--r--examples/core/core_3d_picking.c15
-rw-r--r--examples/core/core_vr_simulator.c6
-rw-r--r--examples/core/core_world_screen.c7
-rw-r--r--examples/models/models_animation.c5
-rw-r--r--examples/models/models_billboard.c6
-rw-r--r--examples/models/models_cubicmap.c5
-rw-r--r--examples/models/models_first_person_maze.c5
-rw-r--r--examples/models/models_heightmap.c5
-rw-r--r--examples/models/models_loading.c5
-rw-r--r--examples/models/models_loading_gltf.c6
-rw-r--r--examples/models/models_loading_m3d.c5
-rw-r--r--examples/models/models_loading_vox.c5
-rw-r--r--examples/models/models_mesh_generation.c5
-rw-r--r--examples/models/models_mesh_picking.c14
-rw-r--r--examples/models/models_rlgl_solar_system.c5
-rw-r--r--examples/models/models_skybox.c5
-rw-r--r--examples/shaders/shaders_basic_lighting.c5
-rw-r--r--examples/shaders/shaders_custom_uniform.c6
-rw-r--r--examples/shaders/shaders_fog.c5
-rw-r--r--examples/shaders/shaders_mesh_instancing.c6
-rw-r--r--examples/shaders/shaders_model_shader.c5
-rw-r--r--examples/shaders/shaders_postprocessing.c6
-rw-r--r--examples/shaders/shaders_raymarching.c5
-rw-r--r--examples/shaders/shaders_simple_mask.c3
-rw-r--r--examples/text/text_draw_3d.c9
27 files changed, 157 insertions, 95 deletions
diff --git a/examples/core/core_3d_camera_first_person.c b/examples/core/core_3d_camera_first_person.c
index a7aa5f49..d98a002f 100644
--- a/examples/core/core_3d_camera_first_person.c
+++ b/examples/core/core_3d_camera_first_person.c
@@ -12,6 +12,7 @@
********************************************************************************************/
#include "raylib.h"
+#include "rcamera.h"
#define MAX_COLUMNS 20
@@ -29,11 +30,14 @@ int main(void)
// Define the camera to look into our 3d world (position, target, up vector)
Camera camera = { 0 };
- camera.position = (Vector3){ 4.0f, 2.0f, 4.0f };
- camera.target = (Vector3){ 0.0f, 1.8f, 0.0f };
+ camera.position = (Vector3){ 0.0f, 2.0f, 4.0f };
+ camera.target = (Vector3){ 0.0f, 2.0f, 0.0f };
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
camera.fovy = 60.0f;
camera.projection = CAMERA_PERSPECTIVE;
+ camera.swingCounter = 1; // Enable view bobbing
+
+ int cameraMode = CAMERA_FIRST_PERSON;
// Generates some random columns
float heights[MAX_COLUMNS] = { 0 };
@@ -47,8 +51,7 @@ int main(void)
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
}
- SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -57,7 +60,51 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ // Switch camera mode
+ if (IsKeyPressed(KEY_ONE)) {
+ cameraMode = CAMERA_FREE;
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
+ }
+ if (IsKeyPressed(KEY_TWO)) {
+ cameraMode = CAMERA_FIRST_PERSON;
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
+ }
+ if (IsKeyPressed(KEY_THREE)) {
+ cameraMode = CAMERA_THIRD_PERSON;
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
+ }
+ if (IsKeyPressed(KEY_FOUR)) {
+ cameraMode = CAMERA_ORBITAL;
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
+ }
+
+ // Switch camera projection
+ if (IsKeyPressed(KEY_P)) {
+ if (camera.projection == CAMERA_PERSPECTIVE) {
+ // Create isometric view
+ cameraMode = CAMERA_THIRD_PERSON;
+ // Note: The target distance is related to the render distance in the orthographic projection
+ camera.position = (Vector3){ 0.0f, 2.0f, -100.0f };
+ camera.target = (Vector3){ 0.0f, 2.0f, 0.0f };
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
+ camera.projection = CAMERA_ORTHOGRAPHIC;
+ camera.fovy = 20.0f; // near plane width in CAMERA_ORTHOGRAPHIC
+ CameraYaw(&camera, -135 * DEG2RAD, true);
+ CameraPitch(&camera, -45 * DEG2RAD, true, true, false);
+ }
+ else if (camera.projection == CAMERA_ORTHOGRAPHIC)
+ {
+ // Reset to default view
+ cameraMode = CAMERA_THIRD_PERSON;
+ camera.position = (Vector3){ 0.0f, 2.0f, 10.0f };
+ camera.target = (Vector3){ 0.0f, 2.0f, 0.0f };
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
+ camera.projection = CAMERA_PERSPECTIVE;
+ camera.fovy = 60.0f;
+ }
+ }
+
+ UpdateCamera(&camera, cameraMode); // Update camera
//----------------------------------------------------------------------------------
// Draw
@@ -80,14 +127,39 @@ int main(void)
DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON);
}
- EndMode3D();
+ // Draw player cube
+ if (cameraMode == CAMERA_THIRD_PERSON)
+ {
+ DrawCube(camera.target, 0.5f, 0.5f, 0.5f, PURPLE);
+ DrawCubeWires(camera.target, 0.5f, 0.5f, 0.5f, DARKPURPLE);
+ }
- DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f));
- DrawRectangleLines( 10, 10, 220, 70, BLUE);
+ EndMode3D();
- DrawText("First person camera default controls:", 20, 20, 10, BLACK);
- DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY);
- DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY);
+ // Draw info boxes
+ DrawRectangle(5, 5, 330, 100, Fade(SKYBLUE, 0.5f));
+ DrawRectangleLines(5, 5, 330, 100, BLUE);
+
+ DrawText("Camera controls:", 15, 15, 10, BLACK);
+ DrawText("- Move keys: W, A, S, D, Space, Left-Ctrl", 15, 30, 10, BLACK);
+ DrawText("- Look around: arrow keys or mouse", 15, 45, 10, BLACK);
+ DrawText("- Camera mode keys: 1, 2, 3, 4", 15, 60, 10, BLACK);
+ DrawText("- Zoom keys: num-plus, num-minus or mouse scroll", 15, 75, 10, BLACK);
+ DrawText("- Camera projection key: P", 15, 90, 10, BLACK);
+
+ DrawRectangle(600, 5, 195, 100, Fade(SKYBLUE, 0.5f));
+ DrawRectangleLines(600, 5, 195, 100, BLUE);
+
+ DrawText("Camera status:", 610, 15, 10, BLACK);
+ DrawText(TextFormat("- Mode: %s", (cameraMode == CAMERA_FREE) ? "FREE" :
+ (cameraMode == CAMERA_FIRST_PERSON) ? "FIRST_PERSON" :
+ (cameraMode == CAMERA_THIRD_PERSON) ? "THIRD_PERSON" :
+ (cameraMode == CAMERA_ORBITAL) ? "ORBITAL" : "CUSTOM"), 610, 30, 10, BLACK);
+ DrawText(TextFormat("- Projection: %s", (camera.projection == CAMERA_PERSPECTIVE) ? "PERSPECTIVE" :
+ (camera.projection == CAMERA_ORTHOGRAPHIC) ? "ORTHOGRAPHIC" : "CUSTOM"), 610, 45, 10, BLACK);
+ DrawText(TextFormat("- Position: (%06.3f, %06.3f, %06.3f)", camera.position.x, camera.position.y, camera.position.z), 610, 60, 10, BLACK);
+ DrawText(TextFormat("- Target: (%06.3f, %06.3f, %06.3f)", camera.target.x, camera.target.y, camera.target.z), 610, 75, 10, BLACK);
+ DrawText(TextFormat("- Up: (%06.3f, %06.3f, %06.3f)", camera.up.x, camera.up.y, camera.up.z), 610, 90, 10, BLACK);
EndDrawing();
//----------------------------------------------------------------------------------
diff --git a/examples/core/core_3d_camera_free.c b/examples/core/core_3d_camera_free.c
index af7ab8d7..887a1df3 100644
--- a/examples/core/core_3d_camera_free.c
+++ b/examples/core/core_3d_camera_free.c
@@ -35,8 +35,6 @@ int main(void)
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
- SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
-
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -45,7 +43,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_FREE);
if (IsKeyDown('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
//----------------------------------------------------------------------------------
diff --git a/examples/core/core_3d_picking.c b/examples/core/core_3d_picking.c
index 8c0df966..0cf56f5f 100644
--- a/examples/core/core_3d_picking.c
+++ b/examples/core/core_3d_picking.c
@@ -40,7 +40,7 @@ int main(void)
RayCollision collision = { 0 };
- SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
+ EnableCursor(); // Disable camera controls
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -50,7 +50,14 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ if (IsCursorHidden()) UpdateCamera(&camera, CAMERA_FIRST_PERSON); // Update camera
+
+ // Toggle camera controls
+ if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT))
+ {
+ if (IsCursorHidden()) EnableCursor();
+ else DisableCursor();
+ }
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
@@ -93,10 +100,12 @@ int main(void)
EndMode3D();
- DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY);
+ DrawText("Try clicking on the box with your mouse!", 240, 10, 20, DARKGRAY);
if (collision.hit) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, (int)(screenHeight * 0.1f), 30, GREEN);
+ DrawText("Right click mouse to toggle camera controls", 10, 430, 10, GRAY);
+
DrawFPS(10, 10);
EndDrawing();
diff --git a/examples/core/core_vr_simulator.c b/examples/core/core_vr_simulator.c
index 5914897b..3024b785 100644
--- a/examples/core/core_vr_simulator.c
+++ b/examples/core/core_vr_simulator.c
@@ -96,11 +96,11 @@ int main(void)
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector
camera.fovy = 60.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera type
+ camera.swingCounter = 1; // Enable view bobbing
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
- SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set first person camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(90); // Set our game to run at 90 frames-per-second
//--------------------------------------------------------------------------------------
@@ -109,7 +109,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_FIRST_PERSON);
//----------------------------------------------------------------------------------
// Draw
diff --git a/examples/core/core_world_screen.c b/examples/core/core_world_screen.c
index d86adf87..f96690ba 100644
--- a/examples/core/core_world_screen.c
+++ b/examples/core/core_world_screen.c
@@ -23,7 +23,7 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
- InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - core world screen");
// Define the camera to look into our 3d world
Camera camera = { 0 };
@@ -36,8 +36,7 @@ int main(void)
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
Vector2 cubeScreenPosition = { 0.0f, 0.0f };
- SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -46,7 +45,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_THIRD_PERSON);
// Calculate cube screen space position (with a little offset to be in top)
cubeScreenPosition = GetWorldToScreen((Vector3){cubePosition.x, cubePosition.y + 2.5f, cubePosition.z}, camera);
diff --git a/examples/models/models_animation.c b/examples/models/models_animation.c
index b9216b21..a36f3fe5 100644
--- a/examples/models/models_animation.c
+++ b/examples/models/models_animation.c
@@ -54,8 +54,7 @@ int main(void)
ModelAnimation *anims = LoadModelAnimations("resources/models/iqm/guyanim.iqm", &animsCount);
int animFrameCounter = 0;
- SetCameraMode(camera, CAMERA_FREE); // Set free camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -64,7 +63,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_FIRST_PERSON);
// Play animation when spacebar is held down
if (IsKeyDown(KEY_SPACE))
diff --git a/examples/models/models_billboard.c b/examples/models/models_billboard.c
index ce313949..6d16cf01 100644
--- a/examples/models/models_billboard.c
+++ b/examples/models/models_billboard.c
@@ -48,14 +48,13 @@ int main(void)
// Here we choose to rotate around the image center
// NOTE: (-1, 1) is the range where origin.x, origin.y is inside the texture
Vector2 rotateOrigin = { 0.0f };
- SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
// Distance is needed for the correct billboard draw order
// Larger distance (further away from the camera) should be drawn prior to smaller distance.
float distanceStatic;
float distanceRotating;
-
float rotation = 0.0f;
+
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -64,7 +63,8 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_ORBITAL);
+
rotation += 0.4f;
distanceStatic = Vector3Distance(camera.position, billPositionStatic);
distanceRotating = Vector3Distance(camera.position, billPositionRotating);
diff --git a/examples/models/models_cubicmap.c b/examples/models/models_cubicmap.c
index 4953a99f..83bfab68 100644
--- a/examples/models/models_cubicmap.c
+++ b/examples/models/models_cubicmap.c
@@ -42,8 +42,7 @@ int main(void)
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
- SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -52,7 +51,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_ORBITAL);
//----------------------------------------------------------------------------------
// Draw
diff --git a/examples/models/models_first_person_maze.c b/examples/models/models_first_person_maze.c
index b5e35b58..3f6a935c 100644
--- a/examples/models/models_first_person_maze.c
+++ b/examples/models/models_first_person_maze.c
@@ -45,8 +45,7 @@ int main(void)
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
- SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -57,7 +56,7 @@ int main(void)
//----------------------------------------------------------------------------------
Vector3 oldCamPos = camera.position; // Store old camera position
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_FIRST_PERSON);
// Check player collision (we simplify to 2D collision detection)
Vector2 playerPos = { camera.position.x, camera.position.z };
diff --git a/examples/models/models_heightmap.c b/examples/models/models_heightmap.c
index a5d17b02..25dc004d 100644
--- a/examples/models/models_heightmap.c
+++ b/examples/models/models_heightmap.c
@@ -39,8 +39,7 @@ int main(void)
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
- SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -49,7 +48,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_ORBITAL);
//----------------------------------------------------------------------------------
// Draw
diff --git a/examples/models/models_loading.c b/examples/models/models_loading.c
index 7bdf1772..56dad408 100644
--- a/examples/models/models_loading.c
+++ b/examples/models/models_loading.c
@@ -57,10 +57,9 @@ int main(void)
// NOTE: bounds are calculated from the original size of the model,
// if model is scaled on drawing, bounds must be also scaled
- SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
-
bool selected = false; // Selected object flag
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -69,7 +68,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_FIRST_PERSON);
// Load new models/textures on drag&drop
if (IsFileDropped())
diff --git a/examples/models/models_loading_gltf.c b/examples/models/models_loading_gltf.c
index 92b517a1..0c907071 100644
--- a/examples/models/models_loading_gltf.c
+++ b/examples/models/models_loading_gltf.c
@@ -51,8 +51,6 @@ int main(void)
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
- SetCameraMode(camera, CAMERA_FREE); // Set free camera mode
-
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -61,6 +59,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
+ UpdateCamera(&camera, CAMERA_THIRD_PERSON);
// Select current animation
if (IsKeyPressed(KEY_UP)) animIndex = (animIndex + 1)%animsCount;
else if (IsKeyPressed(KEY_DOWN)) animIndex = (animIndex + animsCount - 1)%animsCount;
@@ -69,9 +68,6 @@ int main(void)
ModelAnimation anim = modelAnimations[animIndex];
animCurrentFrame = (animCurrentFrame + 1)%anim.frameCount;
UpdateModelAnimation(model, anim, animCurrentFrame);
-
- // Update camera
- UpdateCamera(&camera);
//----------------------------------------------------------------------------------
// Draw
diff --git a/examples/models/models_loading_m3d.c b/examples/models/models_loading_m3d.c
index 52dc9522..c1a4af07 100644
--- a/examples/models/models_loading_m3d.c
+++ b/examples/models/models_loading_m3d.c
@@ -53,8 +53,7 @@ int main(void)
int animFrameCounter = 0, animId = 0;
ModelAnimation *anims = LoadModelAnimations(modelFileName, &animsCount); // Load skeletal animation data
- SetCameraMode(camera, CAMERA_FREE); // Set free camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -63,7 +62,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_FIRST_PERSON);
if (animsCount)
{
diff --git a/examples/models/models_loading_vox.c b/examples/models/models_loading_vox.c
index 49477cd9..6a38fe89 100644
--- a/examples/models/models_loading_vox.c
+++ b/examples/models/models_loading_vox.c
@@ -69,8 +69,7 @@ int main(void)
int currentModel = 0;
- SetCameraMode(camera, CAMERA_ORBITAL); // Set a orbital camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -79,7 +78,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_ORBITAL);
// Cycle between models on mouse click
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) currentModel = (currentModel + 1)%MAX_VOX_FILES;
diff --git a/examples/models/models_mesh_generation.c b/examples/models/models_mesh_generation.c
index b4ff018c..8e9fdf90 100644
--- a/examples/models/models_mesh_generation.c
+++ b/examples/models/models_mesh_generation.c
@@ -68,8 +68,7 @@ int main(void)
int currentModel = 0;
- SetCameraMode(camera, CAMERA_ORBITAL); // Set a orbital camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -78,7 +77,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_ORBITAL);
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
diff --git a/examples/models/models_mesh_picking.c b/examples/models/models_mesh_picking.c
index 52f9974d..1118168c 100644
--- a/examples/models/models_mesh_picking.c
+++ b/examples/models/models_mesh_picking.c
@@ -64,8 +64,7 @@ int main(void)
Vector3 sp = (Vector3){ -30.0f, 5.0f, 5.0f };
float sr = 4.0f;
- SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
-
+ EnableCursor(); // Disable camera controls
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
@@ -73,7 +72,14 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ if (IsCursorHidden()) UpdateCamera(&camera, CAMERA_FIRST_PERSON); // Update camera
+
+ // Toggle camera controls
+ if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT))
+ {
+ if (IsCursorHidden()) EnableCursor();
+ else DisableCursor();
+ }
// Display information about closest hit
RayCollision collision = { 0 };
@@ -219,7 +225,7 @@ int main(void)
DrawText(TextFormat("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK);
}
- DrawText("Use Mouse to Move Camera", 10, 430, 10, GRAY);
+ DrawText("Right click mouse to toggle camera controls", 10, 430, 10, GRAY);
DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
diff --git a/examples/models/models_rlgl_solar_system.c b/examples/models/models_rlgl_solar_system.c
index 903752f7..24f8b9a5 100644
--- a/examples/models/models_rlgl_solar_system.c
+++ b/examples/models/models_rlgl_solar_system.c
@@ -49,8 +49,6 @@ int main(void)
camera.fovy = 45.0f;
camera.projection = 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
@@ -58,6 +56,7 @@ int main(void)
float moonRotation = 0.0f; // Rotation of moon around itself
float moonOrbitRotation = 0.0f; // Rotation of moon around earth in degrees
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -66,7 +65,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_ORBITAL);
earthRotation += (5.0f*rotationSpeed);
earthOrbitRotation += (365/360.0f*(5.0f*rotationSpeed)*rotationSpeed);
diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c
index 1b992333..d12cc557 100644
--- a/examples/models/models_skybox.c
+++ b/examples/models/models_skybox.c
@@ -87,8 +87,7 @@ int main(void)
UnloadImage(img);
}
- SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -97,7 +96,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_FIRST_PERSON);
// Load new cubemap texture on drag&drop
if (IsFileDropped())
diff --git a/examples/shaders/shaders_basic_lighting.c b/examples/shaders/shaders_basic_lighting.c
index 1b29b852..702177f1 100644
--- a/examples/shaders/shaders_basic_lighting.c
+++ b/examples/shaders/shaders_basic_lighting.c
@@ -80,8 +80,7 @@ int main(void)
lights[2] = CreateLight(LIGHT_POINT, (Vector3){ -2, 1, 2 }, Vector3Zero(), GREEN, shader);
lights[3] = CreateLight(LIGHT_POINT, (Vector3){ 2, 1, -2 }, Vector3Zero(), BLUE, shader);
- SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -90,7 +89,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_ORBITAL);
// Update the shader with the camera view vector (points towards { 0.0f, 0.0f, 0.0f })
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
diff --git a/examples/shaders/shaders_custom_uniform.c b/examples/shaders/shaders_custom_uniform.c
index 75f6112e..c617a6d1 100644
--- a/examples/shaders/shaders_custom_uniform.c
+++ b/examples/shaders/shaders_custom_uniform.c
@@ -67,9 +67,7 @@ int main(void)
// Create a RenderTexture2D to be used for render to texture
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
- // Setup orbital camera
- SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -78,7 +76,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_ORBITAL);
Vector2 mousePosition = GetMousePosition();
diff --git a/examples/shaders/shaders_fog.c b/examples/shaders/shaders_fog.c
index ac84a018..c4b619ed 100644
--- a/examples/shaders/shaders_fog.c
+++ b/examples/shaders/shaders_fog.c
@@ -84,8 +84,7 @@ int main(void)
// Using just 1 point lights
CreateLight(LIGHT_POINT, (Vector3){ 0, 2, 6 }, Vector3Zero(), WHITE, shader);
- SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -94,7 +93,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_ORBITAL);
if (IsKeyDown(KEY_UP))
{
diff --git a/examples/shaders/shaders_mesh_instancing.c b/examples/shaders/shaders_mesh_instancing.c
index f4e6b40b..0c2f9e1d 100644
--- a/examples/shaders/shaders_mesh_instancing.c
+++ b/examples/shaders/shaders_mesh_instancing.c
@@ -94,9 +94,7 @@ int main(void)
Material matDefault = LoadMaterialDefault();
matDefault.maps[MATERIAL_MAP_DIFFUSE].color = BLUE;
- // Set an orbital camera mode
- SetCameraMode(camera, CAMERA_ORBITAL);
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -105,7 +103,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_ORBITAL);
// Update the light shader with the camera view position
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
diff --git a/examples/shaders/shaders_model_shader.c b/examples/shaders/shaders_model_shader.c
index de3cb5f8..069d0ee2 100644
--- a/examples/shaders/shaders_model_shader.c
+++ b/examples/shaders/shaders_model_shader.c
@@ -60,8 +60,7 @@ int main(void)
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
- SetCameraMode(camera, CAMERA_FREE); // Set an orbital camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -70,7 +69,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_FIRST_PERSON);
//----------------------------------------------------------------------------------
// Draw
diff --git a/examples/shaders/shaders_postprocessing.c b/examples/shaders/shaders_postprocessing.c
index d0555f21..688ca909 100644
--- a/examples/shaders/shaders_postprocessing.c
+++ b/examples/shaders/shaders_postprocessing.c
@@ -107,9 +107,7 @@ int main(void)
// Create a RenderTexture2D to be used for render to texture
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
- // Setup orbital camera
- SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
-
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -118,7 +116,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_ORBITAL);
if (IsKeyPressed(KEY_RIGHT)) currentShader++;
else if (IsKeyPressed(KEY_LEFT)) currentShader--;
diff --git a/examples/shaders/shaders_raymarching.c b/examples/shaders/shaders_raymarching.c
index 9b8bc30c..5cc9af05 100644
--- a/examples/shaders/shaders_raymarching.c
+++ b/examples/shaders/shaders_raymarching.c
@@ -41,8 +41,6 @@ int main(void)
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 65.0f; // Camera field-of-view Y
- SetCameraMode(camera, CAMERA_FREE); // Set camera mode
-
// Load raymarching shader
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/raymarching.fs", GLSL_VERSION));
@@ -58,6 +56,7 @@ int main(void)
float runTime = 0.0f;
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -66,7 +65,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_FIRST_PERSON);
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
float cameraTarget[3] = { camera.target.x, camera.target.y, camera.target.z };
diff --git a/examples/shaders/shaders_simple_mask.c b/examples/shaders/shaders_simple_mask.c
index ce3fc8bb..49470294 100644
--- a/examples/shaders/shaders_simple_mask.c
+++ b/examples/shaders/shaders_simple_mask.c
@@ -85,6 +85,7 @@ int main(void)
int framesCounter = 0;
Vector3 rotation = { 0 }; // Model rotation angles
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -93,7 +94,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, CAMERA_FIRST_PERSON);
framesCounter++;
rotation.x += 0.01f;
diff --git a/examples/text/text_draw_3d.c b/examples/text/text_draw_3d.c
index 127eb7c6..c90ea665 100644
--- a/examples/text/text_draw_3d.c
+++ b/examples/text/text_draw_3d.c
@@ -98,11 +98,12 @@ int main(void)
camera.fovy = 45.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
- SetCameraMode(camera, CAMERA_ORBITAL);
+ int camera_mode = CAMERA_ORBITAL;
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
+ DisableCursor(); // Catch cursor
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
// Use the default font
@@ -141,7 +142,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- UpdateCamera(&camera);
+ UpdateCamera(&camera, camera_mode);
// Handle font files dropped
if (IsFileDropped())
@@ -181,12 +182,12 @@ int main(void)
if (spin)
{
camera.position = (Vector3){ -10.0f, 15.0f, -10.0f }; // Camera position
- SetCameraMode(camera, CAMERA_ORBITAL);
+ camera_mode = CAMERA_ORBITAL;
}
else
{
camera.position = (Vector3){ 10.0f, 10.0f, -10.0f }; // Camera position
- SetCameraMode(camera, CAMERA_FREE);
+ camera_mode = CAMERA_FREE;
}
}