Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-01-14 11:57:47 +0000
committerStijn Buys <ingar@osirion.org>2012-01-14 11:57:47 +0000
commit8ecbe636dd7e4930265614152914be6cb7b42583 (patch)
treeeeca918e2e38c6213898e63a415f0e45b4188252 /src/ui/modelview.cc
parentc508960e040e49a7c3c2d91b234bc46ac9a1f8b3 (diff)
Corrected ui::modelview lighting.
Diffstat (limited to 'src/ui/modelview.cc')
-rwxr-xr-xsrc/ui/modelview.cc49
1 files changed, 22 insertions, 27 deletions
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);