fixed nippy camera bug
authormatthew <matthew@owens.tech>
Mon, 5 Nov 2018 21:24:26 +0000 (21:24 +0000)
committermatthew <matthew@owens.tech>
Mon, 5 Nov 2018 21:24:26 +0000 (21:24 +0000)
gl/camera.c
gl/camera.h
gl/main.c

index 9142d3c..9980fdc 100644 (file)
@@ -48,6 +48,7 @@ void updateMatrix(crpgCamera_t *ct)
        vec3_t to = v3_add(ct->position, ct->front);
 
        mat4_t lookat = m4_look_at(ct->position, to, ct->up);
+       /* TODO: change first param to calcualated value */
        mat4_t perspective = m4_perspective(60, ct->aspectRatio, ct->near, ct->far);
        ct->matrix = m4_mul(perspective, lookat);
 }
@@ -61,7 +62,7 @@ void updateVectors(crpgCamera_t *ct)
        ct->front = v3_norm(ct->front);
 
        /* calculating the new right and up vectors */
-       ct->right = v3_norm(v3_cross(ct->position, ct->worldUp));
+       ct->right = v3_norm(v3_cross(ct->front, ct->worldUp));
        ct->up = v3_norm(v3_cross(ct->right, ct->front));
 }
 
@@ -142,10 +143,10 @@ void crpgCameraUpdate(crpgCamera *c, float dtms)
                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));
+               ct->position = v3_add(ct->position, v3_muls(ct->worldUp, velocity));
        }
        if(crpgInputHeld(INPUT_CAMERA_PAN_DOWN)){
-               ct->position = v3_sub(ct->position, v3_muls(ct->up, velocity));
+               ct->position = v3_sub(ct->position, v3_muls(ct->worldUp, velocity));
        }
 
        /* processing mouse movement */
@@ -154,11 +155,22 @@ void crpgCameraUpdate(crpgCamera *c, float dtms)
        mouseOffset.y *= ct->mouseSensitivity;
 
        ct->yaw += mouseOffset.x;
-       ct->pitch += mouseOffset.y;
+       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;
+       /* preventing the screen from flipping */
+       ct->pitch = (ct->pitch > 89.0f) ? 89.0f : ct->pitch;
+       ct->pitch = (ct->pitch < -89.0f) ? -89.0f : ct->pitch;
+
+       /* constricting the yaw */
+       ct->yaw = (ct->yaw < 0.f) ? 360.f : ct->yaw;
+       ct->yaw = (ct->yaw > 360.f) ? 0.f : ct->yaw;
+
+       printf("ct->pitch: %f\tct->yaw: %f\tpos: (%f,%f,%f)\r",
+                       ct->pitch, ct->yaw, ct->position.x, ct->position.y, ct->position.z);
 
        updateVectors(ct);
 }
+
+void crpgCameraRender(crpgCamera *c)
+{
+}
index 8fb288e..2b8ba1b 100644 (file)
@@ -12,4 +12,5 @@ void crpgCameraSetSpeed(crpgCamera *c, float speed);
 void crpgCameraSetSensitivity(crpgCamera *c, float sensitivity);
 
 void crpgCameraUpdate(crpgCamera *c, float dtms);
+void crpgCameraRender(crpgCamera *c);
 #endif//CAMERA_H
index 3d6ddfa..8aa5d6e 100644 (file)
--- a/gl/main.c
+++ b/gl/main.c
@@ -17,8 +17,8 @@
 
 static SDL_Window *window = NULL;
 static SDL_GLContext *context = NULL;
-static int screen_width = 1280;
-static int screen_height = 720;
+static int screen_width = 1920;
+static int screen_height = 1080;
 static bool quit = false;
 //static Uint32 ltime, ctime, numframes, cftime, lftime;
 
@@ -120,7 +120,8 @@ static bool init()
 
        window = SDL_CreateWindow("csrpg - opengl", SDL_WINDOWPOS_CENTERED,
                         SDL_WINDOWPOS_CENTERED, screen_width, screen_height,
-                        SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_INPUT_FOCUS);
+                        SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_INPUT_FOCUS |
+                        SDL_WINDOW_BORDERLESS);
 
        if (window == NULL){
                printf("SDL couldn't make an OpenGL window! SDL_Error: %s\n", SDL_GetError());
@@ -218,5 +219,6 @@ int main()
        crpgInputCleanup();
        crpgCubeFree(cubes[0]);
        crpgCubeFree(cubes[1]);
+       printf("\n");
        return 0;
 }