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

Method LocalToWorld

Source/Engine/Core/Math/Transform.cpp:96–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96void Transform::LocalToWorld(const Transform& other, Transform& result) const
97{
98 //Quaternion::Multiply(Orientation, other.Orientation, result.Orientation);
99 const float a = Orientation.Y * other.Orientation.Z - Orientation.Z * other.Orientation.Y;
100 const float b = Orientation.Z * other.Orientation.X - Orientation.X * other.Orientation.Z;
101 const float c = Orientation.X * other.Orientation.Y - Orientation.Y * other.Orientation.X;
102 const float d = Orientation.X * other.Orientation.X + Orientation.Y * other.Orientation.Y + Orientation.Z * other.Orientation.Z;
103 result.Orientation.X = Orientation.X * other.Orientation.W + other.Orientation.X * Orientation.W + a;
104 result.Orientation.Y = Orientation.Y * other.Orientation.W + other.Orientation.Y * Orientation.W + b;
105 result.Orientation.Z = Orientation.Z * other.Orientation.W + other.Orientation.Z * Orientation.W + c;
106 result.Orientation.W = Orientation.W * other.Orientation.W - d;
107
108 //result.Orientation.Normalize();
109 const float length = result.Orientation.Length();
110 if (length > ZeroTolerance)
111 {
112 const float inv = 1.0f / length;
113 result.Orientation.X *= inv;
114 result.Orientation.Y *= inv;
115 result.Orientation.Z *= inv;
116 result.Orientation.W *= inv;
117 }
118
119 //Vector3::Multiply(Scale, other.Scale, result.Scale);
120 result.Scale = Float3(Scale.X * other.Scale.X, Scale.Y * other.Scale.Y, Scale.Z * other.Scale.Z);
121
122 //Vector3 tmp; Vector3::Multiply(other.Translation, Scale, tmp);
123 Vector3 tmp = Vector3(other.Translation.X * Scale.X, other.Translation.Y * Scale.Y, other.Translation.Z * Scale.Z);
124
125 //Vector3::Transform(tmp, Orientation, tmp);
126 const float x = Orientation.X + Orientation.X;
127 const float y = Orientation.Y + Orientation.Y;
128 const float z = Orientation.Z + Orientation.Z;
129 const float wx = Orientation.W * x;
130 const float wy = Orientation.W * y;
131 const float wz = Orientation.W * z;
132 const float xx = Orientation.X * x;
133 const float xy = Orientation.X * y;
134 const float xz = Orientation.X * z;
135 const float yy = Orientation.Y * y;
136 const float yz = Orientation.Y * z;
137 const float zz = Orientation.Z * z;
138 tmp = Vector3(
139 tmp.X * (1.0f - yy - zz) + tmp.Y * (xy - wz) + tmp.Z * (xz + wy),
140 tmp.X * (xy + wz) + tmp.Y * (1.0f - xx - zz) + tmp.Z * (yz - wx),
141 tmp.X * (xz - wy) + tmp.Y * (yz + wx) + tmp.Z * (1.0f - xx - yy));
142
143 //Vector3::Add(tmp, Translation, result.Translation);
144 result.Translation = Vector3(tmp.X + Translation.X, tmp.Y + Translation.Y, tmp.Z + Translation.Z);
145}
146
147void Transform::LocalToWorldVector(const Vector3& vector, Vector3& result) const
148{

Callers 15

OnRenderMethod · 0.45
WriteObjectsMethod · 0.45
onJobRenderMethod · 0.45
IntersectsMethod · 0.45
DrawInstanceMethod · 0.45
DrawClusterMethod · 0.45
DrawClusterGlobalSDFMethod · 0.45
DrawClusterGlobalSAMethod · 0.45
AddInstanceMethod · 0.45
SetInstanceTransformMethod · 0.45
DrawMethod · 0.45

Calls 5

Float3Class · 0.85
Vector3Class · 0.70
TransformClass · 0.70
AddFunction · 0.70
LengthMethod · 0.45

Tested by 2

TestLocalToWorldMethod · 0.36