首页 > 解决方案 > 旋转 Y 轴以翻转纹理朝向反转 X 轴

问题描述

我想沿 Y 轴旋转我的精灵(将旋转应用于变换矩阵)以翻转精灵的方向。

但不知何故,它似​​乎也影响了我的输入系统......
按右变成左......而且似乎精灵不再呈现在实体真实位置..“真实位置”由输入系统和紧随其后的是相机,但精灵的方向相反,就好像输入被反转了一样。(输入改变与按下的键相对应的速度,并且变换分量在每次更新时由该向量平移)

这是我用来获取矩阵的代码:

    public Matrix4f getTransformationMatrix() {
            Matrix4f matrix = new Matrix4f();
            matrix.scale(scale);
            matrix.rotateX((float) Math.toRadians(rotation.getX()));
            matrix.rotateY((float) Math.toRadians(rotation.getY()));
            matrix.rotateZ((float) Math.toRadians(rotation.getZ()));
            matrix.translate(position);
            return matrix;
        }
    
       
        public Matrix4f getViewMatrix() {
            Matrix4f matrix = new Matrix4f();
            matrix.rotateZ((float) Math.toRadians(rotation.getZ()));
            matrix.translate(Vector3f.scale(position, -1));
            return matrix;
        }

我已经检查并重新检查了我的旋转矩阵,但他们在这里过于自信:

X = new Matrix4f(new float[][] { {1, 0, 0, 0}, {0, cos, -sin, 0}, {0, sin, cos, 0}, {0, 0, 0, 1} })
Y = new Matrix4f(new float[][] { {cos, 0, sin, 0}, {0, 1, 0, 0}, {-sin, 0, cos, 0}, {0, 0, 0, 1} })
Z = new Matrix4f(new float[][] { {cos, sin, 0, 0}, {-sin, cos, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} })

我按这个顺序在我的着色器中使用 mvp 矩阵projection_matrix * view_matrix * transformation_matrix * vec4(attribute_position, 1.0)

标签: javaopengl2drotational-matricestransformation-matrix

解决方案


推荐阅读