MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / TestWorldToLocal

Method TestWorldToLocal

Source/Engine/Tests/TestTransform.cs:79–106  ·  view source on GitHub ↗

Tests the world space to local space conversion.

()

Source from the content-addressed store, hash-verified

77 /// Tests the world space to local space conversion.
78 /// </summary>
79 [Test]
80 public void TestWorldToLocal()
81 {
82 Transform t1 = new Transform(new Vector3(10, 1, 10), Quaternion.Euler(45, 0, -15), new Float3(1.5f, 0.5f, 0.1f));
83 Transform t2 = new Transform(new Vector3(0, 20, 0), Quaternion.Euler(0, 0, 15), new Float3(1.0f, 2.0f, 1.0f));
84
85 Transform a1 = t1.WorldToLocal(t2);
86 Float3 a2 = t1.WorldToLocal(t2.Translation);
87
88 Float3 a3;
89 {
90 Matrix scale, rotation, scaleRotation;
91 Matrix.Scaling(ref t1.Scale, out scale);
92 Matrix.RotationQuaternion(ref t1.Orientation, out rotation);
93 Matrix.Multiply(ref scale, ref rotation, out scaleRotation);
94 Matrix.Invert(ref scaleRotation, out scale);
95 a3 = t2.Translation - t1.Translation;
96 Float3.Transform(ref a3, ref scale, out a3);
97 }
98
99 var a4T = new Vector3[1];
100 t1.WorldToLocal(new Vector3[1] { t2.Translation }, a4T);
101 Float3 a4 = a4T[0];
102
103 Assert.IsTrue(Float3.NearEqual((Float3)a1.Translation, a2));
104 Assert.IsTrue(Float3.NearEqual(a2, a3, 0.0001f));
105 Assert.IsTrue(Float3.NearEqual(a2, a4));
106 }
107
108 /// <summary>
109 /// Test conversions between transform local/world space

Callers

nothing calls this directly

Calls 9

EulerMethod · 0.45
WorldToLocalMethod · 0.45
ScalingMethod · 0.45
RotationQuaternionMethod · 0.45
MultiplyMethod · 0.45
InvertMethod · 0.45
TransformMethod · 0.45
IsTrueMethod · 0.45
NearEqualMethod · 0.45

Tested by

no test coverage detected