#ifndef PW_SCENE_TRANSFORM_HPP
#define PW_SCENE_TRANSFORM_HPP

#include <pw/core/matrix.hpp>
#include <pw/core/quaternion.hpp>
#include <pw/core/vector.hpp>

#include <pw/scene/component.hpp>

namespace pw {

class transform : public component {
public:

	using component::component;

	transform();

	inline const matrix4x4& local() const { return _local; }
	void set_local(const matrix4x4 &local);

	inline const matrix4x4& global() const { return _global; }
	void set_global(const matrix4x4 &global);

	inline void translate(const real_t &x, const real_t &y, const real_t &z) {
        _local(0,3) += x;_local(1,3) += y;_local(2,3) += z;
		update_global_from_local();
	}

	inline void rotate(const quaternion& q) {
        _local = _local * q.to_matrix();
		update_global_from_local();
	}

	inline void scale(const real_t &x, const real_t &y, const real_t &z) {
        _local(0,0) *= x; _local(1,1) *= y; _local(2,2) *= z;
		update_global_from_local();
	}

	inline void scale(const real_t& uniform_scale) {
		scale(uniform_scale,uniform_scale,uniform_scale);
	}

	inline void set_translation(const real_t &x, const real_t &y, const real_t &z) {
        _local(0,3) = x;_local(1,3) = y;_local(2,3) = z;
		update_global_from_local();
	}




	void update(node &node);

protected:

	matrix4x4 _local;
	matrix4x4 _global;

private:

	//! updates the global transform from parent globals and local transform
	void update_global_from_local();

	//! updates the local transform from parent and new global
	void update_local_from_global();
};



}

#endif
