From 8ae3c23ec84da6f4dc69ff282569eda971056731 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 15 Jul 2021 22:07:25 +0200 Subject: [PATCH] Add `Actor.RotateAround` --- Source/Engine/Level/Actor.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Source/Engine/Level/Actor.cs b/Source/Engine/Level/Actor.cs index 669945e7e..c3b13bece 100644 --- a/Source/Engine/Level/Actor.cs +++ b/Source/Engine/Level/Actor.cs @@ -317,6 +317,23 @@ namespace FlaxEngine } } + /// + /// Rotates the actor around axis passing through point in world-space by angle (in degrees). + /// + /// Modifies both the position and the rotation of the actor (scale remains the same). + /// The point (world-space). + /// The axis (normalized). + /// The angle (in degrees). + public void RotateAround(Vector3 point, Vector3 axis, float angle) + { + var transform = Transform; + var q = Quaternion.RotationAxis(axis, angle * Mathf.DegreesToRadians); + var dif = (transform.Translation - point) * q; + transform.Translation = point + dif; + transform.Orientation = q; + Transform = transform; + } + /// public override string ToString() {