Skip to content

Commit aab4134

Browse files
mcdubhghlasArctis-Fireblight
authored andcommitted
Reduced redundancy in Vector3::slerp(), technically removed 18 ops from the function.
1 parent 58d31dd commit aab4134

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

core/math/vector3.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,11 @@ Vector3 Vector3::slerp(const Vector3 &p_to, real_t p_weight) const {
264264
// Colinear vectors have no rotation axis or angle between them, so the best we can do is lerp.
265265
return lerp(p_to, p_weight);
266266
}
267-
axis /= Math::sqrt(axis_length_sq);
267+
real_t axis_length = Math::sqrt(axis_length_sq);
268+
axis /= axis_length;
268269
real_t start_length = Math::sqrt(start_length_sq);
269270
real_t result_length = Math::lerp(start_length, Math::sqrt(end_length_sq), p_weight);
270-
real_t angle = angle_to(p_to);
271+
real_t angle = Math::atan2(axis_length, dot(p_to));
271272
return rotated(axis, angle * p_weight) * (result_length / start_length);
272273
}
273274

0 commit comments

Comments
 (0)