From: matthew Date: Sat, 3 Nov 2018 21:36:59 +0000 (+0000) Subject: removed crpgCameraRender(), implemented crpgCameraUpdate() X-Git-Url: https://git.owens.tech/assets/static/git-logo.png/assets/static/git-logo.png/git?a=commitdiff_plain;h=2276ee66f7d2d1bf06fbd6cb9ea19ef3d258a8d5;p=csrpg.git removed crpgCameraRender(), implemented crpgCameraUpdate() --- diff --git a/gl/camera.c b/gl/camera.c index fc6c456..9142d3c 100644 --- a/gl/camera.c +++ b/gl/camera.c @@ -5,7 +5,7 @@ static const float YAW = -90.f; static const float PITCH = 0.0f; -static const float SPEED = 2.5f; +static const float SPEED = 0.2f; static const float SENSITIVITY = 0.1f; static const float ZOOM = 45.0f; @@ -88,7 +88,7 @@ crpgCamera *crpgCameraNew(vec3_t position, vec3_t up) ct->mouseSensitivity = SENSITIVITY; ct->aspectRatio = 16.f/9.f; ct->near = 1.f; - ct->far = 10.f; + ct->far = 30.f; updateVectors(ct); @@ -123,21 +123,42 @@ void crpgCameraSetSensitivity(crpgCamera *c, float sensitivity) ct->mouseSensitivity = sensitivity; } -void crpgCameraRender(crpgCamera *c, float dtms) -{ -} - void crpgCameraUpdate(crpgCamera *c, float dtms) { - /* crpgCamera_t *ct = (crpgCamera_t *)c; float velocity = ct->movementSpeed * dtms; + /* updating the pan values */ if(crpgInputHeld(INPUT_CAMERA_PAN_IN)){ ct->position = v3_add(ct->position, v3_muls(ct->front, velocity)); } if(crpgInputHeld(INPUT_CAMERA_PAN_OUT)){ ct->position = v3_sub(ct->position, v3_muls(ct->front, velocity)); } - */ + if(crpgInputHeld(INPUT_CAMERA_PAN_RIGHT)){ + ct->position = v3_add(ct->position, v3_muls(ct->right, velocity)); + } + if(crpgInputHeld(INPUT_CAMERA_PAN_LEFT)){ + ct->position = v3_sub(ct->position, v3_muls(ct->right, velocity)); + } + if(crpgInputHeld(INPUT_CAMERA_PAN_UP)){ + ct->position = v3_add(ct->position, v3_muls(ct->up, velocity)); + } + if(crpgInputHeld(INPUT_CAMERA_PAN_DOWN)){ + ct->position = v3_sub(ct->position, v3_muls(ct->up, velocity)); + } + + /* processing mouse movement */ + vec2_t mouseOffset = crpgInputMouseRelPos(); + mouseOffset.x *= ct->mouseSensitivity; + mouseOffset.y *= ct->mouseSensitivity; + + ct->yaw += mouseOffset.x; + ct->pitch += mouseOffset.y; + + // preventing the screen from flipping + ct->pitch > 89.0f ? 89.0f : ct->pitch; + ct->pitch < -89.0f ? -89.0f : ct->pitch; + + updateVectors(ct); } diff --git a/gl/camera.h b/gl/camera.h index fbede13..8fb288e 100644 --- a/gl/camera.h +++ b/gl/camera.h @@ -11,6 +11,5 @@ void crpgCameraSetZoom(crpgCamera *c, float zoom); void crpgCameraSetSpeed(crpgCamera *c, float speed); void crpgCameraSetSensitivity(crpgCamera *c, float sensitivity); -void crpgCameraRender(crpgCamera *c, float dtms); void crpgCameraUpdate(crpgCamera *c, float dtms); #endif//CAMERA_H