MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / rotationMatrix

Method rotationMatrix

testbed/opengl-framework/src/maths/Matrix4.h:408–436  ·  view source on GitHub ↗

Return a 4x4 rotation matrix

Source from the content-addressed store, hash-verified

406
407// Return a 4x4 rotation matrix
408inline Matrix4 Matrix4::rotationMatrix(const Vector3& axis, float angle) {
409
410 float cosA = cos(angle);
411 float sinA = sin(angle);
412 Matrix4 rotationMatrix;
413 rotationMatrix.setToIdentity();
414
415 rotationMatrix.m[0][0] = cosA + (1-cosA) * axis.x * axis.x;
416 rotationMatrix.m[0][1] = (1-cosA) * axis.x * axis.y - axis.z * sinA;
417 rotationMatrix.m[0][2] = (1-cosA) * axis.x * axis.z + axis.y * sinA;
418 rotationMatrix.m[0][3] = 0.f;
419
420 rotationMatrix.m[1][0] = (1-cosA) * axis.x * axis.y + axis.z * sinA;
421 rotationMatrix.m[1][1] = cosA + (1-cosA) * axis.y * axis.y;
422 rotationMatrix.m[1][2] = (1-cosA) * axis.y * axis.z - axis.x * sinA;
423 rotationMatrix.m[1][3] = 0.f;
424
425 rotationMatrix.m[2][0] = (1-cosA) * axis.x * axis.z - axis.y * sinA;
426 rotationMatrix.m[2][1] = (1-cosA) * axis.y * axis.z + axis.x * sinA;
427 rotationMatrix.m[2][2] = cosA + (1-cosA) * axis.z * axis.z;
428 rotationMatrix.m[2][3] = 0.f;
429
430 rotationMatrix.m[3][0] = 0.f;
431 rotationMatrix.m[3][1] = 0.f;
432 rotationMatrix.m[3][2] = 0.f;
433 rotationMatrix.m[3][3] = 1.f;
434
435 return rotationMatrix;
436}
437
438// Return a 4x4 perspective projection matrix
439inline Matrix4 Matrix4::perspectiveProjectionMatrix(float nearDistance, float farDistance, int width, int height,

Callers

nothing calls this directly

Calls 1

setToIdentityMethod · 0.45

Tested by

no test coverage detected