]>
Dogcows Code - chaz/yoink/blob - src/Moof/Camera.cc
cdebc7a7b735b7e681e3b28f041f576aa9166d7f
2 /*******************************************************************************
4 Copyright (c) 2009, Charles McGarvey
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *******************************************************************************/
30 #include <Moof/Camera.hh>
31 #include <Moof/OpenGL.hh>
37 void Camera::setPosition(const Vector3
& point
)
40 //Vector3 coeff[2] = {position_, point};
41 //pInterp_.init(coeff, 0.1);
43 void Camera::setRotation(const Quaternion
& rotation
)
49 void Camera::setProjection(const Matrix4
& projection
)
51 projection_
= projection
;
54 void Camera::setProjection(Scalar fovy
, Scalar aspect
, Scalar near
, Scalar far
)
56 cml::matrix_perspective_yfov_RH(projection_
, fovy
, aspect
, near
, far
,
63 void Camera::uploadProjectionToGL() const
65 glMatrixMode(GL_PROJECTION
);
66 glLoadMatrix(projection_
.data());
68 glMatrixMode(GL_MODELVIEW
);
71 void Camera::update(Scalar t
, Scalar dt
)
73 //pInterp_.update(dt);
74 //position_ = pInterp_.getState(0.0);
76 //calculateSecondary();
80 void Camera::lookAt(const Vector3
& point
)
82 quaternion_rotation_aim_at(rotation_
, position_
, point
);
85 void Camera::adjustFromInput(const Event
& event
)
90 if (event
.key
.keysym
.sym
== SDLK_RIGHT
||
91 event
.key
.keysym
.sym
== SDLK_d
)
93 Vector3 vec
= position_
;
97 else if (event
.key
.keysym
.sym
== SDLK_LEFT
||
98 event
.key
.keysym
.sym
== SDLK_a
)
100 Vector3 vec
= position_
;
104 else if (event
.key
.keysym
.sym
== SDLK_UP
||
105 event
.key
.keysym
.sym
== SDLK_w
)
107 Vector3 vec
= position_
;
111 else if (event
.key
.keysym
.sym
== SDLK_DOWN
||
112 event
.key
.keysym
.sym
== SDLK_s
)
114 Vector3 vec
= position_
;
118 else if (event
.key
.keysym
.sym
== SDLK_PAGEUP
)
120 Vector3 vec
= position_
;
124 else if (event
.key
.keysym
.sym
== SDLK_PAGEDOWN
)
126 //position_[2] -= 50.0;
127 Vector3 vec
= position_
;
133 case SDL_MOUSEMOTION
:
135 Scalar xrel
= cml::rad(Scalar(event
.motion
.xrel
) / 5.0);
136 Scalar yrel
= cml::rad(Scalar(event
.motion
.yrel
) / 5.0);
138 Quaternion rotation
= rotation_
;
140 quaternion_rotate_about_world_x(rotation
, yrel
);
141 //rotation_.normalize();
142 quaternion_rotate_about_world_y(rotation
, xrel
);
143 rotation
.normalize();
145 setRotation(rotation
);
149 case SDL_MOUSEBUTTONDOWN
:
150 if (event
.button
.button
== SDL_BUTTON_WHEELUP
)
152 Vector3 vec
= position_
;
156 else if (event
.button
.button
== SDL_BUTTON_WHEELDOWN
)
158 Vector3 vec
= position_
;
165 calculateSecondary();
168 void Camera::calculateSecondary()
170 matrix_rotation_quaternion(modelview_
, rotation_
);
173 matrix_translation(translate
, position_
);
175 //modelview_ = translate * modelview_;
176 modelview_
*= translate
;
178 frustum_
.init(modelview_
, projection_
);
184 /** vim: set ts=4 sw=4 tw=80: *************************************************/
This page took 0.04237 seconds and 4 git commands to generate.