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 
00026 // Default constructor
00027 GLC_RepCrossMover::GLC_RepCrossMover(GLC_Viewport* pViewport)
00028 : GLC_RepMover(pViewport)
00029 {
00030 
00031 }
00032 
00033 // Copy constructor
00034 GLC_RepCrossMover::GLC_RepCrossMover(const GLC_RepCrossMover& repMover)
00035 : GLC_RepMover(repMover)
00036 {
00037 
00038 }
00039 
00040 GLC_RepCrossMover::~GLC_RepCrossMover()
00041 {
00042 
00043 }
00044 
00046 // Get Functions
00048 
00049 // Return a clone of the repmover
00050 GLC_RepMover* GLC_RepCrossMover::clone() const
00051 {
00052         return new GLC_RepCrossMover(*this);
00053 }
00054 
00056 // OpenGL Functions
00058 
00059 // Virtual interface for OpenGL Geometry set up.
00060 void GLC_RepCrossMover::glDraw()
00061 {
00062         int nLgAxe;
00063         const int winHSize= m_pViewport->viewHSize();
00064         const int winVSize= m_pViewport->viewVSize();
00065         if (winHSize > winVSize)
00066         {
00067                 nLgAxe = static_cast<int>(static_cast<double>(winVSize) / 2.0);
00068         }
00069         else
00070         {
00071                 nLgAxe = static_cast<int>(static_cast<double>(winHSize) / 2.0);
00072         }
00073 
00074         // Compute the length of camera's field of view
00075         const double ChampsVision = 2 * (m_pViewport->cameraHandle()->distEyeTarget()) *  tan((m_pViewport->viewAngle() * glc::PI / 180.0) / 2.0);
00076 
00077         // the side of camera's square is mapped on Vertical length of window
00078         // Axis length in OpenGL unit = length(Pixel) * (dimend GL / dimens Pixel)
00079         const double dLgAxe= ((double)nLgAxe * ChampsVision / (double)winVSize) / 7;
00080         const double dDecAxe= dLgAxe / 3;
00081         glPushMatrix();
00082 
00083         glTranslated(m_pViewport->cameraHandle()->target().x(), m_pViewport->cameraHandle()->target().y(),
00084                         m_pViewport->cameraHandle()->target().z() );
00085 
00086         // Graphic properties
00087         glDisable(GL_TEXTURE_2D);
00088         glDisable(GL_LIGHTING);
00089         glColor4d(m_MainColor.redF(), m_MainColor.greenF(), m_MainColor.blueF(), m_MainColor.alphaF());
00090         glLineWidth(1.0);
00091 
00092         // Display camera's target lines
00093         glBegin(GL_LINES);
00094                 //X axis
00095                 glVertex3d(-dLgAxe, 0, 0);
00096                 glVertex3d(-dDecAxe, 0, 0);
00097                 glVertex3d(dDecAxe, 0, 0);
00098                 glVertex3d(dLgAxe, 0, 0);
00099 
00100                 //Y axis
00101                 glVertex3d(0, -dLgAxe, 0);
00102                 glVertex3d(0, -dDecAxe, 0);
00103                 glVertex3d(0, dDecAxe, 0);
00104                 glVertex3d(0, dLgAxe, 0);
00105 
00106                 //Z axis
00107                 glVertex3d(0, 0, -dLgAxe);
00108                 glVertex3d(0, 0, -dDecAxe);
00109                 glVertex3d(0, 0, dDecAxe);
00110                 glVertex3d(0, 0, dLgAxe);
00111 
00112         glEnd();
00113 
00114         glPopMatrix();
00115 
00116 }
00117 
00118 

SourceForge.net Logo

©2005-2011 Laurent Ribon