Caricamento v0.3

This commit is contained in:
2026-05-31 11:06:50 +02:00
parent e50e2987c9
commit 5169bc4096
18 changed files with 208 additions and 62 deletions
+4 -3
View File
@@ -3,11 +3,12 @@
#ifndef CAVIGLIA_H
#define CAVIGLIA_H
const sf::Vector2f caviglia_Dim = {60, 200};
const sf::Color caviglia_Col = sf::Color(230,160,11,255);
class Caviglia : public PieceInterface{
private:
const sf::Vector3f caviglia_Dim = {60, 200, 60};
const sf::Color caviglia_Col = sf::Color(230,160,11,255);
public:
Caviglia(rb::Vector3 coords, _Float16 mass);
+4 -2
View File
@@ -3,11 +3,13 @@
#ifndef COSCIA_H
#define COSCIA_H
const sf::Vector2f coscia_Dim = {80, 200};
const sf::Color coscia_Col = sf::Color::Yellow;
class Coscia : public PieceInterface{
private:
const sf::Vector3f coscia_Dim = {80, 200, 80};
const sf::Color coscia_Col = sf::Color::Yellow;
public:
Coscia(rb::Vector3 coords, _Float16 mass);
+9 -3
View File
@@ -17,11 +17,17 @@ enum class ReferencePlane {
class PieceInterface{
protected:
//std::vector<JointInterface*> joints;
void initialize_shapes(sf::Vector3f dim){
shapeXZ = new sf::RectangleShape({dim.x, dim.y});
shapeYZ = new sf::RectangleShape({dim.z, dim.y});
shapeXZ->setOrigin({dim.x/2,dim.y/2});
shapeYZ->setOrigin({dim.z/2,dim.y/2});
shapeXZ->setFillColor(color);
shapeYZ->setFillColor(color);
}
public:
sf::Shape* shape;
sf::Vector2f size;
sf::Shape* shapeXZ, *shapeYZ;
rb::Vector3 globalPos;
rb::rigidbody body;
sf::Color color;
+5 -2
View File
@@ -3,11 +3,13 @@
#ifndef SENSORE_H
#define SENSORE_H
const sf::Vector2f sensore_Dim = {30, 60};
const sf::Color sensore_Col = sf::Color::Red;
class Sensore : public PieceInterface{
private:
const sf::Vector3f sensore_Dim = {30, 60, 30};
const sf::Color sensore_Col = sf::Color::Red;
std::vector<std::vector<float>> accData;
std::vector<std::vector<float>> gData;
std::vector<std::vector<float>> rotData;
@@ -21,6 +23,7 @@ class Sensore : public PieceInterface{
//funzioni ausiliarie
void calcRotWithG(unsigned int index);
public:
Sensore(rb::Vector3 coords, _Float16 mass);
+21
View File
@@ -0,0 +1,21 @@
#include "piece_interface.hpp"
#ifndef TORSO_H
#define TORSO_H
class Torso : public PieceInterface{
private:
const sf::Vector3f torso_Dim = {100, 100, 250};
const sf::Color torso_Col = sf::Color::Red;
public:
Torso(rb::Vector3 coords, _Float16 mass);
~Torso();
void update(sf::Clock cl) override;
sf::Shape* draw(ReferencePlane plane) override;
};
#endif
+20 -10
View File
@@ -1,17 +1,18 @@
#include "../headers/caviglia.hpp"
Caviglia::Caviglia(rb::Vector3 coords, _Float16 mass){
size = caviglia_Dim;
rb::Vector3 com = {size.x/2,0, size.y/2};
rb::Vector3 com = {caviglia_Dim.x/2,caviglia_Dim.x/2, caviglia_Dim.y/2};
body = rb::rigidbody(coords, com, mass);
color = caviglia_Col;
shape = new sf::RectangleShape(size);
shape->setOrigin({size.x/2,size.y/2});
globalPos = {0,0,0};
initialize_shapes(caviglia_Dim);
}
Caviglia::~Caviglia(){
delete shape;
delete shapeXZ;
delete shapeYZ;
}
void Caviglia::update(sf::Clock cl){
@@ -19,22 +20,31 @@ void Caviglia::update(sf::Clock cl){
}
sf::Shape* Caviglia::draw(ReferencePlane plane){
shape->setFillColor(color);
rb::Vector3 tmpPos = body.getPos();
rb::Vector3_s tmpRot = body.getRot();
switch (plane)
{
case ReferencePlane::XZ:
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
{
sf::Shape* shape = shapeXZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[2])));
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
return shape;}
break;
case ReferencePlane::YZ:
{
sf::Shape* shape = shapeYZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[1])));
shape->setPosition({tmpPos[1]+globalPos[1],tmpPos[2]+globalPos[2]});
return shape;}
break;
default:
break;
}
return shape;
return nullptr;
}
+19 -9
View File
@@ -1,17 +1,16 @@
#include "../headers/coscia.hpp"
Coscia::Coscia(rb::Vector3 coords, _Float16 mass){
size = coscia_Dim;
rb::Vector3 com = {size.x/2,0, size.y/2};
rb::Vector3 com = {coscia_Dim.x/2,coscia_Dim.z/2,coscia_Dim.y/2};
body = rb::rigidbody(coords, com, mass);
color = coscia_Col;
shape = new sf::RectangleShape(size);
shape->setOrigin({size.x/2,size.y/2});
globalPos = {0,0,0};
initialize_shapes(coscia_Dim);
}
Coscia::~Coscia(){
delete shape;
delete shapeXZ;
delete shapeYZ;
}
void Coscia::update(sf::Clock cl){
@@ -19,22 +18,33 @@ void Coscia::update(sf::Clock cl){
}
sf::Shape* Coscia::draw(ReferencePlane plane){
shape->setFillColor(color);
rb::Vector3 tmpPos = body.getPos();
rb::Vector3_s tmpRot = body.getRot();
switch (plane)
{
case ReferencePlane::XZ:
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
{
sf::Shape* shape = shapeXZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[2])));
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
return shape;}
break;
case ReferencePlane::YZ:
{
sf::Shape* shape = shapeYZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[1])));
shape->setPosition({tmpPos[1]+globalPos[1],tmpPos[2]+globalPos[2]});
return shape;}
break;
default:
break;
}
return shape;
return nullptr;
}
+25 -14
View File
@@ -2,12 +2,11 @@
Sensore::Sensore(rb::Vector3 coords, _Float16 mass){
size = sensore_Dim;
rb::Vector3 com = {size.x/2,0, size.y/2};
rb::Vector3 com = {sensore_Dim.x/2,sensore_Dim.z/2, sensore_Dim.y/2};
body = rb::rigidbody(coords, com, mass);
color = sensore_Col;
shape = new sf::RectangleShape(size);
globalPos = {0,0,0};
initialize_shapes(sensore_Dim);
}
Sensore::Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, unsigned int dataIntvl, std::vector<std::vector<float>> data) : Sensore(coords, mass){
@@ -18,7 +17,8 @@ Sensore::Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, unsigned in
Sensore::~Sensore(){
delete shape;
delete shapeXZ;
delete shapeYZ;
}
void Sensore::initCSV(std::vector<std::vector<float>> data){
@@ -48,6 +48,8 @@ void Sensore::update(sf::Clock cl){
//calcolo la posizione e velocità
calcRotWithG(dataPos);
body.setAcc(rb::Vector3{accData[dataPos]});
body.step(cl);
}
@@ -55,30 +57,33 @@ void Sensore::update(sf::Clock cl){
}
sf::Shape* Sensore::draw(ReferencePlane plane){
shape->setFillColor(color);
shape->setOrigin({sensore_Dim.x/2, sensore_Dim.y/2});
rb::Vector3_s tmpRot = body.getRot();
rb::Vector3 tmpPos = body.getPos();
switch (plane)
{
case ReferencePlane::XZ:
{
sf::Shape* shape = shapeXZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[2])));
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
return shape;}
break;
case ReferencePlane::YZ:
{
sf::Shape* shape = shapeYZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[1])));
shape->setPosition({tmpPos[1]+globalPos[1],tmpPos[2]+globalPos[2]});
return shape;}
break;
default:
break;
}
return shape;
return nullptr;
}
@@ -99,4 +104,10 @@ void Sensore::calcRotWithG(unsigned int index){ // calcolo rotazione con valori
body.setRot(rb::Vector3_s{_Float16( tmpAX),_Float16( tmpAY),_Float16( tmpAZ) });
}
}
/*
void Sensore::calcRotWithConstraint(){
};*/
/////////////// cinematica inversa
+50
View File
@@ -0,0 +1,50 @@
#include "../headers/torso.hpp"
Torso::Torso(rb::Vector3 coords, _Float16 mass){
rb::Vector3 com = {torso_Dim.x/2, torso_Dim.y/2, torso_Dim.z/2};
body = rb::rigidbody(coords,com, mass);
color = torso_Col;
globalPos = {0,0,0};
initialize_shapes(torso_Dim);
}
Torso::~Torso(){
delete shapeXZ;
delete shapeYZ;
}
void Torso::update(sf::Clock cl){
}
sf::Shape* Torso::draw(ReferencePlane plane){
rb::Vector3_s tmpRot = body.getRot();
rb::Vector3 tmpPos = body.getPos();
switch (plane)
{
case ReferencePlane::XZ:
{
sf::Shape* shape = shapeXZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[2])));
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
return shape;}
break;
case ReferencePlane::YZ:
{
sf::Shape* shape = shapeYZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[1])));
shape->setPosition({tmpPos[1]+globalPos[1],tmpPos[2]+globalPos[2]});
return shape;}
break;
default:
break;
}
return nullptr;
}