glc_repflymover.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021  *****************************************************************************/
00022 
00024 
00025 #include "glc_repflymover.h"
00026 #include "glc_viewport.h"
00027 #include "../geometry/glc_polylines.h"
00028 #include "../glc_context.h"
00029 
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         // Rotation
00074         double deltaX= vector.x();
00075         double angle= - deltaX;
00076         GLC_Matrix4x4 rotation(glc::Z_AXIS, angle);
00077 
00078         // Translation
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         // Get viewport informations
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         GLC_Context::current()->glcEnableLighting(false);
00113         glDisable(GL_DEPTH_TEST);
00114 
00115         GLC_Context::current()->glcMatrixMode(GL_PROJECTION);
00116         GLC_Context::current()->glcPushMatrix();
00117         GLC_Context::current()->glcLoadIdentity();
00118         GLC_Context::current()->glcOrtho(hRatio * -1.0 ,hRatio * 1.0 ,vRatio * -1.0 ,vRatio * 1.0 ,-1.0 ,1.0);
00119         GLC_Context::current()->glcMatrixMode(GL_MODELVIEW);
00120         GLC_Context::current()->glcPushMatrix();
00121         GLC_Context::current()->glcLoadIdentity();
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         // Render velocity value + text
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         GLC_Context::current()->glcPopMatrix();
00144         GLC_Context::current()->glcMatrixMode(GL_PROJECTION);
00145         GLC_Context::current()->glcPopMatrix();
00146         GLC_Context::current()->glcMatrixMode(GL_MODELVIEW);
00147 
00148         glEnable(GL_DEPTH_TEST);
00149 }
00150 
00151 void GLC_RepFlyMover::createRepresentation()
00152 {
00153         // HUD creation
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.addGeometry(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.addGeometry(pPolylines);
00173 
00174         // Plane creation
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.addGeometry(pPolylines);
00187 }

SourceForge.net Logo

©2005-2011 Laurent Ribon