Aggiunta viusalizzazione collection su sfml_util
This commit is contained in:
+2
-2
@@ -3,8 +3,8 @@ Pos=60,60
|
|||||||
Size=400,400
|
Size=400,400
|
||||||
|
|
||||||
[Window][Dear ImGui Demo]
|
[Window][Dear ImGui Demo]
|
||||||
Pos=473,13
|
Pos=781,47
|
||||||
Size=936,873
|
Size=455,873
|
||||||
|
|
||||||
[Window][Hello, world!]
|
[Window][Hello, world!]
|
||||||
Pos=11,12
|
Pos=11,12
|
||||||
|
|||||||
Binary file not shown.
@@ -24,9 +24,16 @@ inline collection operator+(collection c1, collection c2){
|
|||||||
for (PieceInterface* i : c1.pieces){
|
for (PieceInterface* i : c1.pieces){
|
||||||
res.pieces.push_back(i);
|
res.pieces.push_back(i);
|
||||||
}
|
}
|
||||||
|
for (PieceInterface* i : c2.pieces){
|
||||||
|
res.pieces.push_back(i);
|
||||||
|
}
|
||||||
for (JointInterface* i : c1.joints){
|
for (JointInterface* i : c1.joints){
|
||||||
res.joints.push_back(i);
|
res.joints.push_back(i);
|
||||||
}
|
}
|
||||||
|
for (JointInterface* i : c2.joints){
|
||||||
|
res.joints.push_back(i);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public:
|
|||||||
~Lower_Body();
|
~Lower_Body();
|
||||||
|
|
||||||
void setVisibility(bool c);
|
void setVisibility(bool c);
|
||||||
|
void setTransparency(float t);
|
||||||
collection create(ReferencePlane plane) override;
|
collection create(ReferencePlane plane) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,15 @@
|
|||||||
Gamba::Gamba(rb::Vector3 pos, unsigned int* dataPos, std::string cosciaData, std::string cavigliaData){
|
Gamba::Gamba(rb::Vector3 pos, unsigned int* dataPos, std::string cosciaData, std::string cavigliaData){
|
||||||
CSVProcessor processor;
|
CSVProcessor processor;
|
||||||
try {
|
try {
|
||||||
processor.readCSVFile (DATA_PATH + "coscia_filt.csv");
|
|
||||||
const auto& coscia = processor.getData();
|
|
||||||
processor.readCSVFile(DATA_PATH + "caviglia_filt.csv");
|
|
||||||
const auto& caviglia = processor.getData();
|
|
||||||
|
|
||||||
pezzi.push_back(new Coscia(pos,2));
|
pezzi.push_back(new Coscia(pos,2));
|
||||||
pezzi.push_back(new Caviglia(rb::Vector3{pos[0],pos[1],pos[2]+200},2));
|
pezzi.push_back(new Caviglia(rb::Vector3{pos[0],pos[1],pos[2]+200},2));
|
||||||
|
|
||||||
|
processor.readCSVFile (DATA_PATH + cosciaData);
|
||||||
|
const auto& coscia = processor.getData();
|
||||||
sensori.push_back(new Sensore(pos,_Float16( 0.2 ),dataPos,coscia));
|
sensori.push_back(new Sensore(pos,_Float16( 0.2 ),dataPos,coscia));
|
||||||
|
|
||||||
|
processor.readCSVFile(DATA_PATH + cavigliaData);
|
||||||
|
const auto& caviglia = processor.getData();
|
||||||
sensori.push_back(new Sensore (rb::Vector3{pos[0],pos[1],pos[2]+200},_Float16( 0.2 ),dataPos,caviglia));
|
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
|
// modifico la rotazione relativa della gamba
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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";
|
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);
|
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],pos[2]+150},data[1].dataPos,data[1].cosciaData,data[1].cavigliaData);
|
dx = new Gamba({pos[0],pos[1]+100,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));
|
t = new Torso({pos[0],pos[1]+100,pos[2]},_Float16(3.0));
|
||||||
|
|
||||||
PieceInterface* psx = sx->getJointPiece();
|
PieceInterface* psx = sx->getJointPiece();
|
||||||
@@ -18,7 +18,6 @@ Lower_Body::Lower_Body(rb::Vector3 pos,std::vector<gamba_data> data){
|
|||||||
collection Lower_Body::create(ReferencePlane plane){
|
collection Lower_Body::create(ReferencePlane plane){
|
||||||
collection coll;
|
collection coll;
|
||||||
|
|
||||||
|
|
||||||
switch (plane)
|
switch (plane)
|
||||||
{
|
{
|
||||||
case ReferencePlane::XZ: case ReferencePlane::XZN:
|
case ReferencePlane::XZ: case ReferencePlane::XZN:
|
||||||
@@ -33,6 +32,10 @@ collection Lower_Body::create(ReferencePlane plane){
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
coll.pieces.push_back(t);
|
||||||
|
coll.joints.push_back(jsx);
|
||||||
|
coll.joints.push_back(jdx);
|
||||||
|
|
||||||
|
|
||||||
return coll;
|
return coll;
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-2
@@ -2,6 +2,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "pieces/headers/piece_interface.hpp"
|
#include "pieces/headers/piece_interface.hpp"
|
||||||
#include "joints/headers/joint_interface.hpp"
|
#include "joints/headers/joint_interface.hpp"
|
||||||
|
#include "collections/headers/collection_interface.hpp"
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <imgui-SFML.h>
|
#include <imgui-SFML.h>
|
||||||
|
|
||||||
@@ -21,6 +22,10 @@ struct State
|
|||||||
int menubar_height = 50;
|
int menubar_height = 50;
|
||||||
std::vector<PieceInterface*> pieces;
|
std::vector<PieceInterface*> pieces;
|
||||||
std::vector<JointInterface*> joints;
|
std::vector<JointInterface*> joints;
|
||||||
|
std::vector<CollectionInterface*> collections;
|
||||||
|
|
||||||
|
std::vector<collection> createdColl;
|
||||||
|
|
||||||
sf::Vector2f cameraOffset = {0.,0.};
|
sf::Vector2f cameraOffset = {0.,0.};
|
||||||
|
|
||||||
sf::Clock clock;
|
sf::Clock clock;
|
||||||
@@ -48,11 +53,19 @@ struct State
|
|||||||
intervalMajLimit = maj;
|
intervalMajLimit = maj;
|
||||||
intervalMinLimit = min;
|
intervalMinLimit = min;
|
||||||
this->pos = pos;
|
this->pos = pos;
|
||||||
|
updateCollections();
|
||||||
}
|
}
|
||||||
void update();
|
void update();
|
||||||
void setIntervall(int n){
|
void setIntervall(int n){
|
||||||
maxEntries = n;
|
maxEntries = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateCollections(){
|
||||||
|
createdColl.clear();
|
||||||
|
for (auto c: collections){
|
||||||
|
createdColl.push_back(c->create(selectedPlane));
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -62,7 +75,23 @@ struct State
|
|||||||
/// Fisics functions
|
/// Fisics functions
|
||||||
|
|
||||||
void State::update(){
|
void State::update(){
|
||||||
|
|
||||||
|
/*
|
||||||
|
std::vector<PieceInterface*> collPieces;
|
||||||
|
std::vector<JointInterface*> collJoints;
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (auto i : createdColl){
|
||||||
|
if (play){
|
||||||
|
for (auto j : i.pieces){
|
||||||
|
j->update(clock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto j : i.joints){
|
||||||
|
j->movechild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (play){
|
if (play){
|
||||||
for(PieceInterface* p : pieces){
|
for(PieceInterface* p : pieces){
|
||||||
p->update(clock);
|
p->update(clock);
|
||||||
@@ -97,6 +126,7 @@ void handle_keyPressed(const sf::Event::KeyPressed &keyPressed, State &gs)
|
|||||||
else
|
else
|
||||||
gs.selectedPlane = ReferencePlane::XZ;
|
gs.selectedPlane = ReferencePlane::XZ;
|
||||||
}
|
}
|
||||||
|
gs.updateCollections();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -125,6 +155,11 @@ void handle_mouseMove(const sf::Event::MouseMoved &mouseMoved, State &gs)
|
|||||||
for(PieceInterface* p : gs.pieces){
|
for(PieceInterface* p : gs.pieces){
|
||||||
p->globalPos = {p->globalPos[0] + (offset.x * px), p->globalPos[1]+ (offset.x * py),p->globalPos[2] + offset.y};
|
p->globalPos = {p->globalPos[0] + (offset.x * px), p->globalPos[1]+ (offset.x * py),p->globalPos[2] + offset.y};
|
||||||
}
|
}
|
||||||
|
for(collection c : gs.createdColl){
|
||||||
|
for(auto p : c.pieces){
|
||||||
|
p->globalPos = {p->globalPos[0] + (offset.x * px), p->globalPos[1]+ (offset.x * py),p->globalPos[2] + offset.y};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_MODE
|
#ifdef DEBUG_MODE
|
||||||
@@ -167,6 +202,7 @@ void handle_mousePressed(const sf::Event::MouseButtonPressed &mouseBP, State &gs
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if ( mouseBP.button == sf::Mouse::Button::Right){
|
if ( mouseBP.button == sf::Mouse::Button::Right){
|
||||||
gs.rot_Piece = true;
|
gs.rot_Piece = true;
|
||||||
@@ -258,7 +294,7 @@ void doGUI(State &gs)
|
|||||||
ImGui::Begin("Set visualization plane",0,sdp_flags);
|
ImGui::Begin("Set visualization plane",0,sdp_flags);
|
||||||
const char* MyEnumNames[] = { "XZ", "YZ", "-XZ" };
|
const char* MyEnumNames[] = { "XZ", "YZ", "-XZ" };
|
||||||
int currentPlane = (int)gs.selectedPlane;
|
int currentPlane = (int)gs.selectedPlane;
|
||||||
ImGui::SliderInt("Selected Plane", ¤tPlane,0,2,MyEnumNames[currentPlane]);
|
if (ImGui::SliderInt("Selected Plane", ¤tPlane,0,2,MyEnumNames[currentPlane])) gs.updateCollections();
|
||||||
gs.selectedPlane = (ReferencePlane)currentPlane;
|
gs.selectedPlane = (ReferencePlane)currentPlane;
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
@@ -275,10 +311,19 @@ void doGraphics(State &gs)
|
|||||||
{
|
{
|
||||||
|
|
||||||
gs.window.clear();
|
gs.window.clear();
|
||||||
|
|
||||||
|
//disegno i pezzi singoli
|
||||||
for(PieceInterface* p: gs.pieces){
|
for(PieceInterface* p: gs.pieces){
|
||||||
gs.window.draw(*p->draw(gs.selectedPlane));
|
gs.window.draw(*p->draw(gs.selectedPlane));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//disegno le collezioni
|
||||||
|
for(auto c : gs.createdColl){
|
||||||
|
for(auto p : c.pieces){
|
||||||
|
gs.window.draw(*p->draw(gs.selectedPlane));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (const std::optional event = gs.window.pollEvent()) {
|
while (const std::optional event = gs.window.pollEvent()) {
|
||||||
ImGui::SFML::ProcessEvent(gs.window, *event);
|
ImGui::SFML::ProcessEvent(gs.window, *event);
|
||||||
if (event->is<sf::Event::Closed>())
|
if (event->is<sf::Event::Closed>())
|
||||||
|
|||||||
+7
-5
@@ -38,11 +38,12 @@ int main() {
|
|||||||
printf("Costruisco gli oggetti\n");
|
printf("Costruisco gli oggetti\n");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
processor.readCSVFile (DATA_PATH + "coscia_filt.csv");
|
processor.readCSVFile (DATA_PATH + "coscia_filt.csv");
|
||||||
const auto& coscia = processor.getData();
|
const auto& coscia = processor.getData();
|
||||||
gs.setIntervall(coscia.size());
|
gs.setIntervall(coscia.size());
|
||||||
|
|
||||||
|
/*
|
||||||
gs.pieces.push_back(new Coscia (rb::Vector3{300,300,300},2));
|
gs.pieces.push_back(new Coscia (rb::Vector3{300,300,300},2));
|
||||||
gs.pieces.push_back(new Sensore (rb::Vector3{300,300,300},_Float16( 0.2 ),&pos,coscia));
|
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));
|
gs.pieces.push_back(new Caviglia (rb::Vector3{300,300,500},1));
|
||||||
@@ -67,19 +68,19 @@ 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]}));
|
||||||
|
*/
|
||||||
|
|
||||||
//provo ad aggiungere una collection
|
//provo ad aggiungere una collection
|
||||||
Gamba g = Gamba({0,0,0},&pos,"coscia_filt.csv","coscia_filt.csv");
|
gs.collections.push_back(new Gamba({220,0,220},&pos,"coscia_filt.csv","caviglia_filt.csv"));
|
||||||
|
|
||||||
std::vector<gamba_data> data;
|
std::vector<gamba_data> data;
|
||||||
gamba_data d;
|
gamba_data d;
|
||||||
d.dataPos = &pos;
|
d.dataPos = &pos;
|
||||||
d.cavigliaData = "coscia_filt.csv";
|
d.cavigliaData = "caviglia_filt.csv";
|
||||||
d.cosciaData = "coscia_filt.csv";
|
d.cosciaData = "coscia_filt.csv";
|
||||||
data.push_back(d);
|
data.push_back(d);
|
||||||
data.push_back(d);
|
data.push_back(d);
|
||||||
Lower_Body b = Lower_Body(rb::Vector3{0,0,0},data);
|
gs.collections.push_back(new Lower_Body(rb::Vector3{0,0,0},data));
|
||||||
|
|
||||||
printf("Ho costruito tutto!\n");
|
printf("Ho costruito tutto!\n");
|
||||||
}
|
}
|
||||||
@@ -95,6 +96,7 @@ int main() {
|
|||||||
|
|
||||||
//Avvio il loop della GUI
|
//Avvio il loop della GUI
|
||||||
gs.clock.start();
|
gs.clock.start();
|
||||||
|
gs.updateCollections();
|
||||||
|
|
||||||
sf::Clock mainClock;
|
sf::Clock mainClock;
|
||||||
while (gs.window.isOpen())
|
while (gs.window.isOpen())
|
||||||
|
|||||||
Reference in New Issue
Block a user