Gem Illuminator
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
Public Slots | Signals | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AbstractGem Class Reference

The AbstractGem class is the base class of all gems. As base class all required information of a gem are stored. Also, useful algorithms for collision detection are provided. Furthermore, this class is supposed to be used within QML. More...

#include <abstractgem.h>

Inheritance diagram for AbstractGem:
CubeGem SceneBounds TetrahedronGem

Public Slots

void setRotationFromEuler (const QVector3D &eulerRotation)
 Sets rotation of gem using euler angles. This method is mainly used to set initial rotation. More...
 

Signals

void positionChanged ()
 
void rotationChanged ()
 
void scaleChanged ()
 
void colorChanged ()
 

Public Member Functions

 AbstractGem (QObject *parent=0)
 
virtual ~AbstractGem ()
 
const QVector3D & color () const
 
void setColor (const QVector3D &color)
 
const GemDatadata () const
 Returns the GemData object describing the gem. This method was not intended to be public, but public access is needed it for rendering. More...
 
const QMatrix4x4 & model () const
 Constructs normal matrix for gem in order to transform it from objectspace into worldsapce. More...
 
const QVector3D & position () const
 
virtual void setPosition (const QVector3D &position)
 
qreal radius () const
 Radius of boundingsphere. This value is influenced by scale and the geometry of gem. More...
 
const QQuaternion & rotation () const
 Rotation around own center. More...
 
virtual void setRotation (const QQuaternion &rotation)
 Sets the rotation of gem around own center. More...
 
void rotate (const QQuaternion &quaternion)
 Rotates the gem around the center of the gem. More...
 
qreal scale () const
 
void setScale (qreal scaleFactor)
 
GemType type () const
 Returns the type of gem, in order to differentiate between types even if you have only AbstractGems. More...
 
float boundingSphereIntersectedBy (const LightRay &ray, QVector3D *collisionPoint=nullptr)
 Calculates distance to collision with gem's boundingsphere. The boundingsphere is specified by gems themself and cannot be influenced from outside. Because the collision point is only calculated with the bondingsphere computation is pretty fast. More...
 
virtual float intersectedBy (const LightRay &ray, QVector3D *collisionPoint=nullptr)
 Calcualtes the distance to collision of ray with gem. This method calculates the real collision point. Therefore, many computations are done especially for complex gems. More...
 
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 attributes. More...
 

Protected Member Functions

int solveQuadricFormula (float a, float b, float c, float &x1, float &x2)
 
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. More...
 
Triangle inWorldCoordinates (const Triangle &triangle)
 Calculates triangle in world coordinates for given triangle. Therefore, position, rotatition and scale of gem are used. More...
 

Protected Attributes

GemDatam_data
 
qreal m_radius
 

Detailed Description

The AbstractGem class is the base class of all gems. As base class all required information of a gem are stored. Also, useful algorithms for collision detection are provided. Furthermore, this class is supposed to be used within QML.

Constructor & Destructor Documentation

AbstractGem::AbstractGem ( QObject *  parent = 0)
explicit
AbstractGem::~AbstractGem ( )
virtual

Member Function Documentation

float AbstractGem::boundingSphereIntersectedBy ( const LightRay ray,
QVector3D *  collisionPoint = nullptr 
)

Calculates distance to collision with gem's boundingsphere. The boundingsphere is specified by gems themself and cannot be influenced from outside. Because the collision point is only calculated with the bondingsphere computation is pretty fast.

Parameters
rayThe ray which might collide with gem's boundingsphere
collisionPointOptional parameter. If provided the collision point of ray with boundingsphere is written into. If no collision occurs the maximum float value is written into all components.
Returns
The factor you need to apply ray.direction() to ray.startPosition(). If no collision occurs maximum float value is returned. Do not compare this value with return values of intersectedBy() intersectedBy()
const QVector3D& AbstractGem::color ( ) const
void AbstractGem::colorChanged ( )
signal
const GemData & AbstractGem::data ( ) const

Returns the GemData object describing the gem. This method was not intended to be public, but public access is needed it for rendering.

