Reputation: 61
glm::vec4 x = glm::vec4(0.0f, 0.0f, 1.0f, 0.0f);
glm::vec4 y = glm::vec4(0.0f, 1.0f, 0.0f, 0.0f);
glm::vec4 z = glm::vec4(-1.0f, 0.0f, 0.0f, 0.0f);
glm::vec4 t(0.0f, 0.0f, 0.0f, 1.0f);
glm::mat4 rot(x, y, z, t);
glm::vec4 test = rot * glm::vec4(10.0f, 0.0f, 0.0f, 1.0f);
The "test" varible should be (0.0f, 0.0f, -10.0f, 1.0f) but the returned result is (0.0f, 0.0f, 10.0f, 1.0f). Is this a bug of glm?
Upvotes: 0
Views: 167
Reputation: 2699
I suppose you are assuming that the four vectors x
, y
, z
, and t
are "row vectors", but it appears that they are "column vectors". Therefore, the matrix rot
is most likely:
x y z t
__________
0 0 -1 0
0 1 0 0
1 0 0 0
0 0 0 1
Which when multiplied with column vector:
10
0
0
1
Gives column vector:
0
0
10
1
EDIT: Fixed inverted terminology
Upvotes: 1
Reputation: 1519
Wouldn't the actual result be (0, 0, 10, 2)
? Essentially, matrix times a vector means a linear combination of matrix columns with coefficients from a vector. So, in your example
rot * glm::vec4(10.0f, 0.0f, 0.0f, 1.0f)
is equivalent to
10.0f * x + 0.0f * y + 0.0f * z + 1.0f * t
Upvotes: 0