void CompPhysics::applyForce(const Vector2D& impulse, const Vector2D& point) { if (m_body==NULL) { log(Warning) << "applyForce: component was not yet initialized by physics system\n"; return; } m_body->ApplyForce(*impulse.to_b2Vec2(), *point.to_b2Vec2(), false); }
Vector2D CompPhysics::globalToLocal(const Vector2D& global) const { if (m_body==NULL) { log(Warning) << "globalToLocal: component was not yet initialized by physics system\n"; return Vector2D(); } return m_body->GetWorldVector(*global.to_b2Vec2()); }
void CompPhysics::setLinearVelocity(const Vector2D& vel) { if (m_body==NULL) { log(Warning) << "setLinearVelocity: component was not yet initialized by physics system\n"; return; } m_body->SetLinearVelocity( *vel.to_b2Vec2() ); }
void CompPhysics::rotate( float deltaAngle, const Vector2D& localPoint ) { if (m_body==NULL) { log(Warning) << "rotate: component was not yet initialized by physics system\n"; return; } float newAngle = m_body->GetAngle() + deltaAngle; Vector2D worldRotationCenter( Vector2D(m_body->GetPosition()) + localPoint.rotated(m_body->GetAngle()) ); Vector2D worldRotationCenterToBodyCenter ( -localPoint.rotated(newAngle) ); Vector2D newPos = worldRotationCenter + worldRotationCenterToBodyCenter; m_body->SetTransform( *newPos.to_b2Vec2(), newAngle ); }