REVIEWED: UpdateCameraPro() to use Vector3

This commit is contained in:
Ray 2023-03-12 19:40:43 +01:00
parent f9c4cc2040
commit 8ca3212701
2 changed files with 30 additions and 17 deletions

View File

@ -123,15 +123,19 @@ int main(void)
// This new camera function allows custom movement/rotation values to be directly provided // This new camera function allows custom movement/rotation values to be directly provided
// as input parameters, with this approach, rcamera module is internally independent of raylib inputs // as input parameters, with this approach, rcamera module is internally independent of raylib inputs
UpdateCameraPro(&camera, UpdateCameraPro(&camera,
(IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward (Vector3){
(IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f, (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f,
(IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f, (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left
0.0f, // Move up-down (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f,
GetMouseWheelMove()*2.0f, // Move to target (zoom) 0.0f // Move up-down
GetMouseDelta().x*0.05f, // Rotation: yaw },
GetMouseDelta().y*0.05f, // Rotation: pitch (Vector3){
0.0f); // Rotation: roll GetMouseDelta().x*0.05f, // Rotation: yaw
GetMouseDelta().y*0.05f, // Rotation: pitch
0.0f // Rotation: roll
},
GetMouseWheelMove()*2.0f); // Move to target (zoom)
*/ */
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

View File

@ -471,25 +471,34 @@ void UpdateCamera(Camera *camera, int mode)
#endif // !CAMERA_STANDALONE #endif // !CAMERA_STANDALONE
// Update camera movement, movement/rotation values should be provided by user // Update camera movement, movement/rotation values should be provided by user
void UpdateCameraPro(Camera *camera, float moveForward, float moveRightLeft, float moveUpDown, float moveToTarget, float yaw, float pitch, float roll) void UpdateCameraPro(Camera *camera, Vector3 movement, Vector3 rotation, float zoom)
{ {
// Required values
// movement.x - Move forward/backward
// movement.y - Move right/left
// movement.z - Move up/down
// rotation.x - yaw
// rotation.y - pitch
// rotation.z - roll
// zoom - Move towards target
bool lockView = true; bool lockView = true;
bool rotateAroundTarget = false; bool rotateAroundTarget = false;
bool rotateUp = false; bool rotateUp = false;
bool moveInWorldPlane = true; bool moveInWorldPlane = true;
// Camera rotation // Camera rotation
CameraPitch(camera, -pitch*DEG2RAD, lockView, rotateAroundTarget, rotateUp); CameraPitch(camera, -rotation.y*DEG2RAD, lockView, rotateAroundTarget, rotateUp);
CameraYaw(camera, -yaw*DEG2RAD, rotateAroundTarget); CameraYaw(camera, -rotation.x*DEG2RAD, rotateAroundTarget);
CameraRoll(camera, roll*DEG2RAD); CameraRoll(camera, rotation.z*DEG2RAD);
// Camera movement // Camera movement
CameraMoveForward(camera, moveForward, moveInWorldPlane); CameraMoveForward(camera, movement.x, moveInWorldPlane);
CameraMoveRight(camera, moveRightLeft, moveInWorldPlane); CameraMoveRight(camera, movement.y, moveInWorldPlane);
CameraMoveUp(camera, moveUpDown); CameraMoveUp(camera, movement.z);
// Zoom target distance // Zoom target distance
CameraMoveToTarget(camera, moveToTarget); CameraMoveToTarget(camera, zoom);
} }
#endif // CAMERA_IMPLEMENTATION #endif // CAMERA_IMPLEMENTATION