QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsraycastingutils_p.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsraycastingutils_p.h
3  --------------------------------------
4  Date : June 2018
5  Copyright : (C) 2018 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSRAYCASTINGUTILS_P_H
17 #define QGSRAYCASTINGUTILS_P_H
18 
20 
21 //
22 // W A R N I N G
23 // -------------
24 //
25 // This file is not part of the QGIS API. It exists purely as an
26 // implementation detail. This header file may change from version to
27 // version without notice, or even be removed.
28 //
29 
30 #include <QVector3D>
31 
32 class QgsAABB;
33 
34 namespace Qt3DRender
35 {
36  class QCamera;
37 }
38 
39 
40 namespace QgsRayCastingUtils
41 {
42 
48  class Ray3D
49  {
50  public:
51  Ray3D();
52  explicit Ray3D( QVector3D origin, QVector3D direction = QVector3D( 0.0f, 0.0f, 1.0f ), float distance = 1.0f );
53 
54  QVector3D origin() const;
55  void setOrigin( QVector3D value );
56 
57  QVector3D direction() const;
58  void setDirection( QVector3D value );
59 
60  float distance() const;
61  void setDistance( float distance );
62 
63  bool contains( QVector3D point ) const;
64  bool contains( const Ray3D &ray ) const;
65 
66  QVector3D point( float t ) const;
67  float projectedDistance( QVector3D point ) const;
68 
69  QVector3D project( QVector3D vector ) const;
70 
71  float distance( QVector3D point ) const;
72 
73  Ray3D &transform( const QMatrix4x4 &matrix );
74  Ray3D transformed( const QMatrix4x4 &matrix ) const;
75 
76  bool operator==( const Ray3D &other ) const;
77  bool operator!=( const Ray3D &other ) const;
78 
79  private:
80  QVector3D m_origin;
81  QVector3D m_direction;
82  float m_distance = 1.0f;
83  };
84 
91  bool rayBoxIntersection( const Ray3D &r, const QgsAABB &aabb );
92 
94  struct Plane3D
95  {
96  QVector3D center;
97  QVector3D normal;
98  };
99 
105  bool rayPlaneIntersection( const Ray3D &r, const Plane3D &plane, QVector3D &pt );
106 
112  bool rayTriangleIntersection( const Ray3D &ray,
113  QVector3D a,
114  QVector3D b,
115  QVector3D c,
116  QVector3D &uvw,
117  float &t );
118 
124  Ray3D rayForViewportAndCamera( const QSize &area,
125  const QPointF &pos,
126  const QRectF &relativeViewport,
127  const Qt3DRender::QCamera *camera );
128 
134  Ray3D rayForCameraCenter( const Qt3DRender::QCamera *camera );
135 }
136 
138 
139 #endif // QGSRAYCASTINGUTILS_P_H
3 Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:30
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c