mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Common: Add Matrix33::FromQuaternion.
This commit is contained in:
parent
7a6a4510f6
commit
8ab3694f51
@ -45,6 +45,22 @@ Matrix33 Matrix33::Identity()
|
|||||||
return mtx;
|
return mtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matrix33 Matrix33::FromQuaternion(float qx, float qy, float qz, float qw)
|
||||||
|
{
|
||||||
|
// Normalize.
|
||||||
|
const float n = 1.0f / sqrt(qx * qx + qy * qy + qz * qz + qw * qw);
|
||||||
|
qx *= n;
|
||||||
|
qy *= n;
|
||||||
|
qz *= n;
|
||||||
|
qw *= n;
|
||||||
|
|
||||||
|
return {
|
||||||
|
1 - 2 * qy * qy - 2 * qz * qz, 2 * qx * qy - 2 * qz * qw, 2 * qx * qz + 2 * qy * qw,
|
||||||
|
2 * qx * qy + 2 * qz * qw, 1 - 2 * qx * qx - 2 * qz * qz, 2 * qy * qz - 2 * qx * qw,
|
||||||
|
2 * qx * qz - 2 * qy * qw, 2 * qy * qz + 2 * qx * qw, 1 - 2 * qx * qx - 2 * qy * qy,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Matrix33 Matrix33::RotateX(float rad)
|
Matrix33 Matrix33::RotateX(float rad)
|
||||||
{
|
{
|
||||||
const float s = std::sin(rad);
|
const float s = std::sin(rad);
|
||||||
|
@ -273,6 +273,7 @@ class Matrix33
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Matrix33 Identity();
|
static Matrix33 Identity();
|
||||||
|
static Matrix33 FromQuaternion(float x, float y, float z, float w);
|
||||||
|
|
||||||
// Return a rotation matrix around the x,y,z axis
|
// Return a rotation matrix around the x,y,z axis
|
||||||
static Matrix33 RotateX(float rad);
|
static Matrix33 RotateX(float rad);
|
||||||
|
Loading…
Reference in New Issue
Block a user