在GLM(OpenGL)中相乘矩阵和向量 [英] Multiplying a matrix and a vector in GLM (OpenGL)

查看:1291
本文介绍了在GLM(OpenGL)中相乘矩阵和向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个转换矩阵 m 和一个向量 v 。我想使用矩阵对向量进行线性变换。我希望我能够做这样的事情:

I have a transformation matrix, m, and a vector, v. I want to do a linear transformation on the vector using the matrix. I'd expect that I would be able to do something like this:

glm::mat4 m(1.0);
glm::vec4 v(1.0);

glm::vec4 result = v * m;

这似乎不起作用。在GLM中执行这种操作的正确方法是什么?

This doesn't seem to work, though. What is the correct way to do this kind of operation in GLM?

只需注意任何遇到类似问题的人。 GLM要求所有操作数都使用相同的类型。不要尝试将 dvec4 mat4 相乘并期望它能正常工作,您需要一个 vec4

Just a note to anyone who runs into a similar problem. GLM requires all operands to use the same type. Don't try multiplying a dvec4 with a mat4 and expect it to work, you need a vec4.

推荐答案

glm :: vec4 表示为列向量。因此,正确的格式为:

glm::vec4 is represented as a column vector. Therefore, the proper form is:

glm::vec4 result = m * v;

(请注意操作数的顺序)

(note the order of the operands)

这篇关于在GLM(OpenGL)中相乘矩阵和向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