Gem Illuminator
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
abstractgem.h
Go to the documentation of this file.
1 #ifndef GEOMETRY_H
2 #define GEOMETRY_H
3 
4 #include <QObject>
5 #include <QQuaternion>
6 #include <QVector3D>
7 
8 class QMatrix4x4;
9 class QOpenGLFunctions;
10 class QOpenGLShaderProgram;
11 class QQuaternion;
12 
13 class AbstractGemRenderer;
14 class GemData;
15 class LightRay;
16 class Triangle;
17 class Scene;
18 
22 enum class GemType {
23  Abstract,
24  Cube,
25  Tetrahedron};
26 
33 uint qHash(GemType key, uint seed);
34 
39 class AbstractGem : public QObject
40 {
41  Q_OBJECT
42  Q_PROPERTY(const QVector3D &position READ position WRITE setPosition NOTIFY positionChanged)
43  Q_PROPERTY(const QQuaternion &rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
44  Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
45  Q_PROPERTY(const QVector3D &color READ color WRITE setColor NOTIFY colorChanged)
46 
47 public:
48  explicit AbstractGem(QObject *parent = 0);
49  virtual ~AbstractGem();
50 
51  const QVector3D &color() const;
52  void setColor(const QVector3D &color);
53 
59  const GemData &data() const;
60 
65  const QMatrix4x4 &model() const;
66 
67  const QVector3D &position() const;
68  virtual void setPosition(const QVector3D &position);
69 
74  qreal radius() const;
75 
80  const QQuaternion &rotation() const;
86  virtual void setRotation(const QQuaternion &rotation);
91  void rotate(const QQuaternion &quaternion);
92 
93  qreal scale() const;
94  void setScale(qreal scaleFactor);
95 
100  GemType type() const;
101 
114  float boundingSphereIntersectedBy(const LightRay &ray, QVector3D *collisionPoint = nullptr);
124  virtual float intersectedBy(const LightRay &ray, QVector3D *collisionPoint = nullptr);
131  virtual QList<LightRay *> processRayIntersection(const LightRay &ray, Scene *scene);
132 
133 public slots:
138  void setRotationFromEuler(const QVector3D &eulerRotation);
139 
140 signals:
141  void positionChanged();
142  void rotationChanged();
143  void scaleChanged();
144  void colorChanged();
145 
146 protected:
147  int solveQuadricFormula(float a, float b, float c, float &x1, float &x2);
148 
156  float faceIntersectedBy(const LightRay &ray, Triangle *&intersectedFace, QVector3D *collisionPoint = nullptr);
157 
163  Triangle inWorldCoordinates(const Triangle &triangle);
164 
165 protected:
167  qreal m_radius;
168 };
169 
170 #endif // GEOMETRY_H
float faceIntersectedBy(const LightRay &ray, Triangle *&intersectedFace, QVector3D *collisionPoint=nullptr)
Finds face of gem intersected by given ray. Ownership of returned face is transferred to caller...
Definition: abstractgem.cpp:194
GemType type() const
Returns the type of gem, in order to differentiate between types even if you have only AbstractGems...
Definition: abstractgem.cpp:89
GemType
An enum describing current gem type. This enum is used for faster comparision of gems, because all gems of one type have same (objectspace) vertices.
Definition: abstractgem.h:22
qreal scale() const
The LightRay class describes the lightrays sent into Scene. Because LightRays are sent into Scene ri...
Definition: lightray.h:24
void setScale(qreal scaleFactor)
Definition: abstractgem.cpp:80
qreal m_radius
Definition: abstractgem.h:167
The Triangle class represents a triangle in three dimensional space.
Definition: triangle.h:11
void rotate(const QQuaternion &quaternion)
Rotates the gem around the center of the gem.
Definition: abstractgem.cpp:273
void setRotationFromEuler(const QVector3D &eulerRotation)
Sets rotation of gem using euler angles. This method is mainly used to set initial rotation...
Definition: abstractgem.cpp:38
void colorChanged()
float boundingSphereIntersectedBy(const LightRay &ray, QVector3D *collisionPoint=nullptr)
Calculates distance to collision with gem's boundingsphere. The boundingsphere is specified by gems ...
Definition: abstractgem.cpp:123
const QVector3D & color() const
virtual float intersectedBy(const LightRay &ray, QVector3D *collisionPoint=nullptr)
Calcualtes the distance to collision of ray with gem. This method calculates the real collision poin...
Definition: abstractgem.cpp:180
virtual ~AbstractGem()
Definition: abstractgem.cpp:33
The GemData class stores all required information to describe an AbstractGem. The advantage of GemDa...
Definition: gemdata.h:20
qreal radius() const
Radius of boundingsphere. This value is influenced by scale and the geometry of gem.
Definition: abstractgem.cpp:113
void setColor(const QVector3D &color)
Definition: abstractgem.cpp:99
void positionChanged()
The Scene class provides access to geometry and collision detection methods. Furthermore, some game logic is implemented, so the scene holds the player, the gem influenced by player and cameras.
Definition: scene.h:22
const QQuaternion & rotation() const
Rotation around own center.
void rotationChanged()
virtual void setPosition(const QVector3D &position)
Definition: abstractgem.cpp:52
int solveQuadricFormula(float a, float b, float c, float &x1, float &x2)
Definition: abstractgem.cpp:158
const GemData & data() const
Returns the GemData object describing the gem. This method was not intended to be public...
Definition: abstractgem.cpp:108
uint qHash(GemType key, uint seed)
Custom implementation of qHash. Providing hash calculation for GemType. In order to use GemType as ke...
Definition: abstractgem.cpp:303
virtual void setRotation(const QQuaternion &rotation)
Sets the rotation of gem around own center.
Definition: abstractgem.cpp:66
const QMatrix4x4 & model() const
Constructs normal matrix for gem in order to transform it from objectspace into worldsapce.
Definition: abstractgem.cpp:118
void scaleChanged()
Triangle inWorldCoordinates(const Triangle &triangle)
Calculates triangle in world coordinates for given triangle. Therefore, position, rotatition and scal...
Definition: abstractgem.cpp:263
AbstractGem(QObject *parent=0)
Definition: abstractgem.cpp:26
virtual QList< LightRay * > processRayIntersection(const LightRay &ray, Scene *scene)
Calculates all new rays, that will be created by a collision with that gem. Also affect gem attribute...
Definition: abstractgem.cpp:278
The AbstractGem class is the base class of all gems. As base class all required information of a gem...
Definition: abstractgem.h:39
const QVector3D & position() const
GemData * m_data
Definition: abstractgem.h:166