class cogs::Transform — HIRO 0.7.0 documentation

# class cogs::Transform

## Overview

Class used for effective management of transformation matrix by handling translation, rotation and scaling separately. More…

    #include <Transform.h>

    class Transform {
    public:
        // construction

        Transform();
        Transform(const glm::mat4& matrix);
        Transform(const std::function<void(void)>& notifier_func);
        Transform(const Transform&);
        Transform(Transform&&);
        virtual ~Transform();

        // methods

        Transform& operator=(const Transform&);
        Transform& operator=(Transform&&);
        void Translate(const glm::vec3& move_vector);
        void SetPosition(const glm::vec3& position);
        const glm::vec3 GetPosition() const;
        void Rotate(const glm::quat& rotation);
        void SetRotation(const glm::quat& rotation);
        const glm::quat GetRotation() const;
        void Scale(const glm::vec3& scale);
        void SetScaling(const glm::vec3& scale);
        const glm::vec3 GetScaling() const;
        void Set(const glm::mat4& trans_mat);
        virtual const glm::mat4& GetMat4() const;
        void AddTransform(const Transform& transform);
        void InterpolateWith(const Transform& target, const float target_weight, Transform* out_transform) const;
        virtual void SaveToStream(std::ostream& ostr) const;
        virtual void LoadFromStream(std::istream& istr);
        Transform operator*(const Transform& t) const;
        operator glm::mat4() const;

    protected:
        // methods

        virtual void OnInvariantChange();
    };

## Detailed Documentation

Class used for effective management of transformation matrix by handling translation, rotation and scaling separately.

Final transformation is computed in order: scaling > rotation > translation.

### Construction

    Transform()

Creates an identity instance.

    Transform(const glm::mat4& matrix)

Creates an instance from a given matrix.

    Transform(const std::function<void(void)>& notifier_func)

Creates an identity instance which notifies whenever its state changes.

### Methods

    void Translate(const glm::vec3& move_vector)

Changes position by a given vector.

    void SetPosition(const glm::vec3& position)

Removes current position and replaces with specified position.

    const glm::vec3 GetPosition() const

Returns position defined by transformation.

    void Rotate(const glm::quat& rotation)

Applies additional rotation to transform, relative to current rotation.

    void SetRotation(const glm::quat& rotation)

Removes current rotation and replaces with specified quaternion.

    const glm::quat GetRotation() const

Returns rotation defined by transformation.

    void Scale(const glm::vec3& scale)

Applies scale to transform, accumulated with previous scaling.

    void SetScaling(const glm::vec3& scale)

Resets scaling of transform.

    const glm::vec3 GetScaling() const

Returns scaling defined by transformation.

    void Set(const glm::mat4& trans_mat)

Resets current transform so that it represents specified matrix.

    virtual const glm::mat4& GetMat4() const

Returns composed matrix of final transformation: scaling > rotation > translation.

    void AddTransform(const Transform& transform)

Multiply this transform by a given one.

    void InterpolateWith(const Transform& target, const float target_weight, Transform* out_transform) const

Interpolates current transform with another, in a specific mix ratio.

Transformations are disassembled into translation, scale and rotation components. Translation and scale components are then interpolated linearly, rotation with SLERP function.

Parameters:

target | The Transform which to interpolate to.
target_weight | Defines how much of target should be taken. Value 0 results in 100% of this transform, value 1 results in 100% of target.
out_transform | A pointer to an object where the computed transformation will be stored.

    virtual void SaveToStream(std::ostream& ostr) const

Writes relevant information to stream.

    virtual void LoadFromStream(std::istream& istr)

Reads relevant information from stream.

    Transform operator*(const Transform& t) const

Multiply two transforms equivalently to matrix multiplication.

    virtual void OnInvariantChange()

Function called each time a change on position, rotation or scaling is performed.