namespace blank {
Camera::Camera()
-: Model()
+: FPSController()
, fov(45.0f)
, aspect(1.0f)
, near_clip(0.1f)
, far_clip(100.0f)
, projection(glm::perspective(fov, aspect, near_clip, far_clip))
+, view(glm::inverse(Transform()))
, vp(projection) {
}
-Camera::~Camera() {
-
-}
-
void Camera::Viewport(int width, int height) {
Viewport(0, 0, width, height);
UpdateProjection();
}
+Ray Camera::Aim() const {
+ const glm::mat4 inv_vp(glm::inverse(vp));
+ glm::vec4 from = inv_vp * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f);
+ from /= from.w;
+ glm::vec4 to = inv_vp * glm::vec4(0.0f, 0.0f, 1.0f, 1.0f);
+ to /= to.w;
+ return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) };
+}
+
void Camera::Update(int dt) {
- Model::Update(dt);
- vp = projection * glm::inverse(Transform());
+ FPSController::Update(dt);
+ view = glm::inverse(Transform());
+ vp = projection * view;
}
void Camera::UpdateProjection() {