GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_repcrossmover.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  *****************************************************************************/
22 
23 #include "glc_repcrossmover.h"
24 #include "glc_viewport.h"
25 #include "../geometry/glc_polylines.h"
26 
27 // Default constructor
29 : GLC_RepMover(pViewport)
30 {
31 
32 }
33 
34 // Copy constructor
36 : GLC_RepMover(repMover)
37 {
38 
39 }
40 
42 {
43 
44 }
45 
47 // Get Functions
49 
50 // Return a clone of the repmover
52 {
53  return new GLC_RepCrossMover(*this);
54 }
55 
57 // OpenGL Functions
59 
60 // Virtual interface for OpenGL Geometry set up.
62 {
63  GLC_3DViewInstance crossInstance(createCrossInstance());
64 
65  glDisable(GL_BLEND);
67  crossInstance.render(glc::WireRenderFlag);
68 
69  glEnable(GL_BLEND);
70  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
72  // Display arcs
73  crossInstance.render(glc::TransparentRenderFlag);
74 }
75 
77 // Private services Functions
80 {
81  GLC_Polylines* pCross= new GLC_Polylines();
82 
83  int nLgAxe;
84  const int winHSize= m_pViewport->viewHSize();
85  const int winVSize= m_pViewport->viewVSize();
86  if (winHSize > winVSize)
87  {
88  nLgAxe = static_cast<int>(static_cast<double>(winVSize) / 2.0);
89  }
90  else
91  {
92  nLgAxe = static_cast<int>(static_cast<double>(winHSize) / 2.0);
93  }
94 
95  // Compute the length of camera's field of view
96  const double ChampsVision = 2 * (m_pViewport->cameraHandle()->distEyeTarget()) * tan((m_pViewport->viewAngle() * glc::PI / 180.0) / 2.0);
97 
98  // the side of camera's square is mapped on Vertical length of window
99  // Axis length in OpenGL unit = length(Pixel) * (dimend GL / dimens Pixel)
100  const double dLgAxe= ((double)nLgAxe * ChampsVision / (double)winVSize) / 7;
101  const double dDecAxe= dLgAxe / 3;
102 
103  //X axis
104  {
105  GLC_Point3d p1(-dLgAxe, 0, 0);
106  GLC_Point3d p2(-dDecAxe, 0, 0);
107  GLC_Point3d p3(dDecAxe, 0, 0);
108  GLC_Point3d p4(dLgAxe, 0, 0);
109  QList<GLC_Point3d> points;
110  points << p1 << p2 << p3 << p4;
111  pCross->addPolyline(points);
112  }
113 
114  //Y axis
115  {
116  GLC_Point3d p1(0, -dLgAxe, 0);
117  GLC_Point3d p2(0, -dDecAxe, 0);
118  GLC_Point3d p3(0, dDecAxe, 0);
119  GLC_Point3d p4(0, dLgAxe, 0);
120  QList<GLC_Point3d> points;
121  points << p1 << p2 << p3 << p4;
122  pCross->addPolyline(points);
123  }
124 
125  //Z axis
126  {
127  GLC_Point3d p1(0, 0, -dLgAxe);
128  GLC_Point3d p2(0, 0, -dDecAxe);
129  GLC_Point3d p3(0, 0, dDecAxe);
130  GLC_Point3d p4(0, 0, dLgAxe);
131  QList<GLC_Point3d> points;
132  points << p1 << p2 << p3 << p4;
133  pCross->addPolyline(points);
134  }
135 
136  pCross->setWireColor(m_MainColor);
137  GLC_3DViewInstance crossInstance(pCross);
138 
139  GLC_Matrix4x4 translation;
140  translation.setMatTranslate(m_pViewport->cameraHandle()->target());
141 
142  crossInstance.setMatrix(translation);
143 
144  return crossInstance;
145 }
146 

©2005-2013 Laurent Ribon