Advertisement

Finding Face Collision happened on, after interval halving test

Started by February 17, 2015 04:32 AM
1 comment, last by _WeirdCat_ 10 years ago

So, I have an interval halving test that works with AABBs, which does a good job of correcting the positioning of objects, so they don't penetrate past each other too far. Now, all I need to do is find which face the objects collided on, and perform the correct collision response for the direction the objects collided at.

For testing intersection I'm testing the absolute value of the objects against their half-widths.


public bool Intersect(AABB3D a, AABB3D b)
{
     if (Math.Abs(a.Center.x - b.Center.x) > (a.HalfWidth + b.HalfWidth))
        return false;
     if (Math.Abs(a.Center.y - b.Center.y) > (a.HalfHeight + b.HalfHeight))
         return false;
     if (Math.Abs(a.Center.z - b.Center.z) > (a.HalfDepth + b.HalfDepth))
         return false;

     return true;
}

When I'm attempting to find which precomputed normal the collision happened on I'm running code like this for each face:


Vector3 bottomVector = b.Bottom.Normal + b.DistanceToBottom;
float top = planeIntersection.ClosestVector3ToPlane(bottomVector, b1.Top);


public float ClosestVector3ToPlane(Vector3 q, Plane p)
{
    return  (Vector3.Dot(p.Normal, q) - p.D) / Vector3.Dot(p.Normal, p.Normal); //q - t * p.Normal;
}

Then I assign the respective normal like so:


private void normalCollision(float top, float bottom, float left, float right, AABB3D movingBox, AABB3D b0)
{
    if(Math.Abs(top) > Math.Abs(bottom))
    {
        Debug.Log("Top: " + top);
        b0.NormalCollision[1] = movingBox.Top.Normal;
    }
    else if(Math.Abs(bottom) > Math.Abs(top))
    {
       Debug.Log("Bottom: " + bottom);
       b0.NormalCollision[1] = movingBox.Bottom.Normal;
    }

    if (Math.Abs(right) > Math.Abs(left))
    {
        Debug.Log("Right: " + right);
        b0.NormalCollision[0] = movingBox.Right.Normal;
    }
    else if (Math.Abs(left) > Math.Abs(right))
    {
        Debug.Log("Left: " + left);
        b0.NormalCollision[0] = movingBox.Left.Normal;
    }
}

Outside of the Interval halved test the appropriate response is assigned.

The one thing I noticed when debugging is towards the center of the platform the left and right normals still get assigned; So, my solution needs some work. How could I go about figuring out which face collided with? SAT doesn't seem ideal here since the left and right faces could be penetrating the platform ever so slightly. Thanks.

I can't really tell what you're asking, and don't really have the patience to decipher your code. Maybe you can try asking the question again in a simpler and different way? Maybe then I could help.

Advertisement

before i can post a solution i need to know what are your object are they just 2d boxes or 3d cubes?

Vector3 bottomVector = b.Bottom.Normal + b.DistanceToBottom; this code doesnt seem right since it should be a multiplication instead of addition. then you can call that bottom vector but i dont know what you are trying to do.

anyway i need to see sample shapes and know what are you really trying to do

is any of functions you posted working?

This topic is closed to new replies.

Advertisement