#include "CTSFixe.h"
#include "CMountain.h"

CTSFixe::CTSFixe(scene::ISceneManager *smg,video::IVideoDriver* dr)
{

    smgr=smg;
    driver=dr;
    meshDepart = smgr->getMesh("media/gareTSfixe2.obj");
    //materialDepart.setTexture(0,driver->getTexture("media/gareTSfixe.mtl"));

    meshPoulieDepart = smgr->getMesh("media/PoulieTS.obj");
    //materialPoulieDepart.setTexture(0,driver->getTexture("media/PoulieTS.mtl"));

    meshPoulieArrivee = smgr->getMesh("media/PoulieTS.obj");
    //materialPoulieArrivee.setTexture(0,driver->getTexture("media/PoulieTS.mtl"));
    posMonteePoulieDepart=0;
    posDescentePoulieDepart=0;

    meshArrivee= smgr->getMesh("media/retourTsFixe.obj");
    //materialArrivee.setTexture(0,driver->getTexture("media/retourTsFixe.mtl"));

    nodePoulieDepart=0;
    nodePoulieArrivee=0;

    posMonteePoulieArrivee=0;
    posDescentePoulieArrivee=0;

    typeRM=RM_TSF2;
    constructionFinie=false;
    proprietesOuvert=false;
    vitesse=2.5f;
    vitesseMax=2.5f;
    espacementVehicules=30.0f;
}

void CTSFixe::SetPositionDepart(core::vector3df p)
{
	positionDepart=p;
}


void CTSFixe::SetPositionArrivee(core::vector3df p)
{
	positionArrivee=p;
}

core::vector3df CTSFixe::GetPositionDepart() {
    return positionDepart;
}

core::vector3df CTSFixe::GetPositionArrivee() {
    return positionArrivee;
}

//Methode a surcharger pour chaque RM
core::stringc CTSFixe::GetID() {
    return nodeDepart->getName();
}

//Methode a surcharger pour chaque RM
void CTSFixe::SetID(core::stringc name) {
    nodeDepart->setName(name);
}

void CTSFixe::DrawRemonteeDepart() {

    nodeDepart=smgr->addMeshSceneNode( meshDepart );
    nodeDepart->setID(CMountain::TSF2_NODE_ID);
    nodeDepart->setScale(core::vector3df(4,4,4));
    nodeDepart->getMaterial(0) = materialDepart;
    nodeDepart->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeDepart->setPosition(positionDepart);
    nodeDepart->updateAbsolutePosition();
    //nodeArbre->setRotation(core::vector3df(0,angle,0));

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

    nodePoulieDepart=smgr->addMeshSceneNode( meshPoulieDepart,nodeDepart );
    nodePoulieDepart->getMaterial(0) = materialPoulieDepart;
    nodePoulieDepart->setMaterialFlag(video::EMF_LIGHTING, false);
    nodePoulieDepart->setScale(core::vector3df(0.15,0.15,0.15));
    nodePoulieDepart->setPosition(core::vector3df(2,2.9,0.14));
    nodePoulieDepart->setRotation(core::vector3df(180,0,0));
    nodePoulieDepart->updateAbsolutePosition();

    posMonteePoulieDepart=smgr->addEmptySceneNode(nodeDepart);
    //posMonteePoulieDepart->setPosition(core::vector3df(2,2.8,0.85));
    posMonteePoulieDepart->setPosition(core::vector3df(2,2.8,1.01));
    posMonteePoulieDepart->updateAbsolutePosition();

    posDescentePoulieDepart=smgr->addEmptySceneNode(nodeDepart);
    posDescentePoulieDepart->setPosition(core::vector3df(2,2.8,-0.69));
    //posDescentePoulieDepart->setPosition(core::vector3df(2,2.8,-0.85));
    posDescentePoulieDepart->updateAbsolutePosition();

    meshGaletDepartD = smgr->getMesh("media/galet.obj");
    nodeGaletDepartD=smgr->addMeshSceneNode( meshGaletDepartD,nodeDepart );
    //nodeGaletArriveeM->getMaterial(0) = materialPoulie1M;
    nodeGaletDepartD->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartD->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartD->setRotation(core::vector3df(90,0,0));
    //nodeGaletDepartD->setPosition(core::vector3df(-4.7,2.76,-3.61));
    nodeGaletDepartD->setPosition(core::vector3df(-4.7,2.76,-0.62));
    nodeGaletDepartD->updateAbsolutePosition();

    meshGaletDepartM = smgr->getMesh("media/galet.obj");
    //materialPoulie1D.setTexture(0,driver->getTexture("media/texture-pylone.png"));
    nodeGaletDepartM=smgr->addMeshSceneNode( meshGaletDepartM,nodeDepart );
    //nodeGaletArriveeD->getMaterial(0) = materialPoulie1D;
    nodeGaletDepartM->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartM->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartM->setRotation(core::vector3df(-90,0,0));
    //nodeGaletDepartM->setPosition(core::vector3df(-4.6,2.74,-2.16));
    nodeGaletDepartM->setPosition(core::vector3df(-4.6,2.74,0.83));
    nodeGaletDepartM->updateAbsolutePosition();

    meshGaletDepartD2 = smgr->getMesh("media/galet.obj");
    nodeGaletDepartD2=smgr->addMeshSceneNode( meshGaletDepartD2,nodeDepart );
    //nodeGaletArriveeM->getMaterial(0) = materialPoulie1M;
    nodeGaletDepartD2->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartD2->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartD2->setRotation(core::vector3df(90,0,0));
    //nodeGaletDepartD2->setPosition(core::vector3df(-6.1,3.04,-3.62));
    nodeGaletDepartD2->setPosition(core::vector3df(-6.1,3.04,-0.63));
    nodeGaletDepartD2->updateAbsolutePosition();

    meshGaletDepartM2 = smgr->getMesh("media/galet.obj");
    //materialPoulie1D.setTexture(0,driver->getTexture("media/texture-pylone.png"));
    nodeGaletDepartM2=smgr->addMeshSceneNode( meshGaletDepartM2,nodeDepart );
    //nodeGaletArriveeD->getMaterial(0) = materialPoulie1D;
    nodeGaletDepartM2->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartM2->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartM2->setRotation(core::vector3df(-90,0,0));
    //nodeGaletDepartM2->setPosition(core::vector3df(-6.1,3.04,-2.16));
    nodeGaletDepartM2->setPosition(core::vector3df(-6.1,3.04,0.83));
    nodeGaletDepartM2->updateAbsolutePosition();

    meshGaletDepartD3 = smgr->getMesh("media/galet.obj");
    nodeGaletDepartD3=smgr->addMeshSceneNode( meshGaletDepartD3,nodeDepart );
    //nodeGaletArriveeM->getMaterial(0) = materialPoulie1M;
    nodeGaletDepartD3->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartD3->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartD3->setRotation(core::vector3df(90,0,0));
    //nodeGaletDepartD3->setPosition(core::vector3df(-6.5,3.12,-3.62));
    nodeGaletDepartD3->setPosition(core::vector3df(-6.5,3.12,-0.63));
    nodeGaletDepartD3->updateAbsolutePosition();

     meshGaletDepartM3 = smgr->getMesh("media/galet.obj");
    //materialPoulie1D.setTexture(0,driver->getTexture("media/texture-pylone.png"));
    nodeGaletDepartM3=smgr->addMeshSceneNode( meshGaletDepartM3,nodeDepart );
    //nodeGaletArriveeD->getMaterial(0) = materialPoulie1D;
    nodeGaletDepartM3->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartM3->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartM3->setRotation(core::vector3df(-90,0,0));
    //nodeGaletDepartM3->setPosition(core::vector3df(-6.5,3.12,-2.19));
    nodeGaletDepartM3->setPosition(core::vector3df(-6.5,3.12,0.80));
    nodeGaletDepartM3->updateAbsolutePosition();

    meshGaletDepartD4 = smgr->getMesh("media/galet.obj");
    nodeGaletDepartD4=smgr->addMeshSceneNode( meshGaletDepartD4,nodeDepart );
    //nodeGaletArriveeM->getMaterial(0) = materialPoulie1M;
    nodeGaletDepartD4->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartD4->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartD4->setRotation(core::vector3df(90,0,0));
    //nodeGaletDepartD4->setPosition(core::vector3df(-6.8,3.2,-3.63));
    nodeGaletDepartD4->setPosition(core::vector3df(-6.8,3.2,-0.64));
    nodeGaletDepartD4->updateAbsolutePosition();

    meshGaletDepartM4 = smgr->getMesh("media/galet.obj");
    //materialPoulie1D.setTexture(0,driver->getTexture("media/texture-pylone.png"));
    nodeGaletDepartM4=smgr->addMeshSceneNode( meshGaletDepartM4,nodeDepart );
    //nodeGaletArriveeD->getMaterial(0) = materialPoulie1D;
    nodeGaletDepartM4->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartM4->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartM4->setRotation(core::vector3df(-90,0,0));
    //nodeGaletDepartM4->setPosition(core::vector3df(-6.8,3.2,-2.18));  //+2.99
    nodeGaletDepartM4->setPosition(core::vector3df(-6.8,3.2,0.81));
    nodeGaletDepartM4->updateAbsolutePosition();

    meshGaletDepartM5 = smgr->getMesh("media/galet.obj");
    //materialPoulie1D.setTexture(0,driver->getTexture("media/texture-pylone.png"));
    nodeGaletDepartM5=smgr->addMeshSceneNode( meshGaletDepartM5,nodeDepart );
    //nodeGaletArriveeD->getMaterial(0) = materialPoulie1D;
    nodeGaletDepartM5->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartM5->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartM5->setRotation(core::vector3df(-90,0,0));
    //nodeGaletDepartM->setPosition(core::vector3df(-5.8,2.98,-2.13));
    nodeGaletDepartM5->setPosition(core::vector3df(-5.8,2.98,0.86));
    nodeGaletDepartM5->updateAbsolutePosition();

    meshGaletDepartM6 = smgr->getMesh("media/galet.obj");
    //materialPoulie1D.setTexture(0,driver->getTexture("media/texture-pylone.png"));
    nodeGaletDepartM6=smgr->addMeshSceneNode( meshGaletDepartM6,nodeDepart );
    //nodeGaletArriveeD->getMaterial(0) = materialPoulie1D;
    nodeGaletDepartM6->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartM6->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartM6->setRotation(core::vector3df(-90,0,0));
    //nodeGaletDepartM->setPosition(core::vector3df(-5.5,2.93,-2.14));
    nodeGaletDepartM6->setPosition(core::vector3df(-5.5,2.93,0.87));
    nodeGaletDepartM6->updateAbsolutePosition();

    meshGaletDepartM7 = smgr->getMesh("media/galet.obj");
    //materialPoulie1D.setTexture(0,driver->getTexture("media/texture-pylone.png"));
    nodeGaletDepartM7=smgr->addMeshSceneNode( meshGaletDepartM7,nodeDepart );
    //nodeGaletArriveeD->getMaterial(0) = materialPoulie1D;
    nodeGaletDepartM7->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartM7->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartM7->setRotation(core::vector3df(-90,0,0));
    //nodeGaletDepartM->setPosition(core::vector3df-5.2,2.87,-2.15));
    nodeGaletDepartM7->setPosition(core::vector3df(-5.2,2.87,0.88));
    nodeGaletDepartM7->updateAbsolutePosition();

    meshGaletDepartM8 = smgr->getMesh("media/galet.obj");
    //materialPoulie1D.setTexture(0,driver->getTexture("media/texture-pylone.png"));
    nodeGaletDepartM8=smgr->addMeshSceneNode( meshGaletDepartM8,nodeDepart );
    //nodeGaletArriveeD->getMaterial(0) = materialPoulie1D;
    nodeGaletDepartM8->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartM8->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartM8->setRotation(core::vector3df(-90,0,0));
    //nodeGaletDepartM->setPosition(core::vector3df(-4.9,2.81,-2.16));
    nodeGaletDepartM8->setPosition(core::vector3df(-4.9,2.81,0.89));
    nodeGaletDepartM8->updateAbsolutePosition();

    meshGaletDepartD5 = smgr->getMesh("media/galet.obj");
    nodeGaletDepartD5=smgr->addMeshSceneNode( meshGaletDepartD5,nodeDepart );
    //nodeGaletArriveeM->getMaterial(0) = materialPoulie1M;
    nodeGaletDepartD5->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartD5->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartD5->setRotation(core::vector3df(90,0,0));
    //nodeGaletDepartD->setPosition(core::vector3df(-5.8,2.98,-3.62));
    nodeGaletDepartD5->setPosition(core::vector3df(-5.8,2.98,-0.63));
    nodeGaletDepartD5->updateAbsolutePosition();

    meshGaletDepartD6 = smgr->getMesh("media/galet.obj");
    nodeGaletDepartD6=smgr->addMeshSceneNode( meshGaletDepartD6,nodeDepart );
    //nodeGaletArriveeM->getMaterial(0) = materialPoulie1M;
    nodeGaletDepartD6->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartD6->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartD6->setRotation(core::vector3df(90,0,0));
    //nodeGaletDepartD->setPosition(core::vector3df(-5.5,2.93,-3.62));
    nodeGaletDepartD6->setPosition(core::vector3df(-5.5,2.93,-0.63));
    nodeGaletDepartD6->updateAbsolutePosition();

    meshGaletDepartD7 = smgr->getMesh("media/galet.obj");
    nodeGaletDepartD7=smgr->addMeshSceneNode( meshGaletDepartD7,nodeDepart );
    //nodeGaletArriveeM->getMaterial(0) = materialPoulie1M;
    nodeGaletDepartD7->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartD7->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartD7->setRotation(core::vector3df(90,0,0));
    //nodeGaletDepartD->setPosition(core::vector3df(-5.2,2.87,-3.62));
    nodeGaletDepartD7->setPosition(core::vector3df(-5.2,2.87,-0.63));
    nodeGaletDepartD7->updateAbsolutePosition();

    meshGaletDepartD8 = smgr->getMesh("media/galet.obj");
    nodeGaletDepartD8=smgr->addMeshSceneNode( meshGaletDepartD8,nodeDepart );
    //nodeGaletArriveeM->getMaterial(0) = materialPoulie1M;
    nodeGaletDepartD8->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletDepartD8->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletDepartD8->setRotation(core::vector3df(90,0,0));
    //nodeGaletDepartD->setPosition(core::vector3df(-4.9,2.81,-3.63));
    nodeGaletDepartD8->setPosition(core::vector3df(-4.9,2.81,-0.64));
    nodeGaletDepartD8->updateAbsolutePosition();

    posGaletDepartDescente4=smgr->addEmptySceneNode(nodeDepart);
    //posGaletDepartDescente4->setPosition(core::vector3df(-6.8,3.1,-3.6));
    posGaletDepartDescente4->setPosition(core::vector3df(-6.8,3.1,-0.61));
    posGaletDepartDescente4->updateAbsolutePosition();

    posGaletDepartMontee4=smgr->addEmptySceneNode(nodeDepart);
    //posGaletDepartMontee4->setPosition(core::vector3df(-6.8,3.1,-2.15));
    posGaletDepartMontee4->setPosition(core::vector3df(-6.8,3.1,0.84));
    posGaletDepartMontee4->updateAbsolutePosition();

    posGaletDepartDescente=smgr->addEmptySceneNode(nodeDepart);
    //posGaletDepartDescente->setPosition(core::vector3df(-4.7,2.67,-3.61));
    posGaletDepartDescente->setPosition(core::vector3df(-4.7,2.67,-0.62));
    posGaletDepartDescente->updateAbsolutePosition();

    posGaletDepartMontee=smgr->addEmptySceneNode(nodeDepart);
    //posGaletDepartMontee->setPosition(core::vector3df(-4.6,2.64,-2.16));
    posGaletDepartMontee->setPosition(core::vector3df(-4.6,2.64,0.85));
    posGaletDepartMontee->updateAbsolutePosition();

}

