Aggiunto clock per i pezzi (aggiusta calcolo veocità)

This commit is contained in:
2026-06-21 12:43:21 +02:00
parent e1965aaf1e
commit 1349de403c
3 changed files with 17 additions and 7 deletions
+12 -4
View File
@@ -78,7 +78,7 @@ bool Lower_Body::setTransparency(float alpha){
void Lower_Body::update(sf::Clock cl){
float sxAcc = sx->getZ_Acc() * 10;
float dxAcc = dx->getZ_Acc() * 10000;
float dxAcc = dx->getZ_Acc();
//float totAcc = sxAcc + dxAcc;
//t->body.setTanAcc({0,totAcc,0}); // non funziona, cambio sistema
@@ -86,6 +86,8 @@ void Lower_Body::update(sf::Clock cl){
/* Posso considerare lo spostamento come A*sin(alpha)*/
/* Mi calcolo le velocità totali sull'asse z */
printf("Acc: %f\n", dxAcc);
int64_t Dtime = cl.getElapsedTime().asMicroseconds();
if (prevT == 0) prevT = Dtime;
float dt = (float(Dtime) / 1000000.0) - (float(prevT) / 1000000.0);
@@ -94,9 +96,15 @@ void Lower_Body::update(sf::Clock cl){
float tmpVelS = sxAcc*dt;
float tmpVelD = dxAcc*dt;
float tmpPosD = velD *dt ;
printf("Vel: %f\n", tmpVelD);
float tmpPosD = velD *dt *100 ;
float tmpPosS = velS * 100 * dt + tmpVelD * 100 *dt;
printf("DPos: %f\n\n", tmpPosD);
velD += tmpVelD;
velS += tmpVelS;
posD += tmpPosD;
@@ -106,7 +114,7 @@ void Lower_Body::update(sf::Clock cl){
float alpha = asin(posD/60.0);
t->body.setRot({alpha,0,0});
//auto tPos = t->body.getPos();
//t->body.setPos({tPos[0],tPos[1],tPos[2]+tmpPosD});
auto tPos = t->body.getPos();
//t->body.setPos({tPos[0],tPos[1],tPos[2]+posD});
}
+5 -3
View File
@@ -29,6 +29,7 @@ struct State
sf::Vector2f cameraOffset = {0.,0.};
sf::Clock clock;
sf::Clock PieceClock;
ReferencePlane selectedPlane = ReferencePlane::XZ;
PieceInterface* selected = nullptr;
@@ -50,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();
PieceClock.restart();
intervalMajLimit = maj;
intervalMinLimit = min;
this->pos = pos;
@@ -82,13 +84,13 @@ void State::update(){
*/
for (auto i : collections){
i->update(clock);
i->update(PieceClock);
}
for (auto i : createdColl){
if (play){
for (auto j : i.pieces){
j->update(clock);
j->update(PieceClock);
}
}
for (auto j : i.joints){
@@ -98,7 +100,7 @@ void State::update(){
if (play){
for(PieceInterface* p : pieces){
p->update(clock);
p->update(PieceClock);
}
}
for(JointInterface* j : joints){