1 /*******************************************************************************************
3 * raylib.camera - Camera system with multiple modes support
5 * NOTE: Memory footprint of this library is aproximately 52 bytes (global variables)
9 * #define CAMERA_IMPLEMENTATION
10 * Generates the implementation of the library into the included file.
11 * If not defined, the library is in header only mode and can be included in other headers
12 * or source files without problems. But only ONE file should hold the implementation.
14 * #define CAMERA_STANDALONE
15 * If defined, the library can be used as standalone as a camera system but some
16 * functions must be redefined to manage inputs accordingly.
19 * Ramon Santamaria: Supervision, review, update and maintenance
20 * Marc Palau: Initial implementation (2014)
23 * LICENSE: zlib/libpng
25 * Copyright (c) 2015-2021 Ramon Santamaria (@raysan5)
27 * This software is provided "as-is", without any express or implied warranty. In no event
28 * will the authors be held liable for any damages arising from the use of this software.
30 * Permission is granted to anyone to use this software for any purpose, including commercial
31 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
33 * 1. The origin of this software must not be misrepresented; you must not claim that you
34 * wrote the original software. If you use this software in a product, an acknowledgment
35 * in the product documentation would be appreciated but is not required.
37 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
38 * as being the original software.
40 * 3. This notice may not be removed or altered from any source distribution.
42 **********************************************************************************************/
47 //----------------------------------------------------------------------------------
49 //----------------------------------------------------------------------------------
52 //----------------------------------------------------------------------------------
53 // Types and Structures Definition
54 // NOTE: Below types are required for CAMERA_STANDALONE usage
55 //----------------------------------------------------------------------------------
56 #if defined(CAMERA_STANDALONE)
58 typedef struct Vector2 {
64 typedef struct Vector3 {
70 // Camera type, defines a camera position/orientation in 3d space
71 typedef struct Camera3D {
72 Vector3 position; // Camera position
73 Vector3 target; // Camera target it looks-at
74 Vector3 up; // Camera up vector (rotation over its axis)
75 float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
76 int type; // Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
79 typedef Camera3D Camera; // Camera type fallback, defaults to Camera3D
81 // Camera system modes
90 // Camera projection modes
92 CAMERA_PERSPECTIVE = 0,
98 extern "C" { // Prevents name mangling of functions
101 //----------------------------------------------------------------------------------
102 // Global Variables Definition
103 //----------------------------------------------------------------------------------
106 //----------------------------------------------------------------------------------
107 // Module Functions Declaration
108 //----------------------------------------------------------------------------------
109 #if defined(CAMERA_STANDALONE)
110 void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available)
111 void UpdateCamera(Camera *camera); // Update camera position for selected mode
113 void SetCameraPanControl(int keyPan); // Set camera pan key to combine with mouse movement (free camera)
114 void SetCameraAltControl(int keyAlt); // Set camera alt key to combine with mouse movement (free camera)
115 void SetCameraSmoothZoomControl(int szoomKey); // Set camera smooth zoom key to combine with mouse (free camera)
116 void SetCameraMoveControls(int keyFront, int keyBack,
117 int keyRight, int keyLeft,
118 int keyUp, int keyDown); // Set camera move controls (1st person and 3rd person cameras)
128 /***********************************************************************************
130 * CAMERA IMPLEMENTATION
132 ************************************************************************************/
134 #if defined(CAMERA_IMPLEMENTATION)
136 #include <math.h> // Required for: sinf(), cosf(), sqrtf()
138 //----------------------------------------------------------------------------------
139 // Defines and Macros
140 //----------------------------------------------------------------------------------
142 #define PI 3.14159265358979323846
145 #define DEG2RAD (PI/180.0f)
148 #define RAD2DEG (180.0f/PI)
151 // Camera mouse movement sensitivity
152 #define CAMERA_MOUSE_MOVE_SENSITIVITY 0.003f
153 #define CAMERA_MOUSE_SCROLL_SENSITIVITY 1.5f
156 #define CAMERA_FREE_MOUSE_SENSITIVITY 0.01f
157 #define CAMERA_FREE_DISTANCE_MIN_CLAMP 0.3f
158 #define CAMERA_FREE_DISTANCE_MAX_CLAMP 120.0f
159 #define CAMERA_FREE_MIN_CLAMP 85.0f
160 #define CAMERA_FREE_MAX_CLAMP -85.0f
161 #define CAMERA_FREE_SMOOTH_ZOOM_SENSITIVITY 0.05f
162 #define CAMERA_FREE_PANNING_DIVIDER 5.1f
165 #define CAMERA_ORBITAL_SPEED 0.01f // Radians per frame
168 //#define CAMERA_FIRST_PERSON_MOUSE_SENSITIVITY 0.003f
169 #define CAMERA_FIRST_PERSON_FOCUS_DISTANCE 25.0f
170 #define CAMERA_FIRST_PERSON_MIN_CLAMP 89.0f
171 #define CAMERA_FIRST_PERSON_MAX_CLAMP -89.0f
173 #define CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER 8.0f
174 #define CAMERA_FIRST_PERSON_STEP_DIVIDER 30.0f
175 #define CAMERA_FIRST_PERSON_WAVING_DIVIDER 200.0f
178 //#define CAMERA_THIRD_PERSON_MOUSE_SENSITIVITY 0.003f
179 #define CAMERA_THIRD_PERSON_DISTANCE_CLAMP 1.2f
180 #define CAMERA_THIRD_PERSON_MIN_CLAMP 5.0f
181 #define CAMERA_THIRD_PERSON_MAX_CLAMP -85.0f
182 #define CAMERA_THIRD_PERSON_OFFSET (Vector3){ 0.4f, 0.0f, 0.0f }
184 // PLAYER (used by camera)
185 #define PLAYER_MOVEMENT_SENSITIVITY 20.0f
187 //----------------------------------------------------------------------------------
188 // Types and Structures Definition
189 //----------------------------------------------------------------------------------
190 // Camera move modes (first person and third person cameras)
200 // Camera global state context data [56 bytes]
202 unsigned int mode; // Current camera mode
203 float targetDistance; // Camera distance from position to target
204 float playerEyesPosition; // Player eyes position from ground (in meters)
205 Vector2 angle; // Camera angle in plane XZ
207 // Camera movement control keys
208 int moveControl[6]; // Move controls (CAMERA_FIRST_PERSON)
209 int smoothZoomControl; // Smooth zoom control key
210 int altControl; // Alternative control key
211 int panControl; // Pan view control key
214 //----------------------------------------------------------------------------------
215 // Global Variables Definition
216 //----------------------------------------------------------------------------------
217 static CameraData CAMERA = { // Global CAMERA state context
220 .playerEyesPosition = 1.85f,
222 .moveControl = { 'W', 'S', 'D', 'A', 'E', 'Q' },
223 .smoothZoomControl = 341, // raylib: KEY_LEFT_CONTROL
224 .altControl = 342, // raylib: KEY_LEFT_ALT
225 .panControl = 2 // raylib: MOUSE_MIDDLE_BUTTON
228 //----------------------------------------------------------------------------------
229 // Module specific Functions Declaration
230 //----------------------------------------------------------------------------------
231 #if defined(CAMERA_STANDALONE)
232 // NOTE: Camera controls depend on some raylib input functions
233 static void EnableCursor() {} // Unlock cursor
234 static void DisableCursor() {} // Lock cursor
236 static int IsKeyDown(int key) { return 0; }
238 static int IsMouseButtonDown(int button) { return 0;}
239 static float GetMouseWheelMove() { return 0.0f; }
240 static Vector2 GetMousePosition() { return (Vector2){ 0.0f, 0.0f }; }
243 //----------------------------------------------------------------------------------
244 // Module Functions Definition
245 //----------------------------------------------------------------------------------
247 // Select camera mode (multiple camera modes available)
248 void SetCameraMode(Camera camera, int mode)
250 Vector3 v1 = camera.position;
251 Vector3 v2 = camera.target;
253 float dx = v2.x - v1.x;
254 float dy = v2.y - v1.y;
255 float dz = v2.z - v1.z;
257 CAMERA.targetDistance = sqrtf(dx*dx + dy*dy + dz*dz); // Distance to target
259 // Camera angle calculation
260 CAMERA.angle.x = atan2f(dx, dz); // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
261 CAMERA.angle.y = atan2f(dy, sqrtf(dx*dx + dz*dz)); // Camera angle in plane XY (0 aligned with X, move positive CW)
263 CAMERA.playerEyesPosition = camera.position.y; // Init player eyes position to camera Y position
265 // Lock cursor for first person and third person cameras
266 if ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON)) DisableCursor();
272 // Update camera depending on selected mode
273 // NOTE: Camera controls depend on some raylib functions:
274 // System: EnableCursor(), DisableCursor()
275 // Mouse: IsMouseButtonDown(), GetMousePosition(), GetMouseWheelMove()
277 // TODO: Port to quaternion-based camera (?)
278 void UpdateCamera(Camera *camera)
280 static int swingCounter = 0; // Used for 1st person swinging movement
281 static Vector2 previousMousePosition = { 0.0f, 0.0f };
283 // TODO: Compute CAMERA.targetDistance and CAMERA.angle here (?)
285 // Mouse movement detection
286 Vector2 mousePositionDelta = { 0.0f, 0.0f };
287 Vector2 mousePosition = GetMousePosition();
288 float mouseWheelMove = GetMouseWheelMove();
290 // Keys input detection
291 // TODO: Input detection is raylib-dependant, it could be moved outside the module
292 bool keyPan = IsMouseButtonDown(CAMERA.panControl);
293 bool keyAlt = IsKeyDown(CAMERA.altControl);
294 bool szoomKey = IsKeyDown(CAMERA.smoothZoomControl);
295 bool direction[6] = { IsKeyDown(CAMERA.moveControl[MOVE_FRONT]),
296 IsKeyDown(CAMERA.moveControl[MOVE_BACK]),
297 IsKeyDown(CAMERA.moveControl[MOVE_RIGHT]),
298 IsKeyDown(CAMERA.moveControl[MOVE_LEFT]),
299 IsKeyDown(CAMERA.moveControl[MOVE_UP]),
300 IsKeyDown(CAMERA.moveControl[MOVE_DOWN]) };
302 if (CAMERA.mode != CAMERA_CUSTOM)
304 mousePositionDelta.x = mousePosition.x - previousMousePosition.x;
305 mousePositionDelta.y = mousePosition.y - previousMousePosition.y;
307 previousMousePosition = mousePosition;
310 // Support for multiple automatic camera modes
311 // NOTE: In case of CAMERA_CUSTOM nothing happens here, user must update it manually
314 case CAMERA_FREE: // Camera free controls, using standard 3d-content-creation scheme
317 if ((CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
319 CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY);
320 if (CAMERA.targetDistance > CAMERA_FREE_DISTANCE_MAX_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MAX_CLAMP;
323 // Camera looking down
324 else if ((camera->position.y > camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
326 camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
327 camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
328 camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
330 else if ((camera->position.y > camera->target.y) && (camera->target.y >= 0))
332 camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
333 camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
334 camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
336 // if (camera->target.y < 0) camera->target.y = -0.001;
338 else if ((camera->position.y > camera->target.y) && (camera->target.y < 0) && (mouseWheelMove > 0))
340 CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY);
341 if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP;
344 else if ((camera->position.y < camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
346 camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
347 camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
348 camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
350 else if ((camera->position.y < camera->target.y) && (camera->target.y <= 0))
352 camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
353 camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
354 camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
356 // if (camera->target.y > 0) camera->target.y = 0.001;
358 else if ((camera->position.y < camera->target.y) && (camera->target.y > 0) && (mouseWheelMove > 0))
360 CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY);
361 if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP;
367 if (keyAlt) // Alternative key behaviour
371 // Camera smooth zoom
372 CAMERA.targetDistance += (mousePositionDelta.y*CAMERA_FREE_SMOOTH_ZOOM_SENSITIVITY);
377 CAMERA.angle.x += mousePositionDelta.x*-CAMERA_FREE_MOUSE_SENSITIVITY;
378 CAMERA.angle.y += mousePositionDelta.y*-CAMERA_FREE_MOUSE_SENSITIVITY;
381 if (CAMERA.angle.y > CAMERA_FREE_MIN_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FREE_MIN_CLAMP*DEG2RAD;
382 else if (CAMERA.angle.y < CAMERA_FREE_MAX_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FREE_MAX_CLAMP*DEG2RAD;
388 camera->target.x += ((mousePositionDelta.x*CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(CAMERA.angle.x) + (mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*sinf(CAMERA.angle.x)*sinf(CAMERA.angle.y))*(CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER);
389 camera->target.y += ((mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(CAMERA.angle.y))*(CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER);
390 camera->target.z += ((mousePositionDelta.x*-CAMERA_FREE_MOUSE_SENSITIVITY)*sinf(CAMERA.angle.x) + (mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(CAMERA.angle.x)*sinf(CAMERA.angle.y))*(CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER);
394 // Update camera position with changes
395 camera->position.x = -sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x;
396 camera->position.y = -sinf(CAMERA.angle.y)*CAMERA.targetDistance + camera->target.y;
397 camera->position.z = -cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z;
400 case CAMERA_ORBITAL: // Camera just orbits around target, only zoom allowed
402 CAMERA.angle.x += CAMERA_ORBITAL_SPEED; // Camera orbit angle
403 CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY); // Camera zoom
405 // Camera distance clamp
406 if (CAMERA.targetDistance < CAMERA_THIRD_PERSON_DISTANCE_CLAMP) CAMERA.targetDistance = CAMERA_THIRD_PERSON_DISTANCE_CLAMP;
408 // Update camera position with changes
409 camera->position.x = sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x;
410 camera->position.y = ((CAMERA.angle.y <= 0.0f)? 1 : -1)*sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y;
411 camera->position.z = cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z;
414 case CAMERA_FIRST_PERSON: // Camera moves as in a first-person game, controls are configurable
416 camera->position.x += (sinf(CAMERA.angle.x)*direction[MOVE_BACK] -
417 sinf(CAMERA.angle.x)*direction[MOVE_FRONT] -
418 cosf(CAMERA.angle.x)*direction[MOVE_LEFT] +
419 cosf(CAMERA.angle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
421 camera->position.y += (sinf(CAMERA.angle.y)*direction[MOVE_FRONT] -
422 sinf(CAMERA.angle.y)*direction[MOVE_BACK] +
423 1.0f*direction[MOVE_UP] - 1.0f*direction[MOVE_DOWN])/PLAYER_MOVEMENT_SENSITIVITY;
425 camera->position.z += (cosf(CAMERA.angle.x)*direction[MOVE_BACK] -
426 cosf(CAMERA.angle.x)*direction[MOVE_FRONT] +
427 sinf(CAMERA.angle.x)*direction[MOVE_LEFT] -
428 sinf(CAMERA.angle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
430 // Camera orientation calculation
431 CAMERA.angle.x += (mousePositionDelta.x*-CAMERA_MOUSE_MOVE_SENSITIVITY);
432 CAMERA.angle.y += (mousePositionDelta.y*-CAMERA_MOUSE_MOVE_SENSITIVITY);
435 if (CAMERA.angle.y > CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD;
436 else if (CAMERA.angle.y < CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD;
438 // Recalculate camera target considering translation and rotation
439 Matrix translation = MatrixTranslate(0, 0, (CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER));
440 Matrix rotation = MatrixRotateXYZ((Vector3){ PI*2 - CAMERA.angle.y, PI*2 - CAMERA.angle.x, 0 });
441 Matrix transform = MatrixMultiply(translation, rotation);
443 camera->target.x = camera->position.x - transform.m12;
444 camera->target.y = camera->position.y - transform.m13;
445 camera->target.z = camera->position.z - transform.m14;
447 // If movement detected (some key pressed), increase swinging
448 for (int i = 0; i < 6; i++) if (direction[i]) { swingCounter++; break; }
450 // Camera position update
451 // NOTE: On CAMERA_FIRST_PERSON player Y-movement is limited to player 'eyes position'
452 camera->position.y = CAMERA.playerEyesPosition - sinf(swingCounter/CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER)/CAMERA_FIRST_PERSON_STEP_DIVIDER;
454 camera->up.x = sinf(swingCounter/(CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER*2))/CAMERA_FIRST_PERSON_WAVING_DIVIDER;
455 camera->up.z = -sinf(swingCounter/(CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER*2))/CAMERA_FIRST_PERSON_WAVING_DIVIDER;
458 case CAMERA_THIRD_PERSON: // Camera moves as in a third-person game, following target at a distance, controls are configurable
460 camera->position.x += (sinf(CAMERA.angle.x)*direction[MOVE_BACK] -
461 sinf(CAMERA.angle.x)*direction[MOVE_FRONT] -
462 cosf(CAMERA.angle.x)*direction[MOVE_LEFT] +
463 cosf(CAMERA.angle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
465 camera->position.y += (sinf(CAMERA.angle.y)*direction[MOVE_FRONT] -
466 sinf(CAMERA.angle.y)*direction[MOVE_BACK] +
467 1.0f*direction[MOVE_UP] - 1.0f*direction[MOVE_DOWN])/PLAYER_MOVEMENT_SENSITIVITY;
469 camera->position.z += (cosf(CAMERA.angle.x)*direction[MOVE_BACK] -
470 cosf(CAMERA.angle.x)*direction[MOVE_FRONT] +
471 sinf(CAMERA.angle.x)*direction[MOVE_LEFT] -
472 sinf(CAMERA.angle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
474 // Camera orientation calculation
475 CAMERA.angle.x += (mousePositionDelta.x*-CAMERA_MOUSE_MOVE_SENSITIVITY);
476 CAMERA.angle.y += (mousePositionDelta.y*-CAMERA_MOUSE_MOVE_SENSITIVITY);
479 if (CAMERA.angle.y > CAMERA_THIRD_PERSON_MIN_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_THIRD_PERSON_MIN_CLAMP*DEG2RAD;
480 else if (CAMERA.angle.y < CAMERA_THIRD_PERSON_MAX_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_THIRD_PERSON_MAX_CLAMP*DEG2RAD;
483 CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY);
485 // Camera distance clamp
486 if (CAMERA.targetDistance < CAMERA_THIRD_PERSON_DISTANCE_CLAMP) CAMERA.targetDistance = CAMERA_THIRD_PERSON_DISTANCE_CLAMP;
488 // TODO: It seems camera->position is not correctly updated or some rounding issue makes the camera move straight to camera->target...
489 camera->position.x = sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x;
491 if (CAMERA.angle.y <= 0.0f) camera->position.y = sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y;
492 else camera->position.y = -sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y;
494 camera->position.z = cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z;
497 case CAMERA_CUSTOM: break;
502 // Set camera pan key to combine with mouse movement (free camera)
503 void SetCameraPanControl(int keyPan) { CAMERA.panControl = keyPan; }
505 // Set camera alt key to combine with mouse movement (free camera)
506 void SetCameraAltControl(int keyAlt) { CAMERA.altControl = keyAlt; }
508 // Set camera smooth zoom key to combine with mouse (free camera)
509 void SetCameraSmoothZoomControl(int szoomKey) { CAMERA.smoothZoomControl = szoomKey; }
511 // Set camera move controls (1st person and 3rd person cameras)
512 void SetCameraMoveControls(int keyFront, int keyBack, int keyRight, int keyLeft, int keyUp, int keyDown)
514 CAMERA.moveControl[MOVE_FRONT] = keyFront;
515 CAMERA.moveControl[MOVE_BACK] = keyBack;
516 CAMERA.moveControl[MOVE_RIGHT] = keyRight;
517 CAMERA.moveControl[MOVE_LEFT] = keyLeft;
518 CAMERA.moveControl[MOVE_UP] = keyUp;
519 CAMERA.moveControl[MOVE_DOWN] = keyDown;
522 #endif // CAMERA_IMPLEMENTATION