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

SourceForge.net Logo

©2005-2011 Laurent Ribon