From 632f4842f13092e2aa5ce196867fab4bac6b920d Mon Sep 17 00:00:00 2001 From: ponchio Date: Tue, 28 Oct 2008 16:43:56 +0000 Subject: [PATCH] Polar mode now working. --- wrap/gui/trackmode.cpp | 25 ++++++++++++++++++++----- wrap/gui/trackmode.h | 8 +++++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/wrap/gui/trackmode.cpp b/wrap/gui/trackmode.cpp index 7a9aa3f7..b6954092 100644 --- a/wrap/gui/trackmode.cpp +++ b/wrap/gui/trackmode.cpp @@ -781,15 +781,30 @@ void PolarMode::Apply (Trackball * tb, Point3f new_point) float dx = (hitNew.X() - hitOld.X()); float dy = (hitNew.Y() - hitOld.Y()); - const float PI2=6.283185307179586232f; + const float scale = 0.5*M_PI; //sensitivity of the mouse + const float top = 0.9*M_PI/2; //maximum top view angle - float anglex = dx/(tb->radius * PI2); - float angley = -dy/(tb->radius * PI2); - - tb->track.rot = Quaternionf (anglex,Point3f(0,1,0)) * Quaternionf (angley,Point3f(1,0,0)) * tb->last_track.rot ; + float anglex = dx/(tb->radius * scale); + float angley = -dy/(tb->radius * scale); + enda = alpha + anglex; + endb = beta + angley; + if(endb > top) endb = top; + if(endb < -top) endb = -top; + tb->track.rot = Quaternionf (endb, Point3f(1,0,0)) * + Quaternionf (enda, Point3f(0,1,0)) ; } +void PolarMode::SetAction() { + alpha = enda; + beta = endb; +} + +void PolarMode::Reset() { + alpha = beta = enda = endb = 0; +} + + void PolarMode::Draw(Trackball * tb){ DrawSphereIcon(tb,true ); } diff --git a/wrap/gui/trackmode.h b/wrap/gui/trackmode.h index e5e02ca3..994d5a39 100644 --- a/wrap/gui/trackmode.h +++ b/wrap/gui/trackmode.h @@ -1016,16 +1016,22 @@ private: }; // Polar mode. +/* WARNING this mode is not compatible with the other rotation modes */ class PolarMode:public TrackMode { public: + PolarMode(): alpha(0), beta(0), enda(0), endb(0) {} void Apply (Trackball * trackball, Point3f new_point); const char *Name () { return "PolarMode"; }; - + void SetAction(); + void Reset(); void Draw (Trackball * trackball); +private: + double alpha, beta; //rotation in y and x axis + double enda, endb; //store intermediate values of alpha and beta };