Exemple #1
0
 /// <summary>
 /// NitroxTransform is always attached to an Entity
 /// </summary>
 public NitroxTransform(NitroxVector3 localPosition, NitroxQuaternion localRotation, NitroxVector3 scale, Entity entity)
 {
     LocalPosition = localPosition;
     LocalRotation = localRotation;
     LocalScale    = scale;
     Entity        = entity;
 }
Exemple #2
0
        public void SetParent(NitroxTransform parent, bool worldPositionStays = true)
        {
            if (!worldPositionStays)
            {
                Parent = parent;
                return;
            }

            NitroxVector3    position = Position;
            NitroxQuaternion rotation = Rotation;

            Parent = parent;

            Position = position;
            Rotation = rotation;
        }
Exemple #3
0
        //Used https://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
        public NitroxVector3 ToEuler()
        {
            float sqw = W * W;
            float sqx = X * X;
            float sqy = Y * Y;
            float sqz = Z * Z;

            float unit = sqx + sqy + sqz + sqw; // if normalized is one, otherwise is correction factor
            float test = X * Y + Z * W;

            float heading, attitude, bank;

            if (test > 0.499f * unit) // singularity at north pole
            {
                heading  = 2 * Mathf.Atan2(X, W);
                attitude = Mathf.PI / 2f;
                bank     = 0;
            }
            else if (test < -0.499f * unit) // singularity at south pole
            {
                heading  = -2 * Mathf.Atan2(X, W);
                attitude = -Mathf.PI / 2f;
                bank     = 0;
            }
            else
            {
                heading  = Mathf.Atan2(2 * Y * W - 2 * X * Z, sqx - sqy - sqz + sqw);
                attitude = Mathf.Asin(2 * test / unit);
                bank     = Mathf.Atan2(2 * X * W - 2 * Y * Z, -sqx + sqy - sqz + sqw);
            }

            NitroxVector3 euler = new NitroxVector3(bank * Mathf.RAD2DEG, heading * Mathf.RAD2DEG, attitude * Mathf.RAD2DEG);

            NormalizeEuler(ref euler);

            return(euler);
        }
Exemple #4
0
 public static void NormalizeEuler(ref NitroxVector3 vector3)
 {
     NormalizeEulerPart(ref vector3.X);
     NormalizeEulerPart(ref vector3.Y);
     NormalizeEulerPart(ref vector3.Z);
 }
Exemple #5
0
 public static NitroxQuaternion FromEuler(NitroxVector3 vector) => FromEuler(vector.X, vector.Y, vector.Z);