Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
updated system numerics extensions (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson authored May 7, 2021
1 parent fcd495e commit d8060ba
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions Runtime/Extensions/SystemNumericsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;

namespace XRTK.Extensions
{
public static class SystemNumericsExtensions
{
/// <summary>
/// Converts a <see cref="System.Numerics.Vector3"/> to a Unity engine <see cref="Vector3"/>.
/// Converts a Numerics <see cref="System.Numerics.Vector3"/> to a Unity <see cref="UnityEngine.Vector3"/>.
/// </summary>
/// <param name="v">Vector value to convert.</param>
/// <returns><see cref="UnityEngine.Vector3"/>.</returns>
public static UnityEngine.Vector3 ToUnity(this System.Numerics.Vector3 v)
{
return new UnityEngine.Vector3(v.X, v.Y, -v.Z);
}

/// <summary>
/// Converts a Unity <see cref="UnityEngine.Vector3"/> to a Numerics <see cref="System.Numerics.Vector3"/>.
/// </summary>
/// <param name="v">Vector value to convert.</param>
/// <returns>Unity vector.</returns>
public static Vector3 ToUnity(this System.Numerics.Vector3 v)
/// <returns><see cref="System.Numerics.Vector3"/>.</returns>
public static System.Numerics.Vector3 ToNumericsVector3(this UnityEngine.Vector3 v)
{
return new System.Numerics.Vector3(v.x, v.y, -v.z);
}

/// <summary>
/// Converts a Numerics <see cref="System.Numerics.Quaternion"/> to a Unity <see cref="UnityEngine.Quaternion"/>.
/// </summary>
/// <param name="q">Quaternion value to convert.</param>
/// <returns><see cref="UnityEngine.Quaternion"/>.</returns>
public static UnityEngine.Quaternion ToUnity(this System.Numerics.Quaternion q)
{
return new Vector3(v.X, v.Y, -v.Z);
return new UnityEngine.Quaternion(-q.X, -q.Y, q.Z, q.W);
}

/// <summary>
/// Converts a <see cref="System.Numerics.Quaternion"/> to a Unity engine <see cref="Quaternion"/>.
/// Converts a Unity <see cref="UnityEngine.Quaternion"/> to a Numerics <see cref="System.Numerics.Quaternion"/>.
/// </summary>
/// <param name="q">Quaternion value to convert.</param>
/// <returns>Unity quaternion.</returns>
public static Quaternion ToUnity(this System.Numerics.Quaternion q)
/// <returns><see cref="System.Numerics.Quaternion"/>.</returns>
public static System.Numerics.Quaternion ToNumericsQuaternion(this UnityEngine.Quaternion q)
{
return new Quaternion(-q.X, -q.Y, q.Z, q.W);
return new System.Numerics.Quaternion(-q.x, -q.y, q.z, q.w);
}
}
}
}

0 comments on commit d8060ba

Please sign in to comment.