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);
}
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));
}
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 */
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)
+{
+}
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;
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());
crpgInputCleanup();
crpgCubeFree(cubes[0]);
crpgCubeFree(cubes[1]);
+ printf("\n");
return 0;
}