void CTSFixe::DrawRemonteeArrivee()
{
    nodeArrivee=smgr->addMeshSceneNode( meshArrivee,0 );
    nodeArrivee->setScale(core::vector3df(4,4,4));
    nodeArrivee->getMaterial(0) = materialArrivee;
    nodeArrivee->setMaterialFlag(video::EMF_LIGHTING, false);
    positionArrivee.Y=positionArrivee.Y-0.5f;
    nodeArrivee->setPosition(positionArrivee);
    nodeArrivee->updateAbsolutePosition();

    nodePoulieArrivee=smgr->addMeshSceneNode( meshPoulieArrivee,nodeArrivee );
    nodePoulieArrivee->setParent(nodeArrivee);
    nodePoulieArrivee->getMaterial(0) = materialPoulieArrivee;
    nodePoulieArrivee->setMaterialFlag(video::EMF_LIGHTING, false);
    nodePoulieArrivee->setScale(core::vector3df(0.15,0.15,0.15));
    nodePoulieArrivee->setRotation(core::vector3df(180,0,0));
    nodePoulieArrivee->setPosition(core::vector3df(1.2,3,0));
    nodePoulieArrivee->updateAbsolutePosition();

    posMonteePoulieArrivee=smgr->addEmptySceneNode(nodeArrivee);
    posMonteePoulieArrivee->setPosition(core::vector3df(1.2,2.9,-0.9));
    posMonteePoulieArrivee->updateAbsolutePosition();

    posDescentePoulieArrivee=smgr->addEmptySceneNode(nodeArrivee);
    posDescentePoulieArrivee->setPosition(core::vector3df(1.2,2.9,0.9));
    posDescentePoulieArrivee->updateAbsolutePosition();

    meshGaletArriveeD = smgr->getMesh("media/galet.obj");
    nodeGaletArriveeD=smgr->addMeshSceneNode( meshGaletArriveeD,nodeArrivee );
    //nodeGaletArriveeM->getMaterial(0) = materialPoulie1M;
    nodeGaletArriveeD->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletArriveeD->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletArriveeD->setRotation(core::vector3df(90,0,0));
    nodeGaletArriveeD->setPosition(core::vector3df(-1.33,2.8,0.84));
    nodeGaletArriveeD->updateAbsolutePosition();

    meshGaletArriveeM = smgr->getMesh("media/galet.obj");
    //materialPoulie1D.setTexture(0,driver->getTexture("media/texture-pylone.png"));
    nodeGaletArriveeM=smgr->addMeshSceneNode( meshGaletArriveeM,nodeArrivee );
    //nodeGaletArriveeD->getMaterial(0) = materialPoulie1D;
    nodeGaletArriveeM->setMaterialFlag(video::EMF_LIGHTING, false);
    nodeGaletArriveeM->setScale(core::vector3df(0.05,0.05,0.05));
    nodeGaletArriveeM->setRotation(core::vector3df(-90,0,0));
    nodeGaletArriveeM->setPosition(core::vector3df(-1.33,2.8,-0.835));
    nodeGaletArriveeM->updateAbsolutePosition();

    posGaletArriveeDescente=smgr->addEmptySceneNode(nodeArrivee);
    posGaletArriveeDescente->setPosition(core::vector3df(-1.33,2.9,0.84));
    posGaletArriveeDescente->updateAbsolutePosition();

    posGaletArriveeMontee=smgr->addEmptySceneNode(nodeArrivee);
    posGaletArriveeMontee->setPosition(core::vector3df(-1.33,2.9,-0.835));
    posGaletArriveeMontee->updateAbsolutePosition();

    //Oriente la rotation du départ et arrivée
    core::vector3df result=positionArrivee-positionDepart;
    result=result.getHorizontalAngle();
    nodeDepart->setRotation(core::vector3df(0,result.Y+90,0));
    nodeArrivee->setRotation(core::vector3df(0,result.Y-90,0));
    //Dessine le cable initial
    //RedrawCable();
}

