-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include "camera.hh"
#include "opengl.hh"
{
// FIXME: this doesn't work as expected
quaternion_rotation_aim_at(state_.orientation, state_.position, point,
- vector3(0.0, 1.0, 0.0));
+ vector3(0.0, 1.0, 0.0));
}
-
void camera::projection(const matrix4& projection)
{
projection_ = projection;
}
-void camera::projection(scalar fovy, scalar aspect, scalar abutting,
- scalar distant)
+void camera::projection(scalar fovy,
+ scalar aspect, scalar abutting, scalar distant)
{
matrix_perspective_yfov_RH(projection_, fovy, aspect, abutting,
- distant, z_clip_neg_one);
+ distant, z_clip_neg_one);
}
-
void camera::upload_to_gl(scalar alpha) const
{
calculate(alpha);
frustum_.init(modelview_, projection_);
}
-
void camera::update(scalar t, scalar dt)
{
rigid_body3::update(t, dt);
sphere_.draw(alpha);
}
-
void camera::handle_event(const event& event)
{
const scalar ds = 50.0;
switch (event.type)
{
- case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_RIGHT)
- {
- state_.position[0] -= ds;
- }
- else if (event.key.keysym.sym == SDLK_LEFT)
- {
- state_.position[0] += ds;
- }
- else if (event.key.keysym.sym == SDLK_UP)
- {
- state_.position[1] -= ds;
- }
- else if (event.key.keysym.sym == SDLK_DOWN)
- {
- state_.position[1] += ds;
- }
- else if (event.key.keysym.sym == SDLK_PAGEUP)
- {
- state_.position[2] += ds;
- }
- else if (event.key.keysym.sym == SDLK_PAGEDOWN)
- {
- state_.position[2] -= ds;
- }
+ case SDL_KEYDOWN:
+ switch (event.key.keysym.sym)
+ {
+ case SDLK_RIGHT:
+ state_.position[0] -= ds; break;
+ case SDLK_LEFT:
+ state_.position[0] += ds; break;
+ case SDLK_UP:
+ state_.position[1] -= ds; break;
+ case SDLK_DOWN:
+ state_.position[1] += ds; break;
+ case SDLK_PAGEUP:
+ state_.position[2] += ds; break;
+ case SDLK_PAGEDOWN:
+ state_.position[2] -= ds; break;
+ default:
break;
+ }
+ break;
- case SDL_MOUSEMOTION:
- {
- scalar xrel = rad(scalar(event.motion.xrel) / 6.0);
- scalar yrel = rad(scalar(event.motion.yrel) / 6.0);
+ case SDL_MOUSEMOTION:
+ {
+ scalar xrel = rad(scalar(event.motion.xrel) / 6.0);
+ scalar yrel = rad(scalar(event.motion.yrel) / 6.0);
- quaternion rotation = state_.orientation;
+ quaternion rotation = state_.orientation;
- quaternion_rotate_about_world_x(rotation, yrel);
- //mRotation.normalize();
- quaternion_rotate_about_world_y(rotation, xrel);
+ quaternion_rotate_about_world_x(rotation, yrel);
+ //mRotation.normalize();
+ quaternion_rotate_about_world_y(rotation, xrel);
- rotation.normalize();
- state_.orientation = rotation;
- }
- break;
+ rotation.normalize();
+ state_.orientation = rotation;
+ break;
+ }
- case SDL_MOUSEBUTTONDOWN:
- if (event.button.button == SDL_BUTTON_WHEELUP)
- {
- state_.position[2] -= ds;
- }
- else if (event.button.button == SDL_BUTTON_WHEELDOWN)
- {
- state_.position[2] -= ds;
- }
+ case SDL_MOUSEBUTTONDOWN:
+ switch (event.button.button)
+ {
+ case SDL_BUTTON_WHEELUP:
+ state_.position[2] -= ds;
+ break;
+ case SDL_BUTTON_WHEELDOWN:
+ state_.position[2] += ds;
break;
+ }
}
}