mirror of https://github.com/raysan5/raylib
Make the oribital camera work like it used to (it is not just a copy of third person) (#2926)
This commit is contained in:
parent
beb44f1dac
commit
9eaed07b77
|
@ -55,8 +55,6 @@ int main(void)
|
||||||
float distanceRotating;
|
float distanceRotating;
|
||||||
float rotation = 0.0f;
|
float rotation = 0.0f;
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,6 @@ int main(void)
|
||||||
|
|
||||||
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
|
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,6 @@ int main(void)
|
||||||
|
|
||||||
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,6 @@ int main(void)
|
||||||
|
|
||||||
int currentModel = 0;
|
int currentModel = 0;
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -68,8 +68,6 @@ int main(void)
|
||||||
|
|
||||||
int currentModel = 0;
|
int currentModel = 0;
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,6 @@ int main(void)
|
||||||
float moonRotation = 0.0f; // Rotation of moon around itself
|
float moonRotation = 0.0f; // Rotation of moon around itself
|
||||||
float moonOrbitRotation = 0.0f; // Rotation of moon around earth in degrees
|
float moonOrbitRotation = 0.0f; // Rotation of moon around earth in degrees
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,6 @@ int main(void)
|
||||||
lights[2] = CreateLight(LIGHT_POINT, (Vector3){ -2, 1, 2 }, Vector3Zero(), GREEN, shader);
|
lights[2] = CreateLight(LIGHT_POINT, (Vector3){ -2, 1, 2 }, Vector3Zero(), GREEN, shader);
|
||||||
lights[3] = CreateLight(LIGHT_POINT, (Vector3){ 2, 1, -2 }, Vector3Zero(), BLUE, shader);
|
lights[3] = CreateLight(LIGHT_POINT, (Vector3){ 2, 1, -2 }, Vector3Zero(), BLUE, shader);
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,6 @@ int main(void)
|
||||||
// Using just 1 point lights
|
// Using just 1 point lights
|
||||||
CreateLight(LIGHT_POINT, (Vector3){ 0, 2, 6 }, Vector3Zero(), WHITE, shader);
|
CreateLight(LIGHT_POINT, (Vector3){ 0, 2, 6 }, Vector3Zero(), WHITE, shader);
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,6 @@ int main(void)
|
||||||
// Camera FOV is pre-calculated in the camera Distance.
|
// Camera FOV is pre-calculated in the camera Distance.
|
||||||
double camDist = 1.0/(tan(camera.fovy*0.5*DEG2RAD));
|
double camDist = 1.0/(tan(camera.fovy*0.5*DEG2RAD));
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,6 @@ int main(void)
|
||||||
Material matDefault = LoadMaterialDefault();
|
Material matDefault = LoadMaterialDefault();
|
||||||
matDefault.maps[MATERIAL_MAP_DIFFUSE].color = BLUE;
|
matDefault.maps[MATERIAL_MAP_DIFFUSE].color = BLUE;
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,6 @@ int main(void)
|
||||||
// Create a RenderTexture2D to be used for render to texture
|
// Create a RenderTexture2D to be used for render to texture
|
||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,6 @@ int main(void)
|
||||||
.projection = CAMERA_PERSPECTIVE // Camera projection type
|
.projection = CAMERA_PERSPECTIVE // Camera projection type
|
||||||
};
|
};
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ Matrix GetCameraProjectionMatrix(Camera* camera, float aspect);
|
||||||
#define CAMERA_MOUSE_MOVE_SENSITIVITY 0.003f // TODO: it should be independant of framerate
|
#define CAMERA_MOUSE_MOVE_SENSITIVITY 0.003f // TODO: it should be independant of framerate
|
||||||
#define CAMERA_MOUSE_SCROLL_SENSITIVITY 1.5f
|
#define CAMERA_MOUSE_SCROLL_SENSITIVITY 1.5f
|
||||||
|
|
||||||
#define CAMERA_ORBITAL_SPEED 0.01f // Radians per frame
|
#define CAMERA_ORBITAL_SPEED 0.5f // Radians per second
|
||||||
|
|
||||||
|
|
||||||
#define CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER 8.0f
|
#define CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER 8.0f
|
||||||
|
@ -418,30 +418,44 @@ void UpdateCamera(Camera *camera, int mode)
|
||||||
bool rotateAroundTarget = mode == CAMERA_THIRD_PERSON || mode == CAMERA_ORBITAL;
|
bool rotateAroundTarget = mode == CAMERA_THIRD_PERSON || mode == CAMERA_ORBITAL;
|
||||||
bool lockView = mode == CAMERA_FIRST_PERSON || mode == CAMERA_THIRD_PERSON || mode == CAMERA_ORBITAL;
|
bool lockView = mode == CAMERA_FIRST_PERSON || mode == CAMERA_THIRD_PERSON || mode == CAMERA_ORBITAL;
|
||||||
bool rotateUp = mode == CAMERA_FREE;
|
bool rotateUp = mode == CAMERA_FREE;
|
||||||
|
|
||||||
// Camera rotation
|
|
||||||
if (IsKeyDown(KEY_DOWN)) CameraPitch(camera, -CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
|
|
||||||
if (IsKeyDown(KEY_UP)) CameraPitch(camera, CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
|
|
||||||
if (IsKeyDown(KEY_RIGHT)) CameraYaw(camera, -CAMERA_ROTATION_SPEED, rotateAroundTarget);
|
|
||||||
if (IsKeyDown(KEY_LEFT)) CameraYaw(camera, CAMERA_ROTATION_SPEED, rotateAroundTarget);
|
|
||||||
if (IsKeyDown(KEY_Q)) CameraRoll(camera, -CAMERA_ROTATION_SPEED);
|
|
||||||
if (IsKeyDown(KEY_E)) CameraRoll(camera, CAMERA_ROTATION_SPEED);
|
|
||||||
|
|
||||||
CameraYaw(camera, -mousePositionDelta.x*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
|
|
||||||
CameraPitch(camera, -mousePositionDelta.y*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
|
|
||||||
|
|
||||||
// Camera movement
|
|
||||||
if (IsKeyDown(KEY_W)) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
|
||||||
if (IsKeyDown(KEY_A)) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
|
||||||
if (IsKeyDown(KEY_S)) CameraMoveForward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
|
||||||
if (IsKeyDown(KEY_D)) CameraMoveRight(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
|
||||||
//if (IsKeyDown(KEY_SPACE)) CameraMoveUp(camera, CAMERA_MOVE_SPEED);
|
|
||||||
//if (IsKeyDown(KEY_LEFT_CONTROL)) CameraMoveUp(camera, -CAMERA_MOVE_SPEED);
|
|
||||||
|
|
||||||
// Zoom target distance
|
if (mode == CAMERA_ORBITAL)
|
||||||
CameraMoveToTarget(camera, -GetMouseWheelMove());
|
{
|
||||||
if (IsKeyPressed(KEY_KP_SUBTRACT)) CameraMoveToTarget(camera, 2.0f);
|
// Obital can just orbit
|
||||||
if (IsKeyPressed(KEY_KP_ADD)) CameraMoveToTarget(camera, -2.0f);
|
Matrix rotatation = MatrixRotate(GetCameraUp(camera), CAMERA_ORBITAL_SPEED * GetFrameTime());
|
||||||
|
Vector3 viewVector = Vector3Subtract(camera->position, camera->target);
|
||||||
|
viewVector = Vector3Transform(viewVector, rotatation);
|
||||||
|
camera->position = Vector3Add(camera->target, viewVector);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Camera rotation
|
||||||
|
if (IsKeyDown(KEY_DOWN)) CameraPitch(camera, -CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
|
||||||
|
if (IsKeyDown(KEY_UP)) CameraPitch(camera, CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
|
||||||
|
if (IsKeyDown(KEY_RIGHT)) CameraYaw(camera, -CAMERA_ROTATION_SPEED, rotateAroundTarget);
|
||||||
|
if (IsKeyDown(KEY_LEFT)) CameraYaw(camera, CAMERA_ROTATION_SPEED, rotateAroundTarget);
|
||||||
|
if (IsKeyDown(KEY_Q)) CameraRoll(camera, -CAMERA_ROTATION_SPEED);
|
||||||
|
if (IsKeyDown(KEY_E)) CameraRoll(camera, CAMERA_ROTATION_SPEED);
|
||||||
|
|
||||||
|
CameraYaw(camera, -mousePositionDelta.x * CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
|
||||||
|
CameraPitch(camera, -mousePositionDelta.y * CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
|
||||||
|
|
||||||
|
// Camera movement
|
||||||
|
if (IsKeyDown(KEY_W)) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||||
|
if (IsKeyDown(KEY_A)) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||||
|
if (IsKeyDown(KEY_S)) CameraMoveForward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||||
|
if (IsKeyDown(KEY_D)) CameraMoveRight(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||||
|
//if (IsKeyDown(KEY_SPACE)) CameraMoveUp(camera, CAMERA_MOVE_SPEED);
|
||||||
|
//if (IsKeyDown(KEY_LEFT_CONTROL)) CameraMoveUp(camera, -CAMERA_MOVE_SPEED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode == CAMERA_THIRD_PERSON || mode == CAMERA_ORBITAL)
|
||||||
|
{
|
||||||
|
// Zoom target distance
|
||||||
|
CameraMoveToTarget(camera, -GetMouseWheelMove());
|
||||||
|
if (IsKeyPressed(KEY_KP_SUBTRACT)) CameraMoveToTarget(camera, 2.0f);
|
||||||
|
if (IsKeyPressed(KEY_KP_ADD)) CameraMoveToTarget(camera, -2.0f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif // !CAMERA_STANDALONE
|
#endif // !CAMERA_STANDALONE
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue