Terminus
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
terminus::Train Class Reference

The Train class works as a logical container for all wagons one train consists of. More...

#include <train.h>

Inheritance diagram for terminus::Train:
terminus::AbstractGraphicsObject

Public Member Functions

 Train (World &world, Track *track)
 
 ~Train ()
 
template<typename WagonType >
void addWagon ()
 Adds a wagon of the given WagonType to the end of the train. More...
 
template<typename WagonType >
void insertWagon (int targetPos)
 Inserts a wagon of the given WagonType at the given position. More...
 
void removeWagon (unsigned int index)
 Removes the wagon at the given index. More...
 
void moveWagon (unsigned int wagonPos, unsigned int targetPos)
 Moves the wagon at position wagonPos to position targetPos. More...
 
void localUpdate () override
 Update train. More...
 
AbstractWagonwagonAt (unsigned int index) const
 
Tracktrack () const
 
void follow (Train *train)
 
float velocity () const
 
void setVelocity (float velocity)
 
float travelledDistance () const
 Returns the travelled distance of the train's head on the spline. More...
 
void setTravelledDistance (float travelledDistance)
 Set the travelled distance of the train's head on the spline. More...
 
float travelledDistanceRelative () const
 Returns the ratio of travelled distance to track length. More...
 
QVector3D headPosition () const
 
unsigned int size () const
 Returns the number of wagons in this train. More...
 
AbstractPlayerplayer () const
 
void setPlayer (AbstractPlayer *player)
 
- Public Member Functions inherited from terminus::AbstractGraphicsObject
 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
 

Static Public Attributes

static const float base_velocity = 0.02
 

Protected Member Functions

virtual bool localRenderEnabled () const override
 override this method to disable or enable rendering conditionally More...
 
void calculateWagonOffset ()
 Calculates offset for every wagon relative to train head. More...
 
virtual void doForAllChildren (std::function< void(AbstractGraphicsObject &)> callback) override
 override this method to make child objects known More...
 
- Protected Member Functions inherited from terminus::AbstractGraphicsObject
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...
 
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

std::vector< std::unique_ptr< AbstractWagon > > m_wagons
 The vector containing all wagons. More...
 
bool m_hasEngine
 Every train needs exactly one engine. More...
 
float m_velocity
 
Trainm_followedTrain
 
float m_travelledDistance
 
Trackm_track
 
AbstractPlayerm_player
 A pointer to the player that controls this train. More...
 
- Protected Attributes inherited from terminus::AbstractGraphicsObject
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 Train class works as a logical container for all wagons one train consists of.

The train itself isn't rendered, but implements all functionality used for determining the current position on the track and the resulting positions for all corresponding wagons.

Constructor & Destructor Documentation

terminus::Train::Train ( World world,
Track track 
)
terminus::Train::~Train ( )

Member Function Documentation

template<typename WagonType >
void terminus::Train::addWagon ( )

Adds a wagon of the given WagonType to the end of the train.

A wagon of the given type will be constructed and added to the end of the train. No additional EngineWagons can be added.

void terminus::Train::calculateWagonOffset ( )
protected

Calculates offset for every wagon relative to train head.

This method calculates and sets the offset for every wagon. If wagons are rearranged, it needs to be called again.

void terminus::Train::doForAllChildren ( std::function< void(AbstractGraphicsObject &)>  callback)
overrideprotectedvirtual

override this method to make child objects known

Parameters
callbackcallback must be called once for every child object

Reimplemented from terminus::AbstractGraphicsObject.

void terminus::Train::follow ( Train train)
QVector3D terminus::Train::headPosition ( ) const
template<typename WagonType >
void terminus::Train::insertWagon ( int  targetPos)

Inserts a wagon of the given WagonType at the given position.

A wagon of the given type will be constructed and inserted at the given position. No additional EngineWagons can be added.

bool terminus::Train::localRenderEnabled ( ) const
overrideprotectedvirtual

override this method to disable or enable rendering conditionally

Returns
true if localRender() shall be called

Reimplemented from terminus::AbstractGraphicsObject.

void terminus::Train::localUpdate ( )
overridevirtual

Update train.

See also
AbstractWagon::localUpdate()

Reimplemented from terminus::AbstractGraphicsObject.

void terminus::Train::moveWagon ( unsigned int  wagonPos,
unsigned int  targetPos 
)

Moves the wagon at position wagonPos to position targetPos.

Parameters
wagonPosThe index of the wagon to be moved
targetPosThe index where the wagon should be moved to

The EngineWagon at index 0 cannot be moved.

AbstractPlayer & terminus::Train::player ( ) const
void terminus::Train::removeWagon ( unsigned int  index)

Removes the wagon at the given index.

The EngineWagon at index 0 cannot be removed.

void terminus::Train::setPlayer ( AbstractPlayer player)
void terminus::Train::setTravelledDistance ( float  travelledDistance)

Set the travelled distance of the train's head on the spline.

void terminus::Train::setVelocity ( float  velocity)
unsigned int terminus::Train::size ( ) const

Returns the number of wagons in this train.

Track * terminus::Train::track ( ) const
float terminus::Train::travelledDistance ( ) const

Returns the travelled distance of the train's head on the spline.

float terminus::Train::travelledDistanceRelative ( ) const

Returns the ratio of travelled distance to track length.

float terminus::Train::velocity ( ) const
AbstractWagon * terminus::Train::wagonAt ( unsigned int  index) const

Member Data Documentation

const float terminus::Train::base_velocity = 0.02
static
Train* terminus::Train::m_followedTrain
protected
bool terminus::Train::m_hasEngine
protected

Every train needs exactly one engine.

AbstractPlayer* terminus::Train::m_player
protected

A pointer to the player that controls this train.

Since the controlling player of a train can change, this is stored as a simple pointer.

Track* terminus::Train::m_track
protected
float terminus::Train::m_travelledDistance
protected
float terminus::Train::m_velocity
protected
std::vector<std::unique_ptr<AbstractWagon> > terminus::Train::m_wagons
protected

The vector containing all wagons.

Every train has exactly one EngineWagon which must be at index 0. It cannot be moved or removed and no additional EngineWagons can be added to the train.


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