simulator.cpp 3.68 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
            Needle_or_knife = atoi(argv[1]) ;
26 27
    else
        Needle_or_knife=true;
pitiot's avatar
pitiot committed
28

Thomas Pitiot 's avatar
Thomas Pitiot committed
29
//     initFixedObjects();
Thomas Pitiot 's avatar
Thomas Pitiot committed
30
     initSurfaces();
pitiot's avatar
pitiot committed
31
     initMovingObject();
pitiot's avatar
pitiot committed
32 33

//    initEmptyMovingObject();
Pierre Kraemer's avatar
Pierre Kraemer committed
34 35
}

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

pitiot's avatar
init  
pitiot committed
39
	++nbSteps_ ;
Pierre Kraemer's avatar
Pierre Kraemer committed
40
}
pitiot's avatar
pitiot committed
41

pitiot's avatar
pitiot committed
42 43 44
void Simulator::initSurfaces()
{

Thomas Pitiot 's avatar
Thomas Pitiot committed
45
    Surface * obj = new Surface(this,VEC3(-1.0f,-1.5f,0.69f));
Thomas Pitiot 's avatar
Thomas Pitiot committed
46
    CGoGNout<<"surface initialisée : "<<obj->index_surface<<CGoGNendl;
pitiot's avatar
pitiot committed
47 48 49

}

pitiot's avatar
pitiot committed
50 51 52 53 54 55 56 57
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;

Thomas Pitiot 's avatar
Thomas Pitiot committed
58 59 60 61
    pos=VEC3(2.21,3.02,3.53);
    p.first=pos;
    p.second=envMap_.getBelongingCell(pos);
    startingPoints.push_back(p);
pitiot's avatar
pitiot committed
62

Thomas Pitiot 's avatar
Thomas Pitiot committed
63
    pos=VEC3(1.23,1.36,2.15);
Thomas Pitiot 's avatar
Thomas Pitiot committed
64 65 66
    p.first=pos;
    p.second=envMap_.getBelongingCell(pos);
    startingPoints.push_back(p);
pitiot's avatar
pitiot committed
67

Thomas Pitiot 's avatar
Thomas Pitiot committed
68 69 70 71
//    pos=VEC3(4,-2,3);
//    p.first=pos;
//    p.second=envMap_.getBelongingCell(pos);
//    startingPoints.push_back(p);
pitiot's avatar
pitiot committed
72

Thomas Pitiot 's avatar
Thomas Pitiot committed
73 74 75 76
//    pos=VEC3(1,-1,1);
//    p.first=pos;
//    p.second=envMap_.getBelongingCell(pos);
//    startingPoints.push_back(p);
pitiot's avatar
pitiot committed
77

78 79 80 81
//    pos=VEC3(2,-2.5f,0.5f);
//    p.first=pos;
//    p.second=envMap_.getBelongingCell(pos);
//    startingPoints.push_back(p);
pitiot's avatar
pitiot committed
82 83 84 85 86

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
87 88 89
//    ind.first=2;
//    ind.second=3;
//    segmentParts.push_back(ind);
pitiot's avatar
pitiot committed
90

Thomas Pitiot 's avatar
Thomas Pitiot committed
91 92 93
//    ind.first=0;
//    ind.second=2;
//    segmentParts.push_back(ind);
94 95 96
//    ind.first=0;
//    ind.second=4;
//    segmentParts.push_back(ind);
pitiot's avatar
pitiot committed
97 98 99 100


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

pitiot's avatar
pitiot committed
101

102 103 104

    CGoGNout<<"Objet Fixe initialisé : "<<obj->index_articulated<<CGoGNendl;

pitiot's avatar
pitiot committed
105 106 107 108 109 110 111 112 113 114 115 116
//    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
117

pitiot's avatar
pitiot committed
118
void Simulator::initMovingObject()
pitiot's avatar
pitiot committed
119
{
pitiot's avatar
pitiot committed
120
    if(Needle_or_knife) // Needle
pitiot's avatar
pitiot committed
121 122
    {
        std::pair<VEC3, Dart> startingPoint ;
pitiot's avatar
up  
pitiot committed
123
        Dart d=envMap_.map.indexDart(0);
Thomas Pitiot 's avatar
Thomas Pitiot committed
124 125
//        startingPoint.first=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(envMap_.map,d,envMap_.position);
        startingPoint.first=VEC3(-5,0,0);
pitiot's avatar
pitiot committed
126
        startingPoint.second=d;
pitiot's avatar
pitiot committed
127
        aiguille=new Needle(this,startingPoint);
pitiot's avatar
pitiot committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    }
    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);
    }
152
CGoGNout<<"Aiguille initialisée : "<<aiguille->index_articulated<<CGoGNendl;
pitiot's avatar
pitiot committed
153 154
//    CGoGNout<<"points :"<<p.first<<" ; "<<p2.first<<" ; "<</*p3.first<<*/CGoGNendl;
}