www.pudn.com > Gimcrack-v0.0051-Source.zip > trsnode.h
///////////////////////////////////////////////////////////////// // TRSNode class // Handles SRT and node stuff // TRS = Translation Rotation Scaling ///////////////////////////////////////////////////////////////// #ifndef _TRSNODE_H_ #define _TRSNODE_H_ #include#include #include "entity.h" #include "../math/vector.h" #include "../math/matrix.h" class GcTRSNode : public GcUpdateEntity, public GcRenderEntity { public: GcTRSNode( const std::string & NodeName = "", GcTRSNode * parent = 0 ); virtual ~GcTRSNode(); /* Node specific methods */ bool AttachNode( GcTRSNode * node ); bool DetachNode( GcTRSNode * node ); void DetachFromParent(); virtual void Update( float deltaTime ); virtual void Render() {} virtual inline void NotifyUpdate( bool bRecurse = true ); bool UpdateWorld(); void SetName( const std::string & name ) { m_name = name; } const std::string & GetName() const { return m_name; } GcTRSNode * GetParent() { return m_parent; } /*************************************************************/ /* 3D representional methods */ /* Resets the translations, rotations and scalings */ void TRSReset(); /* Local transitions, rotation and scaling */ //void Translate( const GcVector4 & v ) { m_translation += v; } //void Translate( float x, float y, float z ) { m_translation.x += x; m_translation.y += y; m_translation.z += z; } //id Rotate( const GcVector4 & angles ) { m_rotation += angles; } //void Rotate( float x, float y, float z ); //void Scale( const GcVector4 & v ) { m_scaling += v; } //id Scale( float x, float y, float z ) { m_scaling.x += x; m_scaling.y += y; m_scaling.z += z; } void Translate( const GcVector3 & pos, bool notifyUpdate = true ) { m_matrix.Translate(pos); if( notifyUpdate ) NotifyUpdate( notifyUpdate ); } void Rotate( float x, float y, float z, bool notifyUpdate = true ); void Rotate( const GcVector3 & angles, bool notifyUpdate = true ); void Scale( const GcVector3 & scale, bool notifyUpdate = true ) { m_scaling += scale; if( notifyUpdate ) NotifyUpdate( notifyUpdate ); } void SetTranslation( const GcVector3 & pos, bool notifyUpdate = true ) { m_matrix.SetTranslation(pos); if( notifyUpdate ) NotifyUpdate( notifyUpdate ); } //void SetRotation( const GcMatrix4 & rotation, bool notifyUpdate = true ); void SetRotation( const GcVector3 & angles, bool notifyUpdate = true ); void SetScaling( const GcVector3 & scale, bool notifyUpdate = true ) { m_scaling = scale; if( notifyUpdate ) NotifyUpdate( notifyUpdate ); } GcVector3 GetTranslation() { return m_matrix.GetTranslation(); } GcMatrix4 & GetMatrix() { return m_matrix; } GcVector3 & GetScaling() { return m_scaling; } void SetMatrix( GcMatrix4 & matrix ) { m_matrix = matrix; } void SetWorldMatrix( GcMatrix4 & matrix ) { m_worldMatrix = matrix; } GcVector3 Axis( int i ) const { return m_worldMatrix.Axis(i); } /* World transitions, rotation and scaling */ /*void WorldTranslate( const GcVector3 & v ) { m_worldTranslation += v; } void WorldTranslate( float x, float y, float z ) { m_worldTranslation.x += x; m_worldTranslation.y += y; m_worldTranslation.z += z; } void WorldRotate( const GcVector3 & angles ); void WorldRotate( float x, float y, float z ); void WorldScale( const GcVector3 & v ) { m_worldScaling += v; } void WorldScale( float x, float y, float z ) { m_worldScaling.x += x; m_worldScaling.y += y; m_worldScaling.z += z; } /*void SetWorldTranslation( const GcVector3 & pos ) { m_worldTranslation = pos; } void SetWorldRotation( const GcVector3 & angles ); void SetWorldScaling( const GcVector3 & scale ) { m_worldScaling = scale; }*/ /* Our world coordinates depends on our relative position therefore we must check if they have changed */ GcVector3 GetWorldTranslation() { if( m_worldUpdate ) UpdateWorld(); return m_worldMatrix.GetTranslation(); } GcMatrix4 & GetWorldMatrix() { if( m_worldUpdate ) UpdateWorld(); return m_worldMatrix; } GcVector3 & GetWorldScaling() { if( m_worldUpdate ) UpdateWorld(); return m_worldScaling; } protected: std::vector m_children; GcTRSNode * m_parent; std::string m_name; bool m_worldUpdate; //GcVector3 m_translation; // The relative translation to the parent GcMatrix4 m_matrix; // The rotation relative to the parent GcVector3 m_scaling; // The scaling relative to the parent //GcVector3 m_worldTranslation; // The absolute translation of the object GcMatrix4 m_worldMatrix; // The absolute rotation of the object GcVector3 m_worldScaling; // The absolute scaling of the object // Did a gimbal lock occur last frame? bool m_gimbalLock; // Dummy - not used //GcMatrix4 m_rotation; }; #endif /* _TRSNODE_H_ */