Flip a corner horizontally

I want to know a way to flip a corner on the horizontal axis without doing a lot of operations. Let's say I have an angle of 0 ("pointing to the right" in my code coordinate system), the flip angle should be 180 (pointing to the left). If it is 90 (pointing up), it should still be 90 upside down. 89 - 91, and so on. I can work at the X / Y speeds implied by the angle, but that will slow things down and I feel this is not the right way to go. I don't know a lot of math, so I can call things by the wrong name ... Can anyone help?

EDIT: Sorry it took me a long time, I had to be away from the computer for a long time, ok ... http://img215.imageshack.us/img215/8095/screenshot031v.jpg

This screenshot could do. The above structure is two satellites and a beam associated with a white dot in the center. The two satellites must inherit the angle of the white point (visible for debugging purposes), so if it is aimed at an angle they will follow. The satellite on the left is mirrored, so I calculated it at 180 as expected, even though this was my first attempt. As you can see, it is not mirrored, but inverted. And when the white point rotates, it rotates backward. The other is doing well.

This is a recalculation of the angle for something related to something else, the pid will be the parent and the id will be the current. pin.ang is a corner offset that is copied when an object is linked to another, so it retains its position when rotated:

if(object[id].mirror)
    object[id].angle = 180 - (object[id].pin.ang + object[pid].angle);
else
    object[id].angle = object[id].pin.ang + object[pid].angle;

      

And this is a specific part of the rotation. OpenGL. offx / y for things spinning out of center, like a ray that is about to come out, it makes everything else right.

glTranslatef(list[index[i]].x, list[index[i]].y, 0);
glRotatef(list[index[i]].angle, 0.0, 0.0, 1.0);
glTranslatef(list[index[i]].offx, -list[index[i]].offy, 0);

      

The rotation also appears to be skipped when the rotation speed (an integer is added each redraw to the current corner, positive for clockwise rotation, as in the following: http://img216.imageshack.us/img216/7/screenshot032ulr.jpg

So it's definitely not 180 degrees, no matter how obvious it is. Mirroring is done by simply changing the coordinates of the texture so that it doesn't affect the corner. I'm afraid this might be a quirk in the GL turn.

+2


source to share


7 replies


The reflected amount (just by looking at the math) would be (180 - angle)

Angle | Reflection
------+-----------
    0 |        180
   90 |         90
   89 |         91
   91 |         89
  360 |       -180
  270 |        -90

      



Pay attention to negatives if you go below the "horizontal plane", which you could leave as is, or treat as a special case.

+10


source


Isn't it easy



result = 180- (your corner)

+3


source


As already explained, you find the opposite angle by subtracting your angle from 180 degrees. For example:

180 - yourangle

      

Direct control of X / Y speeds would not be very cumbersome. You simply change the speed of the X, multiplying it by minus 1, for example speedx = (-1) * speedx

. This will change the direction left-right, for example: something moving to the left will start moving to the right, and vice versa, and the vertical speed will not be affected.

If you are using sine / cosine (sin / cos) to recalculate your X / Y velocity components, then the method *(-1)

will probably be more efficient. Ultimately it depends on the context of your program. If you are looking for a better solution please update your question in more detail.

+2


source


Ahh, it seems the problem came from the negative numbers, in the end I made them positive and now the rotation is fine, I don't even need to recalculate the angle ... Thanks everyone, I ended up figuring out because of the bits of every answer.

0


source


flip counterclockwise clockwise (270 right → 90 right)

angle - 360

-

flip vertically (180 on top → 0/360 on top)

Math.Normalize(angle - 180)

-

both:

float flipped_vertical = angle - 360 float flipped_vertical_and_horizontal = Math.Normalize(flipped_vertical- 180)

0


source


This is the solution for -Y oriented angles (like a clock)! For orientation + X (like school math) you need to swap X and Y.

public static float FlipAngleX(float angle)
{
    angle = NormalizeAngle(angle);

    angle = TwoPi - angle;

    return angle;
}

public static float FlipAngleY(float angle)
{
    angle = NormalizeAngle(angle);

    if (angle < Pi)
    {
        angle = Pi - angle;
    }
    else
    {
        angle = TwoPi - angle + Pi;
    }
    return angle;
}

/// <summary>
/// Keeps angle between 0 - Two Pi
/// </summary>
public static float NormalizeAngle(float angle)
{
    if (angle < 0)
    {
        int backRevolutions = (int)(-angle / TwoPi);
        return angle + TwoPi * (backRevolutions + 1);
    }
    else
    {
        return angle % TwoPi;
    }
}

      

0


source


just 360-angle

will flip your corner horizontally but not vertically

-1


source







All Articles