glc_repcrossmover.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 
00023 #include "glc_repcrossmover.h"
00024 #include "glc_viewport.h"
00025 #include "../geometry/glc_polylines.h"
00026 
00027 // Default constructor
00028 GLC_RepCrossMover::GLC_RepCrossMover(GLC_Viewport* pViewport)
00029 : GLC_RepMover(pViewport)
00030 {
00031 
00032 }
00033 
00034 // Copy constructor
00035 GLC_RepCrossMover::GLC_RepCrossMover(const GLC_RepCrossMover& repMover)
00036 : GLC_RepMover(repMover)
00037 {
00038 
00039 }
00040 
00041 GLC_RepCrossMover::~GLC_RepCrossMover()
00042 {
00043 
00044 }
00045 
00047 // Get Functions
00049 
00050 // Return a clone of the repmover
00051 GLC_RepMover* GLC_RepCrossMover::clone() const
00052 {
00053         return new GLC_RepCrossMover(*this);
00054 }
00055 
00057 // OpenGL Functions
00059 
00060 // Virtual interface for OpenGL Geometry set up.
00061 void GLC_RepCrossMover::glDraw()
00062 {
00063         GLC_3DViewInstance crossInstance(createCrossInstance());
00064 
00065         glDisable(GL_BLEND);
00066         m_RenderProperties.setRenderingFlag(glc::WireRenderFlag);
00067         crossInstance.render(glc::WireRenderFlag);
00068 
00069     glEnable(GL_BLEND);
00070     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00071         m_RenderProperties.setRenderingFlag(glc::TransparentRenderFlag);
00072         // Display arcs
00073         crossInstance.render(glc::TransparentRenderFlag);
00074 }
00075 
00077 // Private services Functions
00079 GLC_3DViewInstance GLC_RepCrossMover::createCrossInstance()
00080 {
00081         GLC_Polylines* pCross= new GLC_Polylines();
00082 
00083         int nLgAxe;
00084         const int winHSize= m_pViewport->viewHSize();
00085         const int winVSize= m_pViewport->viewVSize();
00086         if (winHSize > winVSize)
00087         {
00088                 nLgAxe = static_cast<int>(static_cast<double>(winVSize) / 2.0);
00089         }
00090         else
00091         {
00092                 nLgAxe = static_cast<int>(static_cast<double>(winHSize) / 2.0);
00093         }
00094 
00095         // Compute the length of camera's field of view
00096         const double ChampsVision = 2 * (m_pViewport->cameraHandle()->distEyeTarget()) *  tan((m_pViewport->viewAngle() * glc::PI / 180.0) / 2.0);
00097 
00098         // the side of camera's square is mapped on Vertical length of window
00099         // Axis length in OpenGL unit = length(Pixel) * (dimend GL / dimens Pixel)
00100         const double dLgAxe= ((double)nLgAxe * ChampsVision / (double)winVSize) / 7;
00101         const double dDecAxe= dLgAxe / 3;
00102 
00103         //X axis
00104         {
00105                 GLC_Point3d p1(-dLgAxe, 0, 0);
00106                 GLC_Point3d p2(-dDecAxe, 0, 0);
00107                 GLC_Point3d p3(dDecAxe, 0, 0);
00108                 GLC_Point3d p4(dLgAxe, 0, 0);
00109                 QList<GLC_Point3d> points;
00110                 points << p1 << p2 << p3 << p4;
00111                 pCross->addPolyline(points);
00112         }
00113 
00114         //Y axis
00115         {
00116                 GLC_Point3d p1(0, -dLgAxe, 0);
00117                 GLC_Point3d p2(0, -dDecAxe, 0);
00118                 GLC_Point3d p3(0, dDecAxe, 0);
00119                 GLC_Point3d p4(0, dLgAxe, 0);
00120                 QList<GLC_Point3d> points;
00121                 points << p1 << p2 << p3 << p4;
00122                 pCross->addPolyline(points);
00123         }
00124 
00125         //Z axis
00126         {
00127                 GLC_Point3d p1(0, 0, -dLgAxe);
00128                 GLC_Point3d p2(0, 0, -dDecAxe);
00129                 GLC_Point3d p3(0, 0, dDecAxe);
00130                 GLC_Point3d p4(0, 0, dLgAxe);
00131                 QList<GLC_Point3d> points;
00132                 points << p1 << p2 << p3 << p4;
00133                 pCross->addPolyline(points);
00134         }
00135 
00136         pCross->setWireColor(m_MainColor);
00137         GLC_3DViewInstance crossInstance(pCross);
00138 
00139         GLC_Matrix4x4 translation;
00140         translation.setMatTranslate(m_pViewport->cameraHandle()->target());
00141 
00142         crossInstance.setMatrix(translation);
00143 
00144         return crossInstance;
00145 }
00146 

SourceForge.net Logo

©2005-2011 Laurent Ribon