#include "CArbre.h"
#include "CMountain.h"

CArbre::CArbre(scene::ISceneManager *smg,video::IVideoDriver* dr)
{
    srand(time(0));

    smgr=smg;
    driver=dr;
    //meshArbre = smgr->getMesh("media/firtree4.3ds");
    meshArbre = smgr->getMesh("media/lowpolytree.3ds");
    /*material.setTexture(0,driver->getTexture("media/nadeln4.jpg"));
    material.setTexture(1,driver->getTexture("media/nadeln4a.jpg"));
    material.setTexture(2,driver->getTexture("media/stamm2.jpg"));
    material.setTexture(3,driver->getTexture("media/stamm21.jpg"));
    material.setTexture(4,driver->getTexture("media/stamm22.jpg"));*/
}

void CArbre::SetPosition(core::vector3df p)
{
	position=p;
}

core::stringc CArbre::GetID() {
    return nodeArbre->getName();
}

void CArbre::SetID(core::stringc name) {
    nodeArbre->setName(name);
}

core::vector3df CArbre::GetPosition() {
    return position;
}

void CArbre::DrawArbre() {
    int angle=rand() % 359;

    nodeArbre=smgr->addMeshSceneNode( meshArbre );
    nodeArbre->setScale(core::vector3df(3,3,3));
    //nodeArbre->getMaterial(0) = material;

    nodeArbre->setID(CMountain::ARBRE_NODE_ID);
    nodeArbre->setMaterialFlag(video::EMF_LIGHTING, false);
    position.Y=position.Y+0.6f;
    nodeArbre->setPosition(position);
    nodeArbre->setRotation(core::vector3df(0,angle,0));

    scene::ITriangleSelector* selector = 0;
    selector =smgr->createTriangleSelector(meshArbre,nodeArbre);
    nodeArbre->setTriangleSelector(selector);
    selector->drop(); // We're done with this selector, so drop it now.
}

void CArbre::DropArbre() {
    nodeArbre->remove();
    nodeArbre->drop();
    smgr->getMeshCache()->removeMesh(meshArbre);
}

CArbre::~CArbre()
{

}
