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