10.8 C
New York
Friday, March 14, 2025

collision decision – The right way to calculate a hard and fast mirrored path from a face (or airplane) regardless of the incident angle or path


In my collision protocol when successful is discovered I’m utilizing AABB faces to find out a mirrored path the place the cellular should transfer (see image left). That is simple as we simply must invert the signal of Dir.x or Dir.z relying on the closest face involved.

This works high-quality but when the result’s happy with low incident angle (angle1) it isn’t fascinating for larger angles like angle2 the place I would love the cellular to return because it does for low angles. A easy technique is to have a hard and fast ensuing path regardless of the incident angle. With a view to have this working for any incident angle in opposition to any face of the AABB I believe a normalized face path ought to be used (like crimson arrows in gray field).

Right here’s my query: how do I calculated the fastened ensuing path based mostly on the incident angle or/and it’s path, given the hit face path as indicated within the gray field.
I’m working with a 2D path (y not used) for my collisions.

Beneath is a part of my code to pick out the closest face to take care of for a AABB hit.

 Hit = NULL;
 For all objects
 If IntersectAABB_AABB(Cellular, Object)
 {
     Hit = Object
     XMFLOAT4 D = XMFLOAT4(Hit.VMax.x – Cellular.VMin.x, Hit.VMin.x - Cellular.VMax.x,
                           Hit.VMax.z - Cellular.VMin.z, Hit.VMin.z - Cellular.VMax.z);
     D.x *= D.x;
     D.y *= D.y;
     D.z *= D.z;
     D.w *= D.w;
     FLOAT R = fmin(D.x, D.y);
     R = fmin(R, D.z);
     R = fmin(R, D.w);
     if (R == D.x) Outcome = DirXMAX;//FaceDir = XMFLOAT3(0,0,-1);
     if (R == D.y) Outcome = DirXMIN; ;//FaceDir = XMFLOAT3(0,0,1);
     if (R == D.z) Outcome = dwZMAX; ;//FaceDir = XMFLOAT3(1,0,0);
     if (R == D.w)) Outcome = dwZMIN; ;//FaceDir = XMFLOAT3(-1,0,0);
  }
  If Hit 
  {
      //my present mirrored path
      if (Outcome == dwXMAX) Cellular.Velocity.x = - Cellular.Velocity.x;
      if (Outcome == dwZMAX) Cellular.Velocity.z = - Cellular.Velocity.z;
      if (Outcome == dwXMIN) Cellular.Velocity.x = - Cellular.Velocity.x;
      if (Outcome == dwZMIN) Cellular.Velocity.z = - Cellular.Velocity.z;
  }

If there’s a Hit the cellular is stopped and reoriented to its new path as described within the multianimation pattern within the DirectX11 sdk.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles