Review camera system
This commit is contained in:
parent
ef36950b72
commit
322ca97c24
2 changed files with 61 additions and 29 deletions
79
src/camera.c
79
src/camera.c
|
@ -123,6 +123,7 @@ static int IsKeyDown(int key) { return 0; }
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Select camera mode (multiple camera modes available)
|
// Select camera mode (multiple camera modes available)
|
||||||
|
// TODO: Review hardcoded values when changing modes...
|
||||||
void SetCameraMode(int mode)
|
void SetCameraMode(int mode)
|
||||||
{
|
{
|
||||||
if ((cameraMode == CAMERA_FIRST_PERSON) && (mode == CAMERA_FREE))
|
if ((cameraMode == CAMERA_FIRST_PERSON) && (mode == CAMERA_FREE))
|
||||||
|
@ -144,7 +145,7 @@ void SetCameraMode(int mode)
|
||||||
cameraTargetDistance = 10;
|
cameraTargetDistance = 10;
|
||||||
cameraAngle.x = 45 * DEG2RAD;
|
cameraAngle.x = 45 * DEG2RAD;
|
||||||
cameraAngle.y = -40 * DEG2RAD;
|
cameraAngle.y = -40 * DEG2RAD;
|
||||||
internalCamera.target = (Vector3){ 0, 0, 0};
|
internalCamera.target = (Vector3){ 0, 0, 0 };
|
||||||
ProcessCamera(&internalCamera, &internalCamera.position);
|
ProcessCamera(&internalCamera, &internalCamera.position);
|
||||||
|
|
||||||
ShowCursor();
|
ShowCursor();
|
||||||
|
@ -154,7 +155,7 @@ void SetCameraMode(int mode)
|
||||||
cameraTargetDistance = 10;
|
cameraTargetDistance = 10;
|
||||||
cameraAngle.x = 225 * DEG2RAD;
|
cameraAngle.x = 225 * DEG2RAD;
|
||||||
cameraAngle.y = -40 * DEG2RAD;
|
cameraAngle.y = -40 * DEG2RAD;
|
||||||
internalCamera.target = (Vector3){ 3, 0, 3};
|
internalCamera.target = (Vector3){ 0, 0, 0};
|
||||||
ProcessCamera(&internalCamera, &internalCamera.position);
|
ProcessCamera(&internalCamera, &internalCamera.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +163,7 @@ void SetCameraMode(int mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update camera with position
|
// Update camera with position
|
||||||
|
// TODO: I don't like how this function works right now... not clear enough...
|
||||||
Camera UpdateCamera(Vector3 *position)
|
Camera UpdateCamera(Vector3 *position)
|
||||||
{
|
{
|
||||||
// Calculate camera
|
// Calculate camera
|
||||||
|
@ -170,6 +172,55 @@ Camera UpdateCamera(Vector3 *position)
|
||||||
return internalCamera;
|
return internalCamera;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set internal camera position
|
||||||
|
void SetCameraPosition(Vector3 position)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set internal camera target
|
||||||
|
void SetCameraTarget(Vector3 target)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set camera move controls (1st person and 3rd person cameras)
|
||||||
void SetCameraMoveControls(int frontKey, int backKey, int leftKey, int rightKey, int upKey, int downKey)
|
void SetCameraMoveControls(int frontKey, int backKey, int leftKey, int rightKey, int upKey, int downKey)
|
||||||
{
|
{
|
||||||
cameraMoveControl[MOVE_FRONT] = frontKey;
|
cameraMoveControl[MOVE_FRONT] = frontKey;
|
||||||
|
@ -180,32 +231,12 @@ void SetCameraMoveControls(int frontKey, int backKey, int leftKey, int rightKey,
|
||||||
cameraMoveControl[MOVE_DOWN] = downKey;
|
cameraMoveControl[MOVE_DOWN] = downKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set camera mouse sensitivity (1st person and 3rd person cameras)
|
||||||
void SetCameraMouseSensitivity(float sensitivity)
|
void SetCameraMouseSensitivity(float sensitivity)
|
||||||
{
|
{
|
||||||
mouseSensitivity = (sensitivity / 10000.0);
|
mouseSensitivity = (sensitivity / 10000.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetCameraPanControl(int panKey)
|
|
||||||
{
|
|
||||||
panControlKey = panKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetCameraAltControl(int altKey)
|
|
||||||
{
|
|
||||||
altControlKey = altKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetCameraSmoothZoomControl(int szKey)
|
|
||||||
{
|
|
||||||
smoothZoomControlKey = szKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetCameraTarget(Vector3 target)
|
|
||||||
{
|
|
||||||
internalCamera.target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Definition
|
// 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))
|
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;
|
if (cameraTargetDistance < FREE_CAMERA_DISTANCE_MIN_CLAMP) cameraTargetDistance = FREE_CAMERA_DISTANCE_MIN_CLAMP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
src/camera.h
11
src/camera.h
|
@ -76,18 +76,19 @@ extern "C" { // Prevents name mangling of functions
|
||||||
// Module Functions Declaration
|
// Module Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
void SetCameraMode(int mode); // Set camera mode (multiple camera modes available)
|
void SetCameraMode(int mode); // Set camera mode (multiple camera modes available)
|
||||||
Camera UpdateCamera(Vector3 *playerPosition); // Update camera and player position (1st person and 3rd person cameras)
|
Camera UpdateCamera(Vector3 *position); // Update camera and player position (1st person and 3rd person cameras)
|
||||||
|
|
||||||
void SetCameraMoveControls(int frontKey, int backKey,
|
void SetCameraPosition(Vector3 position); // Set internal camera position
|
||||||
int leftKey, int rightKey,
|
void SetCameraTarget(Vector3 target); // Set internal camera target
|
||||||
int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras)
|
|
||||||
|
|
||||||
void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera)
|
void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera)
|
||||||
void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera)
|
void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera)
|
||||||
void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera)
|
void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera)
|
||||||
|
|
||||||
|
void SetCameraMoveControls(int frontKey, int backKey,
|
||||||
|
int leftKey, int rightKey,
|
||||||
|
int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras)
|
||||||
void SetCameraMouseSensitivity(float sensitivity); // Set camera mouse sensitivity (1st person and 3rd person cameras)
|
void SetCameraMouseSensitivity(float sensitivity); // Set camera mouse sensitivity (1st person and 3rd person cameras)
|
||||||
void SetCameraTarget(Vector3 target); // Set internal camera target
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue