0

this is my code

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

glm::vec3 twiceV = 2 * v;

I have included glm Stable and experimental glm extensions. Why I cannot use int * vec?

Ðаn
  • 10,400
  • 11
  • 57
  • 90
Morovo
  • 3
  • 3

2 Answers2

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.

Wander Nauta
  • 14,707
  • 1
  • 39
  • 59
2

This is because there is no global overloaded operator of the form

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

Does v * 2 work by any chance? (A member function operator overload would suffice for that.)

Or perhaps even 2f * v, which would then require the first parameter of the overloaded * operator to be a float?

Bathsheba
  • 220,365
  • 33
  • 331
  • 451