4 Commits

21 changed files with 50 additions and 30 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ target_compile_options(common INTERFACE
set(METHODS_PATH "./src/*/methods/*.cpp")
set(VERSION "V8")
set(VERSION "V9")
file(GLOB_RECURSE METHODS_SRC "${METHODS_PATH}")
add_executable(main${VERSION} ./src/testMain.cpp ${METHODS_SRC} )
+5 -1
View File
@@ -54,10 +54,14 @@ Per spostare l'intera scena si tiene premuto il tasto centrale del mouse.
- Aggiunta oscillazione bacino
- Aggiustato calcolo posizione con clock dedicato
## Nella versione v0.9
- Modificata la funzione update di pezzi e collezioni per implementare controllo sul tempo
- Aggiunta finestra con slider per selezione moltiplicatore del tempo
# Per compilare:
cmake --build
# Per lanciare:
./build/bin/mainV8
./build/bin/mainV9
+4
View File
@@ -42,3 +42,7 @@ Size=353,1005
Pos=400,0
Size=400,30
[Window][Set time multiplier]
Pos=400,640
Size=400,30
Binary file not shown.
@@ -13,7 +13,7 @@ struct collection{
class CollectionInterface{
public:
virtual collection create(ReferencePlane plane) = 0;
virtual void update(sf::Clock cl) = 0;
virtual void update(sf::Clock cl, float multiplier) = 0;
virtual bool setTransparency(float alpha) = 0;
virtual ~CollectionInterface(){};
};
+1 -1
View File
@@ -15,7 +15,7 @@ class Gamba : public CollectionInterface {
PieceInterface* getJointPiece();
void setDirection(Direction dir);
bool setTransparency(float alpha) override;
void update(sf::Clock cl)override {};
void update(sf::Clock cl, float multiplier)override {};
float getZ_Acc();
};
+1 -1
View File
@@ -33,7 +33,7 @@ protected:
public:
Lower_Body(rb::Vector3 pos, std::vector<gamba_data> data);
~Lower_Body();
void update(sf::Clock cl) override;
void update(sf::Clock cl, float multiplier) override;
void setVisibility(bool c);
bool setTransparency(float alpha) override;
collection create(ReferencePlane plane) override;
+2 -2
View File
@@ -76,12 +76,12 @@ bool Lower_Body::setTransparency(float alpha){
return true;
}
void Lower_Body::update(sf::Clock cl){
void Lower_Body::update(sf::Clock cl, float multiplier){
float sxAcc = sx->getZ_Acc() ;
float dxAcc = dx->getZ_Acc() ;
int64_t Dtime = cl.getElapsedTime().asMicroseconds();
if (prevT == 0) prevT = Dtime;
if (prevT == 0) prevT >= Dtime;
float dt = (float(Dtime) / 1000000.0) - (float(prevT) / 1000000.0);
prevT = Dtime;
+1 -1
View File
@@ -14,7 +14,7 @@ class Caviglia : public PieceInterface{
Caviglia(rb::Vector3 coords, _Float16 mass);
~Caviglia();
void update(sf::Clock cl) override;
void update(sf::Clock cl, float multiplier) override;
sf::Shape* draw(ReferencePlane plane) override;
};
+1 -1
View File
@@ -15,7 +15,7 @@ class Coscia : public PieceInterface{
Coscia(rb::Vector3 coords, _Float16 mass);
~Coscia();
void update(sf::Clock cl) override;
void update(sf::Clock cl, float multiplier) override;
sf::Shape* draw(ReferencePlane plane) override;
};
+1 -1
View File
@@ -38,7 +38,7 @@ class PieceInterface{
sf::Color color;
float transparency = 1.0; //canale alpha del pezzo
virtual void update(sf::Clock cl) = 0;
virtual void update(sf::Clock cl, float multiplier) = 0;
virtual sf::Shape* draw(ReferencePlane plane) = 0;
virtual ~PieceInterface(){}
virtual void setDirection(Direction dir){
+1 -1
View File
@@ -29,7 +29,7 @@ class Sensore : public PieceInterface{
Sensore(rb::Vector3 coords, _Float16 mass, unsigned int* st, std::vector<std::vector<float>> data);
~Sensore();
void update(sf::Clock cl) override;
void update(sf::Clock cl,float multiplier) override;
sf::Shape* draw(ReferencePlane plane) override;
//funzioni specifiche
+1 -1
View File
@@ -14,7 +14,7 @@ class Torso : public PieceInterface{
Torso(rb::Vector3 coords, _Float16 mass);
~Torso();
void update(sf::Clock cl) override;
void update(sf::Clock cl, float multiplier) override;
sf::Shape* draw(ReferencePlane plane) override;
};
+1 -1
View File
@@ -15,7 +15,7 @@ Caviglia::~Caviglia(){
delete shapeYZ;
}
void Caviglia::update(sf::Clock cl){
void Caviglia::update(sf::Clock cl,float multiplier){
//body.step(cl);
}
+1 -1
View File
@@ -13,7 +13,7 @@ Coscia::~Coscia(){
delete shapeYZ;
}
void Coscia::update(sf::Clock cl){
void Coscia::update(sf::Clock cl, float multiplier){
//body.step(cl);
}
+2 -2
View File
@@ -49,7 +49,7 @@ void Sensore::initCSV(std::vector<std::vector<float>> data){
}
void Sensore::update(sf::Clock cl){
void Sensore::update(sf::Clock cl, float multiplier){
//calcolo la posizione e velocità
if (*dataPos >= gData.size()) *dataPos = gData.size()-1;
@@ -58,7 +58,7 @@ void Sensore::update(sf::Clock cl){
body.setAcc(rb::Vector3{accData[*dataPos]});
body.step(cl);
body.step(cl, multiplier);
}
+1 -1
View File
@@ -14,7 +14,7 @@ Torso::~Torso(){
delete shapeYZ;
}
void Torso::update(sf::Clock cl){
void Torso::update(sf::Clock cl,float multiplier){
}
+1 -1
View File
@@ -49,7 +49,7 @@
void setVel(const Vector3 Nacc);
void setAcc(const Vector3 Nvel);
void setTanAcc(const Vector3 Dacc);
void step(const sf::Clock time);
void step(const sf::Clock time, float multiplier);
//complesso, deve definire accelerazione e accelerazione tangenziale
void appForce(Vector3 f, Vector3 pos);
+3 -3
View File
@@ -85,12 +85,12 @@ void rigidbody::calcPos(const float Dtime){
}
}
void rigidbody::step(const sf::Clock time){
void rigidbody::step(const sf::Clock time, float multiplier){
int64_t Dtime = time.getElapsedTime().asMicroseconds();
if (prevT == 0) prevT = Dtime;
if (prevT == 0) prevT >= Dtime;
float dt = (float(Dtime) / 1000000.0) - (float(prevT) / 1000000.0);
float dt = ((float(Dtime) / 1000000.0) - (float(prevT) / 1000000.0)) * multiplier;
prevT = Dtime;
calcRot(dt);
+19 -7
View File
@@ -29,11 +29,11 @@ struct State
sf::Vector2f cameraOffset = {0.,0.};
sf::Clock clock;
float* tMul;
sf::Clock PieceClock;
ReferencePlane selectedPlane = ReferencePlane::XZ;
PieceInterface* selected = nullptr;
bool rot_Piece = false;
bool drag_Piece = false;
bool drag = false;
@@ -51,6 +51,7 @@ struct State
window = sf::RenderWindow(sf::VideoMode({w, h}), title);
if (ImGui::SFML::Init(window)); // L'if è solo per togliere il warning, va aggiustato gestendo le eccezioni
clock.restart();
tMul = new float(1.0);
PieceClock.restart();
intervalMajLimit = maj;
intervalMinLimit = min;
@@ -68,6 +69,9 @@ struct State
createdColl.push_back(c->create(selectedPlane));
}
}
~State(){
delete tMul;
}
};
///
@@ -84,14 +88,14 @@ void State::update(){
*/
if (play){
for (auto i : collections){
i->update(PieceClock);
i->update(PieceClock, *tMul);
}
}
for (auto i : createdColl){
if (play){
for (auto j : i.pieces){
j->update(PieceClock);
j->update(PieceClock, *tMul);
}
}
for (auto j : i.joints){
@@ -101,7 +105,7 @@ void State::update(){
if (play){
for(PieceInterface* p : pieces){
p->update(PieceClock);
p->update(PieceClock, *tMul);
}
}
for(JointInterface* j : joints){
@@ -331,15 +335,21 @@ void doGUI(State &gs)
gs.selectedPlane = (ReferencePlane)currentPlane;
gs.updateCollections();
}
ImGui::End();
/*////// DA FARE ///////*/
//Finestra gestione velocità di riproduzione
ImGui::Begin("Set time multiplier", 0,sdp_flags);
const float TimeMul[] = {0.5, 0.75, 1, 1.25, 1.5};
const char* TimeMulChar[] = {"0.5", "0.75", "1", "1.25", "1.5"};
static int Timeid = 2;
ImGui::SliderInt("Time", &Timeid,0,4,TimeMulChar[Timeid]);
*gs.tMul = TimeMul[Timeid];
ImGui::End();
//Finestra controllo sovrapposizione
ImGui::End();
sf::Vector2u wsize = gs.window.getSize();
@@ -347,6 +357,8 @@ void doGUI(State &gs)
ImGui::SetWindowSize("Set data position",ImVec2(wsize.x,30));
ImGui::SetWindowPos("Set visualization plane",ImVec2(wsize.x-400,0));
ImGui::SetWindowSize("Set visualization plane",ImVec2(400,30));
ImGui::SetWindowPos("Set time multiplier",ImVec2(wsize.x-400,wsize.y - 60));
ImGui::SetWindowSize("Set time multiplier",ImVec2(400,30));
ImGui::SFML::Render(gs.window);
}
+1 -1
View File
@@ -106,7 +106,7 @@ int main() {
sf::Clock mainClock;
while (gs.window.isOpen())
{
curTime += mainClock.restart().asMilliseconds();
curTime += mainClock.restart().asMilliseconds() *(*gs.tMul) ;
if (curTime > T){
if (gs.play && pos+curTime/T < maj) pos += curTime / T;
curTime = 0;