Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sgluSphericalTransform.hpp

00001 /*****************************************************************************
00002  * SGL: A Scene Graph Library
00003  *
00004  * Copyright (C) 1997-2001  Scott McMillan   All Rights Reserved.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free
00018  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *****************************************************************************
00020  *     File: sgluSphericalTransform.hpp
00021  *  Created: 15 January 2001
00022  *  Summary: spherical behavior subclass (adding GLUT mouse functionality to
00023  *           sglSphericalTransform class
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    // update the matrix using the pointer device information.
00078    virtual void update(sgluMouse *mouse);
00079 
00080 private:  // not implemented
00081    sgluSphericalTransform(const sgluSphericalTransform&);
00082    sgluSphericalTransform &operator=(const sgluSphericalTransform&);
00083 
00084 protected:
00085    // for update
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    // change viewpoint if delta is non-zero
00121    if (m_delta.dot(m_delta) > 0.0)
00122    {
00123       if (m_last_button & sgluMouse::eLEFT_DOWN)
00124       {
00125          // mouse x position controls azimuth
00126          // mouse y position controls elevation
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

Generated at Mon Jul 1 18:00:06 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001