Open dfkeenan opened 6 years ago
This seems to work:
public static void Translate(this TransformComponent transform, ref Vector3 translation, Space relativeTo = Space.Self)
{
if (transform == null)
{
throw new ArgumentNullException(nameof(transform));
}
var localTranslation = translation;
if (relativeTo == Space.Self) {
Vector3.TransformNormal(ref translation, ref transform.WorldMatrix, out localTranslation);
}
if (transform.Parent != null)
{
Matrix.Invert(ref transform.Parent.WorldMatrix, out var inverseParent);
Vector3.TransformNormal(ref localTranslation, ref inverseParent, out localTranslation);
}
if (transform.UseTRS) {
transform.Position += localTranslation;
} else {
transform.LocalMatrix.TranslationVector += localTranslation;
}
transform.UpdateWorldMatrix();
}
My first attempt to do these methods that worked with
UseTRS
set totrue
orfalse
didn't seem to work correctly when updating the matrices directly. So temporarily not supportingTransformComponent
s withUserTRS
set to false.Need some help with people who know there math better than I do.