Update C sources

This commit is contained in:
Milan Nikolic 2021-05-25 14:35:17 +02:00
parent 9d258bad65
commit c1525b67af
No known key found for this signature in database
GPG key ID: 9229D0EAA3AA4E75
68 changed files with 34056 additions and 25957 deletions

View file

@ -22,7 +22,7 @@
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2015-2020 Ramon Santamaria (@raysan5)
* Copyright (c) 2015-2021 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
@ -91,7 +91,7 @@
typedef enum {
CAMERA_PERSPECTIVE = 0,
CAMERA_ORTHOGRAPHIC
} CameraType;
} CameraProjection;
#endif
#ifdef __cplusplus
@ -110,12 +110,12 @@ extern "C" { // Prevents name mangling of functions
void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available)
void UpdateCamera(Camera *camera); // Update camera position for selected mode
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 SetCameraPanControl(int keyPan); // Set camera pan key to combine with mouse movement (free camera)
void SetCameraAltControl(int keyAlt); // Set camera alt key to combine with mouse movement (free camera)
void SetCameraSmoothZoomControl(int szoomKey); // Set camera smooth zoom key to combine with mouse (free camera)
void SetCameraMoveControls(int frontKey, int backKey,
int rightKey, int leftKey,
int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras)
void SetCameraMoveControls(int keyFront, int keyBack,
int keyRight, int keyLeft,
int keyUp, int keyDown); // Set camera move controls (1st person and 3rd person cameras)
#endif
#ifdef __cplusplus
@ -222,7 +222,7 @@ static CameraData CAMERA = { // Global CAMERA state context
.moveControl = { 'W', 'S', 'D', 'A', 'E', 'Q' },
.smoothZoomControl = 341, // raylib: KEY_LEFT_CONTROL
.altControl = 342, // raylib: KEY_LEFT_ALT
.panControl = 2 // raylib: MOUSE_MIDDLE_BUTTON
.panControl = 2 // raylib: MOUSE_BUTTON_MIDDLE
};
//----------------------------------------------------------------------------------
@ -236,7 +236,7 @@ static void DisableCursor() {} // Lock cursor
static int IsKeyDown(int key) { return 0; }
static int IsMouseButtonDown(int button) { return 0;}
static int GetMouseWheelMove() { return 0; }
static float GetMouseWheelMove() { return 0.0f; }
static Vector2 GetMousePosition() { return (Vector2){ 0.0f, 0.0f }; }
#endif
@ -285,12 +285,12 @@ void UpdateCamera(Camera *camera)
// Mouse movement detection
Vector2 mousePositionDelta = { 0.0f, 0.0f };
Vector2 mousePosition = GetMousePosition();
int mouseWheelMove = GetMouseWheelMove();
float 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 keyPan = IsMouseButtonDown(CAMERA.panControl);
bool keyAlt = IsKeyDown(CAMERA.altControl);
bool szoomKey = IsKeyDown(CAMERA.smoothZoomControl);
bool direction[6] = { IsKeyDown(CAMERA.moveControl[MOVE_FRONT]),
IsKeyDown(CAMERA.moveControl[MOVE_BACK]),
@ -319,7 +319,7 @@ void UpdateCamera(Camera *camera)
CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY);
if (CAMERA.targetDistance > CAMERA_FREE_DISTANCE_MAX_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MAX_CLAMP;
}
// Camera looking down
else if ((camera->position.y > camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
{
@ -362,9 +362,9 @@ void UpdateCamera(Camera *camera)
}
// Input keys checks
if (panKey)
if (keyPan)
{
if (altKey) // Alternative key behaviour
if (keyAlt) // Alternative key behaviour
{
if (szoomKey)
{
@ -443,7 +443,7 @@ void UpdateCamera(Camera *camera)
camera->target.x = camera->position.x - transform.m12;
camera->target.y = camera->position.y - transform.m13;
camera->target.z = camera->position.z - transform.m14;
// If movement detected (some key pressed), increase swinging
for (int i = 0; i < 6; i++) if (direction[i]) { swingCounter++; break; }
@ -487,10 +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;
@ -500,23 +500,23 @@ void UpdateCamera(Camera *camera)
}
// Set camera pan key to combine with mouse movement (free camera)
void SetCameraPanControl(int panKey) { CAMERA.panControl = panKey; }
void SetCameraPanControl(int keyPan) { CAMERA.panControl = keyPan; }
// Set camera alt key to combine with mouse movement (free camera)
void SetCameraAltControl(int altKey) { CAMERA.altControl = altKey; }
void SetCameraAltControl(int keyAlt) { CAMERA.altControl = keyAlt; }
// Set camera smooth zoom key to combine with mouse (free camera)
void SetCameraSmoothZoomControl(int szoomKey) { CAMERA.smoothZoomControl = szoomKey; }
// Set camera move controls (1st person and 3rd person cameras)
void SetCameraMoveControls(int frontKey, int backKey, int rightKey, int leftKey, int upKey, int downKey)
void SetCameraMoveControls(int keyFront, int keyBack, int keyRight, int keyLeft, int keyUp, int keyDown)
{
CAMERA.moveControl[MOVE_FRONT] = frontKey;
CAMERA.moveControl[MOVE_BACK] = backKey;
CAMERA.moveControl[MOVE_RIGHT] = rightKey;
CAMERA.moveControl[MOVE_LEFT] = leftKey;
CAMERA.moveControl[MOVE_UP] = upKey;
CAMERA.moveControl[MOVE_DOWN] = downKey;
CAMERA.moveControl[MOVE_FRONT] = keyFront;
CAMERA.moveControl[MOVE_BACK] = keyBack;
CAMERA.moveControl[MOVE_RIGHT] = keyRight;
CAMERA.moveControl[MOVE_LEFT] = keyLeft;
CAMERA.moveControl[MOVE_UP] = keyUp;
CAMERA.moveControl[MOVE_DOWN] = keyDown;
}
#endif // CAMERA_IMPLEMENTATION