13.4 C
New York
Tuesday, April 29, 2025

Collision decision: The way to calculate a mirrored route mounted from a face (or flat), regardless of the angle or incident route


In my collision protocol, when a blow is, I’m utilizing AABB faces to find out a mirrored route the place the cell should transfer (see picture to the left). That is simple since we simply want to take a position the signal of Dir.xo dir.z relying on the closest face in touch.

This works properly, but when the result’s fantastic with a low incident angle (Angle1), it isn’t fascinating for larger angles like Angle2, the place I would really like the cell to return because it does for low angles. A easy technique is to have a hard and fast ensuing route, regardless of the incident angle. For this to work for any incident angle towards any face of the AABB, I believe a standardized face tackle (equivalent to crimson arrows in grey field) must be used.

Right here is my query: How did I calculate the ensuing route mounted relying on the incident angle or/and its route, given the route of the face as indicated within the grey field? I’m working with a 2D tackle (and never used) for my collisions.

Beneath is a part of my code to pick out the closest face to cope with an AABB success.

 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) Consequence = DirXMAX;//FaceDir = XMFLOAT3(0,0,-1);
     if (R == D.y) Consequence = DirXMIN; ;//FaceDir = XMFLOAT3(0,0,1);
     if (R == D.z) Consequence = dwZMAX; ;//FaceDir = XMFLOAT3(1,0,0);
     if (R == D.w)) Consequence = dwZMIN; ;//FaceDir = XMFLOAT3(-1,0,0);
  }
  If Hit 
  {
      //my present mirrored route
      if (Consequence == dwXMAX) Cellular.Velocity.x = - Cellular.Velocity.x;
      if (Consequence == dwZMAX) Cellular.Velocity.z = - Cellular.Velocity.z;
      if (Consequence == dwXMIN) Cellular.Velocity.x = - Cellular.Velocity.x;
      if (Consequence == dwZMIN) Cellular.Velocity.z = - Cellular.Velocity.z;
  }

If there’s a success, the cell stops and reor

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles