MCPcopy Index your code
hub / github.com/HandmadeMath/HandmadeMath / HMM_QToM4

Function HMM_QToM4

HandmadeMath.h:2344–2387  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2342
2343COVERAGE(HMM_QToM4, 1)
2344static inline HMM_Mat4 HMM_QToM4(HMM_Quat Left)
2345{
2346 ASSERT_COVERED(HMM_QToM4);
2347
2348 HMM_Mat4 Result;
2349
2350 HMM_Quat NormalizedQ = HMM_NormQ(Left);
2351
2352 float XX, YY, ZZ,
2353 XY, XZ, YZ,
2354 WX, WY, WZ;
2355
2356 XX = NormalizedQ.X * NormalizedQ.X;
2357 YY = NormalizedQ.Y * NormalizedQ.Y;
2358 ZZ = NormalizedQ.Z * NormalizedQ.Z;
2359 XY = NormalizedQ.X * NormalizedQ.Y;
2360 XZ = NormalizedQ.X * NormalizedQ.Z;
2361 YZ = NormalizedQ.Y * NormalizedQ.Z;
2362 WX = NormalizedQ.W * NormalizedQ.X;
2363 WY = NormalizedQ.W * NormalizedQ.Y;
2364 WZ = NormalizedQ.W * NormalizedQ.Z;
2365
2366 Result.Elements[0][0] = 1.0f - 2.0f * (YY + ZZ);
2367 Result.Elements[0][1] = 2.0f * (XY + WZ);
2368 Result.Elements[0][2] = 2.0f * (XZ - WY);
2369 Result.Elements[0][3] = 0.0f;
2370
2371 Result.Elements[1][0] = 2.0f * (XY - WZ);
2372 Result.Elements[1][1] = 1.0f - 2.0f * (XX + ZZ);
2373 Result.Elements[1][2] = 2.0f * (YZ + WX);
2374 Result.Elements[1][3] = 0.0f;
2375
2376 Result.Elements[2][0] = 2.0f * (XZ + WY);
2377 Result.Elements[2][1] = 2.0f * (YZ - WX);
2378 Result.Elements[2][2] = 1.0f - 2.0f * (XX + YY);
2379 Result.Elements[2][3] = 0.0f;
2380
2381 Result.Elements[3][0] = 0.0f;
2382 Result.Elements[3][1] = 0.0f;
2383 Result.Elements[3][2] = 0.0f;
2384 Result.Elements[3][3] = 1.0f;
2385
2386 return Result;
2387}
2388
2389// This method taken from Mike Day at Insomniac Games.
2390// https://d3cw3dd2w32x2b.cloudfront.net/wp-content/uploads/2015/01/matrix-to-quat.pdf

Callers 1

TESTFunction · 0.85

Calls 1

HMM_NormQFunction · 0.85

Tested by

no test coverage detected