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')
-rw-r--r--src/render/camera.cc37
-rw-r--r--src/render/camera.h13
2 files changed, 37 insertions, 13 deletions
diff --git a/src/render/camera.cc b/src/render/camera.cc
index 507a81f..e37fd0d 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -23,6 +23,8 @@ const float pitch_track = -15.0f;
const float pitch_overview = -75.0f;
float Camera::camera_aspect = 1.0f;
+float Camera::camera_frustum_size = 0.5f;
+float Camera::camera_frustum_front = 1.0f;
math::Vector3f Camera::camera_eye;
math::Vector3f Camera::camera_target;
math::Axis Camera::camera_axis;
@@ -43,6 +45,9 @@ float Camera::distance;
void Camera::init()
{
camera_aspect = 1.0f;
+
+ camera_frustum_size = 0.5f;
+ camera_frustum_front = 1.0f;
direction_current = 0;
direction_target = 0;
@@ -67,13 +72,13 @@ void Camera::shutdown()
{
}
-void Camera::set_aspect(float aspect)
+void Camera::set_aspect(int width, int height)
{
- camera_aspect = aspect;
+ camera_aspect = (float) width / (float) height;
}
void Camera::set_mode(Mode newmode) {
-
+
direction_target = 0;
direction_current = direction_target;
pitch_target = pitch_track;
@@ -83,6 +88,9 @@ void Camera::set_mode(Mode newmode) {
target_pitch = 0.0f;
distance = 0.4f;
+ camera_frustum_size = 0.5f;
+ camera_frustum_front = 1.0f;
+
camera_axis.clear();
switch(newmode) {
@@ -174,7 +182,7 @@ void Camera::frame(float seconds)
set_mode(Track);
camera_target.assign(core::localcontrol()->state()->location());
- target_axis.assign(core::localcontrol()->state()->axis());
+ target_axis.assign(core::localcontrol()->state()->axis());
distance = core::localcontrol()->radius();
if (mode() == Track) {
@@ -291,7 +299,7 @@ void Camera::frame(float seconds)
}
}
- distance += frustum_front;
+ distance += camera_frustum_front;
// calculate eye position
camera_eye = camera_target - (distance * camera_axis.forward());
@@ -302,15 +310,16 @@ void Camera::draw()
// Change to the projection matrix and set our viewing volume large enough for the skysphere
gl::matrixmode(GL_PROJECTION);
gl::loadidentity();
- gl::frustum(-frustum_size*Camera::aspect(), frustum_size*Camera::aspect(),
- -frustum_size, frustum_size, frustum_front, 2048.0f);
+// gl::frustum(-camera_frustum_size*Camera::aspect(), camera_frustum_size*Camera::aspect(),
+// -camera_frustum_size, camera_frustum_size, camera_frustum_front, 2048.0f);
+ gl::frustum(-camera_frustum_size, camera_frustum_size, -camera_frustum_size/Camera::aspect(), camera_frustum_size/Camera::aspect(), camera_frustum_front, 2048.0f);
gl::matrixmode(GL_MODELVIEW);
gl::loadidentity();
// map world coordinates to opengl coordinates
- gl::rotate(90.0f, 0, 1.0, 0);
- gl::rotate(-90.0f, 1.0f , 0, 0);
+ gl::rotate(90.0f, 0.0f, 1.0f, 0.0f);
+ gl::rotate(-90.0f, 1.0f , 0.0f, 0.0f);
// apply the transpose of the axis transformation (the axis is orhtonormal)
math::Matrix4f matrix;
@@ -343,4 +352,14 @@ void Camera::reset()
set_mode(camera_mode);
}
+float Camera::frustum_front()
+{
+ return camera_frustum_front;
+}
+
+float Camera::frustum_size()
+{
+ return camera_frustum_size;
+}
+
}
diff --git a/src/render/camera.h b/src/render/camera.h
index edc3496..253661f 100644
--- a/src/render/camera.h
+++ b/src/render/camera.h
@@ -11,9 +11,6 @@
namespace render {
-const float frustum_size = 0.5f;
-const float frustum_front = 1.0f;
-
/// camera functions
class Camera
{
@@ -65,7 +62,13 @@ public:
static void set_mode(Mode newmode);
/// set camera aspect ratio
- static void set_aspect(float aspect);
+ static void set_aspect(int width, int height);
+
+ /// current frustum front
+ static float frustum_front();
+
+ /// current frustum size (height);
+ static float frustum_size();
private:
static math::Vector3f camera_eye;
@@ -73,6 +76,8 @@ private:
static math::Axis camera_axis;
static Mode camera_mode;
static float camera_aspect;
+ static float camera_frustum_size;
+ static float camera_frustum_front;
// current and target yaw angle in XZ plane, positive is looking left
static float direction_current;