NCBI C++ ToolKit
glarcball.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_OPENGL___ARC_BALL___HPP
2 #define GUI_OPENGL___ARC_BALL___HPP
3 
4 /* $Id: glarcball.hpp 14973 2007-09-14 12:11:32Z dicuccio $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software / database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software / database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Mike DiCuccio
30  *
31  * File Description:
32  *
33  */
34 
35 
36 #include <corelib/ncbistd.hpp>
37 
38 #include <gui/gui.hpp>
39 #include <gui/utils/quat.hpp>
40 #include <gui/utils/vect3.hpp>
41 #include <gui/utils/matrix4.hpp>
42 
43 /** @addtogroup GUI_OPENGL
44  *
45  * @{
46  */
47 
49 
50 
51 //
52 // class CGlArcBall implements an arbitrary rotation arc ball.
53 //
54 // This class interprets mouse drags as drags of a virtual globe centered at a
55 // position of the user's choice. The requirements to using this are:
56 // -- call BeginDrag() when the mouse drag starts
57 // -- call EndDrag() when the mouse drag ends
58 // -- call Update() on mouse movement in a drag as well as before calling
59 // both BeginDrag() and EndDrag()
60 // -- set the resolution of the window on resize
61 //
63 {
64 public:
67 
68  // ctor
69  CGlArcBall(void);
70  // construct at a center and radius
71  CGlArcBall(const TVect& center, float radius);
72  // dtor
73  ~CGlArcBall(void);
74 
75  // set the screen resolution
76  void Resolution(int x, int y);
77 
78  // place the world at a center and radius
79  void Place(const TVect& center, float radius);
80 
81  // place a world at a center, keeping the current radius
82  void Place(const TVect& center);
83 
84  // update the arc ball for a given mouse position
85  void Update(int x, int y);
86 
87  // begin a drag event
88  void BeginDrag(void);
89 
90  // end a drag event
91  void EndDrag(void);
92 
93  // determine if the arc ball is in a drag state
94  bool IsDragging(void) const;
95 
96  // apply the arcball using OpenGL
97  void ApplyGL() const;
98 
99  // access the current matrix
100  const CMatrix4<float>& GetMatrix() const { return m_MatNow; }
101 
102 private:
103  // boolean flag: are we dragging?
105 
106  // screen resolution
109 
110  // current mouse position(in scaled coordinates)
111  float m_MouseX;
112  float m_MouseY;
113 
114  // mouse position at the start of the drag cycle
116 
117  // center of the arcball world
119 
120  // radius of the arcball world
121  float m_Radius;
122 
123  // quaternions for rotation
127 
128  // current rotation matrix
130 
131 
132  // hidden and unimplemented
134  CGlArcBall& operator= (const CGlArcBall&);
135 
136  // convert screen coordinates to sphere coordinates
137  CVect4<float> x_ToSphere(float x, float y);
138 };
139 
140 
141 //
142 // set the screen resolution
143 inline
144 void CGlArcBall::Resolution(int x, int y)
145 {
146  m_ScreenX = x;
147  m_ScreenY = y;
148 }
149 
150 
151 //
152 // determine if the arc ballis being dragged
153 //
154 inline
155 bool CGlArcBall::IsDragging(void) const
156 {
157  return m_IsDragging;
158 }
159 
160 
162 
163 /* @} */
164 
165 #endif // GUI_OPENGL___ARC_BALL___HPP
Include a standard set of the NCBI C++ Toolkit most basic headers.
TQuat m_QuatDown
Definition: glarcball.hpp:125
CVect3< float > TVect
Definition: glarcball.hpp:65
CMatrix4< float > m_MatNow
Definition: glarcball.hpp:129
void Resolution(int x, int y)
Definition: glarcball.hpp:144
float m_MouseY
Definition: glarcball.hpp:112
CQuat< float > TQuat
Definition: glarcball.hpp:66
float m_Radius
Definition: glarcball.hpp:121
bool m_IsDragging
Definition: glarcball.hpp:104
CVect4< float > m_DragFrom
Definition: glarcball.hpp:115
bool IsDragging(void) const
Definition: glarcball.hpp:155
TQuat m_QuatNow
Definition: glarcball.hpp:124
TQuat m_QuatDrag
Definition: glarcball.hpp:126
CVect4< float > m_Center
Definition: glarcball.hpp:118
float m_MouseX
Definition: glarcball.hpp:111
CGlArcBall(const CGlArcBall &)
const CMatrix4< float > & GetMatrix() const
Definition: glarcball.hpp:100
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIOPENGL_EXPORT
Definition: gui_export.h:514
Modified on Fri May 24 14:50:42 2024 by modify_doxy.py rev. 669887