#include "AdeptHeaders.hpp"

#include "Site.hpp"
#include "Entity.hpp"

//#############################################################################
//############################     Site   #####################################
//#############################################################################

Site::Site(const LinearMatrix4D& local_to_parent, Entity *parent, const MString& site_name) : 
	Plug(Plug::DefaultData),
	m_localToParent(local_to_parent),
	m_name(site_name)
{
	Check_Pointer(parent);
	
	m_parent = parent;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Site::~Site()
{
	DESTRUCTOR("Site");
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	Site::SaveToStream(MemoryStream *stream)
{
	Check_Object(this);
	Check_Pointer(stream);

	YawPitchRoll rotation;
	Point3D translation;

	rotation = m_localToParent;
	translation = m_localToParent;

	*stream << rotation;
	*stream << translation;
	*stream << m_name;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
LinearMatrix4D
	Site::GetLocalToWorld()
{
	Check_Object(this);
	Check_Object(m_parent);

	LinearMatrix4D local_to_world;
	LinearMatrix4D parent_to_world = m_parent->GetLocalToWorld();

	local_to_world.Multiply(m_localToParent, parent_to_world);

	return local_to_world;
}