simulator.cpp 3.26 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2
#include "simulator.h"

pitiot's avatar
stats  
pitiot committed
3 4


pitiot's avatar
pitiot committed
5

pitiot's avatar
init  
pitiot committed
6
Simulator::Simulator()
pitiot's avatar
pitiot committed
7 8 9 10 11 12
{



}

pitiot's avatar
init  
pitiot committed
13
Simulator::~Simulator()
Pierre Kraemer's avatar
Pierre Kraemer committed
14 15 16 17
{

}

pitiot's avatar
init  
pitiot committed
18
void Simulator::init(int argc, char **argv)
Pierre Kraemer's avatar
Pierre Kraemer committed
19
{
pitiot's avatar
pitiot committed
20
    envMap_.init(argc,argv);
pitiot's avatar
pitiot committed
21

pitiot's avatar
init  
pitiot committed
22
	nbSteps_=0;
pitiot's avatar
pitiot committed
23 24

    if (argc > 1)
pitiot's avatar
pitiot committed
25 26
            Needle_or_knife = atoi(argv[1]) ;
//    Needle_or_knife=false;
pitiot's avatar
pitiot committed
27

pitiot's avatar
pitiot committed
28
     initFixedObjects();
pitiot's avatar
pitiot committed
29
     initMovingObject();
pitiot's avatar
pitiot committed
30 31

//    initEmptyMovingObject();
Pierre Kraemer's avatar
Pierre Kraemer committed
32 33
}

pitiot's avatar
init  
pitiot committed
34
void Simulator::doStep()
Pierre Kraemer's avatar
Pierre Kraemer committed
35
{
Pierre Kraemer's avatar
Pierre Kraemer committed
36

pitiot's avatar
init  
pitiot committed
37
	++nbSteps_ ;
Pierre Kraemer's avatar
Pierre Kraemer committed
38
}
pitiot's avatar
pitiot committed
39

pitiot's avatar
pitiot committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
void Simulator::initFixedObjects()
{
    std::vector<std::pair<VEC3, Dart>> startingPoints ;
    std::vector<std::pair<unsigned int, unsigned int>> segmentParts ;
    std::pair<VEC3, Dart> p;
    std::pair<unsigned int,unsigned int> ind;
    VEC3 pos;

    pos=VEC3(3,3,3);
    p.first=pos;
    p.second=envMap_.getBelongingCell(pos);
    startingPoints.push_back(p);

    pos=VEC3(-5,1,2);
    p.first=pos;
    p.second=envMap_.getBelongingCell(pos);
    startingPoints.push_back(p);

    pos=VEC3(4,-2,3);
    p.first=pos;
    p.second=envMap_.getBelongingCell(pos);
    startingPoints.push_back(p);

    pos=VEC3(1,-1,1);
    p.first=pos;
    p.second=envMap_.getBelongingCell(pos);
    startingPoints.push_back(p);

    pos=VEC3(2,-2.5f,0.5f);
    p.first=pos;
    p.second=envMap_.getBelongingCell(pos);
    startingPoints.push_back(p);

    ind.first=0;
    ind.second=1;
    segmentParts.push_back(ind);

    ind.first=2;
    ind.second=3;
    segmentParts.push_back(ind);

    ind.first=0;
    ind.second=2;
    segmentParts.push_back(ind);
    ind.first=0;
    ind.second=4;
    segmentParts.push_back(ind);


    ArticulatedObject * obj = new Tree(this,startingPoints,segmentParts);

    objects.push_back(obj);
//    CGoGNout<<"points :"<<p.first<<" ; "<<p2.first<<" ; "<</*p3.first<<*/CGoGNendl;
}

void Simulator::initEmptyMovingObject()
{

    std::vector<std::pair<VEC3, Dart>> startingPoints ;
    aiguille=new Knife(this,startingPoints);

//    CGoGNout<<"points :"<<p.first<<" ; "<<p2.first<<" ; "<</*p3.first<<*/CGoGNendl;
}

pitiot's avatar
pitiot committed
104

pitiot's avatar
pitiot committed
105
void Simulator::initMovingObject()
pitiot's avatar
pitiot committed
106
{
pitiot's avatar
pitiot committed
107
    if(Needle_or_knife) // Needle
pitiot's avatar
pitiot committed
108 109 110 111 112
    {
        std::pair<VEC3, Dart> startingPoint ;
        Dart d=envMap_.map.indexDart(40);
        startingPoint.first=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(envMap_.map,d,envMap_.position);
        startingPoint.second=d;
pitiot's avatar
pitiot committed
113
        aiguille=new Needle(this,startingPoint);
pitiot's avatar
pitiot committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
    }
    else // knife
    {
        std::vector<std::pair<VEC3, Dart>> startingPoints ;
        std::pair<VEC3, Dart> p;
        Dart d=envMap_.map.indexDart(40);
        p.first=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(envMap_.map,d,envMap_.position);
        p.second=d;
        startingPoints.push_back(p);
        std::pair<VEC3, Dart> p2;
        Dart d2=envMap_.map.indexDart(120);
        p2.first=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(envMap_.map,d2,envMap_.position);
        p2.second=d2;
        startingPoints.push_back(p2);
        std::pair<VEC3, Dart> p3;
        Dart d3=envMap_.map.indexDart(240);
        p3.first=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(envMap_.map,d3,envMap_.position);
        p3.second=d3;
        startingPoints.push_back(p3);



        aiguille=new Knife(this,startingPoints);
    }
pitiot's avatar
pitiot committed
138 139 140

//    CGoGNout<<"points :"<<p.first<<" ; "<<p2.first<<" ; "<</*p3.first<<*/CGoGNendl;
}