]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Camera.cc
dispatcher alias methods
[chaz/yoink] / src / Moof / Camera.cc
index 26e24ba358fbfd7494517a66409e75c5150f8b59..376e2c5a4ff5398ea9f1c388f23ce4cc0bbd5000 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <iostream>
 #include <Moof/Camera.hh>
+#include <Moof/OpenGL.hh>
 
 
 namespace Mf {
@@ -35,64 +36,78 @@ namespace Mf {
 
 void Camera::setPosition(const Vector3& point)
 {
-       //position_ = point;
-       Vector3 coeff[2] = {position_, point};
-       pInterp_.init(coeff, 0.1);
+       position_ = point;
+       calculateSecondary();
+       //Vector3 coeff[2] = {position_, point};
+       //pInterp_.init(coeff, 0.1);
 }
 void Camera::setRotation(const Quaternion& rotation)
 {
        rotation_ = rotation;
-       //srcRotation_ = rotation_;
-       //dstRotation_ = rotation;
-       //tInterp_ = 0.0;
 }
 
-void Camera::update(Scalar t, Scalar dt)
+
+void Camera::setProjection(const Matrix4& projection)
 {
-       pInterp_.update(dt);
-       position_ = pInterp_.getState(0.0);
+       projection_ = projection;
+}
 
-       //tInterp_ += dt * 10.0;
-       //rotation_ = cml::slerp(srcRotation_, dstRotation_, cml::clamp(tInterp_, 0.0, 1.0));
-       //rotation_.normalize();
+void Camera::setProjection(Scalar fovy, Scalar aspect, Scalar near, Scalar far)
+{
+       cml::matrix_perspective_yfov_RH(projection_, fovy, aspect, near, far,
+                       cml::z_clip_neg_one);
 
        calculateSecondary();
 }
 
 
+void Camera::uploadProjectionToGL() const
+{
+       glMatrixMode(GL_PROJECTION);
+       glLoadMatrix(projection_.data());
+
+       glMatrixMode(GL_MODELVIEW);
+}
+
+void Camera::update(Scalar t, Scalar dt)
+{
+       //pInterp_.update(dt);
+       //position_ = pInterp_.getState(0.0);
+
+       //calculateSecondary();
+}
+
+
 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;
@@ -106,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);
@@ -120,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);
@@ -150,13 +164,16 @@ void Camera::adjustFromInput(const Event& event)
 
 void Camera::calculateSecondary()
 {
-       matrix_rotation_quaternion(transformation_, rotation_);
+       cml::matrix_rotation_quaternion(modelview_, rotation_);
 
        Matrix4 translate;
-       matrix_translation(translate, position_);
+       cml::matrix_translation(translate, position_);
+
+       //modelview_.transpose();
+       modelview_ *= translate;
+       //modelview_ = translate * modelview_;
 
-       //transformation_ = translate * transformation_;
-       transformation_ *= translate;
+       frustum_.init(modelview_, projection_);
 }
 
 
This page took 0.022552 seconds and 4 git commands to generate.