mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[Impeller] Add Quaternion to Matrix conversion (flutter/engine#38056)
This commit is contained in:
parent
cfccb9ed0b
commit
39362b24b5
@ -265,6 +265,26 @@ TEST(GeometryTest, MatrixVectorMultiplication) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GeometryTest, MatrixMakeRotationFromQuaternion) {
|
||||
{
|
||||
auto matrix = Matrix::MakeRotation(Quaternion({1, 0, 0}, kPiOver2));
|
||||
auto expected = Matrix::MakeRotationX(Radians(kPiOver2));
|
||||
ASSERT_MATRIX_NEAR(matrix, expected);
|
||||
}
|
||||
|
||||
{
|
||||
auto matrix = Matrix::MakeRotation(Quaternion({0, 1, 0}, kPiOver2));
|
||||
auto expected = Matrix::MakeRotationY(Radians(kPiOver2));
|
||||
ASSERT_MATRIX_NEAR(matrix, expected);
|
||||
}
|
||||
|
||||
{
|
||||
auto matrix = Matrix::MakeRotation(Quaternion({0, 0, 1}, kPiOver2));
|
||||
auto expected = Matrix::MakeRotationZ(Radians(kPiOver2));
|
||||
ASSERT_MATRIX_NEAR(matrix, expected);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GeometryTest, MatrixTransformDirection) {
|
||||
{
|
||||
auto matrix = Matrix::MakeTranslation({100, 100, 100}) *
|
||||
|
||||
@ -122,6 +122,31 @@ struct Matrix {
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
static Matrix MakeRotation(Quaternion q) {
|
||||
// clang-format off
|
||||
return Matrix(
|
||||
1.0 - 2.0 * q.y * q.y - 2.0 * q.z * q.z,
|
||||
2.0 * q.x * q.y + 2.0 * q.z * q.w,
|
||||
2.0 * q.x * q.z - 2.0 * q.y * q.w,
|
||||
0.0,
|
||||
|
||||
2.0 * q.x * q.y - 2.0 * q.z * q.w,
|
||||
1.0 - 2.0 * q.x * q.x - 2.0 * q.z * q.z,
|
||||
2.0 * q.y * q.z + 2.0 * q.x * q.w,
|
||||
0.0,
|
||||
|
||||
2.0 * q.x * q.z + 2.0 * q.y * q.w,
|
||||
2.0 * q.y * q.z - 2.0 * q.x * q.w,
|
||||
1.0 - 2.0 * q.x * q.x - 2.0 * q.y * q.y,
|
||||
0.0,
|
||||
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
static Matrix MakeRotation(Scalar radians, const Vector4& r) {
|
||||
const Vector4 v = r.Normalize();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user