Ejemplo n.º 1
0
        public static void ConstructTransformFromMatrixWithDesiredScale(FMatrix aMatrix, FMatrix bMatrix,
                                                                        FVector desiredScale, ref FTransform outTransform)
        {
            // the goal of using M is to get the correct orientation
            // but for translation, we still need scale
            var m = aMatrix * bMatrix;

            m.RemoveScaling();

            // apply negative scale back to axes
            var signedScale = desiredScale.GetSignVector();

            m.SetAxis(0, m.GetScaledAxis(EAxis.X) * signedScale.X);
            m.SetAxis(1, m.GetScaledAxis(EAxis.Y) * signedScale.Y);
            m.SetAxis(2, m.GetScaledAxis(EAxis.Z) * signedScale.Z);

            // @note: if you have negative with 0 scale, this will return rotation that is identity
            // since matrix loses that axes
            var rotation = new FQuat(m);

            rotation.Normalize();

            // set values back to output
            outTransform.Scale3D  = desiredScale;
            outTransform.Rotation = rotation;

            // technically I could calculate this using FTransform but then it does more quat multiplication
            // instead of using Scale in matrix multiplication
            // it's a question of between RemoveScaling vs using FTransform to move translation
            outTransform.Translation = m.GetOrigin();
        }