void CTSFixe::RedrawCable()
{
    core::vector3df deltaPoulieM;
    core::vector3df deltaPoulieD;
    core::vector3df deltaPoulieM2;
    core::vector3df deltaPoulieD2;

    if(nodePoulieDepart && nodePoulieArrivee) {
        driver->setTransform(video::ETS_WORLD,core::IdentityMatrix);
        //driver->draw3DLine(nodePoulieDepart->getAbsolutePosition() , nodePoulieArrivee->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));

        if(arrPylones.size()==0)
        {
            //posGaletDepartMontee4
            //posGaletDepartDescente4

            driver->draw3DLine(posMonteePoulieDepart->getAbsolutePosition() , posGaletDepartMontee->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));
            driver->draw3DLine(posDescentePoulieDepart->getAbsolutePosition() , posGaletDepartDescente->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));

            driver->draw3DLine(posGaletDepartMontee->getAbsolutePosition() , posGaletDepartMontee4->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));
            driver->draw3DLine(posGaletDepartDescente->getAbsolutePosition() , posGaletDepartDescente4->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));

            driver->draw3DLine(posGaletDepartMontee4->getAbsolutePosition()  , posGaletArriveeMontee->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));
            driver->draw3DLine(posGaletDepartDescente4->getAbsolutePosition() , posGaletArriveeDescente->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));

            driver->draw3DLine(posGaletArriveeMontee->getAbsolutePosition() , posMonteePoulieArrivee->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));
            driver->draw3DLine(posGaletArriveeDescente->getAbsolutePosition() , posDescentePoulieArrivee->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));
        } else {

            driver->draw3DLine(posMonteePoulieDepart->getAbsolutePosition() , posGaletDepartMontee->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));
            driver->draw3DLine(posDescentePoulieDepart->getAbsolutePosition() , posGaletDepartDescente->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));

            driver->draw3DLine(posGaletDepartMontee->getAbsolutePosition() , posGaletDepartMontee4->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));
            driver->draw3DLine(posGaletDepartDescente->getAbsolutePosition() , posGaletDepartDescente4->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));

            //Pour la montée
            for(unsigned int i=0;i<arrPylones.size();i++)
            {
                if(i==0)
                {
                    if(arrPylones[i]->monteeSupportCompression==1)
                    {
                        deltaPoulieM=core::vector3df(0.0f,0.2f,0.0f);
                    } else {
                        deltaPoulieM=core::vector3df(0.0f,-0.2f,0.0f);
                    }
                    driver->draw3DLine(posGaletDepartMontee4->getAbsolutePosition() , arrPylones[i]->posMonteePylone->getAbsolutePosition()+deltaPoulieM,  video::SColor(255, 0, 0, 0));
                } else {
                    if(arrPylones[i]->monteeSupportCompression==1)
                    {
                        deltaPoulieM=core::vector3df(0.0f,0.2f,0.0f);
                    } else {
                        deltaPoulieM=core::vector3df(0.0f,-0.2f,0.0f);
                    }

                    if(arrPylones[i-1]->monteeSupportCompression==1)
                    {
                        deltaPoulieM2=core::vector3df(0.0f,0.2f,0.0f);
                    } else {
                        deltaPoulieM2=core::vector3df(0.0f,-0.2f,0.0f);
                    }

                    driver->draw3DLine(arrPylones[i-1]->posMonteePylone->getAbsolutePosition()+deltaPoulieM2, arrPylones[i]->posMonteePylone->getAbsolutePosition()+deltaPoulieM, video::SColor(255, 0, 0, 0));
                }

                if(i==arrPylones.size()-1)
                {
                    if(arrPylones[i]->monteeSupportCompression==1)
                    {
                        deltaPoulieM=core::vector3df(0.0f,0.2f,0.0f);
                    } else {
                        deltaPoulieM=core::vector3df(0.0f,-0.2f,0.0f);
                    }

                    driver->draw3DLine(arrPylones[i]->posMonteePylone->getAbsolutePosition()+deltaPoulieM, posGaletArriveeMontee->getAbsolutePosition(), video::SColor(255, 0, 0, 0));
                }
            }

            driver->draw3DLine(posGaletArriveeMontee->getAbsolutePosition() , posMonteePoulieArrivee->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));
            driver->draw3DLine(posGaletArriveeDescente->getAbsolutePosition() , posDescentePoulieArrivee->getAbsolutePosition(),  video::SColor(255, 0, 0, 0));

            //Pour la descente
            for(int i=arrPylones.size()-1;i>=0;i--)
            {
                if(i==arrPylones.size()-1)
                {
                    if(arrPylones[i]->descenteSupportCompression==1)
                    {
                        deltaPoulieD=core::vector3df(0.0f,0.2f,0.0f);
                    } else {
                        deltaPoulieD=core::vector3df(0.0f,-0.2f,0.0f);
                    }
                    driver->draw3DLine(posGaletArriveeDescente->getAbsolutePosition() , arrPylones[i]->posDescentePylone->getAbsolutePosition()+deltaPoulieD,  video::SColor(255, 0, 0, 0));
                } else {
                    if(arrPylones[i]->descenteSupportCompression==1)
                    {
                        deltaPoulieD=core::vector3df(0.0f,0.2f,0.0f);
                    } else {
                        deltaPoulieD=core::vector3df(0.0f,-0.2f,0.0f);
                    }

                    if(arrPylones[i+1]->descenteSupportCompression==1)
                    {
                        deltaPoulieD2=core::vector3df(0.0f,0.2f,0.0f);
                    } else {
                        deltaPoulieD2=core::vector3df(0.0f,-0.2f,0.0f);
                    }

                    driver->draw3DLine(arrPylones[i+1]->posDescentePylone->getAbsolutePosition()+deltaPoulieD2, arrPylones[i]->posDescentePylone->getAbsolutePosition()+deltaPoulieD, video::SColor(255, 0, 0, 0));
                }

                if(i==0)
                {
                    if(arrPylones[i]->descenteSupportCompression==1)
                    {
                        deltaPoulieD=core::vector3df(0.0f,0.2f,0.0f);
                    } else {
                        deltaPoulieD=core::vector3df(0.0f,-0.2f,0.0f);
                    }

                    driver->draw3DLine(arrPylones[i]->posDescentePylone->getAbsolutePosition()+deltaPoulieD, posGaletDepartDescente4->getAbsolutePosition(), video::SColor(255, 0, 0, 0));
                }
            }

        }


    //printf("RedrawCable entre %f %f %f  et %f %f %f \n",nodePoulieDepart->getAbsolutePosition().X,nodePoulieDepart->getAbsolutePosition().Y,nodePoulieDepart->getAbsolutePosition().Z,nodePoulieArrivee->getAbsolutePosition().X,nodePoulieArrivee->getAbsolutePosition().Y,nodePoulieArrivee->getAbsolutePosition().Z);
    }
}

core::vector3df CTSFixe::GetRotationRM()
{
    return nodeDepart->getRotation();
}

