#include "sceneObject.h"



sceneObject::sceneObject()
{
}

sceneObject::~sceneObject()
{

}

//NOTE: Width, Height & Depth are the default dimensions of the mesh/object
void sceneObject::init( float width, float height, float depth, float mass)
{
	//Assign scene node handle
	//this->object = obj;

	//Create a physics object
	pb = PF->CreateBox();


	//Initialise physics object using scene node properties
	float tx,ty,tz,rx,ry,rz,sx,sy,sz;
	bool success = Horde3D::getNodeTransform(object,&tx,&ty,&tz,&rx,&ry,&rz,&sx,&sy,&sz);
	

	if(success)
	{
		//Get the scale of the object
		this->sx = sx; this->sy = sy; this->sz = sz;
		
		//Set position, dimensions and mass
		pb->Init(tx,ty,tz,width*this->sx,height*this->sy,depth*this->sz,mass);

		//Set orientation
		//roll: rotation around z	pitch: rotation around x	yaw: rotation around y
		pb->SetOrientation(rz*DegToRad,rx*DegToRad,ry*DegToRad);
		
	}
	
}

void sceneObject::update()
{
	//Get updated position & orientation from physics engine
	palMatrix4x4 mat = pb->GetLocationMatrix();

	//Extract rotation
	float rotX,rotY,rotZ;
	mat_get_rotation(&mat,&rotX,&rotY,&rotZ);

	//Update scene node
    Horde3D::setNodeTransform( object,  mat._41, mat._42, mat._43,     // Translation
                                        rotX*RadToDeg, rotY*RadToDeg, rotZ*RadToDeg,     // Rotation
                                        this->sx, this->sy,  this->sz);   // Scale
}

