]>
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::setPosition(const Vector3
& position
)
21 mState
.position
= position
;
24 void Camera::setRotation(const Quaternion
& rotation
)
26 mState
.orientation
= rotation
;
29 void Camera::lookAt(const Vector3
& point
)
31 // FIXME this doesn't work as expected
32 cml::quaternion_rotation_aim_at(mState
.orientation
,
33 mState
.position
, point
,
34 Vector3(0.0, 1.0, 0.0));
38 void Camera::setProjection(const Matrix4
& projection
)
40 mProjection
= projection
;
43 void Camera::setProjection(Scalar fovy
, Scalar aspect
, Scalar abutting
,
46 cml::matrix_perspective_yfov_RH(mProjection
, fovy
, aspect
, abutting
,
47 distant
, cml::z_clip_neg_one
);
51 void Camera::uploadToGL(Scalar alpha
) const
55 glMatrixMode(GL_PROJECTION
);
56 glMultMatrix(mProjection
.data());
58 glMatrixMode(GL_MODELVIEW
);
59 glMultMatrix(mModelview
.data());
62 void Camera::calculate(Scalar alpha
) const
64 State3 state
= getState(alpha
);
66 cml::matrix_rotation_quaternion(mModelview
, state
.orientation
);
69 cml::matrix_translation(translate
, state
.position
);
71 mModelview
*= translate
;
73 mFrustum
.init(mModelview
, mProjection
);
77 void Camera::update(Scalar t
, Scalar dt
)
79 RigidBody3::update(t
, dt
);
82 void Camera::draw(Scalar alpha
) const
88 void Camera::handleEvent(const Event
& event
)
90 const Scalar ds
= 50.0;
95 if (event
.key
.keysym
.sym
== SDLK_RIGHT
)
97 mState
.position
[0] -= ds
;
99 else if (event
.key
.keysym
.sym
== SDLK_LEFT
)
101 mState
.position
[0] += ds
;
103 else if (event
.key
.keysym
.sym
== SDLK_UP
)
105 mState
.position
[1] -= ds
;
107 else if (event
.key
.keysym
.sym
== SDLK_DOWN
)
109 mState
.position
[1] += ds
;
111 else if (event
.key
.keysym
.sym
== SDLK_PAGEUP
)
113 mState
.position
[2] += ds
;
115 else if (event
.key
.keysym
.sym
== SDLK_PAGEDOWN
)
117 mState
.position
[2] -= ds
;
121 case SDL_MOUSEMOTION
:
123 Scalar xrel
= cml::rad(Scalar(event
.motion
.xrel
) / 6.0);
124 Scalar yrel
= cml::rad(Scalar(event
.motion
.yrel
) / 6.0);
126 Quaternion rotation
= mState
.orientation
;
128 cml::quaternion_rotate_about_world_x(rotation
, yrel
);
129 //mRotation.normalize();
130 cml::quaternion_rotate_about_world_y(rotation
, xrel
);
132 rotation
.normalize();
133 mState
.orientation
= rotation
;
137 case SDL_MOUSEBUTTONDOWN
:
138 if (event
.button
.button
== SDL_BUTTON_WHEELUP
)
140 mState
.position
[2] -= ds
;
142 else if (event
.button
.button
== SDL_BUTTON_WHEELDOWN
)
144 mState
.position
[2] -= ds
;
This page took 0.042912 seconds and 5 git commands to generate.