Skip to content
Permalink
Browse files

Straightforward changes

  • Loading branch information
Eideren committed Dec 10, 2018
1 parent 6d4eb5a commit adf536642f7f93cca99e218c7b62c7de5e2dd7cf
@@ -32,6 +32,7 @@
using System;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

namespace Xenko.Core.Mathematics
{
@@ -3477,5 +3478,41 @@ public override bool Equals(object 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)
{
unsafe { return *(BulletSharp.Math.Matrix*)&value; }
/*return new BulletSharp.Math.Matrix()
{
M11 = value.M11, M12 = value.M12, M13 = value.M13, M14 = value.M14,
M21 = value.M21, M22 = value.M22, M23 = value.M23, M24 = value.M24,
M31 = value.M31, M32 = value.M32, M33 = value.M33, M34 = value.M34,
M41 = value.M41, M42 = value.M42, M43 = value.M43, M44 = value.M44
};*/
}

/// <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)
{
unsafe { return *(Matrix*)&value; }
/*return new Matrix()
{
M11 = value.M11, M12 = value.M12, M13 = value.M13, M14 = value.M14,
M21 = value.M21, M22 = value.M22, M23 = value.M23, M24 = value.M24,
M31 = value.M31, M32 = value.M32, M33 = value.M33, M34 = value.M34,
M41 = value.M41, M42 = value.M42, M43 = value.M43, M44 = value.M44
};*/
}
}
}
@@ -1732,5 +1732,29 @@ public override bool Equals(object 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; }
//return new BulletSharp.Math.Vector3(value.X, value.Y, value.Z);
}

/// <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; }
//return new Vector3(value.X, value.Y, value.Z);
}
}
}
@@ -633,7 +633,7 @@ private class XenkoAllHitsRayResultCallback : BulletSharp.AllHitsRayResultCallba
{
private IList<HitResult> resultsList;

public XenkoAllHitsRayResultCallback(ref Vector3 from, ref Vector3 to, IList<HitResult> results) : base(ref from, ref to)
public XenkoAllHitsRayResultCallback(ref Vector3 from, ref Vector3 to, IList<HitResult> results) : base(from, to)
{
resultsList = results;
}
@@ -661,9 +661,10 @@ public HitResult Raycast(Vector3 from, Vector3 to)
{
var result = new HitResult(); //result.Succeeded is false by default

using (var rcb = new BulletSharp.ClosestRayResultCallback(from, to))
BulletSharp.Math.Vector3 fromBullet = from, toBullet = to;
using (var rcb = new BulletSharp.ClosestRayResultCallback(ref fromBullet, ref toBullet))
{
collisionWorld.RayTest(ref from, ref to, rcb);
collisionWorld.RayTest(fromBullet, toBullet, rcb);

if (rcb.CollisionObject == null) return result;
result.Succeeded = true;
@@ -688,13 +689,14 @@ public HitResult Raycast(Vector3 from, Vector3 to, CollisionFilterGroups collisi
{
var result = new HitResult(); //result.Succeeded is false by default

using (var rcb = new BulletSharp.ClosestRayResultCallback(from, to)
BulletSharp.Math.Vector3 fromBullet = from, toBullet = to;
using (var rcb = new BulletSharp.ClosestRayResultCallback(ref fromBullet, ref toBullet)
{
CollisionFilterGroup = (short)collisionFilterGroups,
CollisionFilterMask = (short)collisionFilterGroupFlags,
})
{
collisionWorld.RayTest(ref from, ref to, rcb);
collisionWorld.RayTest(fromBullet, toBullet, rcb);

if (rcb.CollisionObject == null) return result;
result.Succeeded = true;
@@ -717,7 +719,7 @@ public void RaycastPenetrating(Vector3 from, Vector3 to, IList<HitResult> result
{
using (var rcb = new XenkoAllHitsRayResultCallback(ref from, ref to, resultsOutput))
{
collisionWorld.RayTest(ref from, ref to, rcb);
collisionWorld.RayTest(from, to, rcb);
}
}

@@ -751,7 +753,7 @@ public void RaycastPenetrating(Vector3 from, Vector3 to, IList<HitResult> result
CollisionFilterMask = (short)collisionFilterGroupFlags,
})
{
collisionWorld.RayTest(ref from, ref to, rcb);
collisionWorld.RayTest(from, to, rcb);
}
}

@@ -785,7 +787,8 @@ public HitResult ShapeSweep(ColliderShape shape, Matrix from, Matrix to)

var result = new HitResult(); //result.Succeeded is false by default

using (var rcb = new BulletSharp.ClosestConvexResultCallback(from.TranslationVector, to.TranslationVector))
BulletSharp.Math.Vector3 fromBullet = from.TranslationVector, toBullet = to.TranslationVector;
using (var rcb = new BulletSharp.ClosestConvexResultCallback(ref fromBullet, ref toBullet))
{
collisionWorld.ConvexSweepTest(sh, from, to, rcb);

@@ -817,10 +820,11 @@ public HitResult ShapeSweep(ColliderShape shape, Matrix from, Matrix to, Collisi

var result = new HitResult(); //result.Succeeded is false by default

using (var rcb = new BulletSharp.ClosestConvexResultCallback(from.TranslationVector, to.TranslationVector)
BulletSharp.Math.Vector3 fromBullet = from.TranslationVector, toBullet = to.TranslationVector;
using (var rcb = new BulletSharp.ClosestConvexResultCallback(ref fromBullet, ref toBullet)
{
CollisionFilterGroup = (BulletSharp.CollisionFilterGroups)collisionFilterGroups,
CollisionFilterMask = (BulletSharp.CollisionFilterGroups)collisionFilterGroupFlags,
CollisionFilterGroup = (int)collisionFilterGroups,
CollisionFilterMask = (int)collisionFilterGroupFlags,
})
{
collisionWorld.ConvexSweepTest(sh, from, to, rcb);
@@ -887,8 +891,8 @@ public void ShapeSweepPenetrating(ColliderShape shape, Matrix from, Matrix to, I

using (var rcb = new XenkoAllHitsConvexResultCallback(resultsOutput)
{
CollisionFilterGroup = (BulletSharp.CollisionFilterGroups)collisionFilterGroups,
CollisionFilterMask = (BulletSharp.CollisionFilterGroups)collisionFilterGroupFlags,
CollisionFilterGroup = (int)collisionFilterGroups,
CollisionFilterMask = (int)collisionFilterGroupFlags,
})
{
collisionWorld.ConvexSweepTest(sh, from, to, rcb);
@@ -5,7 +5,7 @@

namespace Xenko.Physics
{
internal class XenkoMotionState : BulletSharp.SharpMotionState
internal class XenkoMotionState : BulletSharp.MotionState//.SharpMotionState
{
private RigidbodyComponent rigidBody;

@@ -19,19 +19,20 @@ public void Clear()
rigidBody = null;
}

public override void GetWorldTransform(out Matrix transform)
public override void GetWorldTransform(out BulletSharp.Math.Matrix transform)
{
if (rigidBody.GetWorldTransformCallback != null)
{
rigidBody.GetWorldTransformCallback(out transform);
rigidBody.GetWorldTransformCallback(out Matrix temp);
transform = temp;
}
else
{
transform = Matrix.Identity;
}
}

public override void SetWorldTransform(Matrix transform)
public override void SetWorldTransform(ref BulletSharp.Math.Matrix transform)
{
rigidBody.SetWorldTransformCallback?.Invoke(transform);
}

0 comments on commit adf5366

Please sign in to comment.
You can’t perform that action at this time.