00001 #ifndef TRANSFORM_H_INCLUDED
00002 #define TRANSFORM_H_INCLUDED
00003
00004 #include "CGLA/Vec3f.h"
00005 #include "CGLA/Vec4f.h"
00006 #include "CGLA/Mat3x3f.h"
00007 #include "CGLA/Mat4x4f.h"
00008 #include "Object.h"
00009
00010 #include <vector>
00011
00012 class GameObject;
00013
00014 using namespace CGLA;
00015
00016 enum SpaceOfReferenceEnum{
00017 LOCAL,
00018 PARENT,
00019 WORLD
00020 };
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 class Transform :public Object{
00031 public :
00032 static const RTTI TYPE;
00033 virtual const RTTI& getType() const{ return TYPE; }
00034
00035 public:
00036 typedef std::vector<Transform*>::const_iterator ChildrenIterator;
00037
00038 protected:
00039 GameObject* gameObject;
00040
00041 Transform * parent;
00042 std::vector<Transform*> children;
00043
00044 Vec3f position;
00045 Vec3f worldPosition;
00046 Vec3f scaling;
00047 Vec3f worldScaling;
00048 Vec3f eulerAngles;
00049 Vec3f worldEulerAngles;
00050
00051 Mat3x3f rotationMatrix;
00052 Mat3x3f worldRotationMatrix;
00053 Mat4x4f transformMatrix;
00054 Mat4x4f worldTransformMatrix;
00055
00056 bool _hasMoved;
00057
00058 public:
00059 Transform();
00060 ~Transform();
00061 Transform(Vec3f const& pos);
00062 Transform(const Transform& transform);
00063 void setGameObject(GameObject* object);
00064 GameObject* getGameObject()const;
00065
00066
00067 void addChild(Transform* child);
00068 void attachChild(Transform* child);
00069 void removeChild(Transform* child);
00070 void removeChild(int index);
00071 ChildrenIterator getChildrenIteratorBegin()const;
00072 ChildrenIterator getChildrenIteratorEnd()const;
00073 int getChildCount()const;
00074 Transform* getChild(int index);
00075 int getChildIndex(Transform * child)const;
00076 Transform* getParent();
00077
00078 void setParent(Transform* par);
00079
00080
00084 void setPosition(const Vec3f& pos);
00088 void setWorldPosition(const Vec3f& pos);
00092 void setScale(const Vec3f& scal);
00096 void setWorldScale(const Vec3f& scal);
00100 void setRotation(const Vec3f& rot);
00101
00102 void translate(float x, float y, float z);
00103 void translate(const Vec3f& translation);
00104
00105 void scale(float x, float y, float z);
00106 void scale(const Vec3f& scaling);
00110 void rotate(float rx, float ry, float rz, SpaceOfReferenceEnum reference = PARENT);
00114 void rotate(const Vec3f& euler_angles, SpaceOfReferenceEnum reference = PARENT);
00118 void rotate(const Vec3f& axis, float angle);
00119
00123 void lookAt(const Vec3f& targetPoint);
00124
00125
00126
00127 Vec3f getPosition()const;
00128 Vec3f getWorldPosition()const;
00129 Vec3f getScale()const;
00130 Vec3f getWorldScale()const;
00131 Vec3f getRotation()const;
00132
00136 Vec3f getForward()const;
00140 Vec3f getUp()const;
00144 Vec3f getRight()const;
00145
00146 Mat3x3f getRotationMatrix()const;
00147 Mat3x3f getWorldRotationMatrix()const;
00148 Mat4x4f getTransformMatrix()const;
00152 Mat4x4f getInverseTransformMatrix()const;
00153
00154 Mat4x4f getWorldTransformMatrix()const;
00155 Mat4x4f getWorldInverseTransformMatrix()const;
00156
00157 Mat4x4f getWorldViewMatrix() const;
00158 Mat4x4f getWorldInverseViewMatrix() const;
00159
00160
00161 void applyTransform()const;
00162 void applyWorldTransform()const;
00163 void applyViewTransform()const;
00164 void applyWorldViewTransform()const;
00165
00169 void _updateWorldPosition();
00173 void _updateTransformMatrix();
00177 void _updateWorldTransformMatrix();
00181 void _updateWorldRotationMatrix();
00182
00183 protected:
00184
00185
00186 private:
00187
00188 friend class boost::serialization::access;
00189 template<class Archive>
00190 void serialize(Archive& ar, const unsigned int version){
00191
00192 ar & boost::serialization::base_object<Object>(*this);
00193 ar & position;
00194 ar & scaling;
00195 ar & eulerAngles;
00196 }
00197
00198 };
00199
00200
00201 #endif // TRANSFORM_H_INCLUDED