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 <raysan5@gmail.com>
This commit is contained in:
Crydsch Cube
2023-02-14 17:47:21 +01:00
committed by GitHub
parent f1bcabcc37
commit 73989a4981
30 changed files with 996 additions and 477 deletions

View File

@ -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))

View File

@ -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);

View File

@ -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

View File

@ -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 };

View File

@ -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

View File

@ -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())

View File

@ -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

View File

@ -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)
{

View File

@ -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;

View File

@ -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))
{

View File

@ -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);

View File

@ -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);

View File

@ -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())