glc_repflymover.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00026
00027 #include "glc_repflymover.h"
00028 #include "glc_viewport.h"
00029 #include "../geometry/glc_polylines.h"
00030 #include <QFontMetrics>
00031
00032 GLC_RepFlyMover::GLC_RepFlyMover(GLC_Viewport* pViewport)
00033 : GLC_RepMover(pViewport)
00034 , m_Radius(0.06)
00035 , m_CenterCircle()
00036 , m_Plane()
00037 , m_Hud()
00038 , m_HudOffset(m_Radius * 5.0, m_Radius * 5.3)
00039 {
00040
00041 createRepresentation();
00042 }
00043
00044 GLC_RepFlyMover::GLC_RepFlyMover(const GLC_RepFlyMover& repFlyMover)
00045 : GLC_RepMover(repFlyMover)
00046 , m_Radius(repFlyMover.m_Radius)
00047 , m_CenterCircle(repFlyMover.m_CenterCircle)
00048 , m_Plane(repFlyMover.m_Plane)
00049 , m_Hud(repFlyMover.m_Hud)
00050 , m_HudOffset(repFlyMover.m_HudOffset)
00051 {
00052
00053 }
00054
00055 GLC_RepFlyMover::~GLC_RepFlyMover()
00056 {
00057
00058 }
00059
00060 GLC_RepMover* GLC_RepFlyMover::clone() const
00061 {
00062 return new GLC_RepFlyMover(*this);
00063 }
00064
00065 void GLC_RepFlyMover::update()
00066 {
00067 Q_ASSERT(NULL != m_pRepMoverInfo);
00068 Q_ASSERT(!m_pRepMoverInfo->m_VectorInfo.isEmpty());
00069 Q_ASSERT(!m_pRepMoverInfo->m_DoubleInfo.isEmpty());
00070
00071 GLC_Vector3d vector(m_pRepMoverInfo->m_VectorInfo.first());
00072
00073
00074 double deltaX= vector.x();
00075 double angle= - deltaX;
00076 GLC_Matrix4x4 rotation(glc::Z_AXIS, angle);
00077
00078
00079 vector.setX(vector.x() * m_Radius * 4.0);
00080 vector.setY(vector.y() * m_Radius * 4.0);
00081 GLC_Matrix4x4 translation(vector);
00082
00083 m_Plane.setMatrix(translation * rotation);
00084 }
00085 void GLC_RepFlyMover::setMainColor(const QColor& color)
00086 {
00087 GLC_RepMover::setMainColor(color);
00088 m_CenterCircle.geomAt(0)->setWireColor(color);
00089 m_Plane.geomAt(0)->setWireColor(color);
00090 m_Hud.geomAt(0)->setWireColor(color);
00091 }
00092
00093 void GLC_RepFlyMover::setThickness(double thickness)
00094 {
00095 GLC_RepMover::setThickness(thickness);
00096 m_CenterCircle.geomAt(0)->setLineWidth(thickness);
00097 m_Plane.geomAt(0)->setLineWidth(thickness);
00098 m_Hud.geomAt(0)->setLineWidth(thickness);
00099 }
00100
00101 void GLC_RepFlyMover::glDraw()
00102 {
00103 Q_ASSERT(NULL != m_pRepMoverInfo);
00104 Q_ASSERT(!m_pRepMoverInfo->m_DoubleInfo.isEmpty());
00105
00106
00107 const double calibre= 800.0;
00108 const double hRatio= static_cast<double>(m_pViewport->viewHSize()) / calibre;
00109 const double vRatio= static_cast<double>(m_pViewport->viewVSize()) / calibre;
00110
00111 glDisable(GL_TEXTURE_2D);
00112 glDisable(GL_LIGHTING);
00113 glDisable(GL_DEPTH_TEST);
00114
00115 glMatrixMode(GL_PROJECTION);
00116 glPushMatrix();
00117 glLoadIdentity();
00118 glOrtho(hRatio * -1.0 ,hRatio * 1.0 ,vRatio * -1.0 ,vRatio * 1.0 ,-1.0 ,1.0);
00119 glMatrixMode(GL_MODELVIEW);
00120 glPushMatrix();
00121 glLoadIdentity();
00122
00123 m_CenterCircle.render(glc::WireRenderFlag);
00124 m_Hud.render(glc::WireRenderFlag);
00125 m_Plane.render(glc::WireRenderFlag);
00126
00127 glEnable(GL_BLEND);
00128 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00129
00130 m_CenterCircle.render(glc::TransparentRenderFlag);
00131 m_Hud.render(glc::TransparentRenderFlag);
00132 m_Plane.render(glc::TransparentRenderFlag);
00133
00134
00135 QString velocity(QChar(' ') + QString::number(static_cast<int>(100.0 * m_pRepMoverInfo->m_DoubleInfo.first())));
00136 QFont myFont;
00137 myFont.setBold(true);
00138 QFontMetrics fontmetrics(myFont);
00139 int txtHeight= fontmetrics.boundingRect(velocity).height();
00140 double posy= 2.0 * static_cast<double>(txtHeight) / calibre;
00141 m_pViewport->qGLWidgetHandle()->renderText(- m_HudOffset.getX(), m_HudOffset.getY() - posy, 0.0, velocity, myFont);
00142
00143 glPopMatrix();
00144 glMatrixMode(GL_PROJECTION);
00145 glPopMatrix();
00146 glMatrixMode(GL_MODELVIEW);
00147
00148 glEnable(GL_DEPTH_TEST);
00149 }
00150
00151 void GLC_RepFlyMover::createRepresentation()
00152 {
00153
00154 GLC_Circle* pCircle= new GLC_Circle(m_Radius);
00155 pCircle->setWireColor(GLC_RepMover::m_MainColor);
00156 pCircle->setLineWidth(GLC_RepMover::m_Thickness);
00157 m_CenterCircle.setGeometry(pCircle);
00158
00159 GLC_Polylines* pPolylines= new GLC_Polylines();
00160 GLfloatVector points;
00161 const double hudx= m_HudOffset.getX();
00162 const double hudy= m_HudOffset.getY();
00163 points << -hudx << -hudy << 0.0;
00164 points << -hudx << hudy << 0.0;
00165 pPolylines->addPolyline(points);
00166 points.clear();
00167 points << hudx << -hudy << 0.0;
00168 points << hudx << hudy << 0.0;
00169 pPolylines->addPolyline(points);
00170 pPolylines->setWireColor(GLC_RepMover::m_MainColor);
00171 pPolylines->setLineWidth(GLC_RepMover::m_Thickness);
00172 m_Hud.setGeometry(pPolylines);
00173
00174
00175 pPolylines= new GLC_Polylines();
00176 points.clear();
00177 const double l1= m_Radius * 1.5;
00178 points << (-m_Radius - l1) << -m_Radius << 0.0;
00179 points << -m_Radius << -m_Radius << 0.0;
00180 points << 0.0 << 0.0 << 0.0;
00181 points << m_Radius << -m_Radius << 0.0;
00182 points << (m_Radius + l1) << -m_Radius << 0.0;
00183 pPolylines->addPolyline(points);
00184 pPolylines->setWireColor(GLC_RepMover::m_MainColor);
00185 pPolylines->setLineWidth(GLC_RepMover::m_Thickness);
00186 m_Plane.setGeometry(pPolylines);
00187 }