diff --git a/build/bin/imgui.ini b/build/bin/imgui.ini index 3f4ad5e..45b6e0c 100644 --- a/build/bin/imgui.ini +++ b/build/bin/imgui.ini @@ -3,8 +3,8 @@ Pos=60,60 Size=400,400 [Window][Dear ImGui Demo] -Pos=473,13 -Size=936,873 +Pos=781,47 +Size=455,873 [Window][Hello, world!] Pos=11,12 diff --git a/build/bin/mainV6 b/build/bin/mainV6 index 1f71b2c..3a34492 100755 Binary files a/build/bin/mainV6 and b/build/bin/mainV6 differ diff --git a/src/collections/headers/collection_interface.hpp b/src/collections/headers/collection_interface.hpp index 2a11279..7931487 100644 --- a/src/collections/headers/collection_interface.hpp +++ b/src/collections/headers/collection_interface.hpp @@ -24,9 +24,16 @@ inline collection operator+(collection c1, collection c2){ for (PieceInterface* i : c1.pieces){ res.pieces.push_back(i); } + for (PieceInterface* i : c2.pieces){ + res.pieces.push_back(i); + } for (JointInterface* i : c1.joints){ res.joints.push_back(i); } + for (JointInterface* i : c2.joints){ + res.joints.push_back(i); + } + return res; } diff --git a/src/collections/headers/lower_body.hpp b/src/collections/headers/lower_body.hpp index 72cbcf4..fb24b7d 100644 --- a/src/collections/headers/lower_body.hpp +++ b/src/collections/headers/lower_body.hpp @@ -28,6 +28,7 @@ public: ~Lower_Body(); void setVisibility(bool c); + void setTransparency(float t); collection create(ReferencePlane plane) override; }; diff --git a/src/collections/methods/gamba.cpp b/src/collections/methods/gamba.cpp index e2dedb1..4959ac8 100644 --- a/src/collections/methods/gamba.cpp +++ b/src/collections/methods/gamba.cpp @@ -3,15 +3,15 @@ Gamba::Gamba(rb::Vector3 pos, unsigned int* dataPos, std::string cosciaData, std::string cavigliaData){ CSVProcessor processor; try { - processor.readCSVFile (DATA_PATH + "coscia_filt.csv"); - const auto& coscia = processor.getData(); - processor.readCSVFile(DATA_PATH + "caviglia_filt.csv"); - const auto& caviglia = processor.getData(); - pezzi.push_back(new Coscia(pos,2)); pezzi.push_back(new Caviglia(rb::Vector3{pos[0],pos[1],pos[2]+200},2)); - + + processor.readCSVFile (DATA_PATH + cosciaData); + const auto& coscia = processor.getData(); sensori.push_back(new Sensore(pos,_Float16( 0.2 ),dataPos,coscia)); + + processor.readCSVFile(DATA_PATH + cavigliaData); + const auto& caviglia = processor.getData(); sensori.push_back(new Sensore (rb::Vector3{pos[0],pos[1],pos[2]+200},_Float16( 0.2 ),dataPos,caviglia)); // modifico la rotazione relativa della gamba diff --git a/src/collections/methods/lower_body.cpp b/src/collections/methods/lower_body.cpp index 70e1719..6bf48b4 100644 --- a/src/collections/methods/lower_body.cpp +++ b/src/collections/methods/lower_body.cpp @@ -4,7 +4,7 @@ Lower_Body::Lower_Body(rb::Vector3 pos,std::vector data){ if (data.size() != 2) throw "Lower_Body_Error: data vector size must be 2"; sx = new Gamba({pos[0],pos[1],pos[2]+150},data[0].dataPos,data[0].cosciaData,data[0].cavigliaData); - dx = new Gamba({pos[0],pos[1],pos[2]+150},data[1].dataPos,data[1].cosciaData,data[1].cavigliaData); + dx = new Gamba({pos[0],pos[1]+100,pos[2]+150},data[1].dataPos,data[1].cosciaData,data[1].cavigliaData); t = new Torso({pos[0],pos[1]+100,pos[2]},_Float16(3.0)); PieceInterface* psx = sx->getJointPiece(); @@ -18,7 +18,6 @@ Lower_Body::Lower_Body(rb::Vector3 pos,std::vector data){ collection Lower_Body::create(ReferencePlane plane){ collection coll; - switch (plane) { case ReferencePlane::XZ: case ReferencePlane::XZN: @@ -33,6 +32,10 @@ collection Lower_Body::create(ReferencePlane plane){ default: break; } + coll.pieces.push_back(t); + coll.joints.push_back(jsx); + coll.joints.push_back(jdx); + return coll; } diff --git a/src/sfml_util.cpp b/src/sfml_util.cpp index 80d488b..a4c5e4f 100644 --- a/src/sfml_util.cpp +++ b/src/sfml_util.cpp @@ -2,6 +2,7 @@ #include #include "pieces/headers/piece_interface.hpp" #include "joints/headers/joint_interface.hpp" +#include "collections/headers/collection_interface.hpp" #include #include @@ -21,6 +22,10 @@ struct State int menubar_height = 50; std::vector pieces; std::vector joints; + std::vector collections; + + std::vector createdColl; + sf::Vector2f cameraOffset = {0.,0.}; sf::Clock clock; @@ -48,11 +53,19 @@ struct State intervalMajLimit = maj; intervalMinLimit = min; this->pos = pos; + updateCollections(); } void update(); void setIntervall(int n){ maxEntries = n; } + + void updateCollections(){ + createdColl.clear(); + for (auto c: collections){ + createdColl.push_back(c->create(selectedPlane)); + } + } }; /// @@ -62,7 +75,23 @@ struct State /// Fisics functions void State::update(){ - + + /* + std::vector collPieces; + std::vector collJoints; + */ + + for (auto i : createdColl){ + if (play){ + for (auto j : i.pieces){ + j->update(clock); + } + } + for (auto j : i.joints){ + j->movechild(); + } + } + if (play){ for(PieceInterface* p : pieces){ p->update(clock); @@ -97,6 +126,7 @@ void handle_keyPressed(const sf::Event::KeyPressed &keyPressed, State &gs) else gs.selectedPlane = ReferencePlane::XZ; } + gs.updateCollections(); } @@ -125,6 +155,11 @@ void handle_mouseMove(const sf::Event::MouseMoved &mouseMoved, State &gs) for(PieceInterface* p : gs.pieces){ p->globalPos = {p->globalPos[0] + (offset.x * px), p->globalPos[1]+ (offset.x * py),p->globalPos[2] + offset.y}; } + for(collection c : gs.createdColl){ + for(auto p : c.pieces){ + p->globalPos = {p->globalPos[0] + (offset.x * px), p->globalPos[1]+ (offset.x * py),p->globalPos[2] + offset.y}; + } + } } #ifdef DEBUG_MODE @@ -167,6 +202,7 @@ void handle_mousePressed(const sf::Event::MouseButtonPressed &mouseBP, State &gs } i++; } + } if ( mouseBP.button == sf::Mouse::Button::Right){ gs.rot_Piece = true; @@ -258,7 +294,7 @@ void doGUI(State &gs) ImGui::Begin("Set visualization plane",0,sdp_flags); const char* MyEnumNames[] = { "XZ", "YZ", "-XZ" }; int currentPlane = (int)gs.selectedPlane; - ImGui::SliderInt("Selected Plane", ¤tPlane,0,2,MyEnumNames[currentPlane]); + if (ImGui::SliderInt("Selected Plane", ¤tPlane,0,2,MyEnumNames[currentPlane])) gs.updateCollections(); gs.selectedPlane = (ReferencePlane)currentPlane; ImGui::End(); @@ -275,10 +311,19 @@ void doGraphics(State &gs) { gs.window.clear(); + + //disegno i pezzi singoli for(PieceInterface* p: gs.pieces){ gs.window.draw(*p->draw(gs.selectedPlane)); } + //disegno le collezioni + for(auto c : gs.createdColl){ + for(auto p : c.pieces){ + gs.window.draw(*p->draw(gs.selectedPlane)); + } + } + while (const std::optional event = gs.window.pollEvent()) { ImGui::SFML::ProcessEvent(gs.window, *event); if (event->is()) diff --git a/src/testMain.cpp b/src/testMain.cpp index 923d4b6..11f76cd 100755 --- a/src/testMain.cpp +++ b/src/testMain.cpp @@ -38,11 +38,12 @@ int main() { printf("Costruisco gli oggetti\n"); try{ + processor.readCSVFile (DATA_PATH + "coscia_filt.csv"); const auto& coscia = processor.getData(); gs.setIntervall(coscia.size()); - + /* 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 ),&pos,coscia)); gs.pieces.push_back(new Caviglia (rb::Vector3{300,300,500},1)); @@ -67,19 +68,19 @@ int main() { gs.joints.push_back(new RigidJoint(gs.pieces[1], {gs.pieces[0]})); gs.joints.push_back(new PivotJoint(gs.pieces[1], {gs.pieces[3]}, rb::Vector3{0,0,100})); gs.joints.push_back(new RigidJoint(gs.pieces[3], {gs.pieces[2]})); - + */ //provo ad aggiungere una collection - Gamba g = Gamba({0,0,0},&pos,"coscia_filt.csv","coscia_filt.csv"); + gs.collections.push_back(new Gamba({220,0,220},&pos,"coscia_filt.csv","caviglia_filt.csv")); std::vector data; gamba_data d; d.dataPos = &pos; - d.cavigliaData = "coscia_filt.csv"; + d.cavigliaData = "caviglia_filt.csv"; d.cosciaData = "coscia_filt.csv"; data.push_back(d); data.push_back(d); - Lower_Body b = Lower_Body(rb::Vector3{0,0,0},data); + gs.collections.push_back(new Lower_Body(rb::Vector3{0,0,0},data)); printf("Ho costruito tutto!\n"); } @@ -95,6 +96,7 @@ int main() { //Avvio il loop della GUI gs.clock.start(); + gs.updateCollections(); sf::Clock mainClock; while (gs.window.isOpen())