How to calculate vec4 cross product with glm?

Kimi picture Kimi · May 25, 2012 · Viewed 14.6k times · Source

Why this throws an compilation error: no matching function for call to ‘cross(glm::vec4&, glm::vec4&)’

glm::vec4 a;
glm::vec4 b;
glm::vec4 c = glm::cross(a, b);

but it works fine for vec3?

Answer

Nicol Bolas picture Nicol Bolas · May 26, 2012

There is no such thing as a 4D vector cross-product; the operation is only defined for 3D vectors. Well, technically, there is a seven-dimensional vector cross-product, but somehow I don't think you're looking for that.

Since 4D vector cross-products aren't mathematically reasonable, GLM doesn't offer a function to compute it.