From 6a61bb6ff7847f020c5c53f0cb70b9ba4f35856a Mon Sep 17 00:00:00 2001 From: Evan Goers Date: Fri, 6 Jan 2012 06:38:05 +0000 Subject: Re-enabled modelview lighting, separate from game lighting. --- src/ui/modelview.cc | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src/ui/modelview.cc') diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc index 0fb8555..7ac8ef3 100755 --- a/src/ui/modelview.cc +++ b/src/ui/modelview.cc @@ -19,6 +19,8 @@ namespace ui { +float modelview_light[] = { 1, 0, 0, 1 }; + ModelView::ModelView(Widget *parent, const char *modelname) : Widget(parent) { set_border(false); @@ -114,14 +116,20 @@ void ModelView::on_mousemove(const math::Vector2f &cursor) const math::Vector3f up(0.0f, 0.0f, 1.0f); const float zrot = 2.0f * M_PI * pos.x() / width(); modelview_axis.rotate(up, -zrot); - + const math::Vector3f left(0.0f, 1.0f, 0.0f); const float yrot = 2.0f * M_PI * pos.y() / height(); modelview_axis.rotate(left, yrot); modelview_cursor.assign(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) @@ -159,7 +167,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; - const float modelscale = reference_radius / model->radius(); + modelscale = reference_radius / model->radius(); // gl 3d mode render::Camera::frustum_default(modelview_zoom, center.x(), center.y()); @@ -187,6 +195,9 @@ void ModelView::draw() // apply manipulation gl::push(); + + + gl::multmatrix(modelview_axis); gl::scale(modelscale, modelscale, modelscale); @@ -200,12 +211,32 @@ void ModelView::draw() thrust = 1.0f; } + // let there be ModelView:: light! + GLfloat ambient_light[] = { 0.0f, 0.0f, 0.0f, 1.0f }; + GLfloat diffuse_light[4]; + GLfloat specular_light[4]; + for (size_t i = 0; i < 3; i++) { + diffuse_light[i] = render::r_diffuse->value() * 0.6f; + specular_light[i] = render::r_specular->value() * 0.2f; + } + diffuse_light[3] = 1.0f; + specular_light[3] = 1.0f; + + glLightfv(GL_LIGHT1, GL_POSITION, modelview_light); + glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light); + glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light); + glLightfv(GL_LIGHT1, GL_SPECULAR, specular_light); + + gl::enable(GL_LIGHT1); + render::draw_model_fragments(model, modelview_color_primary, modelview_color_secondary, core::application()->time(), true, true, thrust); render::State::set_normalize(false); gl::pop(); + gl::disable(GL_LIGHT1); + glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); -- cgit v1.2.3