From 409d3ce47d8a4d48947c7b19fc2460fd801b742c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 29 Nov 2010 13:37:16 +0000 Subject: Added 'testmodel' function, enabled autoscaling on ui::ModelView --- src/ui/modelview.cc | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/ui/modelview.cc') 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); -- cgit v1.2.3