Add getState and setState

This commit is contained in:
thegrb93
2020-09-15 12:56:56 -04:00
committed by Garrett Brown
parent 365387150e
commit e4c7a4e777
3 changed files with 55 additions and 0 deletions
+15
View File
@@ -112,6 +112,14 @@ float Body::getAngularVelocity() const
return body->GetAngularVelocity();
}
void Body::getState(b2Vec2 &pos_o, float &a_o, b2Vec2 &vel_o, float &da_o) const
{
pos_o = Physics::scaleUp(body->GetPosition());
a_o = body->GetAngle();
vel_o = Physics::scaleUp(body->GetLinearVelocity());
da_o = body->GetAngularVelocity();
}
float Body::getMass() const
{
return body->GetMass();
@@ -225,6 +233,13 @@ void Body::setAngularVelocity(float r)
body->SetAngularVelocity(r);
}
void Body::setState(b2Vec2 pos, float a, b2Vec2 vel, float da)
{
body->SetTransform(Physics::scaleDown(pos), a);
body->SetLinearVelocity(Physics::scaleDown(vel));
body->SetAngularVelocity(da);
}
void Body::setPosition(float x, float y)
{
body->SetTransform(Physics::scaleDown(b2Vec2(x, y)), body->GetAngle());