I have a function that rotates a vector 90 degrees. Only problem is, i never get negative values. For some strange reason, no matter what i do, the value of x is positive. And even if the x is negative. Once i put it into direction (struct with 2 values x and y) it turns again to positive. Im using VSC++2013 ultimate. Can anyone tell me what is causing this strange problem. At first direction was SDL_Point, so i thought it was SDL problem, but now it seems its something else.
1 2 3 4 5 6 7
if (c == '-')
{
int x = direction.y;
x *= -1;
int y = direction.x;
direction = { x, y };
}
Code should work fine. Try placing breakpoint inside this if statement. I think that execution does not run these statements at all. Mayby problem is with your conditions?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
struct Point
{
int x;
int y;
};
int main()
{
Point direction {5, 1};
int x = direction.y;
x *= -1;
int y = direction.x;
direction = { x, y };
std::cout << direction.x << ' ' << direction.y;
}
So i made it like this. Its inside the if statement. Since it gets printed out, the condition is initialized. But i always get positive values. I have another if statement like this. It turns the other way and it seems to be working fine. I get occasional negative values from there.
This code looks okay to me. I notice that the code does NOT rotate the angle. It reflects it about the Y axis. So I suspect the problem is elsewhere. Can you post the full rotation code?