X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FMoof%2FCamera.cc;h=06261a1b41ba811b75a7746da669d6e5f6768531;hb=df541170776dc4ac4f241ca480812bd70bcb6eca;hp=cdebc7a7b735b7e681e3b28f041f576aa9166d7f;hpb=72d4af22710317acffab861421c4364b1780b6fe;p=chaz%2Fyoink diff --git a/src/Moof/Camera.cc b/src/Moof/Camera.cc index cdebc7a..06261a1 100644 --- a/src/Moof/Camera.cc +++ b/src/Moof/Camera.cc @@ -26,9 +26,8 @@ *******************************************************************************/ -#include -#include -#include +#include "Camera.hh" +#include "OpenGL.hh" namespace Mf { @@ -37,6 +36,7 @@ namespace Mf { void Camera::setPosition(const Vector3& point) { position_ = point; + calculateSecondary(); //Vector3 coeff[2] = {position_, point}; //pInterp_.init(coeff, 0.1); } @@ -51,11 +51,11 @@ void Camera::setProjection(const Matrix4& projection) projection_ = projection; } -void Camera::setProjection(Scalar fovy, Scalar aspect, Scalar near, Scalar far) +void Camera::setProjection(Scalar fovy, Scalar aspect, Scalar abutting, + Scalar distant) { - cml::matrix_perspective_yfov_RH(projection_, fovy, aspect, near, far, - cml::z_clip_neg_one); - + cml::matrix_perspective_yfov_RH(projection_, fovy, aspect, abutting, + distant, cml::z_clip_neg_one); calculateSecondary(); } @@ -79,37 +79,35 @@ void Camera::update(Scalar t, Scalar dt) void Camera::lookAt(const Vector3& point) { - quaternion_rotation_aim_at(rotation_, position_, point); + cml::quaternion_rotation_aim_at(rotation_, position_, point, + Vector3(0.0, -1.0, 0.0)); + calculateSecondary(); } -void Camera::adjustFromInput(const Event& event) +void Camera::handleEvent(const Event& event) { switch (event.type) { case SDL_KEYDOWN: - if (event.key.keysym.sym == SDLK_RIGHT || - event.key.keysym.sym == SDLK_d) + if (event.key.keysym.sym == SDLK_RIGHT) { Vector3 vec = position_; vec[0] -= 50.0; setPosition(vec); } - else if (event.key.keysym.sym == SDLK_LEFT || - event.key.keysym.sym == SDLK_a) + else if (event.key.keysym.sym == SDLK_LEFT) { Vector3 vec = position_; vec[0] += 50.0; setPosition(vec); } - else if (event.key.keysym.sym == SDLK_UP || - event.key.keysym.sym == SDLK_w) + else if (event.key.keysym.sym == SDLK_UP) { Vector3 vec = position_; vec[1] -= 50.0; setPosition(vec); } - else if (event.key.keysym.sym == SDLK_DOWN || - event.key.keysym.sym == SDLK_s) + else if (event.key.keysym.sym == SDLK_DOWN) { Vector3 vec = position_; vec[1] += 50.0; @@ -123,7 +121,6 @@ void Camera::adjustFromInput(const Event& event) } else if (event.key.keysym.sym == SDLK_PAGEDOWN) { - //position_[2] -= 50.0; Vector3 vec = position_; vec[2] -= 50.0; setPosition(vec); @@ -137,9 +134,9 @@ void Camera::adjustFromInput(const Event& event) Quaternion rotation = rotation_; - quaternion_rotate_about_world_x(rotation, yrel); + cml::quaternion_rotate_about_world_x(rotation, yrel); //rotation_.normalize(); - quaternion_rotate_about_world_y(rotation, xrel); + cml::quaternion_rotate_about_world_y(rotation, xrel); rotation.normalize(); setRotation(rotation); @@ -167,13 +164,14 @@ void Camera::adjustFromInput(const Event& event) void Camera::calculateSecondary() { - matrix_rotation_quaternion(modelview_, rotation_); + cml::matrix_rotation_quaternion(modelview_, rotation_); Matrix4 translate; - matrix_translation(translate, position_); + cml::matrix_translation(translate, position_); - //modelview_ = translate * modelview_; + //modelview_.transpose(); modelview_ *= translate; + //modelview_ = translate * modelview_; frustum_.init(modelview_, projection_); }