Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - BlackCrock

Pages: [1]
1
Graphics / Re: Rotate around 2 points at the same time
« on: October 13, 2016, 08:17:57 am »
This is what I actually did, and yeah, indeed, it's hard to move mouse along one axis. What I noticed, square moves around the 50:100 in any case.

The greatest problem anyway, is to rotate around 2 points at the same time (or maybe to make an illusion of it? If I move mouse diagonally square has to move around 50:100 and it's center). I was thinking about using the Transform directly, but I don't know how to apply it here.

2
Graphics / Rotate around 2 points at the same time
« on: October 13, 2016, 06:35:53 am »
Hello,

I'm trying to rotate a square around it's center when I'm moving mouse left/right, and to rotate it around point 50:100, when mouse is moving up/down. My implementation (which is wrong, obviously) makes my square to jump around 2 points on the screen; when it's supposed to rotate only around the center, it rotates around 50:100. Any suggestions/directions how to overcome this?
#include <SFML/Graphics.hpp>
#include <iostream>
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;
}
 

Pages: [1]