Modifica di update() per gestire moltiplicatore tempo

This commit is contained in:
2026-06-22 12:16:32 +02:00
parent f05db110ff
commit c6094c6a44
18 changed files with 35 additions and 25 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} )
+1 -1
View File
@@ -60,4 +60,4 @@ Per spostare l'intera scena si tiene premuto il tasto centrale del mouse.
# Per lanciare:
./build/bin/mainV8
./build/bin/mainV9
@@ -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;
+1 -1
View File
@@ -76,7 +76,7 @@ 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() ;
+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);
+2 -2
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;
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);
+15 -5
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){
@@ -333,9 +337,15 @@ void doGUI(State &gs)
}
/*////// 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"};
int id = 2;
ImGui::SliderInt("Selected Plane", &id,0,4,TimeMulChar[id]);
gs.tMul* = TimeMul[id];
ImGui::End();
//Finestra controllo sovrapposizione