Aggiunto clock per i pezzi (aggiusta calcolo veocità)
This commit is contained in:
Binary file not shown.
@@ -78,7 +78,7 @@ bool Lower_Body::setTransparency(float alpha){
|
|||||||
|
|
||||||
void Lower_Body::update(sf::Clock cl){
|
void Lower_Body::update(sf::Clock cl){
|
||||||
float sxAcc = sx->getZ_Acc() * 10;
|
float sxAcc = sx->getZ_Acc() * 10;
|
||||||
float dxAcc = dx->getZ_Acc() * 10000;
|
float dxAcc = dx->getZ_Acc();
|
||||||
|
|
||||||
//float totAcc = sxAcc + dxAcc;
|
//float totAcc = sxAcc + dxAcc;
|
||||||
//t->body.setTanAcc({0,totAcc,0}); // non funziona, cambio sistema
|
//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)*/
|
/* Posso considerare lo spostamento come A*sin(alpha)*/
|
||||||
/* Mi calcolo le velocità totali sull'asse z */
|
/* Mi calcolo le velocità totali sull'asse z */
|
||||||
|
|
||||||
|
printf("Acc: %f\n", dxAcc);
|
||||||
|
|
||||||
int64_t Dtime = cl.getElapsedTime().asMicroseconds();
|
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);
|
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 tmpVelS = sxAcc*dt;
|
||||||
float tmpVelD = dxAcc*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;
|
float tmpPosS = velS * 100 * dt + tmpVelD * 100 *dt;
|
||||||
|
|
||||||
|
|
||||||
|
printf("DPos: %f\n\n", tmpPosD);
|
||||||
|
|
||||||
velD += tmpVelD;
|
velD += tmpVelD;
|
||||||
velS += tmpVelS;
|
velS += tmpVelS;
|
||||||
posD += tmpPosD;
|
posD += tmpPosD;
|
||||||
@@ -106,7 +114,7 @@ void Lower_Body::update(sf::Clock cl){
|
|||||||
float alpha = asin(posD/60.0);
|
float alpha = asin(posD/60.0);
|
||||||
|
|
||||||
t->body.setRot({alpha,0,0});
|
t->body.setRot({alpha,0,0});
|
||||||
//auto tPos = t->body.getPos();
|
auto tPos = t->body.getPos();
|
||||||
//t->body.setPos({tPos[0],tPos[1],tPos[2]+tmpPosD});
|
//t->body.setPos({tPos[0],tPos[1],tPos[2]+posD});
|
||||||
|
|
||||||
}
|
}
|
||||||
+5
-3
@@ -29,6 +29,7 @@ struct State
|
|||||||
sf::Vector2f cameraOffset = {0.,0.};
|
sf::Vector2f cameraOffset = {0.,0.};
|
||||||
|
|
||||||
sf::Clock clock;
|
sf::Clock clock;
|
||||||
|
sf::Clock PieceClock;
|
||||||
ReferencePlane selectedPlane = ReferencePlane::XZ;
|
ReferencePlane selectedPlane = ReferencePlane::XZ;
|
||||||
|
|
||||||
PieceInterface* selected = nullptr;
|
PieceInterface* selected = nullptr;
|
||||||
@@ -50,6 +51,7 @@ struct State
|
|||||||
window = sf::RenderWindow(sf::VideoMode({w, h}), title);
|
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
|
if (ImGui::SFML::Init(window)); // L'if è solo per togliere il warning, va aggiustato gestendo le eccezioni
|
||||||
clock.restart();
|
clock.restart();
|
||||||
|
PieceClock.restart();
|
||||||
intervalMajLimit = maj;
|
intervalMajLimit = maj;
|
||||||
intervalMinLimit = min;
|
intervalMinLimit = min;
|
||||||
this->pos = pos;
|
this->pos = pos;
|
||||||
@@ -82,13 +84,13 @@ void State::update(){
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (auto i : collections){
|
for (auto i : collections){
|
||||||
i->update(clock);
|
i->update(PieceClock);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i : createdColl){
|
for (auto i : createdColl){
|
||||||
if (play){
|
if (play){
|
||||||
for (auto j : i.pieces){
|
for (auto j : i.pieces){
|
||||||
j->update(clock);
|
j->update(PieceClock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto j : i.joints){
|
for (auto j : i.joints){
|
||||||
@@ -98,7 +100,7 @@ void State::update(){
|
|||||||
|
|
||||||
if (play){
|
if (play){
|
||||||
for(PieceInterface* p : pieces){
|
for(PieceInterface* p : pieces){
|
||||||
p->update(clock);
|
p->update(PieceClock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(JointInterface* j : joints){
|
for(JointInterface* j : joints){
|
||||||
|
|||||||
Reference in New Issue
Block a user