Search code examples
mathvectormath

How to calculate vec4 cross product with glm?


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?


Solution

  • 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.