//Anime le ts
void CTSFixe::AnimateRm(core::vector3df cameraPosition,f32 deltaTime)
{
    if(nodePoulieDepart==0 || nodePoulieArrivee==0) {
        return;
    }

    if(enMarche) {
        core::vector3df rotation=nodePoulieDepart->getRotation();
        //rotation.X=0;
        rotation.Y-=vitesse*deltaTime*15;
        //rotation.Z=0;
        if(rotation.Y<0.0f) {
            rotation.Y=rotation.Y+360.0f;
        }
        nodePoulieDepart->setRotation(rotation);

        core::vector3df rotationGaletDepartM=nodeGaletDepartM->getRotation();
        core::vector3df rotationGaletDepartD=nodeGaletDepartD->getRotation();
        core::vector3df rotationGaletDepartM2=nodeGaletDepartM2->getRotation();
        core::vector3df rotationGaletDepartD2=nodeGaletDepartD2->getRotation();
        core::vector3df rotationGaletDepartM3=nodeGaletDepartM3->getRotation();
        core::vector3df rotationGaletDepartD3=nodeGaletDepartD3->getRotation();
        core::vector3df rotationGaletDepartM4=nodeGaletDepartM4->getRotation();
        core::vector3df rotationGaletDepartD4=nodeGaletDepartD4->getRotation();
        core::vector3df rotationGaletDepartM5=nodeGaletDepartM5->getRotation();
        core::vector3df rotationGaletDepartD5=nodeGaletDepartD5->getRotation();
        core::vector3df rotationGaletDepartM6=nodeGaletDepartM6->getRotation();
        core::vector3df rotationGaletDepartD6=nodeGaletDepartD6->getRotation();
        core::vector3df rotationGaletDepartM7=nodeGaletDepartM7->getRotation();
        core::vector3df rotationGaletDepartD7=nodeGaletDepartD7->getRotation();
        core::vector3df rotationGaletDepartM8=nodeGaletDepartM8->getRotation();
        core::vector3df rotationGaletDepartD8=nodeGaletDepartD8->getRotation();

        rotationGaletDepartD.Z+=(vitesse*deltaTime*50);
        if(rotationGaletDepartD.Z>360.0f)
        {
            rotationGaletDepartD.Z=rotationGaletDepartD.Z-360.0f;
        }
        nodeGaletDepartD->setRotation(rotationGaletDepartD);

        rotationGaletDepartM.Z-=(vitesse*deltaTime*50);
        if(rotationGaletDepartM.Z<0.0f)
        {
            rotationGaletDepartM.Z=rotationGaletDepartM.Z+360.0f;
        }
        nodeGaletDepartM->setRotation(rotationGaletDepartM);

        rotationGaletDepartD2.Z+=(vitesse*deltaTime*50);
        if(rotationGaletDepartD2.Z>360.0f)
        {
            rotationGaletDepartD2.Z=rotationGaletDepartD2.Z-360.0f;
        }
        nodeGaletDepartD2->setRotation(rotationGaletDepartD2);

        rotationGaletDepartM2.Z-=(vitesse*deltaTime*50);
        if(rotationGaletDepartM2.Z<0.0f)
        {
            rotationGaletDepartM2.Z=rotationGaletDepartM2.Z+360.0f;
        }
        nodeGaletDepartM2->setRotation(rotationGaletDepartM2);

        rotationGaletDepartD3.Z+=(vitesse*deltaTime*50);
        if(rotationGaletDepartD3.Z>360.0f)
        {
            rotationGaletDepartD3.Z=rotationGaletDepartD3.Z-360.0f;
        }
        nodeGaletDepartD3->setRotation(rotationGaletDepartD3);

        rotationGaletDepartM3.Z-=(vitesse*deltaTime*50);
        if(rotationGaletDepartM3.Z<0.0f)
        {
            rotationGaletDepartM3.Z=rotationGaletDepartM3.Z+360.0f;
        }
        nodeGaletDepartM3->setRotation(rotationGaletDepartM3);

        rotationGaletDepartD4.Z+=(vitesse*deltaTime*50);
        if(rotationGaletDepartD4.Z>360.0f)
        {
            rotationGaletDepartD4.Z=rotationGaletDepartD4.Z-360.0f;
        }
        nodeGaletDepartD4->setRotation(rotationGaletDepartD4);

        rotationGaletDepartM4.Z-=(vitesse*deltaTime*50);
        if(rotationGaletDepartM4.Z<0.0f)
        {
            rotationGaletDepartM4.Z=rotationGaletDepartM4.Z+360.0f;
        }
        nodeGaletDepartM4->setRotation(rotationGaletDepartM4);

        rotationGaletDepartD5.Z+=(vitesse*deltaTime*50);
        if(rotationGaletDepartD5.Z>360.0f)
        {
            rotationGaletDepartD5.Z=rotationGaletDepartD5.Z-360.0f;
        }
        nodeGaletDepartD5->setRotation(rotationGaletDepartD5);

        rotationGaletDepartM5.Z-=(vitesse*deltaTime*50);
        if(rotationGaletDepartM5.Z<0.0f)
        {
            rotationGaletDepartM5.Z=rotationGaletDepartM5.Z+360.0f;
        }
        nodeGaletDepartM5->setRotation(rotationGaletDepartM5);

        rotationGaletDepartD6.Z+=(vitesse*deltaTime*50);
        if(rotationGaletDepartD6.Z>360.0f)
        {
            rotationGaletDepartD6.Z=rotationGaletDepartD6.Z-360.0f;
        }
        nodeGaletDepartD6->setRotation(rotationGaletDepartD6);

        rotationGaletDepartM6.Z-=(vitesse*deltaTime*50);
        if(rotationGaletDepartM6.Z<0.0f)
        {
            rotationGaletDepartM6.Z=rotationGaletDepartM6.Z+360.0f;
        }
        nodeGaletDepartM6->setRotation(rotationGaletDepartM6);

        rotationGaletDepartD7.Z+=(vitesse*deltaTime*50);
        if(rotationGaletDepartD7.Z>360.0f)
        {
            rotationGaletDepartD7.Z=rotationGaletDepartD7.Z-360.0f;
        }
        nodeGaletDepartD7->setRotation(rotationGaletDepartD7);

        rotationGaletDepartM7.Z-=(vitesse*deltaTime*50);
        if(rotationGaletDepartM7.Z<0.0f)
        {
            rotationGaletDepartM7.Z=rotationGaletDepartM7.Z+360.0f;
        }
        nodeGaletDepartM7->setRotation(rotationGaletDepartM7);

        rotationGaletDepartD8.Z+=(vitesse*deltaTime*50);
        if(rotationGaletDepartD8.Z>360.0f)
        {
            rotationGaletDepartD8.Z=rotationGaletDepartD8.Z-360.0f;
        }
        nodeGaletDepartD8->setRotation(rotationGaletDepartD8);

        rotationGaletDepartM8.Z-=(vitesse*deltaTime*50);
        if(rotationGaletDepartM8.Z<0.0f)
        {
            rotationGaletDepartM8.Z=rotationGaletDepartM8.Z+360.0f;
        }
        nodeGaletDepartM8->setRotation(rotationGaletDepartM8);

        rotation=nodePoulieArrivee->getRotation();
        core::matrix4 m;
        core::matrix4 mp;
        m.setRotationDegrees(rotation);
        mp.setRotationDegrees(core::vector3df(0.0f,vitesse*deltaTime*15,0.0f));

        m*=mp;
        rotation=m.getRotationDegrees();
        nodePoulieArrivee->setRotation(rotation);

        core::vector3df rotationGaletArriveeM=nodeGaletArriveeM->getRotation();
        core::vector3df rotationGaletArriveeD=nodeGaletArriveeD->getRotation();

        rotationGaletArriveeM.Z-=(vitesse*deltaTime*50);
        if(rotationGaletArriveeM.Z<0.0f)
        {
            rotationGaletArriveeM.Z=rotationGaletArriveeM.Z+360.0f;
        }
        nodeGaletArriveeM->setRotation(rotationGaletArriveeM);

        rotationGaletArriveeD.Z+=vitesse*deltaTime*50;
        if(rotationGaletArriveeD.Z>360.0f)
        {
            rotationGaletArriveeD.Z=rotationGaletArriveeD.Z-360.0f;
        }
        nodeGaletArriveeD->setRotation(rotationGaletArriveeD);

        //Anime les sièges
        for(unsigned int i=0;i<arrVehicules.size();i++)
        {
            //trouve le tronçon de la perche
            CTronconRM* t= GetTronconByNumero(arrVehicules[i]->numeroTroncon);
            if(t)
            {
                 //Mouvement rectiligne pour un troncon de ligne normale
                if(t->GetType()==CTronconRM::TRONCON_LIGNE)
                {
                    core::vector3df lastPosition=arrVehicules[i]->getPosition();
                    //printf("lastPosition = %f ; %f ; %f\n",lastPosition.X,lastPosition.Y,lastPosition.Z);
                    //printf("positionFin = %f ; %f ; %f\n",t->positionFin.X,t->positionFin.Y,t->positionFin.Z);
                    core::vector3df difference=t->positionFin-t->positionDebut;
                    f32 longueur=difference.getLength();

                    arrVehicules[i]->pas+=deltaTime*vitesse/longueur;

                    /*if(i==0) {
                        printf("siege %i  troncon=%i pas=%f  sur longueur=%f\n",i,t->numero,arrVehicules[i]->pas,longueur);
                    }*/
                    core::vector3df vecPosSiege;

                    vecPosSiege.X=t->positionDebut.X+difference.X*arrVehicules[i]->pas;
                    vecPosSiege.Y=t->positionDebut.Y+difference.Y*arrVehicules[i]->pas;
                    vecPosSiege.Z=t->positionDebut.Z+difference.Z*arrVehicules[i]->pas;

                    arrVehicules[i]->setPosition(vecPosSiege);

                    core::vector3df newPosition=arrVehicules[i]->getPosition();
                    //printf("2-perche %i => %f ; %f ; %f\n",i,newPosition.X,newPosition.Y,newPosition.Z);
                    //Verifie si on a atteint la fin du troncon. On se laisse une marge pour eviter d'avoir un mouvement qui rate la fin
                    if(newPosition.X>=t->positionFin.X-0.1f && newPosition.X<=t->positionFin.X+0.1f && newPosition.Y>=t->positionFin.Y-0.1f && newPosition.Y<=t->positionFin.Y+0.1f && newPosition.Z>=t->positionFin.Z-0.1f && newPosition.Z<=t->positionFin.Z+0.1f)
                    {
                        arrVehicules[i]->setPosition(t->positionFin);
                        arrVehicules[i]->pas=0;
                        //printf("Changement troncon perche %i\n",i);
                        //On passe au troncon suivant, sauf si c est le dernier
                        if(t->numero<arrTroncons.size()-1) {
                            arrVehicules[i]->numeroTroncon++;
                        } else {
                            arrVehicules[i]->numeroTroncon=0;
                        }
                    }
                }

                 //Demi cercle autour de la poulie d'arrivée
                if(t->GetType()==CTronconRM::TRONCON_POULIEARRIVEE)
                {
                    core::vector3df lastPosition=arrVehicules[i]->getPosition();
                    core::vector3df lastRotation=arrVehicules[i]->getRotation();

                    //printf("getRotation-perche %i => %f ; %f ; %f\n",i,lastRotation.X,lastRotation.Y,lastRotation.Z);

                    core::vector3df vecteurRayon=posDescentePoulieArrivee->getPosition()-posMonteePoulieArrivee->getPosition();
                    f32 rayon=(vecteurRayon.getLength()/2)+2.9f;
                    //core::vector3df centreCercle=posMonteePoulieArrivee->getPosition()+(posDescentePoulieArrivee->getPosition()-posMonteePoulieArrivee-> getPosition())/2.0f;

                    //arrVehicules[i]->pas+=0.005f;
                    arrVehicules[i]->pas+=(vitesse*deltaTime*7.0f)/(core::PI*rayon);
                    f32 angle=arrVehicules[i]->pas;
                    //f32 angle=arrVehicules[i]->pas-core::PI;

                    //Rotation du siège
                    core::quaternion rot(lastRotation * core::DEGTORAD);
                    core::quaternion toAdd;
                    toAdd.fromAngleAxis(-(vitesse*deltaTime*7.0f)/(core::PI*rayon), core::vector3df(0.0f,1.0f,0.0f));
                    rot *= toAdd;

                    core::vector3df r;
                    rot.toEuler(r);
                    arrVehicules[i]->setRotation(r * core::RADTODEG);


                    core::vector3df vecPosPyl;
                    /*f32 diffY=posDescentePoulieArrivee->getAbsolutePosition().Y-posMonteePoulieArrivee->getAbsolutePosition().Y;
                    f32 deltaY=diffY*arrVehicules[i]->pas/core::PI;*/
                    vecPosPyl.X=t->centreRotation.X+rayon*cos(angle-(nodeDepart->getRotation().Y*core::PI/180.0f)+core::PI/2.0f);
                    vecPosPyl.Y=t->centreRotation.Y-0.3f;
                    vecPosPyl.Z=t->centreRotation.Z+rayon*sin(angle-(nodeDepart->getRotation().Y*core::PI/180.0f)+core::PI/2.0f);
                    //printf("Rotation-perche %i angle=%f => %f ; %f ; %f\n",i,angle,vecPosPyl.X,vecPosPyl.Y,vecPosPyl.Z);
                    arrVehicules[i]->setPosition(vecPosPyl);



                    //Verifie si on a atteint la fin du troncon. On se laisse une marge pour eviter d'avoir un mouvement qui rate la fin
                    //if(angle>=0)
                    if(angle>=core::PI)
                    {
                        arrVehicules[i]->setPosition(t->positionFin);
                        arrVehicules[i]->pas=0;
                        arrVehicules[i]->setRotation(core::vector3df(0.0f,nodeDepart->getRotation().Y+180.0f,0.0f));
                        //printf("Changement troncon poulie arrivee perche %i\n",i);
                        //On passe au troncon suivant, sauf si c est le dernier
                        if(t->numero<arrTroncons.size()-1) {
                            arrVehicules[i]->numeroTroncon++;
                        } else {
                            arrVehicules[i]->numeroTroncon=0;
                        }
                    }
                }

                //Demi cercle autour de la poulie de départ
                if(t->GetType()==CTronconRM::TRONCON_POULIEDEPART)
                {
                    core::vector3df lastPosition=arrVehicules[i]->getPosition();
                    core::vector3df lastRotation=arrVehicules[i]->getRotation();

                    //printf("getRotation-perche %i => %f ; %f ; %f\n",i,lastRotation.X,lastRotation.Y,lastRotation.Z);

                    core::vector3df vecteurRayon=posDescentePoulieDepart->getPosition()-posMonteePoulieDepart->getPosition();
                    f32 rayon=(vecteurRayon.getLength()/2.0f)+2.9f;

                    //arrVehicules[i]->pas+=0.005f;
                    arrVehicules[i]->pas+=(vitesse*deltaTime*7.0f)/(core::PI*rayon);

                    core::vector3df vecPosPyl;
                    f32 angle=core::PI-arrVehicules[i]->pas;
                    /*vecPosPyl.X=t->centreRotation.X+rayon*cos(-angle-(nodeDepart->getRotation().Y*core::PI/180.0f)-core::PI/2.0f);
                    vecPosPyl.Y=t->centreRotation.Y;
                    vecPosPyl.Z=t->centreRotation.Z+rayon*sin(-angle-(nodeDepart->getRotation().Y*core::PI/180.0f)-core::PI/2.0f);*/

                    vecPosPyl.X=t->centreRotation.X+rayon*cos(-angle-(nodeDepart->getRotation().Y*core::PI/180.0f)+core::PI/2.0f);
                    vecPosPyl.Y=t->centreRotation.Y-0.2f;
                    vecPosPyl.Z=t->centreRotation.Z+rayon*sin(-angle-(nodeDepart->getRotation().Y*core::PI/180.0f)+core::PI/2.0f);
                    //printf("Rotation-perche %i angle=%f => %f ; %f ; %f\n",i,angle,vecPosPyl.X,vecPosPyl.Y,vecPosPyl.Z);
                    arrVehicules[i]->setPosition(vecPosPyl);

                    //Rotation du siege
                    core::quaternion rot(lastRotation * core::DEGTORAD);
                    core::quaternion toAdd;
                    toAdd.fromAngleAxis(-(vitesse*deltaTime*7.0f)/(core::PI*rayon), core::vector3df(0.0f,1.0f,0.0f));
                    rot *= toAdd;

                    core::vector3df r;
                    rot.toEuler(r);
                    arrVehicules[i]->setRotation(r * core::RADTODEG);

                     //Verifie si on a atteint la fin du troncon. On se laisse une marge pour eviter d'avoir un mouvement qui rate la fin
                    if(angle<=0)
                    {
                        arrVehicules[i]->setPosition(t->positionFin);
                        arrVehicules[i]->pas=0;
                        arrVehicules[i]->setRotation(core::vector3df(0.0f,nodeDepart->getRotation().Y,0.0f));
                        //printf("Changement troncon poulie arrivee perche %i\n",i);
                        //On passe au troncon suivant, sauf si c est le dernier
                        if(t->numero<arrTroncons.size()-1) {
                            arrVehicules[i]->numeroTroncon++;
                        } else {
                            arrVehicules[i]->numeroTroncon=0;
                        }
                    }
                }
            } else {
                printf("ERREUR GetTronconByNumero for CTSFixe t->0\n");
            }
        }
    }
}

