From 8ecbe636dd7e4930265614152914be6cb7b42583 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 14 Jan 2012 11:57:47 +0000 Subject: Corrected ui::modelview lighting. --- src/ui/modelview.cc | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) (limited to 'src/ui/modelview.cc') diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc index b370029..61504d1 100755 --- a/src/ui/modelview.cc +++ b/src/ui/modelview.cc @@ -19,8 +19,6 @@ namespace ui { -float modelview_light[] = { 1, 0, 0, 1 }; - ModelView::ModelView(Widget *parent, const char *modelname) : Widget(parent) { set_border(false); @@ -125,11 +123,6 @@ void ModelView::on_mousemove(const math::Vector2f &cursor) } modelview_cursor.assign(cursor); - - //FIXME this is perhaps not the best way to do this - for(size_t i = 0; i<3; i++) { - modelview_light[i] = (-modelview_axis[i][0] / modelscale * 2); - } } void ModelView::on_mouseover(const math::Vector2f &cursor) @@ -167,7 +160,7 @@ void ModelView::draw() const float minscreen(math::min(root()->width(),root()->height())); const float minwidget(math::min(width(), height())); const float reference_radius = radius() * minwidget / minscreen; - modelscale = reference_radius / model->radius(); + const float modelscale = reference_radius / model->radius(); // gl 3d mode render::Camera::frustum_default(modelview_zoom, center.x(), center.y()); @@ -193,26 +186,10 @@ void ModelView::draw() glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); - // apply manipulation - gl::push(); - - - - gl::multmatrix(modelview_axis); - gl::scale(modelscale, modelscale, modelscale); - - render::State::set_normalize(true); - // FIXME the inventory window needs to be able to use actual thrust values - float thrust = ::sinf(core::application()->time() * 0.5f); - if (thrust < 0.0f ) { - thrust = 1.0f + thrust; - } else { - thrust = 1.0f; - } - - // let there be ModelView:: light! - GLfloat ambient_light[] = { 0.0f, 0.0f, 0.0f, 1.0f }; + // we set up the light in camera space + GLfloat modelview_light[] = { -2.0f * model->radius(), 0, 0, 1.0f }; + GLfloat ambient_light[] = { 0.25f, 0.25f, 0.25f, 1.0f }; GLfloat diffuse_light[4]; GLfloat specular_light[4]; for (size_t i = 0; i < 3; i++) { @@ -230,6 +207,24 @@ void ModelView::draw() glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05f); gl::enable(GL_LIGHT1); + + // push transformation matrix to stack + gl::push(); + + + + gl::multmatrix(modelview_axis); + gl::scale(modelscale, modelscale, modelscale); + + render::State::set_normalize(true); + + // FIXME the inventory window needs to be able to use actual thrust values + float thrust = ::sinf(core::application()->time() * 0.5f); + if (thrust < 0.0f ) { + thrust = 1.0f + thrust; + } else { + thrust = 1.0f; + } render::draw_model_fragments(model, modelview_color_primary, modelview_color_secondary, core::application()->time(), true, true, thrust); -- cgit v1.2.3