简体   繁体   English

二维旋转OpenGL

[英]2d rotation opengl

Here is the code I am using. 这是我正在使用的代码。

#define ANGLETORADIANS 0.017453292519943295769236907684886f // PI / 180
#define RADIANSTOANGLE 57.295779513082320876798154814105f   // 180 / PI

rotation = rotation *ANGLETORADIANS;

cosRotation = cos(rotation);
sinRotation = sin(rotation);

for(int i = 0; i < 3; i++)
{
    px[i] = (vec[i].x + centerX) * (cosRotation - (vec[i].y + centerY)) * sinRotation;
    py[i] = (vec[i].x + centerX) * (sinRotation + (vec[i].y + centerY)) * cosRotation;
    printf("num: %i, px: %f, py: %f\n", i, px[i], py[i]);
}

so far it seams my Y value is being fliped.. say I enter the value of X = 1 and Y = 1 with a 45 rotation you should see about x = 0 and y = 1.25 ish but I get x = 0 y = -1.25. 到目前为止,它接缝了我的Y值被翻转了。说我输入X = 1和Y = 1并旋转45度,您应该看到大约x = 0和y = 1.25 ish,但是我得到x = 0 y =- 1.25。

Also my 90 degree rotation always return x = 0 and y = 0. 同样,我的90度旋转总是返回x = 0和y = 0。

ps I know I'm only centering my values and not putting them back where they came from. ps:我知道我只是在集中我的价值观,而不是把它们放回原来的位置。 It's not needed to put them back as all I need to know is the value I'm getting now. 不需要将它们放回去,因为我需要知道的就是我现在所获得的价值。

Your bracket placement doesn't look right to me. 您的支架位置对我而言不合适。 I would expect: 我期望:

px[i] = (vec[i].x + centerX) * cosRotation - (vec[i].y + centerY) * sinRotation;
py[i] = (vec[i].x + centerX) * sinRotation + (vec[i].y + centerY) * cosRotation;

Your brackets are wrong. 你的括号是错误的。 It should be 它应该是

px[i] = ((vec[i].x + centerX) * cosRotation) - ((vec[i].y + centerY) * sinRotation);
py[i] = ((vec[i].x + centerX) * sinRotation) + ((vec[i].y + centerY) * cosRotation);

instead 代替

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM