Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/camera.cc')
-rw-r--r--src/render/camera.cc225
1 files changed, 113 insertions, 112 deletions
diff --git a/src/render/camera.cc b/src/render/camera.cc
index 913adfb..329ab36 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -1,7 +1,7 @@
-/*
+/*
render/camera.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <cmath>
@@ -50,10 +50,10 @@ float Camera::camera_zoom;
void Camera::init()
{
direction_current = 0;
- direction_target = 0;
+ direction_target = 0;
- pitch_current = pitch_track * 2;
- pitch_target = pitch_track;
+ pitch_current = pitch_track * 2;
+ pitch_target = pitch_track;
target_pitch = 0.0f;
target_direction = 0.0f;
@@ -68,15 +68,16 @@ void Camera::init()
camera_axis.clear();
camera_eye.clear();
camera_target.clear();
-
+
}
void Camera::shutdown()
{
}
-void Camera::set_mode(Mode newmode) {
-
+void Camera::set_mode(Mode newmode)
+{
+
direction_target = 0;
direction_current = direction_target;
pitch_target = pitch_track;
@@ -91,103 +92,103 @@ void Camera::set_mode(Mode newmode) {
if (camera_mode != Overview)
camera_previous_mode = camera_mode;
- switch(newmode) {
- case Track:
- // switch camera to Track mode
- camera_mode = Track;
- if (core::localcontrol()) {
- camera_axis.assign(core::localcontrol()->axis());
- }
- break;
+ switch (newmode) {
+ case Track:
+ // switch camera to Track mode
+ camera_mode = Track;
+ if (core::localcontrol()) {
+ camera_axis.assign(core::localcontrol()->axis());
+ }
+ break;
- case Free:
- // switch camera to Free mode
- camera_mode = Free;
- pitch_target = pitch_free;
- pitch_current = pitch_target;
- break;
+ case Free:
+ // switch camera to Free mode
+ camera_mode = Free;
+ pitch_target = pitch_free;
+ pitch_current = pitch_target;
+ break;
- case Cockpit:
- camera_mode = Cockpit;
- break;
+ case Cockpit:
+ camera_mode = Cockpit;
+ break;
- case Overview:
- // switch camera to Overview mode
- camera_mode = Overview;
+ case Overview:
+ // switch camera to Overview mode
+ camera_mode = Overview;
- default:
- break;
+ default:
+ break;
}
}
void Camera::view_next()
{
-
- if (!core::localcontrol()) {
+
+ if (!core::localcontrol()) {
set_mode(Overview);
return;
}
- switch(camera_mode) {
- case Free:
- // switch camera to Track mode
- set_mode(Track);
- //con_print << "view: track" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: track"));
- break;
-
- case Track:
- // switch camera to Cockpit mode
- set_mode(Cockpit);
- //con_print << "view: cockpit" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
- break;
-
- case Cockpit:
- // switch camera to Free mode
- set_mode(Free);
- //con_print << "view: free" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: free"));
- break;
-
- default:
- break;
+ switch (camera_mode) {
+ case Free:
+ // switch camera to Track mode
+ set_mode(Track);
+ //con_print << "view: track" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: track"));
+ break;
+
+ case Track:
+ // switch camera to Cockpit mode
+ set_mode(Cockpit);
+ //con_print << "view: cockpit" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
+ break;
+
+ case Cockpit:
+ // switch camera to Free mode
+ set_mode(Free);
+ //con_print << "view: free" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: free"));
+ break;
+
+ default:
+ break;
}
}
void Camera::view_previous()
{
-
- if (!core::localcontrol()) {
+
+ if (!core::localcontrol()) {
set_mode(Overview);
return;
}
- switch(camera_mode) {
- case Cockpit:
- // switch camera to Track mode
- set_mode(Track);
- //con_print << "view: track" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: track"));
- break;
-
- case Free:
- // switch camera to Cockpit mode
- set_mode(Cockpit);
- //con_print << "view: cockpit" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
- break;
-
- case Track:
- // switch camera to Free mode
- set_mode(Free);
- //con_print << "view: free" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: free"));
- break;
-
- default:
- break;
+ switch (camera_mode) {
+ case Cockpit:
+ // switch camera to Track mode
+ set_mode(Track);
+ //con_print << "view: track" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: track"));
+ break;
+
+ case Free:
+ // switch camera to Cockpit mode
+ set_mode(Cockpit);
+ //con_print << "view: cockpit" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
+ break;
+
+ case Track:
+ // switch camera to Free mode
+ set_mode(Free);
+ //con_print << "view: free" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: free"));
+ break;
+
+ default:
+ break;
}
}
@@ -197,8 +198,8 @@ void Camera::set_zoom(float zoom)
math::clamp(camera_zoom, 1.0f, 10.0f);
}
-void Camera::frame(float seconds)
-{
+void Camera::frame(float seconds)
+{
math::Axis target_axis;
float d = 0;
@@ -218,10 +219,10 @@ void Camera::frame(float seconds)
if (mode() == Overview) {
camera_eye.clear();
-
+
if (core::localplayer()->view()) {
// player view entity
-
+
camera_axis.assign(core::localplayer()->view()->axis());
if (core::localplayer()->view() == core::localcontrol()) {
camera_axis.change_pitch(pitch_free);
@@ -230,17 +231,17 @@ void Camera::frame(float seconds)
} else {
distance = math::max(core::localplayer()->view()->radius(), 1.0f) * 3.0f;
camera_axis.change_direction(180.0f);
- camera_target.assign(core::localplayer()->view()->location() - core::localplayer()->view()->axis().left()* (math::max(core::localplayer()->view()->radius(), 1.0f)*0.5f) );
+ camera_target.assign(core::localplayer()->view()->location() - core::localplayer()->view()->axis().left()*(math::max(core::localplayer()->view()->radius(), 1.0f)*0.5f));
}
-
-/*
- } else if (core::localplayer()->zone()->default_view()) {
- // default zone view entity
- camera_target.assign(core::localplayer()->zone()->default_view()->location());
- camera_axis.assign(core::localplayer()->zone()->default_view()->axis());
- camera_axis.change_direction(180.0f);
- distance = math::max(core::localplayer()->zone()->default_view()->radius(), 1.0f) * 2.0f;
-*/
+
+ /*
+ } else if (core::localplayer()->zone()->default_view()) {
+ // default zone view entity
+ camera_target.assign(core::localplayer()->zone()->default_view()->location());
+ camera_axis.assign(core::localplayer()->zone()->default_view()->axis());
+ camera_axis.change_direction(180.0f);
+ distance = math::max(core::localplayer()->zone()->default_view()->radius(), 1.0f) * 2.0f;
+ */
} else {
// default location (0,0,0)
camera_target.clear();
@@ -258,7 +259,7 @@ void Camera::frame(float seconds)
if (mode() == Track) {
float cosangle; // cosine of an angle
- float angle; // angle in radians
+ float angle; // angle in radians
math::Vector3f n; // normal of a plane
n.assign(math::crossproduct(camera_axis.forward(), target_axis.forward()));
@@ -286,36 +287,36 @@ void Camera::frame(float seconds)
angle = acos(cosangle) * seconds; // * 180.0f / M_PI;
if (angle > MIN_DELTA)
camera_axis.rotate(n, -angle);
- }
+ }
if (core::localcontrol()->model()) {
camera_target -= camera_axis.forward() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->maxbbox().x());
camera_target += camera_axis.up() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->maxbbox().z() * 2.0f);
} else {
- camera_target -= camera_axis.forward() * math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
- camera_target += camera_axis.up() * math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
+ camera_target -= camera_axis.forward() * math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
+ camera_target += camera_axis.up() * math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
}
- distance = math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
+ distance = math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
} else if (mode() == Free) {
camera_axis.assign(target_axis);
-
+
direction_target = direction_current - 90 * target_direction;
pitch_target = pitch_current - 90 * target_pitch;
// adjust direction
d = degrees180f(direction_current - direction_target);
- direction_current = degrees360f( direction_current - d * seconds);
+ direction_current = degrees360f(direction_current - d * seconds);
camera_axis.change_direction(direction_current);
- // adjust pitch
+ // adjust pitch
d = degrees180f(pitch_current - pitch_target);
pitch_current = degrees360f(pitch_current - d * seconds);
camera_axis.change_pitch(pitch_current);
- distance = math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
+ distance = math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
} else if (mode() == Cockpit) {
@@ -323,10 +324,10 @@ void Camera::frame(float seconds)
if (core::localcontrol()->model()) {
camera_target += (core::localcontrol()->model()->maxbbox().x()) *
- core::localcontrol()->axis().forward();
+ core::localcontrol()->axis().forward();
} else {
camera_target += (core::localcontrol()->radius()) *
- core::localcontrol()->axis().forward();
+ core::localcontrol()->axis().forward();
}
distance = (FRUSTUMFRONT / WORLDSCALE) - 0.001f;
}
@@ -342,7 +343,7 @@ void Camera::frustum()
gl::matrixmode(GL_PROJECTION);
gl::loadidentity();
- gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE/State::aspect(), FRUSTUMSIZE/State::aspect(), FRUSTUMFRONT, core::range::maxdistance * WORLDSCALE);
+ gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE / State::aspect(), FRUSTUMSIZE / State::aspect(), FRUSTUMFRONT, core::range::maxdistance * WORLDSCALE);
gl::matrixmode(GL_MODELVIEW);
gl::loadidentity();
@@ -369,9 +370,9 @@ void Camera::frustum_default(float distance, float cx, float cy)
// move eye to (cx, cy)
// note: the factor 2.0f probably has to be 1.0f/frustum_size
- gl::translate(2.0f*(-State::width() * 0.5f + cx)/State::width() , 2.0f*(State::height() * 0.5f - cy)/State::height(), 0.0f);
+ gl::translate(2.0f*(-State::width() * 0.5f + cx) / State::width() , 2.0f*(State::height() * 0.5f - cy) / State::height(), 0.0f);
- gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE/State::aspect(), FRUSTUMSIZE/State::aspect(), FRUSTUMFRONT, 1023.0f);
+ gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE / State::aspect(), FRUSTUMSIZE / State::aspect(), FRUSTUMFRONT, 1023.0f);
gl::matrixmode(GL_MODELVIEW);
gl::loadidentity();
@@ -380,7 +381,7 @@ void Camera::frustum_default(float distance, float cx, float cy)
gl::rotate(90.0f, 0.0f, 1.0f, 0.0f);
gl::rotate(-90.0f, 1.0f , 0.0f, 0.0f);
- gl::translate(distance+1.0f, 0.0f, 0.0f);
+ gl::translate(distance + 1.0f, 0.0f, 0.0f);
// extra model rotation
gl::rotate(-core::application()->time() / 8.0f *360.0f , 0.0f, 0.0f, 1.0f);