GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_reptrackballmover.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  *****************************************************************************/
22 
24 
25 #include "glc_reptrackballmover.h"
26 #include "glc_viewport.h"
27 #include "../glc_factory.h"
28 #include "../glc_context.h"
29 #include <QGLContext>
30 
31 using namespace glc;
33 #define ARCANGLE (30 * PI / 180)
34 
36 : GLC_RepMover(pViewport)
37 , m_Radius(1.0)
38 , m_MainCircle(m_Radius)
39 , m_Arc1(GLC_Factory::instance()->createCircle(m_Radius, ARCANGLE))
40 , m_MatArc1()
41 , m_Arc2(GLC_Factory::instance()->createCircle(m_Radius, ARCANGLE))
42 , m_MatArc2()
43 , m_Ratio(0.95)
44 {
48 
49  // 2 circle arcs position
50  GLC_Matrix4x4 MatRot(Z_AXIS, -ARCANGLE / 2);
51  GLC_Matrix4x4 MatInt(Y_AXIS, -PI / 2);
52  MatRot= MatInt * MatRot;
53 
54  m_MatArc1= MatRot;
55 
56  MatInt.setMatRot(Z_AXIS, PI/2);
57  MatRot= MatInt * MatRot;
58 
59  m_MatArc2= MatRot;
60 
61 }
62 
63 // Copy constructor
65 : GLC_RepMover(repMover)
66 , m_Radius(repMover.m_Radius)
67 , m_MainCircle(repMover.m_MainCircle)
68 , m_Arc1(repMover.m_Arc1.deepCopy())
69 , m_MatArc1(repMover.m_MatArc1)
70 , m_Arc2(repMover.m_Arc2.deepCopy())
71 , m_MatArc2(repMover.m_MatArc2)
72 , m_Ratio(repMover.m_Ratio)
73 {
74 
75 }
76 
78 {
79 
80 }
81 
82 
84 // Get Functions
86 
87 // Return a clone of the repmover
89 {
90  return new GLC_RepTrackBallMover(*this);
91 }
92 
94 // Set Functions
96 
97 // Set Arcs orientation and position in concordance with mouse position
99 {
100  Q_ASSERT(NULL != m_pRepMoverInfo);
101  Q_ASSERT(!m_pRepMoverInfo->m_VectorInfo.isEmpty());
102  Q_ASSERT(!m_pRepMoverInfo->m_MatrixInfo.isEmpty());
103 
104  GLC_Vector3d VectAngle(m_pRepMoverInfo->m_VectorInfo.first());
105  VectAngle.setZ(0);
106  VectAngle.setLength(1);
107 
108  GLC_Matrix4x4 MatRot;
109  double Angle;
110 
111  // Compute the 2 arcs orientation
112  if (VectAngle.y() > 0)
113  { // Angle entre 0 et PI
114  Angle= acos(VectAngle.x());
115  MatRot.setMatRot(Z_AXIS, Angle);
116  }
117  else
118  { // Angle between 0 et -PI
119  Angle= -acos(VectAngle.x());
120  MatRot.setMatRot(Z_AXIS, Angle);
121  }
122 
123  // Composition of orientation matrix and mapping matrix
124  MatRot= m_pRepMoverInfo->m_MatrixInfo.first() * MatRot;
125 
126  m_Arc1.setMatrix(MatRot * m_MatArc1);
127  m_Arc2.setMatrix(MatRot * m_MatArc2);
128 }
129 
130 // Set Arcs position in concordance with mouse position
132 {
133  Q_ASSERT(NULL != m_pRepMoverInfo);
134  Q_ASSERT(!m_pRepMoverInfo->m_MatrixInfo.isEmpty());
135  const GLC_Matrix4x4 matrix(m_pRepMoverInfo->m_MatrixInfo.first());
136  m_Arc1.multMatrix(matrix);
137  m_Arc2.multMatrix(matrix);
138 }
139 
140 // overload function setColor(color);
141 void GLC_RepTrackBallMover::setMainColor(const QColor& color)
142 {
147 }
148 
150 // OpenGL Functions
152 
153 // Virtual interface for OpenGL Geometry set up.
155 {
156  computeRadius();
157  const double aspectRatio= static_cast<double>(m_pViewport->viewHSize())/static_cast<double>(m_pViewport->viewVSize());
158 
159  // orbit circle must be shown
160  glDisable(GL_DEPTH_TEST);
161 
162  GLC_Context::current()->glcMatrixMode(GL_PROJECTION);
165  GLC_Context::current()->glcOrtho(aspectRatio * -1.0 ,aspectRatio * 1.0 ,-1.0 ,1.0 ,-1.0 ,1.0);
166  GLC_Context::current()->glcMatrixMode(GL_MODELVIEW);
169 
170  glDisable(GL_BLEND);
172  // Display arcs
175  // Display base class (Main circle)
177 
178  glEnable(GL_BLEND);
179  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
181  // Display arcs
184  // Display base class (Main circle)
186 
188  GLC_Context::current()->glcMatrixMode(GL_PROJECTION);
190  GLC_Context::current()->glcMatrixMode(GL_MODELVIEW);
191 
192 }
193 
195 // Private services Functions
197 
198 // Compute trackball radius
200 {
201  int nRayonSph;
202  const double winHSize= static_cast<double>(m_pViewport->viewHSize());
203  const double winVSize= static_cast<double>(m_pViewport->viewVSize());
204 
205  if (winHSize > winVSize)
206  {
207  nRayonSph = static_cast<int>(m_Ratio * winVSize / 2.0);
208  }
209  else
210  {
211  nRayonSph = static_cast<int>(m_Ratio * winHSize / 2.0);
212  }
213 
214  // Compute the length of camera's field of view
215  const double ChampsVision = 2.0;
216 
217  // the side of camera's square is mapped on Vertical length of window
218  // Circle radius in OpenGL unit = Radius(Pixel) * (dimend GL / dimens Pixel)
219  const double RayonSph= fabs((static_cast<double>(nRayonSph) * ChampsVision / winVSize));
220 
221  if ((!qFuzzyCompare(RayonSph, 0.0) && !qFuzzyCompare(RayonSph - m_Radius, 0.0)) || (RayonSph < 2.0))
222  {
223  // Main circle radius
224  m_MainCircle.setRadius(RayonSph);
225 
226  GLC_Circle* pCircle;
227  // Arc 1 radius
228  pCircle= static_cast<GLC_Circle*>(m_Arc1.geomAt(0));
229  pCircle->setRadius(RayonSph);
230  // Arc 2 radius
231  pCircle= static_cast<GLC_Circle*>(m_Arc2.geomAt(0));
232  pCircle->setRadius(RayonSph);
233  }
234 
235 }

©2005-2013 Laurent Ribon