summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-05-07 12:45:23 +0200
committerraysan5 <[email protected]>2020-05-07 12:45:23 +0200
commit67d8b43b0ebaa6a3e3b54c26c9538df59ffc00fc (patch)
treeaeb9865e8fe8228559ac45c8b7d1b7c76394fc05 /src
parentfdad1f023b0f4de982957a3baaa41b0ac2666748 (diff)
downloadraylib-67d8b43b0ebaa6a3e3b54c26c9538df59ffc00fc.tar.gz
raylib-67d8b43b0ebaa6a3e3b54c26c9538df59ffc00fc.zip
Review first person movement Y waving
Some comments added
Diffstat (limited to 'src')
-rw-r--r--src/camera.h38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/camera.h b/src/camera.h
index 31db38f0..3b0feb43 100644
--- a/src/camera.h
+++ b/src/camera.h
@@ -170,7 +170,7 @@ void SetCameraMoveControls(int frontKey, int backKey,
#define CAMERA_FIRST_PERSON_MIN_CLAMP 89.0f
#define CAMERA_FIRST_PERSON_MAX_CLAMP -89.0f
-#define CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER 5.0f
+#define CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER 8.0f
#define CAMERA_FIRST_PERSON_STEP_DIVIDER 30.0f
#define CAMERA_FIRST_PERSON_WAVING_DIVIDER 200.0f
@@ -197,17 +197,18 @@ typedef enum {
MOVE_DOWN
} CameraMove;
-// Camera global state context data
+// Camera global state context data [56 bytes]
typedef struct {
- int mode; // Current camera mode
+ unsigned int mode; // Current camera mode
float targetDistance; // Camera distance from position to target
- float playerEyesPosition; // Default player eyes position from ground (in meters)
+ float playerEyesPosition; // Player eyes position from ground (in meters)
Vector2 angle; // Camera angle in plane XZ
- int moveControl[6];
- int smoothZoomControl; // raylib: KEY_LEFT_CONTROL
- int altControl; // raylib: KEY_LEFT_ALT
- int panControl; // raylib: MOUSE_MIDDLE_BUTTON
+ // Camera movement control keys
+ int moveControl[6]; // Move controls (CAMERA_FIRST_PERSON)
+ int smoothZoomControl; // Smooth zoom control key
+ int altControl; // Alternative control key
+ int panControl; // Pan view control key
} CameraData;
//----------------------------------------------------------------------------------
@@ -219,9 +220,9 @@ static CameraData CAMERA = { // Global CAMERA state context
.playerEyesPosition = 1.85f,
.angle = { 0 },
.moveControl = { 'W', 'S', 'D', 'A', 'E', 'Q' },
- .smoothZoomControl = 341,
- .altControl = 342,
- .panControl = 2
+ .smoothZoomControl = 341, // raylib: KEY_LEFT_CONTROL
+ .altControl = 342, // raylib: KEY_LEFT_ALT
+ .panControl = 2 // raylib: MOUSE_MIDDLE_BUTTON
};
//----------------------------------------------------------------------------------
@@ -253,13 +254,13 @@ void SetCameraMode(Camera camera, int mode)
float dy = v2.y - v1.y;
float dz = v2.z - v1.z;
- CAMERA.targetDistance = sqrtf(dx*dx + dy*dy + dz*dz);
+ CAMERA.targetDistance = sqrtf(dx*dx + dy*dy + dz*dz); // Distance to target
// Camera angle calculation
- CAMERA.angle.x = atan2f(dx, dz); // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
- CAMERA.angle.y = atan2f(dy, sqrtf(dx*dx + dz*dz)); // Camera angle in plane XY (0 aligned with X, move positive CW)
+ CAMERA.angle.x = atan2f(dx, dz); // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
+ CAMERA.angle.y = atan2f(dy, sqrtf(dx*dx + dz*dz)); // Camera angle in plane XY (0 aligned with X, move positive CW)
- CAMERA.playerEyesPosition = camera.position.y;
+ CAMERA.playerEyesPosition = camera.position.y; // Init player eyes position to camera Y position
// Lock cursor for first person and third person cameras
if ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON)) DisableCursor();
@@ -287,6 +288,7 @@ void UpdateCamera(Camera *camera)
int mouseWheelMove = GetMouseWheelMove();
// Keys input detection
+ // TODO: Input detection is raylib-dependant, it could be moved outside the module
bool panKey = IsMouseButtonDown(CAMERA.panControl);
bool altKey = IsKeyDown(CAMERA.altControl);
bool szoomKey = IsKeyDown(CAMERA.smoothZoomControl);
@@ -297,8 +299,6 @@ void UpdateCamera(Camera *camera)
IsKeyDown(CAMERA.moveControl[MOVE_UP]),
IsKeyDown(CAMERA.moveControl[MOVE_DOWN]) };
- // TODO: Touch input detection (probably gestures system required)
-
if (CAMERA.mode != CAMERA_CUSTOM)
{
mousePositionDelta.x = mousePosition.x - previousMousePosition.x;
@@ -321,7 +321,6 @@ void UpdateCamera(Camera *camera)
}
// Camera looking down
- // TODO: Review, weird comparison of CAMERA.targetDistance == 120.0f?
else if ((camera->position.y > camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
{
camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
@@ -342,7 +341,6 @@ void UpdateCamera(Camera *camera)
if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP;
}
// Camera looking up
- // TODO: Review, weird comparisson of CAMERA.targetDistance == 120.0f?
else if ((camera->position.y < camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
{
camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance;
@@ -489,8 +487,10 @@ void UpdateCamera(Camera *camera)
// TODO: It seems camera->position is not correctly updated or some rounding issue makes the camera move straight to camera->target...
camera->position.x = sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x;
+
if (CAMERA.angle.y <= 0.0f) camera->position.y = sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y;
else camera->position.y = -sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y;
+
camera->position.z = cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z;
} break;