Terminus
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
terminus::AbstractGraphicsObject Class Reference

The AbstractGraphicsObject class is the root of a class hierarchy of objects that contain independen game logic and are visible in the game. More...

#include <abstractgraphicsobject.h>

Inheritance diagram for terminus::AbstractGraphicsObject:
terminus::AbstractPhysicsObject terminus::Explosion terminus::SkyBox terminus::Terrain terminus::Track terminus::Train terminus::DynamicPhysicsObject terminus::KinematicPhysicsObject terminus::Projectile terminus::AbstractWagon terminus::EngineWagon terminus::RepairWagon terminus::WeaponWagon

Public Member Functions

 AbstractGraphicsObject (World &world)
 
virtual ~AbstractGraphicsObject ()
 
virtual void update () final
 update object hierarchy beginning at this object More...
 
virtual void render (QOpenGLFunctions &gl) final
 render object hierarchy beginning at this object More...
 
virtual void bindCamera (Camera *camera)
 binds a camera to track this object More...
 
virtual void unbindCamera (Camera *camera)
 release a camera so that it wont track this object any longer More...
 
virtual void onBindCamera ()
 override this method to perform specific actions once a camera has been bound More...
 
virtual void onUnbindCamera ()
 override this method to perform specific actions once a camera has been released More...
 
virtual void adjustCamera ()
 override this method to adjust the parameters of a bound camera according to this objects own state More...
 
virtual void moveEvent (QVector3D movement)
 override this method to react to move events received by a bound camera More...
 
virtual void rotateEvent (QVector2D rotation)
 override this method to react to rotate events received by a bound camera More...
 
const QVector3D & minBB () const
 
const QVector3D & maxBB () const
 
QVector3D worldUp ()
 
QVector3D worldFront ()
 
QVector3D worldSide ()
 
QVector3D position () const
 
QQuaternion rotation () const
 
QVector3D scale () const
 
QMatrix4x4 modelMatrix () const
 
QMatrix4x4 modelMatrixInverted () const
 

Protected Member Functions

virtual void localUpdate ()
 override this method to update this objects state More...
 
virtual void localRender (QOpenGLFunctions &gl) const
 this method contains the default render code using m_geometry, m_program and m_material More...
 
virtual void localRenderSetup (QOpenGLFunctions &gl, Program &program) const
 override this method to customize the rendering process More...
 
virtual void localRenderCleanup (QOpenGLFunctions &gl, Program &program) const
 override this method to customize the rendering process More...
 
virtual bool localRenderEnabled () const
 override this method to disable or enable rendering conditionally More...
 
virtual void doForAllChildren (std::function< void(AbstractGraphicsObject &)> callback)
 override this method to make child objects known More...
 
void setPosition (const QVector3D &position)
 sets the position and invalidates the model matrices More...
 
void setRotation (const QQuaternion &rotation)
 sets the rotation and invalidates the model matrices More...
 
void setScale (const QVector3D &scale)
 sets the scale and invalidates the model matrices More...
 
void setScale (float scale)
 sets the scale uniformly on all three axes and invalidates the model matrices More...
 
QVector3D worldToModel (const QVector3D &vWorld)
 
QVector3D modelToWorld (const QVector3D &vModel)
 
void dispose ()
 remove this object from the world and delete it as soon as it is safe to do so More...
 

Protected Attributes

Worldm_world
 
bool m_validState
 
Cameram_camera
 
std::shared_ptr< std::unique_ptr< Program > > m_program
 
std::shared_ptr< std::unique_ptr< Geometry > > m_geometry
 
std::shared_ptr< std::unique_ptr< Material > > m_material
 
QVector3D m_position
 
QQuaternion m_rotation
 
QVector3D m_scale
 
bool m_modelMatrixChanged
 
QMatrix4x4 m_modelMatrix
 
bool m_modelMatrixInvertedChanged
 
QMatrix4x4 m_modelMatrixInverted
 

Detailed Description

