]>
Dogcows Code - chaz/yoink/blob - src/moof/camera.cc
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
19 void camera::position(const vector3
& position
)
21 state_
.position
= position
;
24 void camera::rotation(const quaternion
& rotation
)
26 state_
.orientation
= rotation
;
29 void camera::look_at(const vector3
& point
)
31 // FIXME: this doesn't work as expected
32 quaternion_rotation_aim_at(state_
.orientation
,
33 state_
.position
, point
,
34 vector3(0.0, 1.0, 0.0));
38 void camera::projection(const matrix4
& projection
)
40 projection_
= projection
;
43 void camera::projection(scalar fovy
, scalar aspect
, scalar abutting
,
46 matrix_perspective_yfov_RH(projection_
, fovy
, aspect
, abutting
,
47 distant
, z_clip_neg_one
);
51 void camera::upload_to_gl(scalar alpha
) const
55 glMatrixMode(GL_PROJECTION
);
56 glMultMatrix(projection_
.data());
58 glMatrixMode(GL_MODELVIEW
);
59 glMultMatrix(modelview_
.data());
62 void camera::calculate(scalar alpha
) const
64 state3 state
= rigid_body3::state(alpha
);
66 matrix_rotation_quaternion(modelview_
, state
.orientation
);
69 matrix_translation(translate
, state
.position
);
71 modelview_
*= translate
;
73 frustum_
.init(modelview_
, projection_
);
77 void camera::update(scalar t
, scalar dt
)
79 rigid_body3::update(t
, dt
);
82 void camera::draw(scalar alpha
) const
88 void camera::handle_event(const event
& event
)
90 const scalar ds
= 50.0;
95 if (event
.key
.keysym
.sym
== SDLK_RIGHT
)
97 state_
.position
[0] -= ds
;
99 else if (event
.key
.keysym
.sym
== SDLK_LEFT
)
101 state_
.position
[0] += ds
;
103 else if (event
.key
.keysym
.sym
== SDLK_UP
)
105 state_
.position
[1] -= ds
;
107 else if (event
.key
.keysym
.sym
== SDLK_DOWN
)
109 state_
.position
[1] += ds
;
111 else if (event
.key
.keysym
.sym
== SDLK_PAGEUP
)
113 state_
.position
[2] += ds
;
115 else if (event
.key
.keysym
.sym
== SDLK_PAGEDOWN
)
117 state_
.position
[2] -= ds
;
121 case SDL_MOUSEMOTION
:
123 scalar xrel
= rad(scalar(event
.motion
.xrel
) / 6.0);
124 scalar yrel
= rad(scalar(event
.motion
.yrel
) / 6.0);
126 quaternion rotation
= state_
.orientation
;
128 quaternion_rotate_about_world_x(rotation
, yrel
);
129 //mRotation.normalize();
130 quaternion_rotate_about_world_y(rotation
, xrel
);
132 rotation
.normalize();
133 state_
.orientation
= rotation
;
137 case SDL_MOUSEBUTTONDOWN
:
138 if (event
.button
.button
== SDL_BUTTON_WHEELUP
)
140 state_
.position
[2] -= ds
;
142 else if (event
.button
.button
== SDL_BUTTON_WHEELDOWN
)
144 state_
.position
[2] -= ds
;
This page took 0.040254 seconds and 4 git commands to generate.