但是,我也想让精灵的旋转反映出b2体的旋转。但是,在我旋转精灵之后,我用它来正确地将它们与b2体位置对齐的偏移不再准确。
void CRoom::RotateGun(const SDL_Event &event)
{
glm::vec2 mousePosition = sdl::GetMousePosition(event.motion);
glm::vec2 delta = mousePosition - GUN_POSITION;
float angle = atan2f(delta.y, delta.x);
m_gun->GetBody()->SetTransform(m_gun->GetPosition(), angle);
}
答案 0 :(得分:1)
Use the matrix multiply.
Using the normal conventions, the transform is
move(-width/2, -height/2) * rotate(angle) * move(width/2 height/2) *move(x, y)
Sometimes you will have to reverse the order.