The AbstractGraphicsObject class is the root of a class hierarchy of objects that contain independen game logic and are visible in the game.

Constructor & Destructor Documentation

terminus::AbstractGraphicsObject::AbstractGraphicsObject ( World world)
terminus::AbstractGraphicsObject::~AbstractGraphicsObject ( )
virtual

Do not delete this destructor, even if it is empty

  • otherwise std::shared_ptr<IncompleteType> in the header will break

Member Function Documentation

void terminus::AbstractGraphicsObject::adjustCamera ( )
virtual

override this method to adjust the parameters of a bound camera according to this objects own state

Reimplemented in terminus::AbstractWagon.

void terminus::AbstractGraphicsObject::bindCamera ( Camera camera)
virtual

binds a camera to track this object

Parameters
camOnce a camera has been bound, it passes move and rotate events on to this object and adjustCamera() will be called from update()
See also
adjustCamera()
moveEvent()
rotateEvent()
void terminus::AbstractGraphicsObject::dispose ( )
protected

remove this object from the world and delete it as soon as it is safe to do so

See also
World::deleteObject()
void terminus::AbstractGraphicsObject::doForAllChildren ( std::function< void(AbstractGraphicsObject &)>  callback)
protectedvirtual

override this method to make child objects known

Parameters
callbackcallback must be called once for every child object

Reimplemented in terminus::Train, and terminus::Terrain.

void terminus::AbstractGraphicsObject::localRender ( QOpenGLFunctions &  gl) const
protectedvirtual

this method contains the default render code using m_geometry, m_program and m_material

Parameters
gllocalRenderSetup() and localRenderCleanup are called from here and are the preferred way to customize the rendering process over overriding this method entirely

Reimplemented in terminus::Terrain.

void terminus::AbstractGraphicsObject::localRenderCleanup ( QOpenGLFunctions &  gl,
Program program 
) const
protectedvirtual

override this method to customize the rendering process

Parameters
gl
program- still bound

Here is the right place to clean up rendering states set in localRenderSetup().

Reimplemented in terminus::Explosion, terminus::Terrain, and terminus::SkyBox.

bool terminus::AbstractGraphicsObject::localRenderEnabled ( ) const
protectedvirtual

override this method to disable or enable rendering conditionally

Returns
true if localRender() shall be called

Reimplemented in terminus::Train, and terminus::Track.

void terminus::AbstractGraphicsObject::localRenderSetup ( QOpenGLFunctions &  gl,
Program program 
) const
protectedvirtual

override this method to customize the rendering process

Parameters
gl
program- already bound

Here is the right place to set additional uniforms and to bind textures &c.

Reimplemented in terminus::Explosion, terminus::Terrain, and terminus::SkyBox.

void terminus::AbstractGraphicsObject::localUpdate ( )
protectedvirtual
const QVector3D & terminus::AbstractGraphicsObject::maxBB ( ) const
Returns
the maximum vector of this objects AABB given that it has a an associated Geometry instance
const QVector3D & terminus::AbstractGraphicsObject::minBB ( ) const
Returns
the minimum vector of this objects AABB given that it has a an associated Geometry instance
QMatrix4x4 terminus::AbstractGraphicsObject::modelMatrix ( ) const
Returns
this objects model matrix

If necessary, the matrix is recalculated from the position, rotation and scaling information

QMatrix4x4 terminus::AbstractGraphicsObject::modelMatrixInverted ( ) const
Returns
this objects inverted model matrix

If necessary, the matrix is recalculated from the model matrix

QVector3D terminus::AbstractGraphicsObject::modelToWorld ( const QVector3D &  vModel)
protected
Parameters
vModel
Returns
the world space position corresponding to vModel in model space
See also
modelMatrix()
void terminus::AbstractGraphicsObject::moveEvent ( QVector3D  movement)
virtual

override this method to react to move events received by a bound camera

Parameters
movement
void terminus::AbstractGraphicsObject::onBindCamera ( )
virtual

