1 /**************************************************************************** 2 ** 3 ** DQt - D bindings for the Qt Toolkit 4 ** 5 ** GNU Lesser General Public License Usage 6 ** This file may be used under the terms of the GNU Lesser 7 ** General Public License version 3 as published by the Free Software 8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 9 ** packaging of this file. Please review the following information to 10 ** ensure the GNU Lesser General Public License version 3 requirements 11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 12 ** 13 ****************************************************************************/ 14 module qt.gui.vector3d; 15 extern(C++): 16 17 import qt.config; 18 import qt.helpers; 19 version(QT_NO_VECTOR2D){}else 20 version(QT_NO_VECTOR3D){}else 21 import qt.gui.vector2d; 22 version(QT_NO_VECTOR3D){}else 23 version(QT_NO_VECTOR4D){}else 24 import qt.gui.vector4d; 25 version(QT_NO_VECTOR3D){}else 26 { 27 import qt.core.metatype; 28 import qt.core.namespace; 29 import qt.core.point; 30 import qt.core.rect; 31 import qt.core.variant; 32 } 33 34 version(QT_NO_VECTOR3D) 35 { 36 extern(C++, class) struct QVector3D; 37 } 38 /+ class QMatrix4x4; 39 class QVector2D; 40 class QVector4D; 41 class QRect; +/ 42 43 version(QT_NO_VECTOR3D){}else 44 { 45 46 @(QMetaType.Type.QVector3D) extern(C++, class) struct /+ Q_GUI_EXPORT +/ QVector3D 47 { 48 public: 49 @disable this(); 50 /+pragma(inline, true) this() 51 { 52 this.v = [0.0f, 0.0f, 0.0f]; 53 }+/ 54 /+ explicit +/this(/+ Qt:: +/qt.core.namespace.Initialization) {} 55 this(float xpos, float ypos, float zpos) 56 { 57 this.v = [xpos, ypos, zpos]; 58 } 59 60 /+ explicit +/pragma(inline, true) this(ref const(QPoint) point) 61 { 62 this.v = [float(point.x()), float(point.y()), float(0.0f)]; 63 } 64 /+ explicit +/pragma(inline, true) this(ref const(QPointF) point) 65 { 66 this.v = [float(point.x()), float(point.y()), 0.0f]; 67 } 68 /+ #ifndef QT_NO_VECTOR2D +/ 69 version(QT_NO_VECTOR2D){}else 70 { 71 this(ref const(QVector2D) vector); 72 this(ref const(QVector2D) vector, float zpos); 73 } 74 /+ #endif 75 #ifndef QT_NO_VECTOR4D +/ 76 version(QT_NO_VECTOR4D){}else 77 { 78 /+ explicit +/this(ref const(QVector4D) vector); 79 } 80 /+ #endif +/ 81 82 pragma(inline, true) bool isNull() const 83 { 84 import qt.core.global; 85 86 return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]); 87 } 88 89 pragma(inline, true) float x() const { return v[0]; } 90 pragma(inline, true) float y() const { return v[1]; } 91 pragma(inline, true) float z() const { return v[2]; } 92 93 pragma(inline, true) void setX(float aX) { v[0] = aX; } 94 pragma(inline, true) void setY(float aY) { v[1] = aY; } 95 pragma(inline, true) void setZ(float aZ) { v[2] = aZ; } 96 97 /+pragma(inline, true) ref float operator [](int i) 98 { 99 import qt.core.global; 100 101 (mixin(Q_ASSERT(q{uint(i) < 3u}))); 102 return v[i]; 103 }+/ 104 /+pragma(inline, true) float operator [](int i) const 105 { 106 import qt.core.global; 107 108 (mixin(Q_ASSERT(q{uint(i) < 3u}))); 109 return v[i]; 110 }+/ 111 112 float length() const; 113 float lengthSquared() const; 114 115 QVector3D normalized() const; 116 void normalize(); 117 118 /+pragma(inline, true) ref QVector3D operator +=(ref const(QVector3D) vector) 119 { 120 v[0] += vector.v[0]; 121 v[1] += vector.v[1]; 122 v[2] += vector.v[2]; 123 return this; 124 }+/ 125 /+pragma(inline, true) ref QVector3D operator -=(ref const(QVector3D) vector) 126 { 127 v[0] -= vector.v[0]; 128 v[1] -= vector.v[1]; 129 v[2] -= vector.v[2]; 130 return this; 131 }+/ 132 /+pragma(inline, true) ref QVector3D operator *=(float factor) 133 { 134 v[0] *= factor; 135 v[1] *= factor; 136 v[2] *= factor; 137 return this; 138 }+/ 139 /+pragma(inline, true) ref QVector3D operator *=(ref const(QVector3D) vector) 140 { 141 v[0] *= vector.v[0]; 142 v[1] *= vector.v[1]; 143 v[2] *= vector.v[2]; 144 return this; 145 }+/ 146 /+pragma(inline, true) ref QVector3D operator /=(float divisor) 147 { 148 v[0] /= divisor; 149 v[1] /= divisor; 150 v[2] /= divisor; 151 return this; 152 }+/ 153 /+pragma(inline, true) ref QVector3D operator /=(ref const(QVector3D) vector) 154 { 155 v[0] /= vector.v[0]; 156 v[1] /= vector.v[1]; 157 v[2] /= vector.v[2]; 158 return this; 159 }+/ 160 161 static float dotProduct(ref const(QVector3D) v1, ref const(QVector3D) v2); //In Qt 6 convert to inline and constexpr 162 static QVector3D crossProduct(ref const(QVector3D) v1, ref const(QVector3D) v2); //in Qt 6 convert to inline and constexpr 163 164 static QVector3D normal(ref const(QVector3D) v1, ref const(QVector3D) v2); 165 static QVector3D normal 166 (ref const(QVector3D) v1, ref const(QVector3D) v2, ref const(QVector3D) v3); 167 168 QVector3D project(ref const(QMatrix4x4) modelView, ref const(QMatrix4x4) projection, ref const(QRect) viewport) const; 169 QVector3D unproject(ref const(QMatrix4x4) modelView, ref const(QMatrix4x4) projection, ref const(QRect) viewport) const; 170 171 float distanceToPoint(ref const(QVector3D) point) const; 172 float distanceToPlane(ref const(QVector3D) plane, ref const(QVector3D) normal) const; 173 float distanceToPlane(ref const(QVector3D) plane1, ref const(QVector3D) plane2, ref const(QVector3D) plane3) const; 174 float distanceToLine(ref const(QVector3D) point, ref const(QVector3D) direction) const; 175 176 /+ friend inline bool operator==(const QVector3D &v1, const QVector3D &v2); +/ 177 /+ friend inline bool operator!=(const QVector3D &v1, const QVector3D &v2); +/ 178 /+ friend inline const QVector3D operator+(const QVector3D &v1, const QVector3D &v2); +/ 179 /+ friend inline const QVector3D operator-(const QVector3D &v1, const QVector3D &v2); +/ 180 /+ friend inline const QVector3D operator*(float factor, const QVector3D &vector); +/ 181 /+ friend inline const QVector3D operator*(const QVector3D &vector, float factor); +/ 182 /+ friend const QVector3D operator*(const QVector3D &v1, const QVector3D& v2); +/ 183 /+ friend inline const QVector3D operator-(const QVector3D &vector); +/ 184 /+ friend inline const QVector3D operator/(const QVector3D &vector, float divisor); +/ 185 /+ friend inline const QVector3D operator/(const QVector3D &vector, const QVector3D &divisor); +/ 186 187 /+ friend inline bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2); +/ 188 189 /+ #ifndef QT_NO_VECTOR2D +/ 190 version(QT_NO_VECTOR2D){}else 191 { 192 QVector2D toVector2D() const; 193 } 194 /+ #endif 195 #ifndef QT_NO_VECTOR4D +/ 196 version(QT_NO_VECTOR4D){}else 197 { 198 QVector4D toVector4D() const; 199 } 200 /+ #endif +/ 201 202 pragma(inline, true) QPoint toPoint() const 203 { 204 import qt.core.global; 205 206 return QPoint(qRound(v[0]), qRound(v[1])); 207 } 208 pragma(inline, true) QPointF toPointF() const 209 { 210 import qt.core.global; 211 212 return QPointF(qreal(v[0]), qreal(v[1])); 213 } 214 215 /+auto opCast(T : QVariant)() const;+/ 216 217 private: 218 float[3] v; 219 220 /+ friend class QVector2D; +/ 221 /+ friend class QVector4D; +/ 222 static if(!defined!"QT_NO_MATRIX4X4") 223 { 224 /+ friend QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix); +/ 225 /+ friend QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector); +/ 226 } 227 } 228 229 /+ Q_DECLARE_TYPEINFO(QVector3D, Q_PRIMITIVE_TYPE); 230 231 QT_WARNING_PUSH 232 QT_WARNING_DISABLE_CLANG("-Wfloat-equal") 233 QT_WARNING_DISABLE_GCC("-Wfloat-equal") 234 QT_WARNING_DISABLE_INTEL(1572) +/ 235 /+pragma(inline, true) bool operator ==(ref const(QVector3D) v1, ref const(QVector3D) v2) 236 { 237 return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1] && v1.v[2] == v2.v[2]; 238 }+/ 239 240 /+pragma(inline, true) bool operator !=(ref const(QVector3D) v1, ref const(QVector3D) v2) 241 { 242 return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1] || v1.v[2] != v2.v[2]; 243 }+/ 244 /+ QT_WARNING_POP +/ 245 246 /+pragma(inline, true) const(QVector3D) operator +(ref const(QVector3D) v1, ref const(QVector3D) v2) 247 { 248 return QVector3D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1], v1.v[2] + v2.v[2]); 249 }+/ 250 251 /+pragma(inline, true) const(QVector3D) operator -(ref const(QVector3D) v1, ref const(QVector3D) v2) 252 { 253 return QVector3D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1], v1.v[2] - v2.v[2]); 254 }+/ 255 256 /+pragma(inline, true) const(QVector3D) operator *(float factor, ref const(QVector3D) vector) 257 { 258 return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor); 259 }+/ 260 261 /+pragma(inline, true) const(QVector3D) operator *(ref const(QVector3D) vector, float factor) 262 { 263 return QVector3D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor); 264 }+/ 265 266 /+pragma(inline, true) const(QVector3D) operator *(ref const(QVector3D) v1, ref const(QVector3D) v2) 267 { 268 return QVector3D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1], v1.v[2] * v2.v[2]); 269 }+/ 270 271 /+pragma(inline, true) const(QVector3D) operator -(ref const(QVector3D) vector) 272 { 273 return QVector3D(-vector.v[0], -vector.v[1], -vector.v[2]); 274 }+/ 275 276 /+pragma(inline, true) const(QVector3D) operator /(ref const(QVector3D) vector, float divisor) 277 { 278 return QVector3D(vector.v[0] / divisor, vector.v[1] / divisor, vector.v[2] / divisor); 279 }+/ 280 281 /+pragma(inline, true) const(QVector3D) operator /(ref const(QVector3D) vector, ref const(QVector3D) divisor) 282 { 283 return QVector3D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1], vector.v[2] / divisor.v[2]); 284 }+/ 285 286 pragma(inline, true) bool qFuzzyCompare(ref const(QVector3D) v1, ref const(QVector3D) v2) 287 { 288 import qt.core.global; 289 290 return qt.core.global.qFuzzyCompare(v1.v[0], v2.v[0]) && 291 qt.core.global.qFuzzyCompare(v1.v[1], v2.v[1]) && 292 qt.core.global.qFuzzyCompare(v1.v[2], v2.v[2]); 293 } 294 295 /+ #ifndef QT_NO_DEBUG_STREAM 296 Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QVector3D &vector); 297 #endif 298 299 #ifndef QT_NO_DATASTREAM 300 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QVector3D &); 301 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector3D &); 302 #endif +/ 303 304 } 305