Пример #1
0
        public FQuat Quaternion()
        {
            //PLATFORM_ENABLE_VECTORINTRINSICS
            const float DEG_TO_RAD = (float)(System.Math.PI / 180.0f);
            const float DIVIDE_BY_2 = DEG_TO_RAD / 2.0f;
            float       sp, sy, sr;
            float       cp, cy, cr;

            sp = (float)System.Math.Sin(Pitch * DIVIDE_BY_2);
            cp = (float)System.Math.Cos(Pitch * DIVIDE_BY_2);
            sy = (float)System.Math.Sin(Yaw * DIVIDE_BY_2);
            cy = (float)System.Math.Cos(Yaw * DIVIDE_BY_2);
            sr = (float)System.Math.Sin(Roll * DIVIDE_BY_2);
            cr = (float)System.Math.Cos(Roll * DIVIDE_BY_2);

            var rotationQuat = new FQuat
            {
                X = cr * sp * sy - sr * cp * cy,
                Y = -cr * sp * cy - sr * cp * sy,
                Z = cr * cp * sy - sr * sp * cy,
                W = cr * cp * cy + sr * sp * sy
            };

            return(rotationQuat);
        }
Пример #2
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, signedScale.X * m.GetScaledAxis(EAxis.X));
            m.SetAxis(1, signedScale.Y * m.GetScaledAxis(EAxis.Y));
            m.SetAxis(2, signedScale.Z * m.GetScaledAxis(EAxis.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();
        }
Пример #3
0
 public FTransform(FStructFallback data)
 {
     Rotation    = data.GetOrDefault <FQuat>(nameof(Rotation));
     Translation = data.GetOrDefault <FVector>(nameof(Translation));
     Scale3D     = data.GetOrDefault <FVector>(nameof(Scale3D));
 }
Пример #4
0
 public FTransform(FRotator rotation, FVector translation, FVector scale3D)
 {
     Rotation    = new FQuat(rotation);
     Translation = translation;
     Scale3D     = scale3D;
 }
Пример #5
0
 public FTransform(FQuat rotation, FVector translation, FVector scale3D)
 {
     Rotation    = rotation;
     Translation = translation;
     Scale3D     = scale3D;
 }
Пример #6
0
 public FTransform(FRotator rotation)
 {
     Rotation    = new FQuat(rotation);
     Translation = FVector.ZeroVector;
     Scale3D     = FVector.OneVector;
 }
Пример #7
0
 public FQuat InverseTransformRotation(FQuat q) => Rotation.Inverse() * q;
Пример #8
0
 public FQuat TransformRotation(FQuat q) => Rotation * q;
Пример #9
0
 public FTransform(FQuat rotation)
 {
     Rotation    = rotation;
     Translation = FVector.ZeroVector;
     Scale3D     = FVector.OneVector;
 }
Пример #10
0
 public FTransform(FVector translation)
 {
     Rotation    = FQuat.Identity;
     Translation = translation;
     Scale3D     = FVector.OneVector;
 }
Пример #11
0
 public FTransform(EForceInit init = EForceInit.ForceInit)
 {
     Rotation    = new FQuat(0f, 0f, 0f, 1f);
     Translation = new FVector(0f);
     Scale3D     = FVector.OneVector;
 }
Пример #12
0
 public void CopyRotation(ref FTransform other)
 {
     Rotation = other.Rotation;
 }