glc_arrow.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00025
00026 #include <QtGlobal>
00027 #include "../maths/glc_utils_maths.h"
00028 #include "glc_arrow.h"
00029
00030
00031 GLC_Arrow::GLC_Arrow(const GLC_Point3d& startPoint, const GLC_Point3d& endPoint, const GLC_Vector3d& viewDir)
00032 : GLC_Geometry("Arrow", true)
00033 , m_StartPoint(startPoint)
00034 , m_EndPoint(endPoint)
00035 , m_HeadLenght((m_EndPoint - m_StartPoint).length() / 10.0)
00036 , m_HeadAngle(glc::toRadian(30.0))
00037 , m_ViewDir(GLC_Vector3d(viewDir).normalize())
00038 {
00039
00040 }
00041
00042 GLC_Arrow::GLC_Arrow(const GLC_Arrow& arrow)
00043 : GLC_Geometry(arrow)
00044 , m_StartPoint(arrow.m_StartPoint)
00045 , m_EndPoint(arrow.m_EndPoint)
00046 , m_HeadLenght(arrow.m_HeadLenght)
00047 , m_HeadAngle(arrow.m_HeadAngle)
00048 , m_ViewDir(arrow.m_ViewDir)
00049 {
00050
00051 }
00052
00053 GLC_Arrow::~GLC_Arrow()
00054 {
00055
00056 }
00058
00060 const GLC_BoundingBox& GLC_Arrow::boundingBox()
00061 {
00062 if (NULL == m_pBoundingBox)
00063 {
00064 m_pBoundingBox= new GLC_BoundingBox();
00065 if (m_WireData.isEmpty()) createWire();
00066 m_pBoundingBox->combine(m_WireData.boundingBox());
00067 }
00068 return *m_pBoundingBox;
00069 }
00070
00071 GLC_Geometry* GLC_Arrow::clone() const
00072 {
00073 return new GLC_Arrow(*this);
00074 }
00075
00077
00079 GLC_Arrow& GLC_Arrow::operator=(const GLC_Arrow& arrow)
00080 {
00081 if (this != &arrow)
00082 {
00083 GLC_Geometry::operator=(arrow);
00084 m_StartPoint= arrow.m_StartPoint;
00085 m_EndPoint= arrow.m_EndPoint;
00086 m_HeadLenght= arrow.m_HeadLenght;
00087 m_HeadAngle= arrow.m_HeadAngle;
00088 m_ViewDir= arrow.m_ViewDir;
00089 }
00090 return *this;
00091 }
00092
00093 void GLC_Arrow::setStartPoint(const GLC_Point3d& startPoint)
00094 {
00095 if (startPoint != m_StartPoint)
00096 {
00097 m_StartPoint= startPoint;
00098 GLC_Geometry::clearWireAndBoundingBox();
00099 }
00100 }
00101
00102 void GLC_Arrow::setEndPoint(const GLC_Point3d& endPoint)
00103 {
00104 if (endPoint != m_EndPoint)
00105 {
00106 m_EndPoint= endPoint;
00107 GLC_Geometry::clearWireAndBoundingBox();
00108 }
00109 }
00110
00111 void GLC_Arrow::setHeadLength(double headLenght)
00112 {
00113 if (!qFuzzyCompare(m_HeadLenght, headLenght))
00114 {
00115 m_HeadLenght= headLenght;
00116 GLC_Geometry::clearWireAndBoundingBox();
00117 }
00118 }
00119
00120 void GLC_Arrow::setHeadAngle(double headAngle)
00121 {
00122 if (!qFuzzyCompare(m_HeadAngle, headAngle))
00123 {
00124 m_HeadAngle= headAngle;
00125 GLC_Geometry::clearWireAndBoundingBox();
00126 }
00127 }
00128
00129 void GLC_Arrow::setViewDir(const GLC_Vector3d& viewDir)
00130 {
00131 if (viewDir != m_ViewDir)
00132 {
00133 m_ViewDir= GLC_Vector3d(viewDir).normalize();
00134 GLC_Geometry::clearWireAndBoundingBox();
00135 }
00136 }
00137
00139
00141 void GLC_Arrow::glDraw(const GLC_RenderProperties& renderProperties)
00142 {
00143 if (m_WireData.isEmpty())
00144 {
00145 createWire();
00146 }
00147
00148 m_WireData.glDraw(renderProperties);
00149 }
00150
00151 void GLC_Arrow::createWire()
00152 {
00153 Q_ASSERT(m_WireData.isEmpty());
00154 GLfloatVector floatVector;
00155 floatVector.append(static_cast<float>(m_StartPoint.x()));
00156 floatVector.append(static_cast<float>(m_StartPoint.y()));
00157 floatVector.append(static_cast<float>(m_StartPoint.z()));
00158 floatVector.append(static_cast<float>(m_EndPoint.x()));
00159 floatVector.append(static_cast<float>(m_EndPoint.y()));
00160 floatVector.append(static_cast<float>(m_EndPoint.z()));
00161
00162 GLC_Geometry::addPolyline(floatVector);
00163
00164
00165 GLC_Point3d headPoint1(-m_HeadLenght, m_HeadLenght * tan(m_HeadAngle / 2.0), 0.0);
00166 GLC_Point3d headPoint2(headPoint1.x(), -(headPoint1.y()), headPoint1.z());
00167
00168
00169 GLC_Vector3d xArrow= (m_EndPoint - m_StartPoint).normalize();
00170 GLC_Vector3d yArrow= ((-m_ViewDir) ^ xArrow).normalize();
00171 GLC_Vector3d zArrow= (xArrow ^ yArrow).normalize();
00172
00173 GLC_Matrix4x4 headMatrix;
00174 headMatrix.setColumn(0, xArrow);
00175 headMatrix.setColumn(1, yArrow);
00176 headMatrix.setColumn(2, zArrow);
00177 GLC_Matrix4x4 translate(m_EndPoint);
00178 headPoint1= translate * headMatrix * headPoint1;
00179 headPoint2= translate * headMatrix * headPoint2;
00180
00181
00182 floatVector.clear();
00183 floatVector.append(static_cast<float>(headPoint1.x()));
00184 floatVector.append(static_cast<float>(headPoint1.y()));
00185 floatVector.append(static_cast<float>(headPoint1.z()));
00186
00187 floatVector.append(static_cast<float>(m_EndPoint.x()));
00188 floatVector.append(static_cast<float>(m_EndPoint.y()));
00189 floatVector.append(static_cast<float>(m_EndPoint.z()));
00190
00191 floatVector.append(static_cast<float>(headPoint2.x()));
00192 floatVector.append(static_cast<float>(headPoint2.y()));
00193 floatVector.append(static_cast<float>(headPoint2.z()));
00194
00195 GLC_Geometry::addPolyline(floatVector);
00196
00197 }