glmtransform.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:5k
- /*
- * ===========================================================================
- * PRODUCTION $Log: glmtransform.hpp,v $
- * PRODUCTION Revision 1000.0 2004/04/12 19:32:56 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [CATCHUP_003] Dev-tree R1.1
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_OPENGL___GLM_TRANSFORM___HPP
- #define GUI_OPENGL___GLM_TRANSFORM___HPP
- /* $Id: glmtransform.hpp,v 1000.0 2004/04/12 19:32:56 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Mike DiCuccio, Vladimir Tereshkov
- *
- * File Description:
- * Arbitrary OpenGL Mouse transformations class based on CGlArcBall with addition of pan and zoom
- */
- #include <corelib/ncbistd.hpp>
- #include <gui/math/quat.hpp>
- #include <gui/math/vect3.hpp>
- #include <gui/math/matrix4.hpp>
- BEGIN_NCBI_SCOPE
- class CGlMTransform
- {
- public:
- typedef CVect3<float> TVect;
- typedef CQuat<float> TQuat;
- enum EMode {
- eRotate,
- ePan,
- eZoom,
- eTranslate, // pan+zoom
- eAll // translate+rotate
- };
- // ctor
- CGlMTransform(void);
- // construct at a center and radius
- CGlMTransform(const TVect& center, float radius);
- // dtor
- ~CGlMTransform(void);
- // set the screen resolution
- void Resolution(int x, int y);
- // place the world at a center and radius
- void Place(const TVect& center, float radius);
- // place a world at a center, keeping the current radius
- void Place(const TVect& center);
- // update the arc ball for a given mouse position
- void Update(int x, int y);
- // begin a drag event
- void BeginDrag(void);
- // end a drag event
- void EndDrag(void);
- // determine if the arc ball is in a drag state
- bool IsDragging(void) const;
- // apply the arcball using OpenGL
- void ApplyGL(EMode mode = eAll) const;
- // mode switches
- void Switch2Mode(int mode);
- void Switch2Rotate();
- void Switch2Pan();
- void Switch2Zoom();
- CGlMTransform& operator= (const CGlMTransform&);
- CGlMTransform(const CGlMTransform&);
- // access the current rotation matrix
- const CMatrix4<float>& GetMatrix() const { return m_MatNow; }
- // access the current translation vector
- const CVect3<float>& GetTranslation() const { return m_Translate; }
- private:
- // current mode
- EMode m_Mode;
- // boolean flag: are we dragging?
- bool m_IsDragging;
- // screen resolution
- int m_ScreenX;
- int m_ScreenY;
- // current mouse position(in scaled coordinates)
- float m_MouseX;
- float m_MouseY;
- // mouse position at the start of the drag cycle
- CVect4 < float> m_DragFrom;
- // center of the arcball world
- CVect4 < float> m_Center;
- // radius of the arcball world
- float m_Radius;
- // quaternions for rotation
- TQuat m_QuatNow;
- TQuat m_QuatDown;
- TQuat m_QuatDrag;
- // current rotation matrix
- CMatrix4<float> m_MatNow;
- // zoom and pan
- CVect3<float> m_Translate;
- CVect3<float> m_TranslateDown;
- // convert screen coordinates to sphere coordinates
- CVect4<float> x_ToSphere(float x, float y);
- };
- //
- // set the screen resolution
- inline
- void CGlMTransform::Resolution(int x, int y)
- {
- m_ScreenX = x;
- m_ScreenY = y;
- }
- //
- // determine if the arc ballis being dragged
- //
- inline
- bool CGlMTransform::IsDragging(void) const
- {
- return m_IsDragging;
- }
- // mode setup functions
- inline
- void CGlMTransform::Switch2Mode(int mode)
- {
- m_Mode = static_cast<EMode>(mode);
- }
- inline
- void CGlMTransform::Switch2Rotate()
- {
- m_Mode = eRotate;
- }
- inline
- void CGlMTransform::Switch2Pan()
- {
- m_Mode = ePan;
- }
- inline
- void CGlMTransform::Switch2Zoom()
- {
- m_Mode = eZoom;
- }
-
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: glmtransform.hpp,v $
- * Revision 1000.0 2004/04/12 19:32:56 gouriano
- * PRODUCTION: IMPORTED [CATCHUP_003] Dev-tree R1.1
- *
- * Revision 1.1 2004/01/05 16:20:49 tereshko
- * Initial revision
- *
- * ===========================================================================
- */
- #endif // GUI_OPENGL___GLM_TRANSFORM___HPP