Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5169bc4096 |
+1
-1
@@ -23,7 +23,7 @@ FetchContent_MakeAvailable(glm)
|
||||
set(METHODS_PATH "./src/*/methods/*.cpp")
|
||||
|
||||
|
||||
set(VERSION "V2")
|
||||
set(VERSION "V3")
|
||||
|
||||
file(GLOB_RECURSE METHODS_SRC "${METHODS_PATH}")
|
||||
add_executable(main${VERSION} ./src/testMain.cpp ${METHODS_SRC} )
|
||||
|
||||
@@ -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
|
||||
- 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
|
||||
|
||||
Per lanciare:
|
||||
# Per lanciare:
|
||||
|
||||
./build/bin/mainV2
|
||||
./build/bin/mainV3
|
||||
|
||||
+3
-3
@@ -573,9 +573,9 @@
|
||||
},
|
||||
{
|
||||
"directoryIndex" : 0,
|
||||
"id" : "mainV2::@6890427a1f51a3e7e1df",
|
||||
"jsonFile" : "target-mainV2-Debug-13e85d69c1816e9e6763.json",
|
||||
"name" : "mainV2",
|
||||
"id" : "mainV3::@6890427a1f51a3e7e1df",
|
||||
"jsonFile" : "target-mainV3-Debug-ee31761362aa79611c23.json",
|
||||
"name" : "mainV3",
|
||||
"projectIndex" : 0
|
||||
},
|
||||
{
|
||||
+2
-2
@@ -26,7 +26,7 @@
|
||||
"objects" :
|
||||
[
|
||||
{
|
||||
"jsonFile" : "codemodel-v2-dbb57b2013933c842c1b.json",
|
||||
"jsonFile" : "codemodel-v2-48a6e2c377bb606c3455.json",
|
||||
"kind" : "codemodel",
|
||||
"version" :
|
||||
{
|
||||
@@ -99,7 +99,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"jsonFile" : "codemodel-v2-dbb57b2013933c842c1b.json",
|
||||
"jsonFile" : "codemodel-v2-48a6e2c377bb606c3455.json",
|
||||
"kind" : "codemodel",
|
||||
"version" :
|
||||
{
|
||||
+22
-6
@@ -2,7 +2,7 @@
|
||||
"artifacts" :
|
||||
[
|
||||
{
|
||||
"path" : "bin/mainV2"
|
||||
"path" : "bin/mainV3"
|
||||
}
|
||||
],
|
||||
"backtrace" : 1,
|
||||
@@ -168,7 +168,9 @@
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6
|
||||
6,
|
||||
7,
|
||||
8
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -191,7 +193,7 @@
|
||||
"id" : "glm::@ce54d98d7b326a3e12a8"
|
||||
}
|
||||
],
|
||||
"id" : "mainV2::@6890427a1f51a3e7e1df",
|
||||
"id" : "mainV3::@6890427a1f51a3e7e1df",
|
||||
"link" :
|
||||
{
|
||||
"commandFragments" :
|
||||
@@ -294,8 +296,8 @@
|
||||
"id" : "glm::@ce54d98d7b326a3e12a8"
|
||||
}
|
||||
],
|
||||
"name" : "mainV2",
|
||||
"nameOnDisk" : "mainV2",
|
||||
"name" : "mainV3",
|
||||
"nameOnDisk" : "mainV3",
|
||||
"paths" :
|
||||
{
|
||||
"build" : ".",
|
||||
@@ -313,7 +315,9 @@
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6
|
||||
6,
|
||||
7,
|
||||
8
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -343,6 +347,12 @@
|
||||
"path" : "src/joints/methods/rigid_joint_class.cpp",
|
||||
"sourceGroupIndex" : 0
|
||||
},
|
||||
{
|
||||
"backtrace" : 1,
|
||||
"compileGroupIndex" : 0,
|
||||
"path" : "src/pieces/methods/caviglia_class.cpp",
|
||||
"sourceGroupIndex" : 0
|
||||
},
|
||||
{
|
||||
"backtrace" : 1,
|
||||
"compileGroupIndex" : 0,
|
||||
@@ -355,6 +365,12 @@
|
||||
"path" : "src/pieces/methods/sensore_class.cpp",
|
||||
"sourceGroupIndex" : 0
|
||||
},
|
||||
{
|
||||
"backtrace" : 1,
|
||||
"compileGroupIndex" : 0,
|
||||
"path" : "src/pieces/methods/torso.cpp",
|
||||
"sourceGroupIndex" : 0
|
||||
},
|
||||
{
|
||||
"backtrace" : 1,
|
||||
"compileGroupIndex" : 0,
|
||||
Executable
BIN
Binary file not shown.
@@ -4,5 +4,6 @@
|
||||
#include "pieces/headers/coscia.hpp"
|
||||
#include "pieces/headers/caviglia.hpp"
|
||||
#include "pieces/headers/sensore.hpp"
|
||||
#include "pieces/headers/torso.hpp"
|
||||
#include "joints/headers/rigid_joint.hpp"
|
||||
#include "joints/headers/pivot_joint.hpp"
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -22,6 +24,7 @@ class Sensore : public PieceInterface{
|
||||
//funzioni ausiliarie
|
||||
void calcRotWithG(unsigned int index);
|
||||
|
||||
|
||||
public:
|
||||
Sensore(rb::Vector3 coords, _Float16 mass);
|
||||
Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, unsigned int dataIntvl, std::vector<std::vector<float>> data);
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) });
|
||||
|
||||
}
|
||||
/*
|
||||
void Sensore::calcRotWithConstraint(){
|
||||
|
||||
};*/
|
||||
|
||||
/////////////// cinematica inversa
|
||||
@@ -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
@@ -22,6 +22,7 @@ struct State
|
||||
sf::Vector2f cameraOffset = {0.,0.};
|
||||
|
||||
sf::Clock clock;
|
||||
ReferencePlane selectedPlane = ReferencePlane::XZ;
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
@@ -113,7 +120,6 @@ void handle(const sf::Event::MouseButtonPressed &mouseBP, State &gs)
|
||||
|
||||
if (dist(pos,mouseBP.position) < 20){
|
||||
gs.selected = i;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -127,7 +133,6 @@ void handle(const sf::Event::MouseButtonPressed &mouseBP, State &gs)
|
||||
|
||||
if (dist(pos,mouseBP.position) < 20){
|
||||
gs.selected = i;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -173,7 +178,7 @@ void doGraphics(State &gs)
|
||||
doGUI(gs);
|
||||
|
||||
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
|
||||
|
||||
+5
-1
@@ -40,7 +40,7 @@ int main() {
|
||||
|
||||
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 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});
|
||||
|
||||
@@ -49,6 +49,8 @@ int main() {
|
||||
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 Torso(rb::Vector3{300,400,150},2));
|
||||
|
||||
// modifico la rotazione relativa della gamba
|
||||
gs.pieces[1]->body.setRot({0,0,_Float16 (1.6)});
|
||||
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 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 PivotJoint(gs.pieces[4], {gs.pieces[1]}, rb::Vector3{0,0,50}));
|
||||
|
||||
|
||||
printf("Ho costruito tutto!\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user