Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-12-04 00:17:15 +0000
committerStijn Buys <ingar@osirion.org>2010-12-04 00:17:15 +0000
commitaffa3d2a6761c4040434e11726695ad6e53a4cab (patch)
treeb707815ba3009c9bdc1f75759633ca9250396e0b /src
parenta92778d557df8bc853153d119224ea28390bdc9a (diff)
Correct camera axis and clear depth buffer when rendering ui models.
Diffstat (limited to 'src')
-rw-r--r--src/render/camera.cc66
-rw-r--r--src/render/camera.h1
-rwxr-xr-xsrc/ui/modelview.cc5
3 files changed, 39 insertions, 33 deletions
diff --git a/src/render/camera.cc b/src/render/camera.cc
index 851ad81..876fa42 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -31,6 +31,7 @@ const float pitch_overview = -5.0f;
math::Vector3f Camera::camera_eye;
math::Vector3f Camera::camera_target;
math::Axis Camera::camera_axis;
+math::Axis Camera::camera_scene_axis;
Camera::Mode Camera::camera_mode;
Camera::Mode Camera::camera_previous_mode;
@@ -66,6 +67,7 @@ void Camera::init()
set_mode(Track);
camera_axis.clear();
+ camera_scene_axis.clear();
camera_eye.clear();
camera_target.clear();
@@ -87,7 +89,7 @@ void Camera::set_mode(Mode newmode)
target_pitch = 0.0f;
distance = 0.4f;
- camera_axis.clear();
+ camera_scene_axis.clear();
if (camera_mode != Overview)
camera_previous_mode = camera_mode;
@@ -97,7 +99,7 @@ void Camera::set_mode(Mode newmode)
// switch camera to Track mode
camera_mode = Track;
if (core::localcontrol()) {
- camera_axis.assign(core::localcontrol()->axis());
+ camera_scene_axis.assign(core::localcontrol()->axis());
}
break;
@@ -170,21 +172,21 @@ void Camera::view_previous()
// 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"));
+ //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"));
+ //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"));
+ //core::application()->notify_message(core::Message::Info, std::string("view: free"));
break;
default:
@@ -223,14 +225,14 @@ void Camera::frame(float seconds)
if (core::localplayer()->view()) {
// player view entity
- camera_axis.assign(core::localplayer()->view()->axis());
+ camera_scene_axis.assign(core::localplayer()->view()->axis());
if (core::localplayer()->view() == core::localcontrol()) {
- camera_axis.change_pitch(pitch_free);
+ camera_scene_axis.change_pitch(pitch_free);
camera_target.assign(core::localplayer()->view()->location());
distance = math::max(core::localplayer()->view()->radius(), 1.0f) * 2.0f;
} else {
distance = math::max(core::localplayer()->view()->radius(), 1.0f) * 3.0f;
- camera_axis.change_direction(180.0f);
+ camera_scene_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));
}
@@ -238,16 +240,16 @@ void Camera::frame(float seconds)
} 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);
+ camera_scene_axis.assign(core::localplayer()->zone()->default_view()->axis());
+ camera_scene_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();
- camera_axis.clear();
+ camera_scene_axis.clear();
pitch_current = pitch_overview;
- camera_axis.change_pitch(pitch_current);
+ camera_scene_axis.change_pitch(pitch_current);
distance = 8.0f;
}
} else {
@@ -262,48 +264,48 @@ void Camera::frame(float seconds)
float angle; // angle in radians
math::Vector3f n; // normal of a plane
- n.assign(math::crossproduct(camera_axis.forward(), target_axis.forward()));
+ n.assign(math::crossproduct(camera_scene_axis.forward(), target_axis.forward()));
if (!(n.length() < MIN_DELTA)) {
n.normalize();
- cosangle = math::dotproduct(camera_axis.forward(), target_axis.forward());
+ cosangle = math::dotproduct(camera_scene_axis.forward(), target_axis.forward());
angle = acos(cosangle) * seconds; // * 180.0f / M_PI;
if (angle > MIN_DELTA)
- camera_axis.rotate(n, -angle);
+ camera_scene_axis.rotate(n, -angle);
}
- n.assign(math::crossproduct(camera_axis.left(), target_axis.left()));
+ n.assign(math::crossproduct(camera_scene_axis.left(), target_axis.left()));
if (!(n.length() < MIN_DELTA)) {
n.normalize();
- cosangle = math::dotproduct(camera_axis.left(), target_axis.left());
+ cosangle = math::dotproduct(camera_scene_axis.left(), target_axis.left());
angle = acos(cosangle) * seconds; // * 180.0f / M_PI;
if (angle > MIN_DELTA)
- camera_axis.rotate(n, -angle);
+ camera_scene_axis.rotate(n, -angle);
}
- n.assign(math::crossproduct(camera_axis.up(), target_axis.up()));
+ n.assign(math::crossproduct(camera_scene_axis.up(), target_axis.up()));
if (!(n.length() < MIN_DELTA)) {
n.normalize();
- cosangle = math::dotproduct(camera_axis.up(), target_axis.up());
+ cosangle = math::dotproduct(camera_scene_axis.up(), target_axis.up());
angle = acos(cosangle) * seconds; // * 180.0f / M_PI;
if (angle > MIN_DELTA)
- camera_axis.rotate(n, -angle);
+ camera_scene_axis.rotate(n, -angle);
}
if (core::localcontrol()->model() && core::localcontrol()->model()->radius()) {
const float modelscale = core::localcontrol()->radius() / core::localcontrol()->model()->radius();
- camera_target -= camera_axis.forward() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->box().max().x() * modelscale);
- camera_target += camera_axis.up() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->box().max().z() * modelscale);
+ camera_target -= camera_scene_axis.forward() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->box().max().x() * modelscale);
+ camera_target += camera_scene_axis.up() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->box().max().z() * modelscale);
} 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_scene_axis.forward() * math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
+ camera_target += camera_scene_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;
} else if (mode() == Free) {
- camera_axis.assign(target_axis);
+ camera_scene_axis.assign(target_axis);
direction_target = direction_current - 90 * target_direction;
pitch_target = pitch_current - 90 * target_pitch;
@@ -311,18 +313,18 @@ void Camera::frame(float seconds)
// adjust direction
d = degrees180f(direction_current - direction_target);
direction_current = degrees360f(direction_current - d * seconds);
- camera_axis.change_direction(direction_current);
+ camera_scene_axis.change_direction(direction_current);
// adjust pitch
d = degrees180f(pitch_current - pitch_target);
pitch_current = degrees360f(pitch_current - d * seconds);
- camera_axis.change_pitch(pitch_current);
+ camera_scene_axis.change_pitch(pitch_current);
distance = math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
} else if (mode() == Cockpit) {
- camera_axis.assign(target_axis);
+ camera_scene_axis.assign(target_axis);
if (core::localcontrol()->model()) {
const float modelscale = core::localcontrol()->radius() / core::localcontrol()->model()->radius();
@@ -337,7 +339,8 @@ void Camera::frame(float seconds)
}
// calculate eye position
- camera_eye = camera_target - (distance * camera_axis.forward());
+ camera_eye = camera_target - (distance * camera_scene_axis.forward());
+ camera_axis.assign(camera_scene_axis);
}
void Camera::frustum()
@@ -356,7 +359,7 @@ void Camera::frustum()
// apply the transpose of the axis transformation (the axis is orhtonormal)
math::Matrix4f matrix;
- matrix.assign(camera_axis);
+ matrix.assign(camera_scene_axis);
gl::multmatrix(matrix.transpose());
gl::scale(4.0f, 4.0f, 4.0f);
@@ -386,6 +389,7 @@ void Camera::frustum_default(float distance, float cx, float cy)
gl::translate(distance + 1.0f, 0.0f, 0.0f);
camera_eye.assign(-distance - 1.0f, 0.0f, 0.0f);
+ camera_axis.clear();
}
void Camera::ortho()
diff --git a/src/render/camera.h b/src/render/camera.h
index 80fdb36..cc6eaa5 100644
--- a/src/render/camera.h
+++ b/src/render/camera.h
@@ -95,6 +95,7 @@ private:
static math::Vector3f camera_eye;
static math::Vector3f camera_target;
static math::Axis camera_axis;
+ static math::Axis camera_scene_axis;
static Mode camera_mode;
static Mode camera_previous_mode;
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc
index 6d4e0e4..613382a 100755
--- a/src/ui/modelview.cc
+++ b/src/ui/modelview.cc
@@ -155,8 +155,6 @@ void ModelView::draw()
math ::Vector2f center(global_location() + size() * 0.5f);
- gl::clear(GL_DEPTH_BUFFER_BIT);
-
const float minscreen(math::min(root()->width(),root()->height()));
const float minwidget(math::min(width(), height()));
const float reference_radius = radius() * minwidget / minscreen;
@@ -178,6 +176,9 @@ void ModelView::draw()
gl::enable(GL_CULL_FACE); // enable culling
gl::enable(GL_COLOR_MATERIAL); // enable color tracking
+ // clear depth buffer
+ gl::clear(GL_DEPTH_BUFFER_BIT);
+
// enable vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);