0

这是我的代码

glm::vec3 v(4, -6, 7);

glm::vec3 twiceV = 2 * v;

我已经包含了 glm 稳定和实验性 glm 扩展。为什么我不能使用int * vec

4

2 回答 2

2

2 is an integer, while the elements of a glm::vec3 are floats. Try this instead:

glm::vec3 twiceV = 2.0f * v;

I would also pass floating-point values to the constructor (4.0f), just to make it explicit that you're dealing with floats.

Alternatively, you can use an integer vector glm::ivec3:

glm::ivec3 v(4, -6, 7);
glm::ivec3 twiceV = 2 * v;

Of course, an integer vector will only hold integer values, which might not be what you want.

于 2017-02-03T15:52:26.753 回答
2

这是因为没有全局重载操作符的形式

glm::vec3 operator*(int, const glm::vec3&)

v * 2有任何机会工作吗?(成员函数运算符重载就足够了。)

或者甚至2f * v可能需要重载*运算符的第一个参数是float?

于 2017-02-03T15:53:31.287 回答