00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GLUON_ENGINE_GAMEOBJECT_H
00022 #define GLUON_ENGINE_GAMEOBJECT_H
00023
00024 #include "gluon_engine_export.h"
00025
00026 #include <core/gluonobject.h>
00027 #include <core/gluonvarianttypes.h>
00028 #include <core/gluonobjectfactory.h>
00029
00030 #include <QtCore/QSharedData>
00031
00032 namespace GluonEngine
00033 {
00034
00035 class Scene;
00036
00037 class GameObjectPrivate;
00038 class Component;
00039
00059 class GLUON_ENGINE_EXPORT GameObject : public GluonCore::GluonObject
00060 {
00061 Q_OBJECT
00062 GLUON_OBJECT( GluonEngine::GameObject );
00071 Q_PROPERTY( QString description READ description WRITE setDescription )
00079 Q_PROPERTY( bool enabled READ enabled WRITE setEnabled )
00080
00085 Q_PROPERTY( QVector3D position READ position WRITE setPosition )
00090 Q_PROPERTY( QVector3D scale READ scale WRITE setScale )
00098 Q_PROPERTY( QQuaternion orientation READ orientation WRITE setOrientation )
00099
00100 public:
00101 enum TransformSpace
00102 {
00103 TS_LOCAL,
00104 TS_WORLD,
00105 };
00106
00107 Q_INVOKABLE GameObject( QObject* parent = 0 );
00108 GameObject( const GameObject& other, QObject* parent = 0 );
00109 ~GameObject();
00110
00117 void sanitize();
00118
00122 Q_INVOKABLE void initialize();
00126 Q_INVOKABLE void start();
00134 Q_INVOKABLE void update( int elapsedMilliseconds );
00142 Q_INVOKABLE void draw( int timeLapse = 0 );
00146 Q_INVOKABLE void stop();
00150 Q_INVOKABLE void cleanup();
00151
00156 Q_INVOKABLE void destroy();
00157
00163 void runCommand( const QString& functionName );
00170 void runCommandInChildren( const QString& functionName );
00171
00172
00173
00174
00175 Q_INVOKABLE Component* findComponent( const QString& name ) const;
00176 Q_INVOKABLE Component* findComponentByType( const QString& typeName ) const;
00177 Q_INVOKABLE Component* findComponentByType( int type ) const;
00178 Q_INVOKABLE QList<Component*> findComponentsByType( const QString& typeName ) const;
00179 Q_INVOKABLE QList<Component*> findComponentsByType( int type ) const;
00180 Q_INVOKABLE Component* findComponentInChildren( const QString& name ) const;
00181 Q_INVOKABLE Component* findComponentInChildrenByType( const QString& typeName ) const;
00182 Q_INVOKABLE QList<Component*> findComponentsInChildren( const QString& name ) const;
00183 Q_INVOKABLE QList<Component*> findComponentsInChildrenByType( const QString& typeName ) const;
00184 Q_INVOKABLE QList<Component*> findComponentsInChildrenByType( int type ) const;
00185 Q_INVOKABLE void addComponent( Component* addThis );
00186 Q_INVOKABLE bool removeComponent( Component* removeThis );
00187 Q_INVOKABLE QList<Component*> components() const;
00188
00189
00190
00191
00202 Scene* scene() const;
00203 GameObject* childGameObject( int index ) const;
00204 GameObject* childGameObject( const QString& name ) const;
00205 void addChild( GluonCore::GluonObject* child );
00206 void addChild( GameObject* addThis );
00207 void addChildAt( GameObject* child, int index );
00208 bool removeChild( GluonObject* child );
00209 bool removeChild( GameObject* removeThis );
00210 int childCount() const;
00211 int childIndex( GameObject* child ) const;
00212
00213 Q_INVOKABLE GameObject* parentGameObject();
00214
00215
00216
00217
00218 void setDescription( const QString& newDescription );
00219 QString description() const;
00220
00221 Q_INVOKABLE bool enabled() const;
00222 Q_INVOKABLE void setEnabled( bool newEnabled );
00223
00224 Q_INVOKABLE QVector3D position() const;
00225 Q_INVOKABLE QVector3D worldPosition() const;
00226
00227
00228 Q_INVOKABLE QVector3D scale() const;
00229 Q_INVOKABLE QVector3D worldScale() const;
00230
00231 Q_INVOKABLE QQuaternion orientation() const;
00232 Q_INVOKABLE QQuaternion worldOrientation() const;
00233
00234 Q_INVOKABLE QMatrix4x4 transform() const;
00235
00236 public slots:
00237 void setParentGameObject( GameObject* newParent );
00238
00239
00248 void setPosition( const QVector3D& newPosition );
00258 void setPosition( float x, float y, float z );
00259
00269 void setPosition( float x, float y );
00270
00282 void translate( const QVector3D& translation, GluonEngine::GameObject::TransformSpace ts = TS_LOCAL );
00293 void translate( float x, float y, float z, TransformSpace ts = TS_LOCAL );
00294
00305 void translate( float x, float y, TransformSpace ts = TS_LOCAL );
00306
00312 void setScale( const QVector3D& newScale );
00313 void setScale( float x, float y, float z );
00314 void scaleRelative( QVector3D scaling, TransformSpace ts = TS_LOCAL );
00315 void scaleRelative( float x, float y, float z, TransformSpace ts = TS_LOCAL );
00316
00323 void setOrientation( const QQuaternion& newOrientation );
00324 void orient( QQuaternion rotation, TransformSpace ts = TS_LOCAL );
00325 void rotate( float angle, const QVector3D& axis, TransformSpace ts = TS_LOCAL );
00326
00327 void updateTransform();
00328 void invalidateTransform();
00329 void removeLater( GluonEngine::GameObject* remove );
00330
00331 protected:
00336 virtual void postCloneSanitize();
00337 private:
00338 GameObjectPrivate* const d;
00339 };
00340 }
00341
00342 Q_DECLARE_METATYPE( GluonEngine::GameObject )
00343 Q_DECLARE_METATYPE( GluonEngine::GameObject* )
00344
00345 #endif // GLUON_ENGINE_GAMEOBJECT_H