-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add experimental support for exporting model animations (#72)
* add experimental support for exporting model animations * spacing
- Loading branch information
Showing
8 changed files
with
798 additions
and
20 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
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
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
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,15 +1,46 @@ | ||
namespace ACViewer | ||
using System; | ||
using System.Numerics; | ||
|
||
namespace ACViewer | ||
{ | ||
public static class QuaternionExtensions | ||
{ | ||
public static System.Numerics.Quaternion ToNumerics(this Microsoft.Xna.Framework.Quaternion q) | ||
public static Quaternion ToNumerics(this Microsoft.Xna.Framework.Quaternion q) | ||
{ | ||
return new System.Numerics.Quaternion(q.X, q.Y, q.Z, q.W); | ||
return new Quaternion(q.X, q.Y, q.Z, q.W); | ||
} | ||
|
||
public static Microsoft.Xna.Framework.Quaternion ToXna(this System.Numerics.Quaternion q) | ||
public static Microsoft.Xna.Framework.Quaternion ToXna(this Quaternion q) | ||
{ | ||
return new Microsoft.Xna.Framework.Quaternion(q.X, q.Y, q.Z, q.W); | ||
} | ||
|
||
public static Vector3 ToEulerAngles(this Quaternion q) | ||
{ | ||
var angles = Vector3.Zero; | ||
|
||
// roll / x | ||
double sinr_cosp = 2 * (q.W * q.X + q.Y * q.Z); | ||
double cosr_cosp = 1 - 2 * (q.X * q.X + q.Y * q.Y); | ||
angles.X = (float)Math.Atan2(sinr_cosp, cosr_cosp); | ||
|
||
// pitch / y | ||
double sinp = 2 * (q.W * q.Y - q.Z * q.X); | ||
if (Math.Abs(sinp) >= 1) | ||
{ | ||
angles.Y = (float)Math.CopySign(Math.PI / 2, sinp); | ||
} | ||
else | ||
{ | ||
angles.Y = (float)Math.Asin(sinp); | ||
} | ||
|
||
// yaw / z | ||
double siny_cosp = 2 * (q.W * q.Z + q.X * q.Y); | ||
double cosy_cosp = 1 - 2 * (q.Y * q.Y + q.Z * q.Z); | ||
angles.Z = (float)Math.Atan2(siny_cosp, cosy_cosp); | ||
|
||
return angles; | ||
} | ||
} | ||
} |
Oops, something went wrong.