GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_repflymover.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_repflymover.h"
26 #include "glc_viewport.h"
27 #include "../geometry/glc_polylines.h"
28 #include "../glc_context.h"
29 
30 #include <QFontMetrics>
31 
33 : GLC_RepMover(pViewport)
34 , m_Radius(0.06)
35 , m_CenterCircle()
36 , m_Plane()
37 , m_Hud()
38 , m_HudOffset(m_Radius * 5.0, m_Radius * 5.3)
39 {
40 
42 }
43 
45 : GLC_RepMover(repFlyMover)
46 , m_Radius(repFlyMover.m_Radius)
47 , m_CenterCircle(repFlyMover.m_CenterCircle)
48 , m_Plane(repFlyMover.m_Plane)
49 , m_Hud(repFlyMover.m_Hud)
50 , m_HudOffset(repFlyMover.m_HudOffset)
51 {
52 
53 }
54 
56 {
57 
58 }
59 
61 {
62  return new GLC_RepFlyMover(*this);
63 }
64 
66 {
67  Q_ASSERT(NULL != m_pRepMoverInfo);
68  Q_ASSERT(!m_pRepMoverInfo->m_VectorInfo.isEmpty());
69  Q_ASSERT(!m_pRepMoverInfo->m_DoubleInfo.isEmpty());
70 
71  GLC_Vector3d vector(m_pRepMoverInfo->m_VectorInfo.first());
72 
73  // Rotation
74  double deltaX= vector.x();
75  double angle= - deltaX;
76  GLC_Matrix4x4 rotation(glc::Z_AXIS, angle);
77 
78  // Translation
79  vector.setX(vector.x() * m_Radius * 4.0);
80  vector.setY(vector.y() * m_Radius * 4.0);
81  GLC_Matrix4x4 translation(vector);
82 
83  m_Plane.setMatrix(translation * rotation);
84 }
85 void GLC_RepFlyMover::setMainColor(const QColor& color)
86 {
89  m_Plane.geomAt(0)->setWireColor(color);
90  m_Hud.geomAt(0)->setWireColor(color);
91 }
92 
93 void GLC_RepFlyMover::setThickness(double thickness)
94 {
95  GLC_RepMover::setThickness(thickness);
96  m_CenterCircle.geomAt(0)->setLineWidth(thickness);
97  m_Plane.geomAt(0)->setLineWidth(thickness);
98  m_Hud.geomAt(0)->setLineWidth(thickness);
99 }
100 
102 {
103  Q_ASSERT(NULL != m_pRepMoverInfo);
104  Q_ASSERT(!m_pRepMoverInfo->m_DoubleInfo.isEmpty());
105 
106  // Get viewport informations
107  const double calibre= 800.0;
108  const double hRatio= static_cast<double>(m_pViewport->viewHSize()) / calibre;
109  const double vRatio= static_cast<double>(m_pViewport->viewVSize()) / calibre;
110 
111  glDisable(GL_TEXTURE_2D);
113  glDisable(GL_DEPTH_TEST);
114 
115  GLC_Context::current()->glcMatrixMode(GL_PROJECTION);
118  GLC_Context::current()->glcOrtho(hRatio * -1.0 ,hRatio * 1.0 ,vRatio * -1.0 ,vRatio * 1.0 ,-1.0 ,1.0);
119  GLC_Context::current()->glcMatrixMode(GL_MODELVIEW);
122 
126 
127  glEnable(GL_BLEND);
128  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
129 
133 
134  /*
135  // Render velocity value + text
136  QString velocity(QChar(' ') + QString::number(static_cast<int>(100.0 * m_pRepMoverInfo->m_DoubleInfo.first())));
137  QFont myFont;
138  myFont.setBold(true);
139  QFontMetrics fontmetrics(myFont);
140  int txtHeight= fontmetrics.boundingRect(velocity).height();
141  double posy= 2.0 * static_cast<double>(txtHeight) / calibre;
142  m_pViewport->qGLWidgetHandle()->renderText(- m_HudOffset.getX(), m_HudOffset.getY() - posy, 0.0, velocity, myFont);
143  */
144 
146  GLC_Context::current()->glcMatrixMode(GL_PROJECTION);
148  GLC_Context::current()->glcMatrixMode(GL_MODELVIEW);
149 
150  glEnable(GL_DEPTH_TEST);
151 }
152 
154 {
155  // HUD creation
156  GLC_Circle* pCircle= new GLC_Circle(m_Radius);
159  m_CenterCircle.addGeometry(pCircle);
160 
161  GLC_Polylines* pPolylines= new GLC_Polylines();
162  GLfloatVector points;
163  const double hudx= m_HudOffset.x();
164  const double hudy= m_HudOffset.y();
165  points << -hudx << -hudy << 0.0;
166  points << -hudx << hudy << 0.0;
167  pPolylines->addPolyline(points);
168  points.clear();
169  points << hudx << -hudy << 0.0;
170  points << hudx << hudy << 0.0;
171  pPolylines->addPolyline(points);
174  m_Hud.addGeometry(pPolylines);
175 
176  // Plane creation
177  pPolylines= new GLC_Polylines();
178  points.clear();
179  const double l1= m_Radius * 1.5;
180  points << (-m_Radius - l1) << -m_Radius << 0.0;
181  points << -m_Radius << -m_Radius << 0.0;
182  points << 0.0 << 0.0 << 0.0;
183  points << m_Radius << -m_Radius << 0.0;
184  points << (m_Radius + l1) << -m_Radius << 0.0;
185  pPolylines->addPolyline(points);
188  m_Plane.addGeometry(pPolylines);
189 }

©2005-2013 Laurent Ribon