#include "CVehicule.h"

CVehicule::CVehicule(scene::ISceneManager* s,video::IVideoDriver* dr)
{
    smgr=s;
    driver=dr;
    meshAttachePerche =0;
    meshPerche =0;
    pas=0;
}

void CVehicule::SetType(u32 t)
{
	type=t;
}

u32 CVehicule::GetType() {
    return type;
}

void CVehicule::DrawVehicule(core::vector3df position,core::vector3df rotation)
{
    if(type==CVehicule::VEHICULE_TKF) {
        meshAttachePerche = smgr->getMesh("media/pinceTKFixe.obj");
        meshPerche = smgr->getMesh("media/percheTK.obj");

        nodeAttachePerche=smgr->addMeshSceneNode( meshAttachePerche );
        nodeAttachePerche->setScale(core::vector3df(0.8,0.8,0.8));
        nodeAttachePerche->setRotation(rotation);
        //printf("set Perche Abs Pisition = %f ; %f ; %f\n",position.X,position.Y,position.Z);
        nodeAttachePerche->setMaterialFlag(video::EMF_LIGHTING, false);
        nodeAttachePerche->setPosition(position);
        nodeAttachePerche->updateAbsolutePosition();

        nodePerche=smgr->addMeshSceneNode(meshPerche,nodeAttachePerche);
        nodePerche->setScale(core::vector3df(3.6,3.6,3.6));
        nodePerche->setPosition(core::vector3df(0.0f,-2.0f,-0.2f));
        nodePerche->setMaterialFlag(video::EMF_LIGHTING, false);
        nodePerche->updateAbsolutePosition();

	}

	if(type==CVehicule::VEHICULE_TKD) {
        meshAttachePerche = smgr->getMesh("media/pinceTKD.obj");
        meshPerche = smgr->getMesh("media/percheTK.obj");

        nodeAttachePerche=smgr->addMeshSceneNode( meshAttachePerche );
        nodeAttachePerche->setScale(core::vector3df(0.8,0.8,0.8));
        nodeAttachePerche->setRotation(rotation);
        materialAttache.setTexture(0,driver->getTexture("media/texture-pylone.png"));
        nodeAttachePerche->getMaterial(0) = materialAttache;
        nodeAttachePerche->setMaterialFlag(video::EMF_LIGHTING, false);
        nodeAttachePerche->setPosition(position);
        nodeAttachePerche->updateAbsolutePosition();

        nodePerche=smgr->addMeshSceneNode(meshPerche,nodeAttachePerche);
        nodePerche->setScale(core::vector3df(3.6,3.6,3.6));
        nodePerche->setPosition(core::vector3df(-0.7f,-4.4f,0.25f));
        nodePerche->setMaterialFlag(video::EMF_LIGHTING, false);
        nodePerche->updateAbsolutePosition();
	}

	if(type==CVehicule::VEHICULE_TSF) {
        meshAttachePerche = smgr->getMesh("media/siege.obj");
        nodeAttachePerche=smgr->addMeshSceneNode( meshAttachePerche );
        nodeAttachePerche->setScale(core::vector3df(3.3,4.0,3.3));
        nodeAttachePerche->setRotation(rotation);
        nodeAttachePerche->setPosition(position);
        nodeAttachePerche->setMaterialFlag(video::EMF_LIGHTING, false);
        nodeAttachePerche->setPosition(position);

        //materialAttache.setTexture(0,driver->getTexture("media/siege.mtl"));
	}
}

void CVehicule::setPosition(core::vector3df p)
{
	if(nodeAttachePerche)
    {
        nodeAttachePerche->setPosition(p);
        nodeAttachePerche->updateAbsolutePosition();
    }

}

core::vector3df CVehicule::getPosition() {
    return nodeAttachePerche->getAbsolutePosition();
}

void CVehicule::setRotation(core::vector3df r)
{
	if(nodeAttachePerche)
    {
        nodeAttachePerche->setRotation(r);
        nodeAttachePerche->updateAbsolutePosition();
    }

}

core::vector3df CVehicule::getRotation() {
    return nodeAttachePerche->getRotation();
}

CVehicule::~CVehicule()
{

}