//Fonction qui met à jour chaque troncon du RM, c'est ce qui permet de connaitre
// pour chacun de ces tronons le point de départ et le point d'arrivée
void CTSFixe::UpdateTroncons()
{
    if(!nodePoulieDepart || !nodePoulieArrivee) {
        RedrawCable();
        return;
    }

    core::vector3df deltaPoulieM;
    core::vector3df deltaPoulieD;

    arrTroncons.clear();
    //Cas particulier si j'ai pas de pylone
    if(arrPylones.size()==0)
    {
        printf("------------------------\n");
        CTronconRM* tronconDep=new CTronconRM();
        tronconDep->numero=0;
        tronconDep->SetType(CTronconRM::TRONCON_POULIEDEPART);
        tronconDep->centreRotation=nodePoulieDepart->getAbsolutePosition();
        arrTroncons.push_back(tronconDep);

        CTronconRM* tronconLigneMontee=new CTronconRM();
        tronconLigneMontee->numero=1;
        tronconLigneMontee->SetType(CTronconRM::TRONCON_LIGNE);
        tronconLigneMontee->positionDebut=posMonteePoulieDepart->getAbsolutePosition();
        tronconLigneMontee->positionFin=posGaletDepartMontee->getAbsolutePosition();
        tronconLigneMontee->positionFin.Y=tronconLigneMontee->positionFin.Y-0.1f;
        tronconLigneMontee->enMontee=true;
        arrTroncons.push_back(tronconLigneMontee);

        CTronconRM *tronconLigneMontee2=new CTronconRM();
        tronconLigneMontee2->numero=2;
        tronconLigneMontee2->SetType(CTronconRM::TRONCON_LIGNE);
        tronconLigneMontee2->positionDebut= posGaletDepartMontee->getAbsolutePosition();
        tronconLigneMontee2->positionFin=posGaletDepartMontee4->getAbsolutePosition();
        tronconLigneMontee2->positionFin.Y=tronconLigneMontee2->positionFin.Y-0.1f;
        tronconLigneMontee2->enMontee=true;
        arrTroncons.push_back(tronconLigneMontee2);

        CTronconRM *tronconLigneMontee3=new CTronconRM();
        tronconLigneMontee3->numero=3;
        tronconLigneMontee3->SetType(CTronconRM::TRONCON_LIGNE);
        tronconLigneMontee3->positionDebut= posGaletDepartMontee4->getAbsolutePosition();
        tronconLigneMontee3->positionDebut.Y=tronconLigneMontee3->positionDebut.Y-0.1f;
        tronconLigneMontee3->positionFin=posGaletArriveeMontee->getAbsolutePosition();
        tronconLigneMontee3->enMontee=true;
        arrTroncons.push_back(tronconLigneMontee3);

        CTronconRM *tronconLigneMontee4=new CTronconRM();
        tronconLigneMontee4->numero=4;
        tronconLigneMontee4->SetType(CTronconRM::TRONCON_LIGNE);
        tronconLigneMontee4->positionDebut= posGaletArriveeMontee->getAbsolutePosition();
        tronconLigneMontee4->positionDebut.Y=tronconLigneMontee4->positionDebut.Y-0.1f;
        tronconLigneMontee4->positionFin=posMonteePoulieArrivee->getAbsolutePosition();
        tronconLigneMontee4->enMontee=true;
        arrTroncons.push_back(tronconLigneMontee4);

        CTronconRM* tronconArr=new CTronconRM();
        tronconArr->numero=5;
        tronconArr->SetType(CTronconRM::TRONCON_POULIEARRIVEE);
        tronconArr->centreRotation=nodePoulieArrivee->getAbsolutePosition();
        arrTroncons.push_back(tronconArr);

        CTronconRM *tronconLigneDescente=new CTronconRM();
        tronconLigneDescente->numero=6;
        tronconLigneDescente->SetType(CTronconRM::TRONCON_LIGNE);
        tronconLigneDescente->positionDebut= posDescentePoulieArrivee->getAbsolutePosition();
        tronconLigneDescente->positionFin=posGaletArriveeDescente->getAbsolutePosition();
        tronconLigneDescente->enMontee=false;
        arrTroncons.push_back(tronconLigneDescente);

        CTronconRM *tronconLigneDescente2=new CTronconRM();
        tronconLigneDescente2->numero=7;
        tronconLigneDescente2->SetType(CTronconRM::TRONCON_LIGNE);
        tronconLigneDescente2->positionDebut= posGaletArriveeDescente->getAbsolutePosition();
        tronconLigneDescente2->positionFin=posGaletDepartDescente4->getAbsolutePosition();
        tronconLigneDescente2->positionFin.Y=tronconLigneDescente2->positionFin.Y-0.1f;
        tronconLigneDescente2->enMontee=false;
        arrTroncons.push_back(tronconLigneDescente2);

        CTronconRM *tronconLigneDescente3=new CTronconRM();
        tronconLigneDescente3->numero=8;
        tronconLigneDescente3->SetType(CTronconRM::TRONCON_LIGNE);
        tronconLigneDescente3->positionDebut= posGaletDepartDescente4->getAbsolutePosition();
        tronconLigneDescente3->positionDebut.Y= tronconLigneDescente3->positionDebut.Y-0.1f;
        tronconLigneDescente3->positionFin=posGaletDepartDescente->getAbsolutePosition();
        tronconLigneDescente3->enMontee=false;
        arrTroncons.push_back(tronconLigneDescente3);

        CTronconRM *tronconLigneDescente4=new CTronconRM();
        tronconLigneDescente4->numero=9;
        tronconLigneDescente4->SetType(CTronconRM::TRONCON_LIGNE);
        tronconLigneDescente4->positionDebut= posGaletDepartDescente->getAbsolutePosition();
        tronconLigneDescente4->positionFin=posDescentePoulieDepart->getAbsolutePosition();
        tronconLigneDescente4->enMontee=false;
        arrTroncons.push_back(tronconLigneDescente4);

    } else { //Sinon c'est qu'il y a au moins 1 pylone
        CTronconRM* tronconDep=new CTronconRM();
        tronconDep->numero=0;
        tronconDep->SetType(CTronconRM::TRONCON_POULIEDEPART);
        tronconDep->centreRotation=nodePoulieDepart->getAbsolutePosition();
        arrTroncons.push_back(tronconDep);
        printf("------------------------\n");
        printf("troncon %i POULIE Depart\n",tronconDep->numero);

        u32 nbTr=10+2*arrPylones.size();

        CTronconRM* tronconDep2M=new CTronconRM();
        tronconDep2M->numero=1;
        tronconDep2M->SetType(CTronconRM::TRONCON_LIGNE);
        tronconDep2M->positionDebut=posMonteePoulieDepart->getAbsolutePosition();
        tronconDep2M->positionFin=posGaletDepartMontee->getAbsolutePosition();
        tronconDep2M->enMontee=true;
        arrTroncons.push_back(tronconDep2M);
        printf("troncon %i TRONCON_DEP montee 2\n",tronconDep2M->numero);

        CTronconRM* tronconDep3M=new CTronconRM();
        tronconDep3M->numero=2;
        tronconDep3M->SetType(CTronconRM::TRONCON_LIGNE);
        tronconDep3M->positionDebut=posGaletDepartMontee->getAbsolutePosition();
        tronconDep3M->positionFin=posGaletDepartMontee4->getAbsolutePosition();
        tronconDep3M->positionFin.Y=tronconDep3M->positionFin.Y-0.1f;
        tronconDep3M->enMontee=true;
        arrTroncons.push_back(tronconDep3M);
        printf("troncon %i TRONCON_DEP montee 3\n",tronconDep3M->numero);

        CTronconRM* tronconDep2D=new CTronconRM();
        tronconDep2D->numero=nbTr-1;
        tronconDep2D->SetType(CTronconRM::TRONCON_LIGNE);
        tronconDep2D->positionDebut=posGaletDepartDescente->getAbsolutePosition();
        tronconDep2D->positionFin=posDescentePoulieDepart->getAbsolutePosition();
        tronconDep2D->enMontee=false;
        arrTroncons.push_back(tronconDep2D);
        printf("troncon %i TRONCON_LIGNE descente 2\n",tronconDep2D->numero);

        CTronconRM* tronconDep3D=new CTronconRM();
        tronconDep3D->numero=nbTr-2;
        tronconDep3D->SetType(CTronconRM::TRONCON_LIGNE);
        tronconDep3D->positionDebut=posGaletDepartDescente4->getAbsolutePosition();
        tronconDep3D->positionDebut.Y=tronconDep3D->positionDebut.Y-0.1f;
        tronconDep3D->positionFin=posGaletDepartDescente->getAbsolutePosition();
        tronconDep3D->enMontee=false;
        arrTroncons.push_back(tronconDep3D);
        printf("troncon %i TRONCON_LIGNE descente 3\n",tronconDep3D->numero);

        core::vector3df v2;
        core::vector3df v1;

        for(unsigned int i=0;i<arrPylones.size();i++)
        {
            CTronconRM* tronconPM=new CTronconRM();
            tronconPM->numero=i+3;
            tronconPM->SetType(CTronconRM::TRONCON_LIGNE);

            if(i==0) {
                tronconPM->positionDebut=posGaletDepartMontee4->getAbsolutePosition();
                //tronconPM->positionFin=arrPylones[0]->posMonteePylone->getAbsolutePosition();
                v1=nodePoulieDepart->getAbsolutePosition();
                if(arrPylones.size()>1)
                {
                    v2=arrPylones[1]->posMonteePylone->getAbsolutePosition();
                } else {
                    v2=nodePoulieArrivee->getAbsolutePosition();
                }
                arrPylones[0]->monteeSupportCompression=CompressionOrSupport(v1,arrPylones[0]->posMonteePylone->getAbsolutePosition(),v2);
                //Ajuste selon compression/support
                if(arrPylones[0]->monteeSupportCompression==1)
                {
                    deltaPoulieM=core::vector3df(0.0f,0.4f,0.0f);
                    printf("P0 support\n");
                } else {
                    deltaPoulieM=core::vector3df(0.0f,-0.4f,0.0f);
                    printf("P0 compression\n");
                }
                tronconPM->positionFin=arrPylones[0]->posMonteePylone->getAbsolutePosition()+deltaPoulieM;

            } else {
                if(i<arrPylones.size()-1) {

                    tronconPM->positionDebut=arrPylones[i-1]->posMonteePylone->getAbsolutePosition();
                    if(arrPylones[i-1]->monteeSupportCompression==1)
                    {
                        deltaPoulieM=core::vector3df(0.0f,0.4f,0.0f);
                    } else {
                        deltaPoulieM=core::vector3df(0.0f,-0.4f,0.0f);
                    }
                    tronconPM->positionDebut=arrPylones[i-1]->posMonteePylone->getAbsolutePosition()+deltaPoulieM;

                    tronconPM->positionFin=arrPylones[i]->posMonteePylone->getAbsolutePosition();

                    if(i>=arrPylones.size()-1) {
                        //tronconPM->positionFin=posMonteePoulieArrivee->getAbsolutePosition();
                        v2=posGaletArriveeMontee->getAbsolutePosition();
                    } else {
                        //tronconPM->positionFin=arrPylones[i+1]->posMonteePylone->getAbsolutePosition();
                        v2=arrPylones[i+1]->posMonteePylone->getAbsolutePosition();
                    }

                    v1=arrPylones[i-1]->posMonteePylone->getAbsolutePosition();
                    arrPylones[i]->monteeSupportCompression=CompressionOrSupport(v1,arrPylones[i]->posMonteePylone->getAbsolutePosition(),v2);
                    //printf("P%i angle montee compression=%i\n",i,arrPylones[i]->monteeSupportCompression);
                    //Ajuste selon compression/support
                    if(arrPylones[i]->monteeSupportCompression==1)
                    {
                        deltaPoulieM=core::vector3df(0.0f,0.4f,0.0f);
                        printf("Pi support\n");
                    } else {
                        deltaPoulieM=core::vector3df(0.0f,-0.4f,0.0f);
                        printf("Pi compression\n");
                    }
                    tronconPM->positionFin=arrPylones[i]->posMonteePylone->getAbsolutePosition()+deltaPoulieM;
                } else {
                    //dernier troncon
                    tronconPM->positionDebut=arrPylones[i-1]->posMonteePylone->getAbsolutePosition();
                    if(arrPylones[i-1]->monteeSupportCompression==1)
                    {
                        deltaPoulieM=core::vector3df(0.0f,0.4f,0.0f);
                    } else {
                        deltaPoulieM=core::vector3df(0.0f,-0.4f,0.0f);
                    }
                    tronconPM->positionDebut=arrPylones[i-1]->posMonteePylone->getAbsolutePosition()+deltaPoulieM;
                    tronconPM->positionFin=arrPylones[i]->posMonteePylone->getAbsolutePosition();
                    v2=nodePoulieArrivee->getAbsolutePosition();
                    if(arrPylones.size()<2)
                    {
                        v1=nodePoulieDepart->getAbsolutePosition();
                    } else {
                        v1=arrPylones[i-1]->posMonteePylone->getAbsolutePosition();
                    }
                    //arrPylones[i]->monteeSupportCompression=CompressionOrSupport(v1,arrPylones[i]->posMonteePylone->getAbsolutePosition(),v2);
                    arrPylones[i]->monteeSupportCompression=CompressionOrSupport(v1,arrPylones[i]->posMonteePylone->getAbsolutePosition(),v2);
                    //Ajuste le cable aux poulies
                    if(arrPylones[i]->monteeSupportCompression==1)
                    {
                        deltaPoulieM=core::vector3df(0.0f,0.4f,0.0f);
                        printf("Pi-1 support\n");
                    } else {
                        deltaPoulieM=core::vector3df(0.0f,-0.4f,0.0f);
                        printf("Pi-1 compression\n");
                    }
                    tronconPM->positionFin=arrPylones[i]->posMonteePylone->getAbsolutePosition()+deltaPoulieM;
                }

            }
            printf("troncon %i LIGNE montee debut = %f ; %f ; %f  fin = %f ; %f ; %f\n",tronconPM->numero,tronconPM->positionDebut.X,tronconPM->positionDebut.Y,tronconPM->positionDebut.Z,tronconPM->positionFin.X,tronconPM->positionFin.Y,tronconPM->positionFin.Z);
            tronconPM->enMontee=true;
            arrTroncons.push_back(tronconPM);
        }

        //dernier troncon
        //if(i==arrPylones.size()-1) {
        CTronconRM* tronconPM2=new CTronconRM();
        //tronconPM2->numero=i+2;
        tronconPM2->numero=arrPylones.size()+3;
        tronconPM2->SetType(CTronconRM::TRONCON_LIGNE);
        //tronconPM2->positionDebut=arrPylones[i]->posMonteePylone->getAbsolutePosition();
        tronconPM2->positionDebut=arrPylones[arrPylones.size()-1]->posMonteePylone->getAbsolutePosition();
        tronconPM2->positionFin=posGaletArriveeMontee->getAbsolutePosition();
        v2=nodePoulieArrivee->getAbsolutePosition();
        if(arrPylones.size()<2)
        {
            v1=nodePoulieDepart->getAbsolutePosition();
        } else {
            v1=arrPylones[arrPylones.size()-2]->posMonteePylone->getAbsolutePosition();
        }
        //arrPylones[i]->monteeSupportCompression=CompressionOrSupport(v1,arrPylones[i]->posMonteePylone->getAbsolutePosition(),v2);
        arrPylones[arrPylones.size()-1]->monteeSupportCompression=CompressionOrSupport(v1,arrPylones[arrPylones.size()-1]->posMonteePylone->getAbsolutePosition(),v2);
        //Ajuste selon compression/support
        //if(arrPylones[i]->monteeSupportCompression==1)
        if(arrPylones[arrPylones.size()-1]->monteeSupportCompression==1)
        {
            deltaPoulieM=core::vector3df(0.0f,0.4f,0.0f);
            printf("P last support\n");
        } else {
            deltaPoulieM=core::vector3df(0.0f,-0.4f,0.0f);
            printf("P last compression\n");
        }
        //tronconPM2->positionDebut=arrPylones[i]->posMonteePylone->getAbsolutePosition()+deltaPoulieM;
        tronconPM2->positionDebut=arrPylones[arrPylones.size()-1]->posMonteePylone->getAbsolutePosition()+deltaPoulieM;
        tronconPM2->enMontee=true;
        printf("troncon %i LIGNE montee debut = %f ; %f ; %f  fin = %f ; %f ; %f\n",tronconPM2->numero,tronconPM2->positionDebut.X,tronconPM2->positionDebut.Y,tronconPM2->positionDebut.Z,tronconPM2->positionFin.X,tronconPM2->positionFin.Y,tronconPM2->positionFin.Z);
        arrTroncons.push_back(tronconPM2);

        CTronconRM *tronconLigneMonteeArrivee=new CTronconRM();
        tronconLigneMonteeArrivee->numero=(nbTr/2)-1;
        tronconLigneMonteeArrivee->SetType(CTronconRM::TRONCON_LIGNE);
        tronconLigneMonteeArrivee->positionDebut= posGaletArriveeMontee->getAbsolutePosition();
        tronconLigneMonteeArrivee->positionFin=posMonteePoulieArrivee->getAbsolutePosition();
        tronconLigneMonteeArrivee->enMontee=true;
        arrTroncons.push_back(tronconLigneMonteeArrivee);

        CTronconRM* tronconArr=new CTronconRM();
        tronconArr->numero=nbTr/2;
        tronconArr->SetType(CTronconRM::TRONCON_POULIEARRIVEE);
        tronconArr->centreRotation=nodePoulieArrivee->getAbsolutePosition();
        arrTroncons.push_back(tronconArr);

        CTronconRM *tronconLigneDescenteArrivee=new CTronconRM();
        tronconLigneDescenteArrivee->numero=(nbTr/2)+1;
        tronconLigneDescenteArrivee->SetType(CTronconRM::TRONCON_LIGNE);
        tronconLigneDescenteArrivee->positionDebut= posDescentePoulieArrivee->getAbsolutePosition();
        tronconLigneDescenteArrivee->positionFin=posGaletArriveeDescente->getAbsolutePosition();
        tronconLigneDescenteArrivee->enMontee=false;
        arrTroncons.push_back(tronconLigneDescenteArrivee);

        printf("troncon %i Galet Montee Arrivee\n",tronconLigneMonteeArrivee->numero);
        printf("troncon %i POULIE Arrivee\n",tronconArr->numero);
        printf("troncon %i Galet Descente Arrivee\n",tronconLigneDescenteArrivee->numero);

        //Pour la descente
        int cptDes=arrPylones.size()-1;
        u32 currentNumero=tronconLigneDescenteArrivee->numero;

        while(cptDes>=0) {
            u32 idnext=findNextPyloneWithDescente(cptDes);
            u32 idprevious=findPreviousPyloneWithDescente(cptDes);

            CTronconRM* tronconD=new CTronconRM();
            tronconD->numero=currentNumero+1;
            tronconD->SetType(CTronconRM::TRONCON_LIGNE);
            //si je traite le 1er pylone
            if(cptDes==arrPylones.size()-1) {
                tronconD->positionDebut=posGaletArriveeDescente->getAbsolutePosition();
                v1=nodePoulieArrivee->getAbsolutePosition();
                tronconD->positionFin=arrPylones[cptDes]->posDescentePylone->getAbsolutePosition();
                u32 idnext2=findNextPyloneWithDescente(cptDes);
                if(idnext2==-1) {
                    v2=nodePoulieDepart->getAbsolutePosition();
                } else {
                    v2=arrPylones[idnext2]->posDescentePylone->getAbsolutePosition();
                }
                arrPylones[cptDes]->descenteSupportCompression=CompressionOrSupport(v1,arrPylones[cptDes]->posDescentePylone->getAbsolutePosition(),v2);
                //Ajuste selon compression/support
                if(arrPylones[cptDes]->descenteSupportCompression==1)
                {
                    deltaPoulieD=core::vector3df(0.0f,0.4f,0.0f);
                } else {
                    deltaPoulieD=core::vector3df(0.0f,-0.4f,0.0f);
                }
                tronconD->positionFin=arrPylones[cptDes]->posDescentePylone->getAbsolutePosition()+deltaPoulieD;
            } else {
                if(idprevious==-1) {
                    tronconD->positionDebut=posGaletArriveeDescente->getAbsolutePosition();
                    v1=posDescentePoulieArrivee->getAbsolutePosition();
                } else {
                    tronconD->positionDebut=arrPylones[idprevious]->posDescentePylone->getAbsolutePosition();
                    if(arrPylones[idprevious]->descenteSupportCompression==1)
                    {
                        deltaPoulieD=core::vector3df(0.0f,0.4f,0.0f);
                    } else {
                        deltaPoulieD=core::vector3df(0.0f,-0.4f,0.0f);
                    }
                    tronconD->positionDebut=arrPylones[idprevious]->posDescentePylone->getAbsolutePosition()+deltaPoulieD;
                    v1=arrPylones[idprevious]->posDescentePylone->getAbsolutePosition();
                }

                if(idnext==-1) {
                     v2=posDescentePoulieDepart->getAbsolutePosition();
                } else {
                     v2=arrPylones[idnext]->posDescentePylone->getAbsolutePosition();
                }

                tronconD->positionFin=arrPylones[cptDes]->posDescentePylone->getAbsolutePosition();

                arrPylones[cptDes]->descenteSupportCompression=CompressionOrSupport(v1,arrPylones[cptDes]->posDescentePylone->getAbsolutePosition(),v2);
                //Ajuste selon compression/support
                if(arrPylones[cptDes]->descenteSupportCompression==1)
                {
                    deltaPoulieD=core::vector3df(0.0f,0.4f,0.0f);
                } else {
                    deltaPoulieD=core::vector3df(0.0f,-0.4f,0.0f);
                }
                tronconD->positionFin=arrPylones[cptDes]->posDescentePylone->getAbsolutePosition()+deltaPoulieD;
            }

            if(cptDes==0) { //Sinon si je traite le dernier pylone
                CTronconRM* tronconD2=new CTronconRM();
                tronconD2->numero=currentNumero+2;
                tronconD2->SetType(CTronconRM::TRONCON_LIGNE);

                tronconD2->positionDebut=arrPylones[cptDes]->posDescentePylone->getAbsolutePosition();
                tronconD2->positionFin=posGaletDepartDescente4->getAbsolutePosition();
                v2=nodePoulieDepart->getAbsolutePosition();
                u32 idprevious2=findPreviousPyloneWithDescente(cptDes);
                if(idprevious2==-1) {
                    v1=nodePoulieArrivee->getAbsolutePosition();
                } else {
                    v1=arrPylones[idprevious2]->posDescentePylone->getAbsolutePosition();
                }
                 arrPylones[cptDes]->descenteSupportCompression=CompressionOrSupport(v1,arrPylones[cptDes]->posDescentePylone->getAbsolutePosition(),v2);
                //Ajuste selon compression/support
                if(arrPylones[cptDes]->descenteSupportCompression==1)
                {
                    deltaPoulieD=core::vector3df(0.0f,0.4f,0.0f);
                } else {
                    deltaPoulieD=core::vector3df(0.0f,-0.4f,0.0f);
                }
                tronconD2->positionDebut=arrPylones[cptDes]->posDescentePylone->getAbsolutePosition()+deltaPoulieD;

                printf("troncon %i LIGNE descente debut = %f ; %f ; %f  fin = %f ; %f ; %f\n",tronconD2->numero,tronconD2->positionDebut.X,tronconD2->positionDebut.Y,tronconD2->positionDebut.Z,tronconD2->positionFin.X,tronconD2->positionFin.Y,tronconD2->positionFin.Z);
                tronconD2->enMontee=false;
                arrTroncons.push_back(tronconD2);

            }

            printf("troncon %i LIGNE descente debut = %f ; %f ; %f  fin = %f ; %f ; %f\n",tronconD->numero,tronconD->positionDebut.X,tronconD->positionDebut.Y,tronconD->positionDebut.Z,tronconD->positionFin.X,tronconD->positionFin.Y,tronconD->positionFin.Z);
            tronconD->enMontee=false;
            arrTroncons.push_back(tronconD);

            currentNumero++;
            cptDes--;
        }

        printf("------------------------\n");
        RedrawCable();
    }

}

