diff options
| author | Crydsch Cube <[email protected]> | 2023-02-14 17:47:21 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-14 17:47:21 +0100 |
| commit | 73989a49817225f11f547d270598e93745bf7df0 (patch) | |
| tree | c5ab826343e7b131c1e3733924156add0d445dbc /examples/models | |
| parent | f1bcabcc3799df741d54593980ac06afe2e0f081 (diff) | |
| download | raylib-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/models')
| -rw-r--r-- | examples/models/models_animation.c | 5 | ||||
| -rw-r--r-- | examples/models/models_billboard.c | 6 | ||||
| -rw-r--r-- | examples/models/models_cubicmap.c | 5 | ||||
| -rw-r--r-- | examples/models/models_first_person_maze.c | 5 | ||||
| -rw-r--r-- | examples/models/models_heightmap.c | 5 | ||||
| -rw-r--r-- | examples/models/models_loading.c | 5 | ||||
| -rw-r--r-- | examples/models/models_loading_gltf.c | 6 | ||||
| -rw-r--r-- | examples/models/models_loading_m3d.c | 5 | ||||
| -rw-r--r-- | examples/models/models_loading_vox.c | 5 | ||||
| -rw-r--r-- | examples/models/models_mesh_generation.c | 5 | ||||
| -rw-r--r-- | examples/models/models_mesh_picking.c | 14 | ||||
| -rw-r--r-- | examples/models/models_rlgl_solar_system.c | 5 | ||||
| -rw-r--r-- | examples/models/models_skybox.c | 5 |
13 files changed, 34 insertions, 42 deletions
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()) |
