C++ 同时围绕2个点旋转

C++ 同时围绕2个点旋转,c++,rotation,sfml,C++,Rotation,Sfml,基本上,我试着同时围绕2个点旋转一个正方形 在这里,当鼠标向左或向右移动时,我试图围绕其中心旋转正方形,当鼠标向上或向下移动时,我围绕任何其他点旋转(这里是50:100)。然而,我的方块在屏幕上跳跃,当我试图只围绕中心旋转时,它会继续围绕50:100旋转。 有什么建议可以解决这个问题吗 #include <SFML/Graphics.hpp> using namespace sf; Event evt; int main(int argc, char* argv)

基本上,我试着同时围绕2个点旋转一个正方形

在这里,当鼠标向左或向右移动时,我试图围绕其中心旋转正方形,当鼠标向上或向下移动时,我围绕任何其他点旋转(这里是50:100)。然而,我的方块在屏幕上跳跃,当我试图只围绕中心旋转时,它会继续围绕50:100旋转。 有什么建议可以解决这个问题吗

#include <SFML/Graphics.hpp>
using namespace sf;

   Event evt;

    int main(int argc, char* argv)
    {
RenderWindow window(VideoMode(600, 600), "test");

RectangleShape test(Vector2<float>(20.0f, 20.0f));
test.setFillColor(Color::Red);
test.setPosition(300, 300);
test.setOrigin(10, 10);


Clock deltaTime;
Clock timer;
timer.restart();

int mouseX = 0, mouseY = 0;
int curMouseX = 0, curMouseY = 0;
float offset = 100;
bool moving = false;

while (window.isOpen())
{
    while (window.pollEvent(evt)) {
        switch (evt.type)
        {
        case Event::MouseMoved:
            curMouseX = mouseX;
            curMouseY = mouseY;
            mouseX = evt.mouseMove.x;
            mouseY = evt.mouseMove.y;
            moving = true;
            break;
        }
    }

    float elaspedTime = deltaTime.restart().asSeconds();

    if (curMouseX != mouseX && moving) {

        test.setOrigin(10, 10);
        test.rotate(360 * elaspedTime);
        //  test.setOrigin(50, 100); Tried this to avoid jumping. When uncommented, doesn't rotate around the center.
    }

    if (curMouseY != mouseY && moving) {
        test.setOrigin(50, 100);
        test.rotate(60 * elaspedTime);
    }
    window.clear();
    window.draw(test);
    window.display();
    moving = false;
}

return 0;
  }    
#包括
使用名称空间sf;
事件evt;
int main(int argc,char*argv)
{
渲染窗口(视频模式(600600),“测试”);
矩形形状试验(矢量2(20.0f,20.0f));
测试。设置填充颜色(颜色:红色);
测试。设置位置(300300);
测试。设定原点(10,10);
时钟时间;
时钟定时器;
timer.restart();
int mouseX=0,mouseY=0;
int curMouseX=0,curMouseY=0;
浮动偏移=100;
布尔移动=假;
while(window.isOpen())
{
while(window.pollEvent(evt)){
开关(电动类型)
{
案例事件::MouseMoved:
curMouseX=mouseX;
curMouseY=mouseY;
mouseX=evt.mouseMove.x;
mouseY=evt.mouseMove.y;
移动=真;
打破
}
}
float elaspedTime=deltaTime.restart().asSeconds();
if(curMouseX!=mouseX&&mousing){
测试。设定原点(10,10);
测试。旋转(360*次);
//setOrigin(50100);尝试此操作以避免跳跃。未注释时,不会围绕中心旋转。
}
if(curMouseY!=鼠标移动(&M){
测试设定原点(50100);
试验.旋转(60*次);
}
window.clear();
窗口绘制(测试);
window.display();
移动=假;
}
返回0;
}    

不要使用从形状继承的
sf::Transfomable
类,而是为它创建一个


每次鼠标在
sf::Vector2f

中移动时,您只需存储鼠标位置。您希望重新角度连续移动还是仅在鼠标移动时移动?