【问题标题】:How to rotate a shape around a point如何围绕一个点旋转形状
【发布时间】:2015-02-15 00:08:11
【问题描述】:

在 SFML 中,我如何使用转换围绕某个点旋转形状?我知道如何使用 cos 和 sin,但想了解如何使用转换。

我认为我的问题是我没有获得 sfml 接口。这是一个例子:

// Draw circle at center
sf::CircleShape c;
c.setFillColor(sf::Color::Red);
c.setPosition(width / 2, height / 2);
c.setRadius(50);
c.setOrigin({50, 50});

现在,我将如何在帧刷新循环内围绕屏幕中心移动和旋转圆圈?

【问题讨论】:

标签: sfml


【解决方案1】:

原来有一个以中心点为中心的旋转功能。

sf::CircleShape c;
c.setFillColor(sf::Color::Red);
c.setPosition(width / 2.f, height / 2.f - 100);
c.setRadius(50);
c.setOrigin({50, 50});

float angle = 1.0;

sf::Transform t;

while(true)
{
    window.clear(sf::Color::Black);

    t.rotate(angle, { width/2.f, height / 2.f });

    window.draw(c, t);

    window.display();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 2018-02-27
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多