GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_arrow.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  *****************************************************************************/
23 
24 #include <QtGlobal>
25 #include "../maths/glc_utils_maths.h"
26 #include "glc_arrow.h"
27 
28 
29 GLC_Arrow::GLC_Arrow(const GLC_Point3d& startPoint, const GLC_Point3d& endPoint, const GLC_Vector3d& viewDir)
30 : GLC_Geometry("Arrow", true)
31 , m_StartPoint(startPoint)
32 , m_EndPoint(endPoint)
33 , m_HeadLenght((m_EndPoint - m_StartPoint).length() / 10.0)
34 , m_HeadAngle(glc::toRadian(30.0))
35 , m_ViewDir(GLC_Vector3d(viewDir).normalize())
36 {
37 
38 }
39 
41 : GLC_Geometry(arrow)
42 , m_StartPoint(arrow.m_StartPoint)
43 , m_EndPoint(arrow.m_EndPoint)
44 , m_HeadLenght(arrow.m_HeadLenght)
45 , m_HeadAngle(arrow.m_HeadAngle)
46 , m_ViewDir(arrow.m_ViewDir)
47 {
48 
49 }
50 
52 {
53 
54 }
56 // Get Functions
59 {
60  if (NULL == m_pBoundingBox)
61  {
63  if (m_WireData.isEmpty()) createWire();
65  }
66  return *m_pBoundingBox;
67 }
68 
70 {
71  return new GLC_Arrow(*this);
72 }
73 
75 // Set Functions
78 {
79  if (this != &arrow)
80  {
83  m_EndPoint= arrow.m_EndPoint;
85  m_HeadAngle= arrow.m_HeadAngle;
86  m_ViewDir= arrow.m_ViewDir;
87  }
88  return *this;
89 }
90 
91 void GLC_Arrow::setStartPoint(const GLC_Point3d& startPoint)
92 {
93  if (startPoint != m_StartPoint)
94  {
97  }
98 }
99 
100 void GLC_Arrow::setEndPoint(const GLC_Point3d& endPoint)
101 {
102  if (endPoint != m_EndPoint)
103  {
106  }
107 }
108 
109 void GLC_Arrow::setHeadLength(double headLenght)
110 {
111  if (!qFuzzyCompare(m_HeadLenght, headLenght))
112  {
115  }
116 }
117 
118 void GLC_Arrow::setHeadAngle(double headAngle)
119 {
120  if (!qFuzzyCompare(m_HeadAngle, headAngle))
121  {
124  }
125 }
126 
128 {
129 
130  if (viewDir != m_ViewDir)
131  {
132  m_ViewDir= GLC_Vector3d(viewDir).normalize();
134  }
135 }
136 
138 // OpenGL Functions
140 void GLC_Arrow::glDraw(const GLC_RenderProperties& renderProperties)
141 {
142  if (m_WireData.isEmpty())
143  {
144  createWire();
145  }
146 
147  m_WireData.glDraw(renderProperties, GL_LINE_STRIP);
148 }
149 
151 {
152  Q_ASSERT(m_WireData.isEmpty());
153  GLfloatVector floatVector;
154  floatVector.append(static_cast<float>(m_StartPoint.x()));
155  floatVector.append(static_cast<float>(m_StartPoint.y()));
156  floatVector.append(static_cast<float>(m_StartPoint.z()));
157  floatVector.append(static_cast<float>(m_EndPoint.x()));
158  floatVector.append(static_cast<float>(m_EndPoint.y()));
159  floatVector.append(static_cast<float>(m_EndPoint.z()));
160 
161  GLC_Geometry::addVerticeGroup(floatVector);
162 
163  // Arrow Head
164  GLC_Point3d headPoint1(-m_HeadLenght, m_HeadLenght * tan(m_HeadAngle / 2.0), 0.0);
165  GLC_Point3d headPoint2(headPoint1.x(), -(headPoint1.y()), headPoint1.z());
166 
167  // Arrow frame
169  GLC_Vector3d yArrow= ((-m_ViewDir) ^ xArrow).normalize();
170  GLC_Vector3d zArrow= (xArrow ^ yArrow).normalize();
171 
172  GLC_Matrix4x4 headMatrix;
173  headMatrix.setColumn(0, xArrow);
174  headMatrix.setColumn(1, yArrow);
175  headMatrix.setColumn(2, zArrow);
176  GLC_Matrix4x4 translate(m_EndPoint);
177  headPoint1= translate * headMatrix * headPoint1;
178  headPoint2= translate * headMatrix * headPoint2;
179 
180  // add head data
181  floatVector.clear();
182  floatVector.append(static_cast<float>(headPoint1.x()));
183  floatVector.append(static_cast<float>(headPoint1.y()));
184  floatVector.append(static_cast<float>(headPoint1.z()));
185 
186  floatVector.append(static_cast<float>(m_EndPoint.x()));
187  floatVector.append(static_cast<float>(m_EndPoint.y()));
188  floatVector.append(static_cast<float>(m_EndPoint.z()));
189 
190  floatVector.append(static_cast<float>(headPoint2.x()));
191  floatVector.append(static_cast<float>(headPoint2.y()));
192  floatVector.append(static_cast<float>(headPoint2.z()));
193 
194  GLC_Geometry::addVerticeGroup(floatVector);
195 
196 }

©2005-2013 Laurent Ribon