MCPcopy Create free account
hub / github.com/cocos/cocos-engine / TEST

Function TEST

native/tests/unit-test/src/math_quaternion_test.cpp:34–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32#include "utils.h"
33
34TEST(mathQuaternionTest, test6) {
35 // identity
36 logLabel = "test the quaternion identity function";
37 cc::Quaternion quat(1, 2, 1, 1);
38 quat = cc::Quaternion::identity();
39 ExpectEq(quat.x == 0 && quat.y == 0 && quat.z == 0 && quat.w == 1, true);
40 // isIdentity
41 logLabel = "test the quaternion isIdentity function";
42 quat.set(5, 10, 10, 2);
43 quat.setIdentity();
44 ExpectEq(quat.isIdentity(), true);
45 // zero
46 logLabel = "test the quaternion zero function";
47 cc::Quaternion zero(1, 2, 1, 1);
48 zero = cc::Quaternion::zero();
49 ExpectEq(zero.x == 0 && zero.y == 0 && zero.z == 0 && zero.w == 0, true);
50 // isZero
51 logLabel = "test the quaternion isZero function";
52 ExpectEq(zero.isZero(), true);
53 // createFromRotationMatrix
54 logLabel = "test the quaternion createFromRotationMatrix function";
55 cc::Mat4 rotMat;
56 rotMat.m[0] = cos(cc::math::PI_DIV2);
57 rotMat.m[2] = sin(cc::math::PI_DIV2);
58 rotMat.m[8] = -sin(cc::math::PI_DIV2);
59 rotMat.m[10] = cos(cc::math::PI_DIV2);
60 cc::Quaternion::createFromRotationMatrix(rotMat, &quat);
61 ExpectEq(IsEqualF(-0.707106, quat.y), true);
62 // createFromAxisAngle
63 logLabel = "test the quaternion createFromAxisAngle function";
64 cc::Vec3 axis(0, 1, 0);
65 cc::Quaternion::createFromAxisAngle(axis, cc::math::PI_DIV2, &quat);
66 ExpectEq(IsEqualF(0.707106, quat.y), true);
67 // conjugate
68 logLabel = "test the quaternion conjugate function";
69 quat.set(1, 2, 1, 1);
70 quat.conjugate();
71 ExpectEq(quat.x == -1 && quat.y == -2 && quat.z == -1, true);
72 quat = quat.getConjugated();
73 ExpectEq(quat.x == 1 && quat.y == 2 && quat.z == 1, true);
74 // inverse
75 logLabel = "test the quaternion inverse function";
76 quat.inverse();
77 ExpectEq(IsEqualF(-0.142857149, quat.x) && IsEqualF(-0.142857149, quat.z), true);
78 quat = quat.getInversed();
79 ExpectEq(IsEqualF(1, quat.x) && IsEqualF(1, quat.z), true);
80 // multiply
81 logLabel = "test the quaternion multiply function";
82 cc::Quaternion mul(3, 2, 0, 1);
83 quat.multiply(mul);
84 ExpectEq(IsEqualF(2, quat.x) && IsEqualF(-3, quat.z), true);
85 // normalize
86 logLabel = "test the quaternion normalize function";
87 quat.normalize();
88 ExpectEq(IsEqualF(0.20203051, quat.x) && IsEqualF(-0.30304575, quat.z), true);
89 quat = quat.getNormalized();
90 ExpectEq(IsEqualF(0.20203051, quat.x) && IsEqualF(-0.30304575, quat.z), true);
91 // toAxisAngle

Callers

nothing calls this directly

Calls 15

ExpectEqFunction · 0.85
cosFunction · 0.85
sinFunction · 0.85
IsEqualFFunction · 0.85
getConjugatedMethod · 0.80
toAxisAngleMethod · 0.80
identityFunction · 0.50
lerpFunction · 0.50
QuaternionClass · 0.50
Vec3Class · 0.50
setMethod · 0.45
setIdentityMethod · 0.45

Tested by

no test coverage detected