MacMillan
MacMillan

Reputation: 593

GLM matrix multiply vector gives incorrect results

glm::fmat4 m(0.001716f, 0.00001f, 0.0f, -0.545988f,
    0.0f, 0.001725f, 0.0f, -0.408158f,
    0.0f, 0.0f, 0.0f, -1.0f,
    0.0f, 0.0f, -0.000029f, 0.031473f);
glm::fvec4 v(320.5f, 240.5f, 781.762634f, 1.0f);
glm::fvec4 result = m * v;
printf("result = (%f, %f, %f, %f)\n", result.x, result.y, result.z, result.w);

The code above gives:

result = (0.549978, 0.418067, -0.000029, -1054.882324)

The same calculation done by WolframAlpha:

(0.006395
0.0067045
-1
0.00880188)

Why? Am I understanding something wrong? If it's relevant, I'm using Visual Studio 2015, 64-bit built target.

Upvotes: 1

Views: 587

Answers (1)

Eissa N.
Eissa N.

Reputation: 1725

You are computing A*b in one and Transpose[A]*b in another.

Upvotes: 1

Related Questions