Aggiunto cambio direzione per corretta visualizzaione dx/sx

This commit is contained in:
2026-06-19 19:04:28 +02:00
parent a16cc97048
commit fa6d6cf76e
7 changed files with 30 additions and 8 deletions
+1
View File
@@ -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
+9
View File
@@ -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);
}
}
+2
View File
@@ -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;
+9 -1
View File
@@ -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;
}
};
+3 -2
View File
@@ -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<float> 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);
+6 -5
View File
@@ -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<gamba_data> 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){