8 Commits

17 changed files with 105 additions and 35 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ target_compile_options(common INTERFACE
set(METHODS_PATH "./src/*/methods/*.cpp")
set(VERSION "V6")
set(VERSION "V7")
file(GLOB_RECURSE METHODS_SRC "${METHODS_PATH}")
add_executable(main${VERSION} ./src/testMain.cpp ${METHODS_SRC} )
+8 -1
View File
@@ -43,10 +43,17 @@ Per spostare l'intera scena si tiene premuto il tasto centrale del mouse.
- Modifica di sfml_util per gestire le collezioni
- Aggiunta modalità debug
## Nella versione v0.7
- Aggiunta impostazione di trasparenza dei pezzi
- Aggiustato cambio direzione della gamba (sulla visualizzazione dei piani XZ e -XZ)
- Aggiunto controllo trasparenza delle collezioni
- Modificato lower_body per gestire la trasparenza della gamba più lontana
- Ridimensionato bacino per migiore visualizzazione
# Per compilare:
cmake --build
# Per lanciare:
./build/bin/mainV6
./build/bin/mainV7
Binary file not shown.
Binary file not shown.
@@ -13,6 +13,7 @@ struct collection{
class CollectionInterface{
public:
virtual collection create(ReferencePlane plane) = 0;
virtual bool setTransparency(float alpha) = 0;
virtual ~CollectionInterface(){};
};
+2
View File
@@ -13,6 +13,8 @@ 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);
bool setTransparency(float alpha) override;
};
#endif
+1 -1
View File
@@ -28,7 +28,7 @@ public:
~Lower_Body();
void setVisibility(bool c);
void setTransparency(float t);
bool setTransparency(float alpha) override;
collection create(ReferencePlane plane) override;
};
+21 -2
View File
@@ -15,8 +15,8 @@ Gamba::Gamba(rb::Vector3 pos, unsigned int* dataPos, std::string cosciaData, std
sensori.push_back(new Sensore (rb::Vector3{pos[0],pos[1],pos[2]+200},_Float16( 0.2 ),dataPos,caviglia));
// modifico la rotazione relativa della gamba
sensori[0]->body.setRot({_Float16 (1.3),_Float16 (1.7),0});
sensori[1]->body.setRot({_Float16 (1.8),_Float16 (1.7),0});
sensori[0]->body.setRot({_Float16 (1.5708),_Float16 (1.5708),0});
sensori[1]->body.setRot({_Float16 (1.5708),_Float16 (1.5708),0});
joints.push_back(new RigidJoint(sensori[0], {pezzi[0]}));
joints.push_back(new PivotJoint(sensori[0], {sensori[1]}, rb::Vector3{0,0,100}));
@@ -47,4 +47,23 @@ 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);
}
}
bool Gamba::setTransparency(float alpha){
for (auto i : pezzi){
if (!i->setTransparency(alpha)) return false;
}
for (auto i : sensori){
if (!i->setTransparency(alpha)) return false;
}
return true;
}
+28 -6
View File
@@ -3,28 +3,43 @@
Lower_Body::Lower_Body(rb::Vector3 pos,std::vector<gamba_data> data){
if (data.size() != 2) throw "Lower_Body_Error: data vector size must be 2";
sx = new Gamba({pos[0],pos[1],pos[2]+150},data[0].dataPos,data[0].cosciaData,data[0].cavigliaData);
dx = new Gamba({pos[0],pos[1]+200,pos[2]+150},data[1].dataPos,data[1].cosciaData,data[1].cavigliaData);
t = new Torso({pos[0],pos[1]+100,pos[2]},_Float16(3.0));
sx = new Gamba({pos[0],pos[1]-60,pos[2]+150},data[0].dataPos,data[0].cosciaData,data[0].cavigliaData);
dx = new Gamba({pos[0],pos[1]+60,pos[2]+150},data[1].dataPos,data[1].cosciaData,data[1].cavigliaData);
t = new Torso({pos[0],pos[1],pos[2]},_Float16(3.0));
PieceInterface* psx = sx->getJointPiece();
PieceInterface* pdx = dx->getJointPiece();
jsx = new PivotJoint(t, {psx}, rb::Vector3{0,-100,50});
jdx = new PivotJoint(t, {pdx}, rb::Vector3{0,100,50});
jsx = new PivotJoint(t, {psx}, rb::Vector3{0,-60,50});
jdx = new PivotJoint(t, {pdx}, rb::Vector3{0,60,50});
}
collection Lower_Body::create(ReferencePlane plane){
collection coll;
sx->setTransparency(1);
dx->setTransparency(1);
switch (plane)
{
case ReferencePlane::XZ: case ReferencePlane::XZN:
case ReferencePlane::XZN:
dx->setTransparency(0.5);
dx->setDirection(Direction::L);
sx->setDirection(Direction::R);
coll = coll + dx->create(plane);
coll = coll + sx->create(plane);
break;
case ReferencePlane::XZ:
sx->setTransparency(0.5);
dx->setDirection(Direction::R);
sx->setDirection(Direction::L);
coll = coll + sx->create(plane);
coll = coll + dx->create(plane);
break;
case ReferencePlane::YZ:
sx->setDirection(Direction::R);
dx->setDirection(Direction::L);
coll = coll + dx->create(plane);
coll = coll + sx->create(plane);
break;
@@ -50,4 +65,11 @@ Lower_Body::~Lower_Body(){
void Lower_Body::setVisibility(bool c){
}
bool Lower_Body::setTransparency(float alpha){
if (!sx->setTransparency(alpha)) return false;
dx->setTransparency(alpha);
t->setTransparency(alpha);
return true;
}
+15 -1
View File
@@ -13,6 +13,11 @@ enum class ReferencePlane {
XZN
};
enum class Direction {
L,
R
};
//classi
class PieceInterface{
protected:
@@ -25,16 +30,25 @@ class PieceInterface{
shapeXZ->setFillColor(color);
shapeYZ->setFillColor(color);
}
Direction direction = Direction::L;
public:
sf::Shape* shapeXZ, *shapeYZ;
rb::Vector3 globalPos;
rb::rigidbody body;
sf::Color color;
float transparency = 1.0; //canale alpha del pezzo
virtual void update(sf::Clock cl) = 0;
virtual sf::Shape* draw(ReferencePlane plane) = 0;
virtual ~PieceInterface(){}
virtual void setDirection(Direction dir){
direction = dir;
}
virtual bool setTransparency(float alpha){
if (alpha < 0 || alpha > 1) return false;
transparency = alpha;
return true;
}
};
+1 -1
View File
@@ -8,7 +8,7 @@
class Torso : public PieceInterface{
private:
const sf::Vector3f torso_Dim = {100, 100, 250};
const sf::Vector3f torso_Dim = {100, 100, 150};
const sf::Color torso_Col = sf::Color::Red;
public:
Torso(rb::Vector3 coords, _Float16 mass);
+3 -1
View File
@@ -26,12 +26,13 @@ sf::Shape* Caviglia::draw(ReferencePlane plane){
switch (plane)
{
case ReferencePlane::XZ:
case ReferencePlane::XZ : case ReferencePlane::XZN:
{
sf::Shape* shape = shapeXZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[1])));
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
shape->setScale({1,cos(float(tmpRot[0]))});
shape->setFillColor(color*sf::Color(255,255,255,transparency*255));
return shape;}
break;
@@ -41,6 +42,7 @@ sf::Shape* Caviglia::draw(ReferencePlane plane){
shape->setRotation(sf::Angle(sf::radians(tmpRot[0])));
shape->setPosition({tmpPos[1]+globalPos[1],tmpPos[2]+globalPos[2]});
shape->setScale({1,cos(float(tmpRot[1]))});
shape->setFillColor(color*sf::Color(255,255,255,transparency*255));
return shape;}
break;
+3 -9
View File
@@ -25,17 +25,13 @@ sf::Shape* Coscia::draw(ReferencePlane plane){
switch (plane)
{
case ReferencePlane::XZ:
case ReferencePlane::XZ : case ReferencePlane::XZN:
{
sf::Shape* shape = shapeXZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[1])));
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
//calcolo ridimensionamento dato da cos(x)-> questo per definire l'ancoraggio corretto del pivot
shape->setScale({1,cos(float(tmpRot[0]))});
//shape->setScale({1,(0.5* cos(float(tmpRot[0]*2)))+0.5});
shape->setFillColor(color*sf::Color(255,255,255,transparency*255));
return shape;}
break;
@@ -44,10 +40,8 @@ sf::Shape* Coscia::draw(ReferencePlane plane){
sf::Shape* shape = shapeYZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[0])));
shape->setPosition({tmpPos[1]+globalPos[1],tmpPos[2]+globalPos[2]});
//calcolo ridimensionamento dato da cos(x) -> questo per definire l'ancoraggio corretto del pivot
shape->setFillColor(color*sf::Color(255,255,255,transparency*255));
shape->setScale({1,cos(float(tmpRot[1]))});
//shape->setScale({1,(0.5* cos(float(tmpRot[1]*2)))+0.5});
return shape;}
break;
+7 -4
View File
@@ -60,11 +60,13 @@ sf::Shape* Sensore::draw(ReferencePlane plane){
switch (plane)
{
case ReferencePlane::XZ:
case ReferencePlane::XZ : case ReferencePlane::XZN:
{
sf::Shape* shape = shapeXZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[1])));
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
shape->setFillColor(color*sf::Color(255,255,255,transparency*255));
return shape;}
break;
@@ -73,6 +75,7 @@ sf::Shape* Sensore::draw(ReferencePlane plane){
sf::Shape* shape = shapeYZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[0])));
shape->setPosition({tmpPos[1]+globalPos[1],tmpPos[2]+globalPos[2]});
shape->setFillColor(color*sf::Color(255,255,255,transparency*255));
return shape;}
break;
@@ -85,7 +88,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,8 +98,8 @@ 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 tmpAY = acos(tmpSinY);
float tmpAX = acos(dir*tmpSinX);
float tmpAY = acos(dir*tmpSinY);
float tmpAZ = acos(tmpSinZ);
body.setRot(rb::Vector3{tmpAY, tmpAX, tmpAZ });
+3 -1
View File
@@ -26,11 +26,12 @@ sf::Shape* Torso::draw(ReferencePlane plane){
switch (plane)
{
case ReferencePlane::XZ:
case ReferencePlane::XZ: case ReferencePlane::XZN:
{
sf::Shape* shape = shapeXZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[1])));
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
shape->setFillColor(color*sf::Color(255,255,255,transparency*255));
return shape;}
break;
@@ -39,6 +40,7 @@ sf::Shape* Torso::draw(ReferencePlane plane){
sf::Shape* shape = shapeYZ;
shape->setRotation(sf::Angle(sf::radians(tmpRot[0])));
shape->setPosition({tmpPos[1]+globalPos[1],tmpPos[2]+globalPos[2]});
shape->setFillColor(color*sf::Color(255,255,255,transparency*255));
return shape;}
break;
+5 -2
View File
@@ -320,8 +320,11 @@ void doGUI(State &gs)
ImGui::Begin("Set visualization plane",0,sdp_flags);
const char* MyEnumNames[] = { "XZ", "YZ", "-XZ" };
int currentPlane = (int)gs.selectedPlane;
if (ImGui::SliderInt("Selected Plane", &currentPlane,0,2,MyEnumNames[currentPlane])) gs.updateCollections();
gs.selectedPlane = (ReferencePlane)currentPlane;
if (ImGui::SliderInt("Selected Plane", &currentPlane,0,2,MyEnumNames[currentPlane])){
gs.selectedPlane = (ReferencePlane)currentPlane;
gs.updateCollections();
}
ImGui::End();
+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){