This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated system numerics extensions (#833)
- Loading branch information
1 parent
fcd495e
commit d8060ba
Showing
1 changed file
with
29 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |