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
+1 -1
View File
@@ -23,7 +23,7 @@ FetchContent_MakeAvailable(glm)
set(METHODS_PATH "./src/*/methods/*.cpp") set(METHODS_PATH "./src/*/methods/*.cpp")
set(VERSION "V2") set(VERSION "V3")
file(GLOB_RECURSE METHODS_SRC "${METHODS_PATH}") file(GLOB_RECURSE METHODS_SRC "${METHODS_PATH}")
add_executable(main${VERSION} ./src/testMain.cpp ${METHODS_SRC} ) add_executable(main${VERSION} ./src/testMain.cpp ${METHODS_SRC} )
+9 -3
View File
@@ -22,10 +22,16 @@ Per spostare l'intera scena si tiene premuto il tasto centrale del mouse.
- Aggiustato calcolo dei pivot implementando le rotazioni con algebra affine e glm - Aggiustato calcolo dei pivot implementando le rotazioni con algebra affine e glm
- Aggiuta classe caviglia (per differenziarla dalla coscia) - Aggiuta classe caviglia (per differenziarla dalla coscia)
Per compliare: ## Nella versione v0.3:
- Applicato refactoring delle classi pieces
- Aggiunta pezzo torso
- Nel testMain vengono agganciate caviglia e coscia al nuovo torso
# Per compliare:
cmake --build cmake --build
Per lanciare: # Per lanciare:
./build/bin/mainV2 ./build/bin/mainV3
@@ -573,9 +573,9 @@
}, },
{ {
"directoryIndex" : 0, "directoryIndex" : 0,
"id" : "mainV2::@6890427a1f51a3e7e1df", "id" : "mainV3::@6890427a1f51a3e7e1df",
"jsonFile" : "target-mainV2-Debug-13e85d69c1816e9e6763.json", "jsonFile" : "target-mainV3-Debug-ee31761362aa79611c23.json",
"name" : "mainV2", "name" : "mainV3",
"projectIndex" : 0 "projectIndex" : 0
}, },
{ {
@@ -26,7 +26,7 @@
"objects" : "objects" :
[ [
{ {
"jsonFile" : "codemodel-v2-dbb57b2013933c842c1b.json", "jsonFile" : "codemodel-v2-48a6e2c377bb606c3455.json",
"kind" : "codemodel", "kind" : "codemodel",
"version" : "version" :
{ {
@@ -99,7 +99,7 @@
} }
}, },
{ {
"jsonFile" : "codemodel-v2-dbb57b2013933c842c1b.json", "jsonFile" : "codemodel-v2-48a6e2c377bb606c3455.json",
"kind" : "codemodel", "kind" : "codemodel",
"version" : "version" :
{ {
@@ -2,7 +2,7 @@
"artifacts" : "artifacts" :
[ [
{ {
"path" : "bin/mainV2" "path" : "bin/mainV3"
} }
], ],
"backtrace" : 1, "backtrace" : 1,
@@ -168,7 +168,9 @@
3, 3,
4, 4,
5, 5,
6 6,
7,
8
] ]
} }
], ],
@@ -191,7 +193,7 @@
"id" : "glm::@ce54d98d7b326a3e12a8" "id" : "glm::@ce54d98d7b326a3e12a8"
} }
], ],
"id" : "mainV2::@6890427a1f51a3e7e1df", "id" : "mainV3::@6890427a1f51a3e7e1df",
"link" : "link" :
{ {
"commandFragments" : "commandFragments" :
@@ -294,8 +296,8 @@
"id" : "glm::@ce54d98d7b326a3e12a8" "id" : "glm::@ce54d98d7b326a3e12a8"
} }
], ],
"name" : "mainV2", "name" : "mainV3",
"nameOnDisk" : "mainV2", "nameOnDisk" : "mainV3",
"paths" : "paths" :
{ {
"build" : ".", "build" : ".",
@@ -313,7 +315,9 @@
3, 3,
4, 4,
5, 5,
6 6,
7,
8
] ]
} }
], ],
@@ -343,6 +347,12 @@
"path" : "src/joints/methods/rigid_joint_class.cpp", "path" : "src/joints/methods/rigid_joint_class.cpp",
"sourceGroupIndex" : 0 "sourceGroupIndex" : 0
}, },
{
"backtrace" : 1,
"compileGroupIndex" : 0,
"path" : "src/pieces/methods/caviglia_class.cpp",
"sourceGroupIndex" : 0
},
{ {
"backtrace" : 1, "backtrace" : 1,
"compileGroupIndex" : 0, "compileGroupIndex" : 0,
@@ -355,6 +365,12 @@
"path" : "src/pieces/methods/sensore_class.cpp", "path" : "src/pieces/methods/sensore_class.cpp",
"sourceGroupIndex" : 0 "sourceGroupIndex" : 0
}, },
{
"backtrace" : 1,
"compileGroupIndex" : 0,
"path" : "src/pieces/methods/torso.cpp",
"sourceGroupIndex" : 0
},
{ {
"backtrace" : 1, "backtrace" : 1,
"compileGroupIndex" : 0, "compileGroupIndex" : 0,
BIN
View File
Binary file not shown.
+1
View File
@@ -4,5 +4,6 @@
#include "pieces/headers/coscia.hpp" #include "pieces/headers/coscia.hpp"
#include "pieces/headers/caviglia.hpp" #include "pieces/headers/caviglia.hpp"
#include "pieces/headers/sensore.hpp" #include "pieces/headers/sensore.hpp"
#include "pieces/headers/torso.hpp"
#include "joints/headers/rigid_joint.hpp" #include "joints/headers/rigid_joint.hpp"
#include "joints/headers/pivot_joint.hpp" #include "joints/headers/pivot_joint.hpp"
+4 -3
View File
@@ -3,11 +3,12 @@
#ifndef CAVIGLIA_H #ifndef CAVIGLIA_H
#define 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{ 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: public:
Caviglia(rb::Vector3 coords, _Float16 mass); Caviglia(rb::Vector3 coords, _Float16 mass);
+4 -2
View File
@@ -3,11 +3,13 @@
#ifndef COSCIA_H #ifndef COSCIA_H
#define COSCIA_H #define COSCIA_H
const sf::Vector2f coscia_Dim = {80, 200};
const sf::Color coscia_Col = sf::Color::Yellow;
class Coscia : public PieceInterface{ class Coscia : public PieceInterface{
private:
const sf::Vector3f coscia_Dim = {80, 200, 80};
const sf::Color coscia_Col = sf::Color::Yellow;
public: public:
Coscia(rb::Vector3 coords, _Float16 mass); Coscia(rb::Vector3 coords, _Float16 mass);
+9 -3
View File
@@ -17,11 +17,17 @@ enum class ReferencePlane {
class PieceInterface{ class PieceInterface{
protected: 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: public:
sf::Shape* shape; sf::Shape* shapeXZ, *shapeYZ;
sf::Vector2f size;
rb::Vector3 globalPos; rb::Vector3 globalPos;
rb::rigidbody body; rb::rigidbody body;
sf::Color color; sf::Color color;
+5 -2
View File
@@ -3,11 +3,13 @@
#ifndef SENSORE_H #ifndef SENSORE_H
#define SENSORE_H #define SENSORE_H
const sf::Vector2f sensore_Dim = {30, 60};
const sf::Color sensore_Col = sf::Color::Red;
class Sensore : public PieceInterface{ class Sensore : public PieceInterface{
private: 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>> accData;
std::vector<std::vector<float>> gData; std::vector<std::vector<float>> gData;
std::vector<std::vector<float>> rotData; std::vector<std::vector<float>> rotData;
@@ -22,6 +24,7 @@ class Sensore : public PieceInterface{
//funzioni ausiliarie //funzioni ausiliarie
void calcRotWithG(unsigned int index); void calcRotWithG(unsigned int index);
public: public:
Sensore(rb::Vector3 coords, _Float16 mass); Sensore(rb::Vector3 coords, _Float16 mass);
Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, unsigned int dataIntvl, std::vector<std::vector<float>> data); Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, unsigned int dataIntvl, std::vector<std::vector<float>> data);
+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
+19 -9
View File
@@ -1,17 +1,18 @@
#include "../headers/caviglia.hpp" #include "../headers/caviglia.hpp"
Caviglia::Caviglia(rb::Vector3 coords, _Float16 mass){ Caviglia::Caviglia(rb::Vector3 coords, _Float16 mass){
size = caviglia_Dim; rb::Vector3 com = {caviglia_Dim.x/2,caviglia_Dim.x/2, caviglia_Dim.y/2};
rb::Vector3 com = {size.x/2,0, size.y/2};
body = rb::rigidbody(coords, com, mass); body = rb::rigidbody(coords, com, mass);
color = caviglia_Col; color = caviglia_Col;
shape = new sf::RectangleShape(size);
shape->setOrigin({size.x/2,size.y/2});
globalPos = {0,0,0}; globalPos = {0,0,0};
initialize_shapes(caviglia_Dim);
} }
Caviglia::~Caviglia(){ Caviglia::~Caviglia(){
delete shape; delete shapeXZ;
delete shapeYZ;
} }
void Caviglia::update(sf::Clock cl){ void Caviglia::update(sf::Clock cl){
@@ -19,22 +20,31 @@ void Caviglia::update(sf::Clock cl){
} }
sf::Shape* Caviglia::draw(ReferencePlane plane){ sf::Shape* Caviglia::draw(ReferencePlane plane){
shape->setFillColor(color);
rb::Vector3 tmpPos = body.getPos(); rb::Vector3 tmpPos = body.getPos();
rb::Vector3_s tmpRot = body.getRot(); rb::Vector3_s tmpRot = body.getRot();
switch (plane) switch (plane)
{ {
case ReferencePlane::XZ: 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->setRotation(sf::Angle(sf::radians(tmpRot[2])));
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
return shape;}
break; 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: default:
break; break;
} }
return nullptr;
return shape;
} }
+18 -8
View File
@@ -1,17 +1,16 @@
#include "../headers/coscia.hpp" #include "../headers/coscia.hpp"
Coscia::Coscia(rb::Vector3 coords, _Float16 mass){ Coscia::Coscia(rb::Vector3 coords, _Float16 mass){
size = coscia_Dim; rb::Vector3 com = {coscia_Dim.x/2,coscia_Dim.z/2,coscia_Dim.y/2};
rb::Vector3 com = {size.x/2,0, size.y/2};
body = rb::rigidbody(coords, com, mass); body = rb::rigidbody(coords, com, mass);
color = coscia_Col; color = coscia_Col;
shape = new sf::RectangleShape(size);
shape->setOrigin({size.x/2,size.y/2});
globalPos = {0,0,0}; globalPos = {0,0,0};
initialize_shapes(coscia_Dim);
} }
Coscia::~Coscia(){ Coscia::~Coscia(){
delete shape; delete shapeXZ;
delete shapeYZ;
} }
void Coscia::update(sf::Clock cl){ void Coscia::update(sf::Clock cl){
@@ -19,22 +18,33 @@ void Coscia::update(sf::Clock cl){
} }
sf::Shape* Coscia::draw(ReferencePlane plane){ sf::Shape* Coscia::draw(ReferencePlane plane){
shape->setFillColor(color);
rb::Vector3 tmpPos = body.getPos(); rb::Vector3 tmpPos = body.getPos();
rb::Vector3_s tmpRot = body.getRot(); rb::Vector3_s tmpRot = body.getRot();
switch (plane) switch (plane)
{ {
case ReferencePlane::XZ: 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->setRotation(sf::Angle(sf::radians(tmpRot[2])));
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
return shape;}
break; 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: default:
break; break;
} }
return shape; return nullptr;
} }
+24 -13
View File
@@ -2,12 +2,11 @@
Sensore::Sensore(rb::Vector3 coords, _Float16 mass){ Sensore::Sensore(rb::Vector3 coords, _Float16 mass){
size = sensore_Dim; rb::Vector3 com = {sensore_Dim.x/2,sensore_Dim.z/2, sensore_Dim.y/2};
rb::Vector3 com = {size.x/2,0, size.y/2};
body = rb::rigidbody(coords, com, mass); body = rb::rigidbody(coords, com, mass);
color = sensore_Col; color = sensore_Col;
shape = new sf::RectangleShape(size);
globalPos = {0,0,0}; 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){ 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(){ Sensore::~Sensore(){
delete shape; delete shapeXZ;
delete shapeYZ;
} }
void Sensore::initCSV(std::vector<std::vector<float>> data){ void Sensore::initCSV(std::vector<std::vector<float>> data){
@@ -48,6 +48,8 @@ void Sensore::update(sf::Clock cl){
//calcolo la posizione e velocità //calcolo la posizione e velocità
calcRotWithG(dataPos); calcRotWithG(dataPos);
body.setAcc(rb::Vector3{accData[dataPos]}); body.setAcc(rb::Vector3{accData[dataPos]});
body.step(cl); body.step(cl);
} }
@@ -55,30 +57,33 @@ void Sensore::update(sf::Clock cl){
} }
sf::Shape* Sensore::draw(ReferencePlane plane){ 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_s tmpRot = body.getRot();
rb::Vector3 tmpPos = body.getPos(); rb::Vector3 tmpPos = body.getPos();
switch (plane) switch (plane)
{ {
case ReferencePlane::XZ: case ReferencePlane::XZ:
{
sf::Shape* shape = shapeXZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[2]))); shape->setRotation(sf::Angle(sf::radians(tmpRot[2])));
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[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; break;
default: default:
break; break;
} }
return nullptr;
return shape;
} }
@@ -100,3 +105,9 @@ void Sensore::calcRotWithG(unsigned int index){ // calcolo rotazione con valori
body.setRot(rb::Vector3_s{_Float16( tmpAX),_Float16( tmpAY),_Float16( tmpAZ) }); 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;
}
+8 -3
View File
@@ -22,6 +22,7 @@ struct State
sf::Vector2f cameraOffset = {0.,0.}; sf::Vector2f cameraOffset = {0.,0.};
sf::Clock clock; sf::Clock clock;
ReferencePlane selectedPlane = ReferencePlane::XZ;
int selected = -1; int selected = -1;
@@ -72,6 +73,12 @@ void handle(const sf::Event::TextEntered &textEnter, State &gs)
void handle(const sf::Event::KeyPressed &keyPressed, State &gs) void handle(const sf::Event::KeyPressed &keyPressed, State &gs)
{ {
if (keyPressed.scancode == sf::Keyboard::Scancode::Space){
if (gs.selectedPlane == ReferencePlane::XZ)
gs.selectedPlane = ReferencePlane::YZ;
else
gs.selectedPlane = ReferencePlane::XZ;
}
} }
void handle(const sf::Event::MouseMoved &mouseMoved, State &gs) void handle(const sf::Event::MouseMoved &mouseMoved, State &gs)
@@ -113,7 +120,6 @@ void handle(const sf::Event::MouseButtonPressed &mouseBP, State &gs)
if (dist(pos,mouseBP.position) < 20){ if (dist(pos,mouseBP.position) < 20){
gs.selected = i; gs.selected = i;
break;
} }
i++; i++;
} }
@@ -127,7 +133,6 @@ void handle(const sf::Event::MouseButtonPressed &mouseBP, State &gs)
if (dist(pos,mouseBP.position) < 20){ if (dist(pos,mouseBP.position) < 20){
gs.selected = i; gs.selected = i;
break;
} }
i++; i++;
} }
@@ -173,7 +178,7 @@ void doGraphics(State &gs)
doGUI(gs); doGUI(gs);
for(PieceInterface* p: gs.pieces){ for(PieceInterface* p: gs.pieces){
gs.window.draw(*p->draw(ReferencePlane::XZ)); gs.window.draw(*p->draw(gs.selectedPlane));
} }
// TODO: add here code to display shapes in your canvas // TODO: add here code to display shapes in your canvas
+5 -1
View File
@@ -40,7 +40,7 @@ int main() {
gs.pieces.push_back(new Coscia (rb::Vector3{300,10,300},2)); gs.pieces.push_back(new Coscia (rb::Vector3{300,10,300},2));
gs.pieces.push_back(new Sensore (rb::Vector3{300,300,300},_Float16( 0.2 ),900,3000,coscia)); gs.pieces.push_back(new Sensore (rb::Vector3{300,300,300},_Float16( 0.2 ),900,3000,coscia));
gs.pieces.push_back(new Coscia (rb::Vector3{300,10,500},1)); gs.pieces.push_back(new Caviglia (rb::Vector3{300,10,500},1));
gs.pieces[1]->body.setRot({0,0,0}); gs.pieces[1]->body.setRot({0,0,0});
@@ -49,6 +49,8 @@ int main() {
const auto& caviglia = processor.getData(); const auto& caviglia = processor.getData();
gs.pieces.push_back(new Sensore (rb::Vector3{300,700,500},_Float16( 0.2 ),900,3000,caviglia)); gs.pieces.push_back(new Sensore (rb::Vector3{300,700,500},_Float16( 0.2 ),900,3000,caviglia));
gs.pieces.push_back(new Torso(rb::Vector3{300,400,150},2));
// modifico la rotazione relativa della gamba // modifico la rotazione relativa della gamba
gs.pieces[1]->body.setRot({0,0,_Float16 (1.6)}); gs.pieces[1]->body.setRot({0,0,_Float16 (1.6)});
gs.pieces[3]->body.setRot({0,0,_Float16 (1.7)}); gs.pieces[3]->body.setRot({0,0,_Float16 (1.7)});
@@ -59,6 +61,8 @@ int main() {
gs.joints.push_back(new RigidJoint(gs.pieces[1], {gs.pieces[0]})); 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 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.joints.push_back(new RigidJoint(gs.pieces[3], {gs.pieces[2]}));
gs.joints.push_back(new PivotJoint(gs.pieces[4], {gs.pieces[1]}, rb::Vector3{0,0,50}));
printf("Ho costruito tutto!\n"); printf("Ho costruito tutto!\n");
} }