Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何";设置原点“;sfml中一个变换的实现_C++_Sfml - Fatal编程技术网

C++ 如何";设置原点“;sfml中一个变换的实现

C++ 如何";设置原点“;sfml中一个变换的实现,c++,sfml,C++,Sfml,我在使用sfml时遇到了一个问题,似乎sf::Transforms应用于整个坐标系的原点,而不是被转换的精灵/事物的原点 例如,在下面的两个例子中,我期望相同的行为,但事实并非如此。 (粗体的不同之处在于,大多数rest只用于实际显示一个sfml窗口,其中有一个圆圈,当按下空格时,该圆圈会缩小) 第一个示例:在这里,圆朝着窗口的左上角缩小 #include <SFML/Graphics.hpp> int main() { sf::Re

我在使用
sfml
时遇到了一个问题,似乎
sf::Transform
s应用于整个坐标系的原点,而不是被转换的精灵/事物的原点

例如,在下面的两个例子中,我期望相同的行为,但事实并非如此。 (粗体的不同之处在于,大多数rest只用于实际显示一个sfml窗口,其中有一个圆圈,当按下空格时,该圆圈会缩小)

第一个示例:在这里,圆朝着窗口的左上角缩小



    #include <SFML/Graphics.hpp>
    
    int main()
    {
        sf::RenderWindow window(sf::VideoMode(800, 800), "Example");
        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);
    
        shape.setPosition(400, 400);
        
        sf::Transform t;
        t.scale( 9/10.f , 9/10.f);
        sf::Transform t_n; 
          
        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                if (event.type == sf::Event::Closed){
                    window.close();
            }
            if (event.type == sf::Event::KeyPressed) {
                if (event.key.code == sf::Keyboard::Space) {
                    t_n = t_n * t; 
                }
            }
        } 
        
              
        window.clear();
        window.draw(shape, t_n); 
        window.display();
        }
        
        return 0;
      
    }

注意:这可能是的副本,但此线程的唯一答案是我自己的,我建议的解决方案确实不理想。

您可以在调用
t.scale
时指定中心。请参阅。您可以在调用
t.scale
时指定中心。看。

    #include <SFML/Graphics.hpp>
    
    int main()
    {
        sf::RenderWindow window(sf::VideoMode(800, 800), "Example");
        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);
    
        shape.setPosition(400, 400);
        
        // no Transforms need declaring
        
        
        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                if (event.type == sf::Event::Closed){
                    window.close();
            }
            if (event.type == sf::Event::KeyPressed) {
                if (event.key.code == sf::Keyboard::Space) {
                    shape.scale(9/10.f, 9/10.f);
                }
            }
        } 
        
              
        window.clear();
        window.draw(shape); 
        window.display();
        }
        
        return 0;
      
    }