java - 旋转 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)
。
解决方案
推荐阅读
- r - 不要使用 data.table 自动返回按列
- powershell - 数组对象到哈希表的 Azure Powershell 转换及相关输出尝试
- r - 基于两个条件过滤:值小于匹配日期?
- javascript - JSON 响应被捕获所有 URL 破坏并返回为 404 页面
- c++ - clang 预处理输出中的元数据是什么?
- python - 检测大型python列表中的重复整数序列
- javascript - 在 ASPX 中使用物化打开模态
- python - 使用python执行多个日期的文件下载
- angular - chartjs错误转换为null
- java - Gradle 问题 - 错误:任务执行失败