Returns
float AbstractGem::faceIntersectedBy ( const LightRay ray,
Triangle *&  intersectedFace,
QVector3D *  collisionPoint = nullptr 
)
protected

Finds face of gem intersected by given ray. Ownership of returned face is transferred to caller.

Parameters
rayRay that might intersect gem
intersectedFaceA pointer to intersected face is written into. Because this triangle is in worldspace and for performance reasons the ownership of face is transferred to caller. If ray does not intersect nullptr is written.
collisionPointOptional parameter. If the given pointer is not nullptr the collisionpoint is written into.
Returns
Returns distance to collisionpoint. If no collission occured the value is maximum of float.
float AbstractGem::intersectedBy ( const LightRay ray,
QVector3D *  collisionPoint = nullptr 
)
virtual

Calcualtes the distance to collision of ray with gem. This method calculates the real collision point. Therefore, many computations are done especially for complex gems.

Parameters
rayThe ray that might collide with gem.
collisionPointOptional parameter. If a collision occurs the collision point will be written into this else all components contain maximum float values.
Returns
The factor you need to apply ray.normalizedDirection() to ray.startDirection(). If no collision occurs this value will be highest possible float. Do not compare this value with return value of boundingsphereIntersectedBy() boundingSphereIntersectedBy()
Triangle AbstractGem::inWorldCoordinates ( const Triangle triangle)
protected

Calculates triangle in world coordinates for given triangle. Therefore, position, rotatition and scale of gem are used.

Parameters
triangleObjectspace triangle whose corresponding worldspace triangle should be calculated.
Returns
Returns the Triangle in world coordinates.
const QMatrix4x4 & AbstractGem::model ( ) const

Constructs normal matrix for gem in order to transform it from objectspace into worldsapce.

Returns
const QVector3D& AbstractGem::position ( ) const
void AbstractGem::positionChanged ( )
signal
QList< LightRay * > AbstractGem::processRayIntersection ( const LightRay ray,
Scene scene 
)
virtual

Calculates all new rays, that will be created by a collision with that gem. Also affect gem attributes.

Parameters
rayRay that might collide.
sceneThe scene the ray and gem are in. This is needed in order to calculate new rays appropriately.
Returns
A List of light rays that should be added to scene. If no collision occurs, the list is empty. Ownership of rays contained in list is transferred to caller.

Reimplemented in SceneBounds.

qreal AbstractGem::radius ( ) const

Radius of boundingsphere. This value is influenced by scale and the geometry of gem.

Returns
void AbstractGem::rotate ( const QQuaternion &  quaternion)

Rotates the gem around the center of the gem.

Parameters
quaternionSpecifies how the gem should be rotated.
const QQuaternion& AbstractGem::rotation ( ) const

Rotation around own center.

Returns
void AbstractGem::rotationChanged ( )
signal
qreal AbstractGem::scale ( ) const
void AbstractGem::scaleChanged ( )
signal
void AbstractGem::setColor ( const QVector3D &  color)
void AbstractGem::setPosition ( const QVector3D &  position)
virtual

Reimplemented in SceneBounds.

void AbstractGem::setRotation ( const QQuaternion &  rotation)
virtual

Sets the rotation of gem around own center.

Parameters
rotationValue the roation will be set to. setRotationFromEuler()

Reimplemented in SceneBounds.

void AbstractGem::setRotationFromEuler ( const QVector3D &  eulerRotation)
slot

Sets rotation of gem using euler angles. This method is mainly used to set initial rotation.

Parameters
eulerRotationQVector3D containing the euler angles. The member of eulerVector contains corresponding rotation along axis (x component = rotation around x axis). The angle around axis is specified in degrees.
void AbstractGem::setScale ( qreal  scaleFactor)
int AbstractGem::solveQuadricFormula ( float  a,
float  b,
float  c,
float &  x1,
float &  x2 
)
protected
GemType AbstractGem::type ( ) const

Returns the type of gem, in order to differentiate between types even if you have only AbstractGems.

Returns

Member Data Documentation

GemData* AbstractGem::m_data
protected
qreal AbstractGem::m_radius
protected

The documentation for this class was generated from the following files: