diff --git a/build/bin/mainV6.exe b/build/bin/mainV6.exe index 4175604..a03add7 100644 Binary files a/build/bin/mainV6.exe and b/build/bin/mainV6.exe differ diff --git a/src/collections/headers/gamba.hpp b/src/collections/headers/gamba.hpp index 92a3092..cf8ab9c 100644 --- a/src/collections/headers/gamba.hpp +++ b/src/collections/headers/gamba.hpp @@ -13,6 +13,7 @@ class Gamba : public CollectionInterface { Gamba(rb::Vector3 pos, unsigned int* dataPos, std::string cosciaData, std::string cavigliaData); collection create(ReferencePlane plane) override; PieceInterface* getJointPiece(); + void setDirection(Direction dir); }; #endif \ No newline at end of file diff --git a/src/collections/methods/gamba.cpp b/src/collections/methods/gamba.cpp index 4959ac8..dc22867 100644 --- a/src/collections/methods/gamba.cpp +++ b/src/collections/methods/gamba.cpp @@ -47,4 +47,13 @@ collection Gamba::create(ReferencePlane plane){ PieceInterface* Gamba::getJointPiece(){ return sensori[0]; +} + +void Gamba::setDirection(Direction dir){ + for (auto i : pezzi){ + i->setDirection(dir); + } + for (auto i : sensori){ + i->setDirection(dir); + } } \ No newline at end of file diff --git a/src/collections/methods/lower_body.cpp b/src/collections/methods/lower_body.cpp index 84b63eb..30f7a79 100644 --- a/src/collections/methods/lower_body.cpp +++ b/src/collections/methods/lower_body.cpp @@ -21,10 +21,12 @@ collection Lower_Body::create(ReferencePlane plane){ switch (plane) { case ReferencePlane::XZ: case ReferencePlane::XZN: + dx->setDirection(Direction::R); coll = coll + sx->create(plane); coll = coll + dx->create(plane); break; case ReferencePlane::YZ: + dx->setDirection(Direction::L); coll = coll + dx->create(plane); coll = coll + sx->create(plane); break; diff --git a/src/pieces/headers/piece_interface.hpp b/src/pieces/headers/piece_interface.hpp index f3cb4cd..3513b83 100644 --- a/src/pieces/headers/piece_interface.hpp +++ b/src/pieces/headers/piece_interface.hpp @@ -13,6 +13,11 @@ enum class ReferencePlane { XZN }; +enum class Direction { + L, + R +}; + //classi class PieceInterface{ protected: @@ -25,7 +30,7 @@ class PieceInterface{ shapeXZ->setFillColor(color); shapeYZ->setFillColor(color); } - + Direction direction = Direction::L; public: sf::Shape* shapeXZ, *shapeYZ; rb::Vector3 globalPos; @@ -35,6 +40,9 @@ class PieceInterface{ virtual void update(sf::Clock cl) = 0; virtual sf::Shape* draw(ReferencePlane plane) = 0; virtual ~PieceInterface(){} + virtual void setDirection(Direction dir){ + direction = dir; + } }; diff --git a/src/pieces/methods/sensore_class.cpp b/src/pieces/methods/sensore_class.cpp index 42ea0d6..4f0e82e 100644 --- a/src/pieces/methods/sensore_class.cpp +++ b/src/pieces/methods/sensore_class.cpp @@ -62,6 +62,7 @@ sf::Shape* Sensore::draw(ReferencePlane plane){ { case ReferencePlane::XZ: { + sf::Shape* shape = shapeXZ; shape->setRotation(sf::Angle(sf::radians(tmpRot[1]))); shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]}); @@ -85,7 +86,7 @@ sf::Shape* Sensore::draw(ReferencePlane plane){ void Sensore::calcRotWithG(unsigned int index){ // calcolo rotazione con valori della gravità - + int dir = direction == Direction::R ? -1 : 1; std::vector grav = gData[index]; float modG = sqrt(pow(grav[0],2)+pow(grav[1],2)+pow(grav[2],2)); @@ -95,7 +96,7 @@ void Sensore::calcRotWithG(unsigned int index){ // calcolo rotazione con valori float tmpSinY = -grav[1] / modG; float tmpSinZ = -grav[2] / modG; - float tmpAX = acos(tmpSinX); + float tmpAX = acos(dir*tmpSinX); float tmpAY = acos(tmpSinY); float tmpAZ = acos(tmpSinZ); diff --git a/src/testMain.cpp b/src/testMain.cpp index 2f870c8..aae6534 100755 --- a/src/testMain.cpp +++ b/src/testMain.cpp @@ -43,8 +43,8 @@ int main() { 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 Coscia (rb::Vector3{0,0,0},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)); @@ -68,11 +68,12 @@ 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]})); + + gs.pieces[2]->setDirection(Direction::R); */ - //provo ad aggiungere una collection //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; @@ -85,7 +86,7 @@ int main() { data.push_back(d); data.push_back(s); gs.collections.push_back(new Lower_Body(rb::Vector3{200,200,100},data)); - + printf("Ho costruito tutto!\n"); } catch(char* e){