diff options
| author | raysan5 <raysan5@gmail.com> | 2015-08-28 14:14:12 +0200 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2015-08-28 14:14:12 +0200 |
| commit | 322ca97c24f214d665cad512a70a696b489ecb52 (patch) | |
| tree | 1c790c99af617e9bf8453ce63622341b22071161 /src/camera.c | |
| parent | ef36950b72fa97785320396cd62ed48318a2b431 (diff) | |
| download | raylib-322ca97c24f214d665cad512a70a696b489ecb52.tar.gz raylib-322ca97c24f214d665cad512a70a696b489ecb52.zip | |
Review camera system
Diffstat (limited to 'src/camera.c')
| -rw-r--r-- | src/camera.c | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/src/camera.c b/src/camera.c index 627451fe..5c4d9ade 100644 --- a/src/camera.c +++ b/src/camera.c @@ -123,6 +123,7 @@ static int IsKeyDown(int key) { return 0; } //---------------------------------------------------------------------------------- // Select camera mode (multiple camera modes available) +// TODO: Review hardcoded values when changing modes... void SetCameraMode(int mode) { if ((cameraMode == CAMERA_FIRST_PERSON) && (mode == CAMERA_FREE)) @@ -144,7 +145,7 @@ void SetCameraMode(int mode) cameraTargetDistance = 10; cameraAngle.x = 45 * DEG2RAD; cameraAngle.y = -40 * DEG2RAD; - internalCamera.target = (Vector3){ 0, 0, 0}; + internalCamera.target = (Vector3){ 0, 0, 0 }; ProcessCamera(&internalCamera, &internalCamera.position); ShowCursor(); @@ -154,7 +155,7 @@ void SetCameraMode(int mode) cameraTargetDistance = 10; cameraAngle.x = 225 * DEG2RAD; cameraAngle.y = -40 * DEG2RAD; - internalCamera.target = (Vector3){ 3, 0, 3}; + internalCamera.target = (Vector3){ 0, 0, 0}; ProcessCamera(&internalCamera, &internalCamera.position); } @@ -162,6 +163,7 @@ void SetCameraMode(int mode) } // Update camera with position +// TODO: I don't like how this function works right now... not clear enough... Camera UpdateCamera(Vector3 *position) { // Calculate camera @@ -170,41 +172,70 @@ Camera UpdateCamera(Vector3 *position) return internalCamera; } -void SetCameraMoveControls(int frontKey, int backKey, int leftKey, int rightKey, int upKey, int downKey) +// Set internal camera position +void SetCameraPosition(Vector3 position) { - cameraMoveControl[MOVE_FRONT] = frontKey; - cameraMoveControl[MOVE_LEFT] = leftKey; - cameraMoveControl[MOVE_BACK] = backKey; - cameraMoveControl[MOVE_RIGHT] = rightKey; - cameraMoveControl[MOVE_UP] = upKey; - cameraMoveControl[MOVE_DOWN] = downKey; + internalCamera.position = position; + + Vector3 v1 = internalCamera.position; + Vector3 v2 = internalCamera.target; + + float dx = v2.x - v1.x; + float dy = v2.y - v1.y; + float dz = v2.z - v1.z; + + cameraTargetDistance = sqrt(dx*dx + dy*dy + dz*dz); } -void SetCameraMouseSensitivity(float sensitivity) +// Set internal camera target +void SetCameraTarget(Vector3 target) { - mouseSensitivity = (sensitivity / 10000.0); + internalCamera.target = target; + + Vector3 v1 = internalCamera.position; + Vector3 v2 = internalCamera.target; + + float dx = v2.x - v1.x; + float dy = v2.y - v1.y; + float dz = v2.z - v1.z; + + cameraTargetDistance = sqrt(dx*dx + dy*dy + dz*dz); } +// Set camera pan key to combine with mouse movement (free camera) void SetCameraPanControl(int panKey) { panControlKey = panKey; } +// Set camera alt key to combine with mouse movement (free camera) void SetCameraAltControl(int altKey) { altControlKey = altKey; } +// Set camera smooth zoom key to combine with mouse (free camera) void SetCameraSmoothZoomControl(int szKey) { smoothZoomControlKey = szKey; } -void SetCameraTarget(Vector3 target) +// Set camera move controls (1st person and 3rd person cameras) +void SetCameraMoveControls(int frontKey, int backKey, int leftKey, int rightKey, int upKey, int downKey) { - internalCamera.target = target; + cameraMoveControl[MOVE_FRONT] = frontKey; + cameraMoveControl[MOVE_LEFT] = leftKey; + cameraMoveControl[MOVE_BACK] = backKey; + cameraMoveControl[MOVE_RIGHT] = rightKey; + cameraMoveControl[MOVE_UP] = upKey; + cameraMoveControl[MOVE_DOWN] = downKey; } +// Set camera mouse sensitivity (1st person and 3rd person cameras) +void SetCameraMouseSensitivity(float sensitivity) +{ + mouseSensitivity = (sensitivity / 10000.0); +} //---------------------------------------------------------------------------------- // Module specific Functions Definition @@ -298,7 +329,7 @@ static void ProcessCamera(Camera *camera, Vector3 *playerPosition) } else if ((camera->position.y < camera->target.y) && (camera->target.y > 0) && (mouseWheelMove > 0)) { - cameraTargetDistance -= (mouseWheelMove * CAMERA_SCROLL_SENSITIVITY); + cameraTargetDistance -= (mouseWheelMove*CAMERA_SCROLL_SENSITIVITY); if (cameraTargetDistance < FREE_CAMERA_DISTANCE_MIN_CLAMP) cameraTargetDistance = FREE_CAMERA_DISTANCE_MIN_CLAMP; } |
