Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-11-29 13:37:16 +0000
committerStijn Buys <ingar@osirion.org>2010-11-29 13:37:16 +0000
commit409d3ce47d8a4d48947c7b19fc2460fd801b742c (patch)
tree3a6a029bcd1041a9bd88f8868bf11372c91ac5a7 /src/ui
parenta7808ebdf39b549f4e0df38e6d897caa2dbb24bd (diff)
Added 'testmodel' function, enabled autoscaling on ui::ModelView
Diffstat (limited to 'src/ui')
-rwxr-xr-xsrc/ui/modelview.cc24
-rwxr-xr-xsrc/ui/modelview.h13
2 files changed, 33 insertions, 4 deletions
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc
index 1485d79..e715119 100755
--- a/src/ui/modelview.cc
+++ b/src/ui/modelview.cc
@@ -8,6 +8,7 @@
#include "core/application.h"
#include "ui/modelview.h"
#include "ui/paint.h"
+#include "ui/ui.h"
#include "sys/sys.h"
#include "render/camera.h"
#include "render/draw.h"
@@ -53,6 +54,8 @@ void ModelView::set_modelname(const char *modelname)
modelview_axis.clear();
modelview_axis.change_direction(180);
modelview_axis.change_pitch(-15);
+ modelview_zoom = 1.0f;
+ modelview_radius = 0.75f;
}
void ModelView::set_color(const math::Color & color)
@@ -147,13 +150,25 @@ 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;
+ const float modelscale = reference_radius / model->radius();
// gl 3d mode
- render::Camera::frustum_default(modelview_zoom * model->radius(), center.x(), center.y());
+ render::Camera::frustum_default(modelview_zoom, center.x(), center.y());
+
+ // reset lighting
+ render::pass_reset_lights();
+ // enable lighting
+ gl::enable(GL_LIGHTING);
+
// apply manipulation
gl::push();
gl::multmatrix(modelview_axis);
+ gl::scale(modelscale, modelscale, modelscale);
gl::disable(GL_BLEND);
gl::depthmask(GL_TRUE); // enable writing to the depth buffer
@@ -162,15 +177,16 @@ void ModelView::draw()
gl::enable(GL_CULL_FACE); // enable culling
gl::enable(GL_COLOR_MATERIAL); // enable color tracking
- // FIXME - initialize lights
- gl::enable(GL_LIGHTING);
-
// enable vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
+
+ render::State::set_normalize(true);
render::draw_model_fragments(model, core::localplayer()->color(), core::localplayer()->color_second(), core::application()->time(), true, true, 0.0f);
+
+ render::State::set_normalize(false);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
diff --git a/src/ui/modelview.h b/src/ui/modelview.h
index 7cbf76d..c235e99 100755
--- a/src/ui/modelview.h
+++ b/src/ui/modelview.h
@@ -26,6 +26,14 @@ public:
inline math::Color const &color() const {
return modelview_color;
}
+
+ inline float zoom() const {
+ return modelview_zoom;
+ }
+
+ inline float radius() const {
+ return modelview_radius;
+ }
void set_modelname(const char *modelname);
@@ -45,6 +53,10 @@ public:
* 1.0 is not zoomed out, 10.0 is zoomed out by a factor of 10
*/
void set_zoom(const float zoom);
+
+ inline void set_radius(const float radius) {
+ modelview_radius = radius;
+ }
protected:
/// draw the widget
@@ -71,6 +83,7 @@ private:
std::string modelview_modelname;
math::Color modelview_color;
float modelview_zoom;
+ float modelview_radius;
math::Axis modelview_axis;
math::Vector2f modelview_cursor;