Skip to content

Commit

Permalink
[Bullet] Remove bullet refs within mathematics
Browse files Browse the repository at this point in the history
  • Loading branch information
Eideren committed Apr 18, 2019
1 parent 45a89aa commit 9b22e54
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 110 deletions.
66 changes: 0 additions & 66 deletions sources/core/Xenko.Core.Mathematics/Matrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3478,71 +3478,5 @@ public static implicit operator Matrix(Microsoft.Xna.Framework.Matrix value)
};
}
#endif

/// <summary>
/// Performs an implicit conversion from <see cref="Xenko.Core.Mathematics.Matrix"/> to <see cref="BulletSharp.Math.Matrix"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator BulletSharp.Math.Matrix(Matrix value)
{
// 11, 22, 33 & 44's offsets are shared, ~10% faster
BulletSharp.Math.Matrix d;
unsafe
{
d = *(BulletSharp.Math.Matrix*)&value;
}
//11
d.M12 = value.M12;
d.M13 = value.M13;
d.M14 = value.M14;
d.M21 = value.M21;
//22
d.M23 = value.M23;
d.M24 = value.M24;
d.M31 = value.M31;
d.M32 = value.M32;
//33
d.M34 = value.M34;
d.M41 = value.M41;
d.M42 = value.M42;
d.M43 = value.M43;
//44
return d;
}

/// <summary>
/// Performs an implicit conversion from <see cref="BulletSharp.Math.Matrix"/> to <see cref="Xenko.Core.Mathematics.Matrix"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Matrix(BulletSharp.Math.Matrix value)
{
// 11, 22, 33 & 44's offsets are shared, ~10% faster
Matrix d;
unsafe
{
d = *(Matrix*)&value;
}
//11
d.M12 = value.M12;
d.M13 = value.M13;
d.M14 = value.M14;
d.M21 = value.M21;
//22
d.M23 = value.M23;
d.M24 = value.M24;
d.M31 = value.M31;
d.M32 = value.M32;
//33
d.M34 = value.M34;
d.M41 = value.M41;
d.M42 = value.M42;
d.M43 = value.M43;
//44
return d;
}
}
}
22 changes: 0 additions & 22 deletions sources/core/Xenko.Core.Mathematics/Quaternion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,27 +1420,5 @@ public static implicit operator Quaternion(Microsoft.Xna.Framework.Quaternion va
return new Quaternion(value.X, value.Y, value.Z, value.W);
}
#endif

/// <summary>
/// Performs an implicit conversion from <see cref="Xenko.Core.Mathematics.Vector3"/> to <see cref="BulletSharp.Math.Quaternion"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator BulletSharp.Math.Quaternion(Quaternion value)
{
unsafe { return *(BulletSharp.Math.Quaternion*)&value; }
}

/// <summary>
/// Performs an implicit conversion from <see cref="BulletSharp.Math.Quaternion"/> to <see cref="Xenko.Core.Mathematics.Quaternion"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Quaternion(BulletSharp.Math.Quaternion value)
{
unsafe { return *(Quaternion*)&value; }
}
}
}
22 changes: 0 additions & 22 deletions sources/core/Xenko.Core.Mathematics/Vector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,27 +1732,5 @@ public static implicit operator Vector3(Microsoft.Xna.Framework.Vector3 value)
return new Vector3(value.X, value.Y, value.Z);
}
#endif

/// <summary>
/// Performs an implicit conversion from <see cref="Xenko.Core.Mathematics.Vector3"/> to <see cref="BulletSharp.Math.Vector3"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator BulletSharp.Math.Vector3(Vector3 value)
{
unsafe { return *(BulletSharp.Math.Vector3*)&value; }
}

/// <summary>
/// Performs an implicit conversion from <see cref="BulletSharp.Math.Vector3"/> to <see cref="Xenko.Core.Mathematics.Vector3"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Vector3(BulletSharp.Math.Vector3 value)
{
unsafe { return *(Vector3*)&value; }
}
}
}
84 changes: 84 additions & 0 deletions sources/engine/Xenko.Physics/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using Xenko.Core.Mathematics;

namespace Xenko.Physics
{
public static class Utils
{
public static BulletSharp.Math.Matrix ToBullet(this Matrix value)
{
// 11, 22, 33 & 44's offsets are shared, ~10% faster
BulletSharp.Math.Matrix d;
unsafe
{
d = *(BulletSharp.Math.Matrix*)&value;
}
//11
d.M12 = value.M12;
d.M13 = value.M13;
d.M14 = value.M14;
d.M21 = value.M21;
//22
d.M23 = value.M23;
d.M24 = value.M24;
d.M31 = value.M31;
d.M32 = value.M32;
//33
d.M34 = value.M34;
d.M41 = value.M41;
d.M42 = value.M42;
d.M43 = value.M43;
//44
return d;
}

public static Matrix ToXenko(this BulletSharp.Math.Matrix value)
{
// 11, 22, 33 & 44's offsets are shared, ~10% faster
Matrix d;
unsafe
{
d = *(Matrix*)&value;
}
//11
d.M12 = value.M12;
d.M13 = value.M13;
d.M14 = value.M14;
d.M21 = value.M21;
//22
d.M23 = value.M23;
d.M24 = value.M24;
d.M31 = value.M31;
d.M32 = value.M32;
//33
d.M34 = value.M34;
d.M41 = value.M41;
d.M42 = value.M42;
d.M43 = value.M43;
//44
return d;
}

public static BulletSharp.Math.Quaternion ToBullet(this Quaternion value)
{
unsafe { return *(BulletSharp.Math.Quaternion*)&value; }
}

public static Quaternion ToXenko(this BulletSharp.Math.Quaternion value)
{
unsafe { return *(Quaternion*)&value; }
}

public static BulletSharp.Math.Vector3 ToBullet(this Vector3 value)
{
unsafe { return *(BulletSharp.Math.Vector3*)&value; }
}

public static Vector3 ToXenko(this BulletSharp.Math.Vector3 value)
{
unsafe { return *(Vector3*)&value; }
}
}
}

0 comments on commit 9b22e54

Please sign in to comment.