It is best to implement the multiplication operator as a friend function; otherwise, it will support the syntax v * 2.0 but not 2.0 * v.
vsg::vec3 n(1.0f, 0.0f, 0.0f);
vsg::vec3 n2 = 2.0f * n; // error: no match for ‘operator*’ (operand types are ‘float’ and ‘vsg::vec3’)
vsg::vec3 n3 = n * 3.0f; // OK, it calls n.operator*(3.0f);
The vec3 type requires this implementation syntax, while vec2 and vec4 have fewer such use cases. For the sake of consistency, please provide the same implementation for all three types.
It is best to implement the multiplication operator as a
friendfunction; otherwise, it will support the syntaxv * 2.0but not2.0 * v.The
vec3type requires this implementation syntax, whilevec2andvec4have fewer such use cases. For the sake of consistency, please provide the same implementation for all three types.