override this method to perform specific actions once a camera has been bound

Reimplemented in terminus::AbstractWagon.

void terminus::AbstractGraphicsObject::onUnbindCamera ( )
virtual

override this method to perform specific actions once a camera has been released

QVector3D terminus::AbstractGraphicsObject::position ( ) const
Returns
the position vector that was used to construct the model matrix
void terminus::AbstractGraphicsObject::render ( QOpenGLFunctions &  gl)
finalvirtual

render object hierarchy beginning at this object

Parameters
glThis method is not meant to be overridden as it contains logic to update child objects.
See also
AbstractGraphicsObject::localRender
void terminus::AbstractGraphicsObject::rotateEvent ( QVector2D  rotation)
virtual

override this method to react to rotate events received by a bound camera

Parameters
rotation

Reimplemented in terminus::AbstractWagon.

QQuaternion terminus::AbstractGraphicsObject::rotation ( ) const
Returns
the quaternion that was used to construct the model matrix
QVector3D terminus::AbstractGraphicsObject::scale ( ) const
Returns
the scaling vector that was used to construct the model matrix
void terminus::AbstractGraphicsObject::setPosition ( const QVector3D &  position)
protected

sets the position and invalidates the model matrices

Parameters
position
void terminus::AbstractGraphicsObject::setRotation ( const QQuaternion &  rotation)
protected

sets the rotation and invalidates the model matrices

Parameters
rotation
void terminus::AbstractGraphicsObject::setScale ( const QVector3D &  scale)
protected

sets the scale and invalidates the model matrices

Parameters
scale
void terminus::AbstractGraphicsObject::setScale ( float  scale)
protected

sets the scale uniformly on all three axes and invalidates the model matrices

Parameters
scale
void terminus::AbstractGraphicsObject::unbindCamera ( Camera camera)
virtual

release a camera so that it wont track this object any longer

See also
bindCamera()
void terminus::AbstractGraphicsObject::update ( )
finalvirtual

update object hierarchy beginning at this object

This method is not meant to be overridden as it contains logic to update child objects.

See also
AbstractGraphicsObject::localUpdate
QVector3D terminus::AbstractGraphicsObject::worldFront ( )
Returns
the front-vector of the model coordinate system transformed to world space
QVector3D terminus::AbstractGraphicsObject::worldSide ( )
Returns
the side-vector of the model coordinate system transformed to world space
QVector3D terminus::AbstractGraphicsObject::worldToModel ( const QVector3D &  vWorld)
protected
Parameters
vWorld
Returns
the model space position corresponding to vWorld in world space
See also
modelMatrixInverted()
QVector3D terminus::AbstractGraphicsObject::worldUp ( )
Returns
the up-vector of the model coordinate system transformed to world space

Member Data Documentation

Camera* terminus::AbstractGraphicsObject::m_camera
protected
std::shared_ptr<std::unique_ptr<Geometry> > terminus::AbstractGraphicsObject::m_geometry
protected
std::shared_ptr<std::unique_ptr<Material> > terminus::AbstractGraphicsObject::m_material
protected
QMatrix4x4 terminus::AbstractGraphicsObject::m_modelMatrix
mutableprotected
bool terminus::AbstractGraphicsObject::m_modelMatrixChanged
mutableprotected
QMatrix4x4 terminus::AbstractGraphicsObject::m_modelMatrixInverted
mutableprotected
bool terminus::AbstractGraphicsObject::m_modelMatrixInvertedChanged
mutableprotected
QVector3D terminus::AbstractGraphicsObject::m_position
protected
std::shared_ptr<std::unique_ptr<Program> > terminus::AbstractGraphicsObject::m_program
protected
QQuaternion terminus::AbstractGraphicsObject::m_rotation
protected
QVector3D terminus::AbstractGraphicsObject::m_scale
protected
bool terminus::AbstractGraphicsObject::m_validState
protected
World& terminus::AbstractGraphicsObject::m_world
protected

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