]>
Dogcows Code - chaz/yoink/blob - src/moof/camera.cc
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
8 *****************************************************************************/
17 void camera::position(const vector3
& position
)
19 state_
.position
= position
;
22 void camera::rotation(const quaternion
& rotation
)
24 state_
.orientation
= rotation
;
27 void camera::look_at(const vector3
& point
)
29 // FIXME: this doesn't work as expected
30 quaternion_rotation_aim_at(state_
.orientation
, state_
.position
, point
,
31 vector3(0.0, 1.0, 0.0));
34 void camera::projection(const matrix4
& projection
)
36 projection_
= projection
;
39 void camera::projection(scalar fovy
,
40 scalar aspect
, scalar abutting
, scalar distant
)
42 matrix_perspective_yfov_RH(projection_
, fovy
, aspect
, abutting
,
43 distant
, z_clip_neg_one
);
46 void camera::upload_to_gl(scalar alpha
) const
50 glMatrixMode(GL_PROJECTION
);
51 glMultMatrix(projection_
.data());
53 glMatrixMode(GL_MODELVIEW
);
54 glMultMatrix(modelview_
.data());
57 void camera::calculate(scalar alpha
) const
59 state3 state
= rigid_body3::state(alpha
);
61 matrix_rotation_quaternion(modelview_
, state
.orientation
);
64 matrix_translation(translate
, state
.position
);
66 modelview_
*= translate
;
68 frustum_
.init(modelview_
, projection_
);
71 void camera::update(scalar t
, scalar dt
)
73 rigid_body3::update(t
, dt
);
76 void camera::draw(scalar alpha
) const
81 void camera::handle_event(const event
& event
)
83 const scalar ds
= 50.0;
88 switch (event
.key
.keysym
.sym
)
91 state_
.position
[0] -= ds
; break;
93 state_
.position
[0] += ds
; break;
95 state_
.position
[1] -= ds
; break;
97 state_
.position
[1] += ds
; break;
99 state_
.position
[2] += ds
; break;
101 state_
.position
[2] -= ds
; break;
107 case SDL_MOUSEMOTION
:
109 scalar xrel
= rad(scalar(event
.motion
.xrel
) / 6.0);
110 scalar yrel
= rad(scalar(event
.motion
.yrel
) / 6.0);
112 quaternion rotation
= state_
.orientation
;
114 quaternion_rotate_about_world_x(rotation
, yrel
);
115 //mRotation.normalize();
116 quaternion_rotate_about_world_y(rotation
, xrel
);
118 rotation
.normalize();
119 state_
.orientation
= rotation
;
123 case SDL_MOUSEBUTTONDOWN
:
124 switch (event
.button
.button
)
126 case SDL_BUTTON_WHEELUP
:
127 state_
.position
[2] -= ds
;
129 case SDL_BUTTON_WHEELDOWN
:
130 state_
.position
[2] += ds
;
This page took 0.037364 seconds and 4 git commands to generate.