Skip to content
Permalink
Browse files

[Physics] Fix ShapeSweeps output

  • Loading branch information
Eideren committed Jun 25, 2019
1 parent d65a7f2 commit c527b174935ebae7eeaf52387d01f7c3f2f6760c
Showing with 27 additions and 15 deletions.
  1. +27 −15 sources/engine/Xenko.Physics/Simulation.cs
@@ -1028,7 +1028,7 @@ private class XenkoClosestConvexResultCallback : XenkoReusableConvexResultCallba
BulletSharp.LocalConvexResult closestHit;
bool normalInWorldSpace;
float? closestFraction;
public HitResult Result => closestFraction != null ? ComputeHitResult(ref closestHit, normalInWorldSpace) : new HitResult() { Succeeded = false };
public HitResult Result => ComputeHitResult(ref closestHit, normalInWorldSpace);

public override float AddSingleResult(ref BulletSharp.LocalConvexResult convexResult, bool normalInWorldSpaceParam)
{
@@ -1093,7 +1093,7 @@ private class XenkoClosestRayResultCallback : XenkoReusableRayResultCallback
BulletSharp.LocalRayResult closestHit;
bool normalInWorldSpace;
float? closestFraction;
public HitResult Result => closestFraction != null ? ComputeHitResult(ref closestHit, normalInWorldSpace) : new HitResult() { Succeeded = false };
public HitResult Result => ComputeHitResult(ref closestHit, normalInWorldSpace);

public XenkoClosestRayResultCallback(ref Vector3 from, ref Vector3 to) : base(ref from, ref to)
{
@@ -1139,16 +1139,22 @@ public XenkoReusableRayResultCallback(ref Vector3 from, ref Vector3 to) : base()

public HitResult ComputeHitResult(ref BulletSharp.LocalRayResult rayResult, bool normalInWorldSpace)
{
Vector3 normal;
if (normalInWorldSpace)
normal = rayResult.m_hitNormalLocal;
else
normal = Vector3.TransformNormal(rayResult.m_hitNormalLocal, rayResult.CollisionObject.WorldTransform.Basis);
var obj = rayResult.CollisionObject;
if (obj == null)
{
return new HitResult() { Succeeded = false };
}

Vector3 normal = rayResult.m_hitNormalLocal;
if (!normalInWorldSpace)
{
normal = Vector3.TransformNormal(normal, obj.WorldTransform.Basis);
}

return new HitResult
{
Succeeded = true,
Collider = rayResult.CollisionObject.UserObject as PhysicsComponent,
Collider = obj.UserObject as PhysicsComponent,
Point = Vector3.Lerp(RayFromWorld, RayToWorld, rayResult.m_hitFraction),
Normal = normal,
HitFraction = rayResult.m_hitFraction,
@@ -1171,17 +1177,23 @@ private abstract class XenkoReusableConvexResultCallback : BulletSharp.ConvexRes
{
public HitResult ComputeHitResult(ref BulletSharp.LocalConvexResult convexResult, bool normalInWorldSpace)
{
Vector3 normal;
if (normalInWorldSpace)
normal = convexResult.m_hitNormalLocal;
else
normal = Vector3.TransformNormal(convexResult.m_hitNormalLocal, convexResult.HitCollisionObject.WorldTransform.Basis);
var obj = convexResult.HitCollisionObject;
if ( obj == null )
{
return new HitResult() { Succeeded = false };
}

Vector3 normal = convexResult.m_hitNormalLocal;
if (!normalInWorldSpace)
{
normal = Vector3.TransformNormal(normal, obj.WorldTransform.Basis);
}

return new HitResult
{
Succeeded = true,
Collider = convexResult.HitCollisionObject.UserObject as PhysicsComponent,
Point = Vector3.TransformCoordinate(convexResult.m_hitPointLocal, convexResult.HitCollisionObject.WorldTransform.Basis),
Collider = obj.UserObject as PhysicsComponent,
Point = convexResult.m_hitPointLocal,
Normal = normal,
HitFraction = convexResult.m_hitFraction,
};

0 comments on commit c527b17

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