00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _SGLU_SPHERICAL_TRANSFORM_HPP
00027 #define _SGLU_SPHERICAL_TRANSFORM_HPP
00028
00029 #include <sgl.h>
00030 #include <sgluMouse.hpp>
00031 #include <sglSphericalTransform.hpp>
00032
00040 template <class T>
00041 class SGLU_DLL_API sgluSphericalTransform : public sglSphericalTransform<T>
00042 {
00043 public:
00045 sgluSphericalTransform()
00046 : sglSphericalTransform<T>(),
00047 m_first_time(true),
00048 m_last_button(0x0),
00049 m_last_pos(0,0),
00050 m_delta(0,0),
00051 m_trans_scale(1.0),
00052 m_rot_scale(1.0)
00053 {
00054 }
00056 virtual ~sgluSphericalTransform() {}
00057
00059 virtual void reset()
00060 {
00061 sglSphericalTransform<T>::reset();
00062
00063 m_first_time = true;
00064 m_last_button = 0x0;
00065 m_last_pos.set(0,0);
00066 m_delta.set(0,0);
00067 m_trans_scale = (T)1.0;
00068 m_rot_scale = (T)1.0;
00069 }
00070
00071 void setTranslationScale(T scale) {m_trans_scale = scale;}
00072 T getTranslationScale() const {return m_trans_scale;}
00073
00074 void setRotationScale(T scale) {m_rot_scale = scale;}
00075 T getRotationScale() const {return m_rot_scale;}
00076
00077
00078 virtual void update(sgluMouse *mouse);
00079
00080 private:
00081 sgluSphericalTransform(const sgluSphericalTransform&);
00082 sgluSphericalTransform &operator=(const sgluSphericalTransform&);
00083
00084 protected:
00085
00086 bool m_first_time;
00087 int m_last_button;
00088 sglVec2<int> m_last_pos;
00089 sglVec2<int> m_delta;
00090 T m_trans_scale;
00091 T m_rot_scale;
00092 };
00093
00094
00095
00096 template <class T>
00097 void sgluSphericalTransform<T>::update(sgluMouse *mouse)
00098 {
00099 if (mouse->in_window_flag)
00100 {
00101 if (mouse->button_flags & (sgluMouse::eLEFT_DOWN|
00102 sgluMouse::eMIDDLE_DOWN|
00103 sgluMouse::eRIGHT_DOWN))
00104 {
00105 if (m_first_time)
00106 {
00107 m_last_pos.set(mouse->xwin, mouse->ywin);
00108 m_first_time = false;
00109 }
00110
00111 m_delta[0] = mouse->xwin - m_last_pos[0];
00112 m_delta[1] = mouse->ywin - m_last_pos[1];
00113
00114 m_last_button = mouse->button_flags;
00115 }
00116
00117 m_last_pos.set(mouse->xwin, mouse->ywin);
00118 }
00119
00120
00121 if (m_delta.dot(m_delta) > 0.0)
00122 {
00123 if (m_last_button & sgluMouse::eLEFT_DOWN)
00124 {
00125
00126
00127 updateAzimuth(-m_delta[0]*(M_PI/360.0)*m_rot_scale);
00128 updateElevation(-m_delta[1]*(M_PI/360.0)*m_rot_scale);
00129 }
00130
00131 if (m_last_button & sgluMouse::eMIDDLE_DOWN)
00132 {
00133 m_delta_pos[0] = -m_trans_scale*m_delta[0];
00134 m_delta_pos[1] = m_trans_scale*m_delta[1];
00135 }
00136
00137 if (m_last_button & sgluMouse::eRIGHT_DOWN)
00138 {
00139 updateRadius(-m_trans_scale*m_delta[1]);
00140 }
00141
00142 computeMatrix();
00143 }
00144 }
00145
00146 #endif