Skip to content

Commit

Permalink
flipper: Use HitVelocity of CollisionEvent instead of FlipperHitData …
Browse files Browse the repository at this point in the history
…and remove it from FlipperHitData.
  • Loading branch information
freezy committed Nov 1, 2023
1 parent cdafd4b commit 9cffca3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public float HitTest(ref CollisionEventData collEvent, ref InsideOfs insideOfs,

hitTime = _hitCircleBase.HitTest(ref collEvent, ref insideOfs, in ball, dTime);
if (hitTime >= 0) {
hitData.HitVelocity.x = 0; // Tangent velocity of contact point (rotate Normal right)
hitData.HitVelocity.y = 0; // rad units*d/t (Radians*diameter/time)
collEvent.HitVelocity.x = 0; // Tangent velocity of contact point (rotate Normal right)
collEvent.HitVelocity.y = 0; // rad units*d/t (Radians*diameter/time)
hitData.HitMomentBit = true;
return hitTime;
}
Expand Down Expand Up @@ -270,7 +270,7 @@ private float HitTestFlipperFace(ref CollisionEventData collEvent, ref FlipperHi
ballVtx = ball.Position.x + ballVx * t - vt.x;
ballVty = ball.Position.y + ballVy * t - vt.y;

bffnd = ballVtx * faceNormal.x+ ballVty * faceNormal.y - ballRadius; // normal distance to segment
bffnd = ballVtx * faceNormal.x + ballVty * faceNormal.y - ballRadius; // normal distance to segment

if (math.abs(bffnd) <= PhysicsConstants.Precision) {
break;
Expand Down Expand Up @@ -381,9 +381,9 @@ private float HitTestFlipperFace(ref CollisionEventData collEvent, ref FlipperHi
var distance = math.sqrt(dist.x * dist.x + dist.y * dist.y); // distance from base center to contact point
var invDist = 1.0f / distance;

hitData.HitVelocity.x = -dist.y * invDist;
hitData.HitVelocity.y = dist.x * invDist; // Unit Tangent velocity of contact point(rotate Normal clockwise)
//coll.Hitvelocity.Z = 0.0f; // used as normal velocity so far, only if isContact is set, see below
collEvent.HitVelocity.x = -dist.y * invDist;
collEvent.HitVelocity.y = dist.x * invDist; // Unit Tangent velocity of contact point(rotate Normal clockwise)
//collEvent.Hitvelocity.Z = 0.0f; // used as normal velocity so far, only if isContact is set, see below

if (contactAng >= angleMax && angleSpeed > 0 || contactAng <= angleMin && angleSpeed < 0) {
// hit limits ???
Expand All @@ -393,8 +393,8 @@ private float HitTestFlipperFace(ref CollisionEventData collEvent, ref FlipperHi
hitData.HitMomentBit = distance == 0;

var dv = new float2( // delta velocity ball to face
ballVx - hitData.HitVelocity.x * angleSpeed * distance,
ballVy - hitData.HitVelocity.y * angleSpeed * distance
ballVx - collEvent.HitVelocity.x * angleSpeed * distance,
ballVy - collEvent.HitVelocity.y * angleSpeed * distance
);

var bnv = dv.x * collEvent.HitNormal.x + dv.y * collEvent.HitNormal.y; // dot Normal to delta v
Expand Down Expand Up @@ -580,14 +580,14 @@ private float HitTestFlipperEnd(ref CollisionEventData collEvent, ref FlipperHit

// Unit Tangent vector velocity of contact point(rotate normal right)
var invDistance = 1.0f / distance;
hitData.HitVelocity.x = -dist.y * invDistance;
hitData.HitVelocity.y = dist.x * invDistance;
collEvent.HitVelocity.x = -dist.y * invDistance;
collEvent.HitVelocity.y = dist.x * invDistance;
hitData.HitMomentBit = distance == 0;

// recheck using actual contact angle of velocity direction
var dv = new float2(
ballVx - hitData.HitVelocity.x * angleSpeed * distance, // delta velocity ball to face
ballVy - hitData.HitVelocity.y * angleSpeed * distance
ballVx - collEvent.HitVelocity.x * angleSpeed * distance, // delta velocity ball to face
ballVy - collEvent.HitVelocity.y * angleSpeed * distance
);

var bnv = dv.x * collEvent.HitNormal.x + dv.y * collEvent.HitNormal.y; // dot Normal to delta v
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ internal FlipperHitData GetHitData()
return new FlipperHitData {
ZeroAngNorm = zeroAngNorm,
HitMomentBit = true,
HitVelocity = new float2(),
LastHitFace = false,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace VisualPinball.Unity
internal struct FlipperHitData
{
public bool LastHitFace;
public float2 HitVelocity;
public bool HitMomentBit;
public float2 ZeroAngNorm;
}
Expand Down

0 comments on commit 9cffca3

Please sign in to comment.