diff --git a/build/bin/imgui.ini b/build/bin/imgui.ini index 8127391..0d64693 100644 --- a/build/bin/imgui.ini +++ b/build/bin/imgui.ini @@ -23,8 +23,8 @@ Pos=68,96 Size=740,472 [Window][Set data position] -Pos=18,542 -Size=534,60 +Pos=10,520 +Size=521,73 [Window][Dear ImGui Demo/ResizableChild_478B81A3] IsChild=1 diff --git a/build/bin/mainV5 b/build/bin/mainV5 index c731567..d7328e1 100755 Binary files a/build/bin/mainV5 and b/build/bin/mainV5 differ diff --git a/src/pieces/headers/piece_interface.hpp b/src/pieces/headers/piece_interface.hpp index 81922ea..7b261e3 100644 --- a/src/pieces/headers/piece_interface.hpp +++ b/src/pieces/headers/piece_interface.hpp @@ -32,7 +32,7 @@ class PieceInterface{ rb::rigidbody body; sf::Color color; - virtual void update(unsigned int pos) = 0; + virtual void update(sf::Clock cl) = 0; virtual sf::Shape* draw(ReferencePlane plane) = 0; virtual ~PieceInterface(){} }; diff --git a/src/pieces/headers/sensore.hpp b/src/pieces/headers/sensore.hpp index e368c13..4eabb53 100644 --- a/src/pieces/headers/sensore.hpp +++ b/src/pieces/headers/sensore.hpp @@ -14,12 +14,9 @@ class Sensore : public PieceInterface{ std::vector> gData; std::vector> rotData; std::vector timeData; - rb::Vector3 stPos; //in che punto sto controllando il segnale - unsigned int dataPos; - std::vector dataIntvl; - unsigned int curTime; + unsigned int* dataPos; //funzioni ausiliarie void calcRotWithG(unsigned int index); @@ -27,10 +24,10 @@ class Sensore : public PieceInterface{ public: Sensore(rb::Vector3 coords, _Float16 mass); - Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, int min, int max, std::vector> data); + Sensore(rb::Vector3 coords, _Float16 mass, unsigned int* st, std::vector> data); ~Sensore(); - void update(unsigned int pos) override; + void update(sf::Clock cl) override; sf::Shape* draw(ReferencePlane plane) override; //funzioni specifiche diff --git a/src/pieces/methods/sensore_class.cpp b/src/pieces/methods/sensore_class.cpp index 36641cb..ba1d8ed 100644 --- a/src/pieces/methods/sensore_class.cpp +++ b/src/pieces/methods/sensore_class.cpp @@ -9,11 +9,9 @@ Sensore::Sensore(rb::Vector3 coords, _Float16 mass){ initialize_shapes(sensore_Dim); } -Sensore::Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, int min, int max, std::vector> data) : Sensore(coords, mass){ +Sensore::Sensore(rb::Vector3 coords, _Float16 mass, unsigned int* st, std::vector> data) : Sensore(coords, mass){ dataPos = st; - this->dataIntvl = {min, max}; initCSV(data); - curTime = 0; } @@ -45,27 +43,14 @@ void Sensore::initCSV(std::vector> data){ void Sensore::update(sf::Clock cl){ - // Aggiorno la posizione nei dati - curTime += cl.getElapsedTime().asMilliseconds(); - /* - if (timeData[dataPos]){ - - } - */ - /* - if (timeData[dataPos] < currTime && dataIntvl - dataPos > 0) { //aggiorno solo se ho cambiato posizione - dataPos++; - - //calcolo la posizione e velocità - calcRotWithG(dataPos); + //calcolo la posizione e velocità + calcRotWithG(*dataPos); - body.setAcc(rb::Vector3{accData[dataPos]}); - body.step(cl); - } - */ - + body.setAcc(rb::Vector3{accData[*dataPos]}); + body.step(cl); + } sf::Shape* Sensore::draw(ReferencePlane plane){ @@ -118,13 +103,5 @@ void Sensore::calcRotWithG(unsigned int index){ // calcolo rotazione con valori } -void Sensore::setIntervall(int min, int max){ - this->dataIntvl = {min, max}; -} - -void Sensore::setPos(int &pos){ - this->dataPos = pos; -} - /////////////// cinematica inversa \ No newline at end of file diff --git a/src/sfml_util.cpp b/src/sfml_util.cpp index f00d737..7fe67e7 100644 --- a/src/sfml_util.cpp +++ b/src/sfml_util.cpp @@ -65,7 +65,7 @@ void State::update(){ for(PieceInterface* p : pieces){ - p->update(*pos); + p->update(clock); } for(JointInterface* j : joints){ j->movechild(); diff --git a/src/testMain.cpp b/src/testMain.cpp index d503e8e..dc6c073 100755 --- a/src/testMain.cpp +++ b/src/testMain.cpp @@ -37,7 +37,7 @@ int main() { //Costruisco la GUI State gs(800, 600, "Visualizzatore passo",&maj,&min,&pos); - gs.window.setFramerateLimit(60); + gs.window.setFramerateLimit(140); printf("Costruisco gli oggetti\n"); try{ @@ -47,7 +47,7 @@ int main() { gs.pieces.push_back(new Coscia (rb::Vector3{300,300,300},2)); - gs.pieces.push_back(new Sensore (rb::Vector3{300,300,300},_Float16( 0.2 ),900,900,3000,coscia)); + gs.pieces.push_back(new Sensore (rb::Vector3{300,300,300},_Float16( 0.2 ),&pos,coscia)); gs.pieces.push_back(new Caviglia (rb::Vector3{300,300,500},1)); gs.pieces[1]->body.setRot({0,0,0}); @@ -55,7 +55,7 @@ int main() { processor.readCSVFile(DATA_PATH + "caviglia_filt.csv"); const auto& caviglia = processor.getData(); - gs.pieces.push_back(new Sensore (rb::Vector3{300,300,500},_Float16( 0.2 ),900,900,3000,caviglia)); + gs.pieces.push_back(new Sensore (rb::Vector3{300,300,500},_Float16( 0.2 ),&pos,caviglia)); gs.pieces.push_back(new Torso(rb::Vector3{300,400,150},2)); @@ -86,12 +86,14 @@ int main() { //Avvio il loop della GUI gs.clock.start(); + + sf::Clock mainClock; while (gs.window.isOpen()) { - curTime += gs.clock.getElapsedTime().asMilliseconds(); + curTime += mainClock.restart().asMilliseconds(); if (curTime > T){ + if (gs.play && pos < maj) pos += curTime / T; curTime = 0; - if (gs.play && pos < maj) pos += 1; } // Show update