Java Matrix4f.transform 等同于 GLM?
Java Matrix4f.transform equivalent in GLM?
在 Java 的 OpenGL 中,Matrix4f 有一个 transform() 方法。我正在尝试查看使用此示例的示例,但想将其转换为使用 GLM。但是我在 GLM 中找不到与 transform() 等价的东西,我也不明白 transform() 的真正作用。
例如:
在Java中:
Vector4f direction = new Vector4f(x, y, z, 1);
Matrix4f rotationMatrix = new Matrix4f();
… set rotationMatrix …
Matrix4f.transform(rotationMatrix, direction, direction);
在 C++ 中使用 GLM:
vec4 direction = vec4(x, y, z, 1);
mat4 rotationMatrix = mat4();
… set rotationMatrix …
??? What to use instead of transform() ???
GLM provides the *
-operator. It can be used similar the operators in OpenGL Shading Language (GLSL)例如:
vec4 direction = vec4(x, y, z, 1.0f);
mat4 rotationMatrix = mat4(1.0f);
direction = rotationMatrix * direction;
请注意,如果您想构造一个 Identity matrix,那么您需要将单个标量 (1.0) 传递给 mat4
的构造函数(例如 mat4(1.0f)
)。 mat4()
构造一个未初始化的矩阵。
在 Java 的 OpenGL 中,Matrix4f 有一个 transform() 方法。我正在尝试查看使用此示例的示例,但想将其转换为使用 GLM。但是我在 GLM 中找不到与 transform() 等价的东西,我也不明白 transform() 的真正作用。
例如:
在Java中:
Vector4f direction = new Vector4f(x, y, z, 1);
Matrix4f rotationMatrix = new Matrix4f();
… set rotationMatrix …
Matrix4f.transform(rotationMatrix, direction, direction);
在 C++ 中使用 GLM:
vec4 direction = vec4(x, y, z, 1);
mat4 rotationMatrix = mat4();
… set rotationMatrix …
??? What to use instead of transform() ???
GLM provides the *
-operator. It can be used similar the operators in OpenGL Shading Language (GLSL)例如:
vec4 direction = vec4(x, y, z, 1.0f);
mat4 rotationMatrix = mat4(1.0f);
direction = rotationMatrix * direction;
请注意,如果您想构造一个 Identity matrix,那么您需要将单个标量 (1.0) 传递给 mat4
的构造函数(例如 mat4(1.0f)
)。 mat4()
构造一个未初始化的矩阵。