diff options
author | Stijn Buys <ingar@osirion.org> | 2010-10-04 13:44:57 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-10-04 13:44:57 +0000 |
commit | 7a75ef50dcf1955739969b47ff88c6fce9c3843a (patch) | |
tree | ae5db0e3315abc8c9066deb3b1e79f5ae48c8775 /src/ui | |
parent | 75906b43ecb9a04fdab365bd8b1a00fbdbc66918 (diff) |
modelview widget rotation manipulation
Diffstat (limited to 'src/ui')
-rwxr-xr-x | src/ui/modelview.cc | 115 | ||||
-rwxr-xr-x | src/ui/modelview.h | 14 |
2 files changed, 125 insertions, 4 deletions
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc index c00cb07..a6a69ed 100755 --- a/src/ui/modelview.cc +++ b/src/ui/modelview.cc @@ -5,6 +5,7 @@ */ #include "auxiliary/functions.h" +#include "core/application.h" #include "ui/modelview.h" #include "ui/paint.h" #include "sys/sys.h" @@ -24,6 +25,11 @@ ModelView::ModelView(Widget *parent, const char *modelname) : Widget(parent) set_modelname(modelname); modelview_zoom = 1.0f; + modelview_manip = false; + + modelview_axis.clear(); + modelview_axis.change_direction(180); + modelview_axis.change_pitch(-15); } ModelView::~ModelView() @@ -68,11 +74,57 @@ bool ModelView::on_keypress(const int key, const unsigned int modifier) if (modelview_zoom > 10.0f) modelview_zoom = 10.0f; return true; + } else if (key == 512 + SDL_BUTTON_LEFT) { + //modelview_manipaxis.clear(); + modelview_manip = true; + return true; } return false; } +bool ModelView::on_keyrelease(const int key, const unsigned int modifier) +{ + if (key == 512 + SDL_BUTTON_LEFT) { + //modelview_manipaxis.clear(); + modelview_manip = false; + return true; + } + + return false; +} + +void ModelView::on_mousemove(const math::Vector2f &cursor) +{ + if ((width() <= 0) || (height() <= 0)) { + return; + } + + if (modelview_manip) { + const math::Vector2f pos(cursor - modelview_cursor); + + const math::Vector3f up(0.0f, 0.0f, 1.0f); + const float zrot = 45.0f * pos.x() / width(); + modelview_axis.rotate(up, -zrot); + //modelview_manipaxis.rotate(up, -zrot); + + const math::Vector3f left(0.0f, 1.0f, 0.0f); + const float yrot = 45.0f * pos.y() / height(); + modelview_axis.rotate(left, yrot); + //modelview_manipaxis.rotate(left, yrot); + + modelview_cursor.assign(cursor); + } + modelview_cursor.assign(cursor); +} + +void ModelView::on_mouseover(const math::Vector2f &cursor) +{ + modelview_cursor.assign(cursor); + //modelview_manipaxis.clear(); + modelview_manip = false; +} + void ModelView::draw_background() { Paint::set_color(1.0f, 1.0f, 1.0f); @@ -98,8 +150,12 @@ void ModelView::draw() gl::clear(GL_DEPTH_BUFFER_BIT); // gl 3d mode - render::Camera::frustum_default(model->radius() * modelview_zoom, center.x(), center.y()); + render::Camera::frustum_default(modelview_zoom * model->radius(), center.x(), center.y()); + // apply manipulation + gl::push(); + gl::multmatrix(modelview_axis); + gl::disable(GL_BLEND); gl::depthmask(GL_TRUE); // enable writing to the depth buffer gl::enable(GL_DEPTH_TEST); @@ -124,12 +180,63 @@ void ModelView::draw() gl::disable(GL_LIGHTING); gl::disable(GL_COLOR_MATERIAL); // disable color tracking gl::disable(GL_CULL_FACE); // disable culling - + + gl::enable(GL_BLEND); // enable alpha blending + gl::pop(); + + /* + // draw manipulation marker + if (has_mouse_focus() && modelview_manip) { + + gl::push(); + gl::multmatrix(modelview_manipaxis); + + const float r = model->radius(); + glAlphaFunc(GL_GREATER, 0.5f); + gl::enable(GL_ALPHA_TEST); + + gl::color(1.0f, 1.0f, 1.0f, 1.0f); + render::Textures::bind("bitmaps/ui/rotate"); + gl::enable(GL_TEXTURE_2D); + + gl::begin(gl::Quads); + + gl::texcoord(0.0f, 0.0f); + gl::vertex(r, 0.0f, r); + + gl::texcoord(1.0f, 0.0f); + gl::vertex(r, 0.0f, -r); + + gl::texcoord(1.0f, 1.0f); + gl::vertex(-r, 0.0f, -r); + + gl::texcoord(0.0f, 1.0f); + gl::vertex(-r, 0.0f, r); + + + gl::texcoord(1.0f, 1.0f); + gl::vertex(r, r, 0.0f); + + gl::texcoord(0.0f, 1.0f); + gl::vertex(r, -r, 0.0f); + + gl::texcoord(0.0f, 0.0f); + gl::vertex(-r, -r, 0.0f); + + gl::texcoord(1.0f, 0.0f); + gl::vertex(-r, r, 0.0f); + + gl::end(); + + gl::disable(GL_TEXTURE_2D); + gl::disable(GL_ALPHA_TEST); + + gl::pop(); + } + */ gl::depthmask(GL_TRUE); // enable depth buffer writing gl::disable(GL_DEPTH_TEST); // disable depth buffer testing - gl::enable(GL_BLEND); - // gl 2d mode render::Camera::ortho(); } diff --git a/src/ui/modelview.h b/src/ui/modelview.h index 89b6554..cb01dcb 100755 --- a/src/ui/modelview.h +++ b/src/ui/modelview.h @@ -7,6 +7,7 @@ #ifndef __INCLUDED_UI_MODELVIEW_H__ #define __INCLUDED_UI_MODELVIEW_H__ +#include "math/axis.h" #include "ui/widget.h" namespace ui @@ -57,11 +58,24 @@ protected: /// keypress event handler virtual bool on_keypress(const int key, const unsigned int modifier); + + /// keyrelease event handler + virtual bool on_keyrelease(const int key, const unsigned int modifier); + + virtual void on_mouseover(const math::Vector2f &cursor); + + /// mouse movement handler + virtual void on_mousemove(const math::Vector2f &cursor); private: std::string modelview_modelname; math::Color modelview_color; float modelview_zoom; + + math::Axis modelview_axis; + math::Vector2f modelview_cursor; + bool modelview_manip; + //math::Axis modelview_manipaxis; }; } |