Represents the scene tree, third level of the GameObject hierarchy. More...
#include <gameobject.h>
Public Types | |
enum | TransformSpace { TS_LOCAL, TS_WORLD } |
Public Slots | |
void | setParentGameObject (GameObject *newParent) |
void | setPosition (const QVector3D &newPosition) |
void | setPosition (float x, float y, float z) |
void | setPosition (float x, float y) |
void | translate (const QVector3D &translation, GluonEngine::GameObject::TransformSpace ts=TS_LOCAL) |
void | translate (float x, float y, float z, TransformSpace ts=TS_LOCAL) |
void | translate (float x, float y, TransformSpace ts=TS_LOCAL) |
void | setScale (const QVector3D &newScale) |
void | setScale (float x, float y, float z) |
void | scaleRelative (QVector3D scaling, TransformSpace ts=TS_LOCAL) |
void | scaleRelative (float x, float y, float z, TransformSpace ts=TS_LOCAL) |
void | setOrientation (const QQuaternion &newOrientation) |
void | orient (QQuaternion rotation, TransformSpace ts=TS_LOCAL) |
void | rotate (float angle, const QVector3D &axis, TransformSpace ts=TS_LOCAL) |
void | updateTransform () |
void | invalidateTransform () |
void | removeLater (GluonEngine::GameObject *remove) |
Public Member Functions | |
Q_INVOKABLE | GameObject (QObject *parent=0) |
GameObject (const GameObject &other, QObject *parent=0) | |
~GameObject () | |
void | sanitize () |
Q_INVOKABLE void | initialize () |
Q_INVOKABLE void | start () |
Q_INVOKABLE void | update (int elapsedMilliseconds) |
Q_INVOKABLE void | draw (int timeLapse=0) |
Q_INVOKABLE void | stop () |
Q_INVOKABLE void | cleanup () |
Q_INVOKABLE void | destroy () |
void | runCommand (const QString &functionName) |
void | runCommandInChildren (const QString &functionName) |
Q_INVOKABLE Component * | findComponent (const QString &name) const |
Q_INVOKABLE Component * | findComponentByType (const QString &typeName) const |
Q_INVOKABLE Component * | findComponentByType (int type) const |
Q_INVOKABLE QList< Component * > | findComponentsByType (const QString &typeName) const |
Q_INVOKABLE QList< Component * > | findComponentsByType (int type) const |
Q_INVOKABLE Component * | findComponentInChildren (const QString &name) const |
Q_INVOKABLE Component * | findComponentInChildrenByType (const QString &typeName) const |
Q_INVOKABLE QList< Component * > | findComponentsInChildren (const QString &name) const |
Q_INVOKABLE QList< Component * > | findComponentsInChildrenByType (const QString &typeName) const |
Q_INVOKABLE QList< Component * > | findComponentsInChildrenByType (int type) const |
Q_INVOKABLE void | addComponent (Component *addThis) |
Q_INVOKABLE bool | removeComponent (Component *removeThis) |
Q_INVOKABLE QList< Component * > | components () const |
Scene * | scene () const |
GameObject * | childGameObject (int index) const |
GameObject * | childGameObject (const QString &name) const |
void | addChild (GluonCore::GluonObject *child) |
void | addChild (GameObject *addThis) |
void | addChildAt (GameObject *child, int index) |
bool | removeChild (GluonObject *child) |
bool | removeChild (GameObject *removeThis) |
int | childCount () const |
int | childIndex (GameObject *child) const |
Q_INVOKABLE GameObject * | parentGameObject () |
void | setDescription (const QString &newDescription) |
QString | description () const |
Q_INVOKABLE bool | enabled () const |
Q_INVOKABLE void | setEnabled (bool newEnabled) |
Q_INVOKABLE QVector3D | position () const |
Q_INVOKABLE QVector3D | worldPosition () const |
Q_INVOKABLE QVector3D | scale () const |
Q_INVOKABLE QVector3D | worldScale () const |
Q_INVOKABLE QQuaternion | orientation () const |
Q_INVOKABLE QQuaternion | worldOrientation () const |
Q_INVOKABLE QMatrix4x4 | transform () const |
Protected Member Functions | |
virtual void | postCloneSanitize () |
Properties | |
QString | description |
bool | enabled |
QVector3D | position |
QVector3D | scale |
QQuaternion | orientation |
Represents the scene tree, third level of the GameObject hierarchy.
A GameObject is in essence just a translation object, meaning that it has a position, a rotation and an orientation in 3D space. However, it also importantly includes simple logic for attaching other bits of logic, as represented by the Component class, which then attach more functionality to the GameObject.
It is the third level of the GameObject hierarchy, and it can be seen as the structure which makes up a scene tree (see also the Scene documentation).
During the course of a game being played, the lifetime of a GameObject is like so:
# GameObject is constructed on Scene load, and initialize() is called # start() is called when game is started, or the current scene changes to the one containing this GameObject # update() and draw() are called consecutively, at staggered intervals depending on which gameloop is used # stop() is called when the game is stopped, or the current scene changes away # cleanup() is called when the GameObject is destroyed
Definition at line 59 of file gameobject.h.
Definition at line 101 of file gameobject.h.
GameObject::GameObject | ( | QObject * | parent = 0 |
) |
Definition at line 32 of file gameobject.cpp.
GameObject::GameObject | ( | const GameObject & | other, | |
QObject * | parent = 0 | |||
) |
Definition at line 39 of file gameobject.cpp.
GameObject::~GameObject | ( | ) |
Definition at line 46 of file gameobject.cpp.
void GameObject::addChild | ( | GameObject * | addThis | ) |
Definition at line 411 of file gameobject.cpp.
void GluonEngine::GameObject::addChild | ( | GluonCore::GluonObject * | child | ) | [virtual] |
Add the passed GluonObject as a new child to this object. The function will ensure that the name is correct
child | The new child |
Reimplemented from GluonCore::GluonObject.
void GameObject::addChildAt | ( | GameObject * | child, | |
int | index | |||
) |
Definition at line 431 of file gameobject.cpp.
void GameObject::addComponent | ( | Component * | addThis | ) |
Definition at line 327 of file gameobject.cpp.
int GameObject::childCount | ( | ) | const |
Definition at line 463 of file gameobject.cpp.
GameObject * GameObject::childGameObject | ( | const QString & | name | ) | const |
Definition at line 388 of file gameobject.cpp.
GameObject * GameObject::childGameObject | ( | int | index | ) | const |
Definition at line 382 of file gameobject.cpp.
int GameObject::childIndex | ( | GameObject * | child | ) | const |
Definition at line 469 of file gameobject.cpp.
void GameObject::cleanup | ( | ) |
The object has served its purpose. Clean up.
Definition at line 163 of file gameobject.cpp.
QList< Component * > GameObject::components | ( | ) | const |
Definition at line 357 of file gameobject.cpp.
QString GluonEngine::GameObject::description | ( | ) | const |
void GameObject::destroy | ( | ) |
Destroy the object. The object will continue existing until just before the next update call.
Definition at line 176 of file gameobject.cpp.
void GameObject::draw | ( | int | timeLapse = 0 |
) |
Draw the GameObject onto the scene By convention, this should not change GameObjects, but rather, only objects needed for correct operation.
int | timeLapse The number of milliseconds which has passed since the last update |
Definition at line 133 of file gameobject.cpp.
Q_INVOKABLE bool GluonEngine::GameObject::enabled | ( | ) | const |
Component * GameObject::findComponent | ( | const QString & | name | ) | const |
Definition at line 205 of file gameobject.cpp.
Component * GameObject::findComponentByType | ( | int | type | ) | const |
Definition at line 228 of file gameobject.cpp.
Component * GameObject::findComponentByType | ( | const QString & | typeName | ) | const |
Definition at line 221 of file gameobject.cpp.
Component * GameObject::findComponentInChildren | ( | const QString & | name | ) | const |
Definition at line 253 of file gameobject.cpp.
Component * GameObject::findComponentInChildrenByType | ( | const QString & | typeName | ) | const |
Definition at line 269 of file gameobject.cpp.
QList< Component * > GameObject::findComponentsByType | ( | int | type | ) | const |
Definition at line 244 of file gameobject.cpp.
QList< Component * > GameObject::findComponentsByType | ( | const QString & | typeName | ) | const |
Definition at line 237 of file gameobject.cpp.
QList< Component * > GameObject::findComponentsInChildren | ( | const QString & | name | ) | const |
Definition at line 285 of file gameobject.cpp.
QList< Component * > GameObject::findComponentsInChildrenByType | ( | int | type | ) | const |
Definition at line 315 of file gameobject.cpp.
QList< Component * > GameObject::findComponentsInChildrenByType | ( | const QString & | typeName | ) | const |
Definition at line 300 of file gameobject.cpp.
void GameObject::initialize | ( | ) |
Initialize to a functional state
Definition at line 72 of file gameobject.cpp.
void GameObject::invalidateTransform | ( | ) | [slot] |
Definition at line 713 of file gameobject.cpp.
void GameObject::orient | ( | QQuaternion | rotation, | |
GameObject::TransformSpace | ts = TS_LOCAL | |||
) | [slot] |
Definition at line 656 of file gameobject.cpp.
Q_INVOKABLE QQuaternion GluonEngine::GameObject::orientation | ( | ) | const |
GameObject * GameObject::parentGameObject | ( | ) |
Definition at line 493 of file gameobject.cpp.
Q_INVOKABLE QVector3D GluonEngine::GameObject::position | ( | ) | const |
void GameObject::postCloneSanitize | ( | ) | [protected, virtual] |
Sanitize a cloned object. Note: This initializes/starts the object if the game is running.
Reimplemented from GluonCore::GluonObject.
Definition at line 725 of file gameobject.cpp.
bool GameObject::removeChild | ( | GameObject * | removeThis | ) |
Definition at line 451 of file gameobject.cpp.
bool GameObject::removeChild | ( | GluonObject * | child | ) |
Definition at line 457 of file gameobject.cpp.
bool GameObject::removeComponent | ( | Component * | removeThis | ) |
Definition at line 349 of file gameobject.cpp.
void GameObject::removeLater | ( | GluonEngine::GameObject * | remove | ) | [slot] |
Definition at line 181 of file gameobject.cpp.
void GameObject::rotate | ( | float | angle, | |
const QVector3D & | axis, | |||
GameObject::TransformSpace | ts = TS_LOCAL | |||
) | [slot] |
Definition at line 668 of file gameobject.cpp.
void GameObject::runCommand | ( | const QString & | functionName | ) |
Run a command on all the components in this GameObject.
functionName | The name of the function you wish to call |
Definition at line 187 of file gameobject.cpp.
void GameObject::runCommandInChildren | ( | const QString & | functionName | ) |
Run a command on all the components in this GameObject and all the children of the GameObject.
functionName | The name of the function you wish to call |
Definition at line 195 of file gameobject.cpp.
void GameObject::sanitize | ( | ) | [virtual] |
Function used on instantiation to fix the parent/child relationship. Used specifically by GDLHandler in the parseGDL() function. If you do not work on GDLHandler, it is unlikely you will need this function.
Reimplemented from GluonCore::GluonObject.
Definition at line 52 of file gameobject.cpp.
Q_INVOKABLE QVector3D GluonEngine::GameObject::scale | ( | ) | const |
void GameObject::scaleRelative | ( | float | x, | |
float | y, | |||
float | z, | |||
GameObject::TransformSpace | ts = TS_LOCAL | |||
) | [slot] |
Definition at line 630 of file gameobject.cpp.
void GameObject::scaleRelative | ( | QVector3D | scaling, | |
GameObject::TransformSpace | ts = TS_LOCAL | |||
) | [slot] |
Definition at line 618 of file gameobject.cpp.
Scene * GameObject::scene | ( | ) | const |
Get the Scene this GameObject is contained within. This will return null in three possible instances:
Definition at line 365 of file gameobject.cpp.
void GameObject::setDescription | ( | const QString & | newDescription | ) |
Definition at line 502 of file gameobject.cpp.
void GameObject::setEnabled | ( | bool | newEnabled | ) |
Definition at line 520 of file gameobject.cpp.
void GameObject::setOrientation | ( | const QQuaternion & | newOrientation | ) | [slot] |
Set the object's orientation. For many reasons, orientation is handled by Quaternions,
newOrientation | The new orientation of the object |
Definition at line 648 of file gameobject.cpp.
void GameObject::setParentGameObject | ( | GameObject * | newParent | ) | [slot] |
Definition at line 475 of file gameobject.cpp.
void GameObject::setPosition | ( | float | x, | |
float | y | |||
) | [slot] |
Set the position of the object. This will not change the z- position.
x | The X-axis component of the new position of the object
|
Definition at line 553 of file gameobject.cpp.
void GameObject::setPosition | ( | float | x, | |
float | y, | |||
float | z | |||
) | [slot] |
Set the position of the object
x | The X-axis component of the new position of the object
|
Definition at line 548 of file gameobject.cpp.
void GameObject::setPosition | ( | const QVector3D & | newPosition | ) | [slot] |
Set the position of the object Note that this position is relative to the object's parent. E.g.: setPosition(QVector3D(0, 0, 0)) set the object at the parent's pivot.
newPosition | The new position of the object |
Definition at line 540 of file gameobject.cpp.
void GameObject::setScale | ( | float | x, | |
float | y, | |||
float | z | |||
) | [slot] |
Definition at line 613 of file gameobject.cpp.
void GameObject::setScale | ( | const QVector3D & | newScale | ) | [slot] |
Set the object's scale
newScale | The new scale of the object |
Definition at line 605 of file gameobject.cpp.
void GameObject::start | ( | ) |
The game loop or scene is starting. Do anything necessary.
Definition at line 86 of file gameobject.cpp.
void GameObject::stop | ( | ) |
The game loop or scene is stopping. Do anything necessary.
Definition at line 149 of file gameobject.cpp.
QMatrix4x4 GameObject::transform | ( | ) | const |
Definition at line 719 of file gameobject.cpp.
void GameObject::translate | ( | float | x, | |
float | y, | |||
GameObject::TransformSpace | ts = TS_LOCAL | |||
) | [slot] |
Translate the object relative to its current position. This will not change the z-position.
x | The X-axis component of the translation
|
Definition at line 585 of file gameobject.cpp.
void GameObject::translate | ( | float | x, | |
float | y, | |||
float | z, | |||
GameObject::TransformSpace | ts = TS_LOCAL | |||
) | [slot] |
Translate the object relative to its current position.
x | The X-axis component of the translation
|
Definition at line 579 of file gameobject.cpp.
void GameObject::translate | ( | const QVector3D & | translation, | |
GluonEngine::GameObject::TransformSpace | ts = TS_LOCAL | |||
) | [slot] |
Translate the object relative to its current position. This moves the object so that its new position will be equal to position + translation. So translating by QVector3D(1, 0, 0) would move the object one unit to the right.
translation | The amount to translate the object by
|
Definition at line 559 of file gameobject.cpp.
void GameObject::update | ( | int | elapsedMilliseconds | ) |
Update the object and any children. Note that by convention any changes made to GameObjects should be done in this phase, not during draw().
int | elapsedMilliseconds The time elapsed since the last update |
Definition at line 100 of file gameobject.cpp.
void GameObject::updateTransform | ( | ) | [slot] |
Definition at line 674 of file gameobject.cpp.
QQuaternion GameObject::worldOrientation | ( | ) | const |
Definition at line 643 of file gameobject.cpp.
QVector3D GameObject::worldPosition | ( | ) | const |
Definition at line 534 of file gameobject.cpp.
QVector3D GameObject::worldScale | ( | ) | const |
Definition at line 599 of file gameobject.cpp.
QString GameObject::description [read, write] |
A little piece of text explaining what this GameObject is supposed to do. Consider this a place for putting in documentation on what a specific GameObject is used for in the game. Many books have been written about the value of documentation, and so here shall just be said: Use it. Documentation is good for your sanity when you return to your work only a few days after first making it.
Definition at line 71 of file gameobject.h.
bool GameObject::enabled [read, write] |
This decides whether the GameObject and its children are included in the update and draw calls. This allows you to construct objects in a game which do not get updated - you may wish to keep objects around which are temoprarily not used, as destroying and re-creating objects is more expensive than disabling and enabling them.
Definition at line 79 of file gameobject.h.
QQuaternion GameObject::orientation [read, write] |
The orientation of the object in the world (the rotation of the object and the axis around which it is rotated, represented by a Quaternion), relative to its parent. If this is a top level object in the world, it is relative to a rotation of 0 around the Z axis (the axis pointing out of the screen). This is also the default for all object.
Definition at line 98 of file gameobject.h.
QVector3D GameObject::position [read, write] |
The object position relative to its parent. If this is a top level object in a scene, this is relative to the world origin (0, 0, 0)
Definition at line 85 of file gameobject.h.
QVector3D GameObject::scale [read, write] |
The scale of the object, relative to its parent object. If this is a top level object in a scene, this is relative to the scale 1, 1, 1
Definition at line 90 of file gameobject.h.