Terminus
|
The Train class works as a logical container for all wagons one train consists of. More...
#include <train.h>
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... | |
AbstractWagon * | wagonAt (unsigned int index) const |
Track * | track () 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... | |
AbstractPlayer & | player () const |
void | setPlayer (AbstractPlayer *player) |
![]() | |
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... | |
![]() | |
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 |
Train * | m_followedTrain |
float | m_travelledDistance |
Track * | m_track |
AbstractPlayer * | m_player |
A pointer to the player that controls this train. More... | |
![]() | |
World & | m_world |
bool | m_validState |
Camera * | m_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 |
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.
terminus::Train::~Train | ( | ) |
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.
|
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.
|
overrideprotectedvirtual |
override this method to make child objects known
callback | callback must be called once for every child object |
Reimplemented from terminus::AbstractGraphicsObject.
void terminus::Train::follow | ( | Train * | train | ) |
QVector3D terminus::Train::headPosition | ( | ) | const |
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.
|
overrideprotectedvirtual |
override this method to disable or enable rendering conditionally
Reimplemented from terminus::AbstractGraphicsObject.
|
overridevirtual |
Update train.
Reimplemented from terminus::AbstractGraphicsObject.
void terminus::Train::moveWagon | ( | unsigned int | wagonPos, |
unsigned int | targetPos | ||
) |
Moves the wagon at position wagonPos to position targetPos.
wagonPos | The index of the wagon to be moved |
targetPos | The 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 |
|
static |
|
protected |
|
protected |
Every train needs exactly one engine.
|
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.
|
protected |
|
protected |
|
protected |
|
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.