u32 CTSFixe::findNextPyloneWithDescente(u32 startindex) {
    u32 idnext=startindex-1;
    return idnext;
}

u32 CTSFixe::findPreviousPyloneWithDescente(u32 startindex) {
    u32 idprevious=startindex+1;

    if(idprevious<arrPylones.size()) {
        return idprevious;
    }

    return -1;
}

void CTSFixe::PlaceVehicules()
{
    //La premier siege commence toujours au troncon 1 (le 0 etant la poulie de départ)
    /*CVehicule *siege=new CVehicule(smgr,driver);
    siege->SetType(CVehicule::VEHICULE_TSF);
    siege->numeroTroncon=1;
    siege->pas=0;
    siege->DrawVehicule(posMonteePoulieDepart->getAbsolutePosition(),core::vector3df(0.0f,nodeDepart->getRotation().Y,0.0f));
    arrVehicules.push_back(siege);

    CTronconRM* t=GetTronconByNumero(1);
    core::vector3df difference=t->positionFin-t->positionDebut;
    f32 longueur=difference.getLength();

    CVehicule *siege2=new CVehicule(smgr,driver);
    siege2->SetType(CVehicule::VEHICULE_TSF);
    siege2->numeroTroncon=1;

    //Trouver pas E [tq
    siege2->pas=5/longueur;
    core::vector3df vecPosSiege;
    vecPosSiege.X=(t->positionDebut.X+difference.X*siege2->pas);
    vecPosSiege.Y=(t->positionDebut.Y+difference.Y*siege2->pas);
    vecPosSiege.Z=(t->positionDebut.Z+difference.Z*siege2->pas);
    siege2->DrawVehicule(vecPosSiege,core::vector3df(0.0f,nodeDepart->getRotation().Y,0.0f));
    arrVehicules.push_back(siege2);*/

        if(arrTroncons.size()>0) {

        f32 deltatroncon=0;
        for(unsigned int i=0;i<arrTroncons.size();i++){
            CTronconRM* tr=GetTronconByNumero(i);

            //On prend en compte que les troncons de type ligne
            if(tr->GetType()==CTronconRM::TRONCON_LIGNE) {
                core::vector3df difference=tr->positionFin-tr->positionDebut;
                f32 longueur=difference.getLength()-deltatroncon;

                u32 nbSiegesTr=(u32)(longueur/espacementVehicules);
                deltatroncon=longueur-nbSiegesTr*espacementVehicules;
                difference=difference.normalize();
                //printf("troncon->%i nbSiegesTr=%i difference=%f ; %f ; %f\n",i,nbSiegesTr,difference.X,difference.Y,difference.Z);
                for(int j=1;j<=nbSiegesTr;j++)
                {
                    core::vector3df vecPosSiege;
                    //vecPosSiege.X=(tr->positionDebut.X+difference.X*j*30)-(difference.X*deltatroncon);
                    //vecPosSiege.Y=(tr->positionDebut.Y+difference.Y*j*30)-(difference.Y*deltatroncon);
                    //vecPosSiege.Z=(tr->positionDebut.Z+difference.Z*j*30)-(difference.Z*deltatroncon);

                    vecPosSiege.X=(tr->positionDebut.X+difference.X*j*espacementVehicules)-(difference.X*deltatroncon);
                    vecPosSiege.Y=(tr->positionDebut.Y+difference.Y*j*espacementVehicules)-(difference.Y*deltatroncon);
                    vecPosSiege.Z=(tr->positionDebut.Z+difference.Z*j*espacementVehicules)-(difference.Z*deltatroncon);

                    CVehicule *siege=new CVehicule(smgr,driver);
                    siege->SetType(CVehicule::VEHICULE_TSF);
                    //printf("siege %i ->setPosition %f,%f,%f troncon:%i\n",j,vecPosSiege.X,vecPosSiege.Y,vecPosSiege.Z,tr->numero);
                    siege->numeroTroncon=tr->numero;
                    siege->pas=((j*espacementVehicules)-deltatroncon)/longueur;
                    //siege->pas=j*40/nbSiegesTr;
                    if(tr->enMontee)
                    {
                        siege->DrawVehicule(vecPosSiege,core::vector3df(0.0f,nodeDepart->getRotation().Y,0.0f));
                    } else {
                        siege->DrawVehicule(vecPosSiege,core::vector3df(0.0f,nodeDepart->getRotation().Y+180.0f,0.0f));
                    }

                    //siege->setPosition(posMonteePoulieDepart->getAbsolutePosition());
                    arrVehicules.push_back(siege);
                }

            }
        }
    }
}

CTSFixe::~CTSFixe()
{

}
