OpenGL ES 2.0-围绕枢轴点2D旋转点(顶点着色器)

时间:2020-05-25 08:36:40

标签: matrix opengl-es opengl-es-2.0 vertex-shader

我正在尝试围绕2D中的某个点旋转顶点。 我在这里https://stackoverflow.com/a/48156351/776388找到了@ Rabbid76解决方案,但我需要绕着z矢量旋转。

1 个答案:

答案 0 :(得分:1)

我找到了解决方法

vec2 rotate(vec2 point, float degree, vec2 pivot)
{
    float radAngle = -radians(degree);// "-" - clockwise
    float x = point.x;
    float y = point.y;

    float rX = pivot.x + (x - pivot.x) * cos(radAngle) - (y - pivot.y) * sin(radAngle);
    float rY = pivot.y + (x - pivot.x) * sin(radAngle) + (y - pivot.y) * cos(radAngle);

    return vec2(rX, rY);
}
相关问题