Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

bounding box

How would I work out if a bounding box hit a triangle plane or triangle and also work out the intersection point.

Also For my collision detection I worked out four vertices around my car.
Now I want to rotate and translate the vertices so they are always the tightest fit around the car. Basically its a OBB.
Any ideas on how to do this. I could cos/sin or use some matrix stuff but I need more info.

Comments

  • flashlaserflashlaser Posts: 49Member
    Sorry for all the questions but just one more.
    I got this code for computing a Oriented Bounding Box from magic-software.com. Can someone explain to me whats happening and how to use this function.

    [source]
    void Box2::ComputeVertices (Vector2 akVertex[4]) const
    {
    Vector2 akEAxis[2] =
    {
    m_afExtent[0]*m_akAxis[0],
    m_afExtent[1]*m_akAxis[1]
    };

    akVertex[0] = m_kCenter - akEAxis[0] - akEAxis[1];
    akVertex[1] = m_kCenter + akEAxis[0] - akEAxis[1];
    akVertex[2] = m_kCenter + akEAxis[0] + akEAxis[1];
    akVertex[3] = m_kCenter - akEAxis[0] + akEAxis[1];
    }
    [/source]

    The code is called MgcBox2.cpp under 2d core.

  • WudanWudan Posts: 66Member
    : How would I work out if a bounding box hit a triangle plane or triangle and also work out the intersection point.
    :
    : Also For my collision detection I worked out four vertices around my car.
    : Now I want to rotate and translate the vertices so they are always the tightest fit around the car. Basically its a OBB.
    : Any ideas on how to do this. I could cos/sin or use some matrix stuff but I need more info.
    :

    To create a bounding box, step through every vertex in the model and store the minumum & maximums for x y and z. From these you can create your 8 verts for the bounding box. The points will be....
    minx,miny,minz,
    maxx,miny,minz
    minx,maxy,minz,
    manx,maxy,minz,
    minx,miny,maxz,
    maxx,miny,maxz
    minx,maxy,maxz,
    manx,maxy,maxz,



    for collision detection, its handy to know about something called a 'normal'. A normal is a small vector, that shows the direction that the face is pointing. If you imagine a triangle flat on the floor, built from the following verts...

    -100,0,0,
    0,0,100
    100,0,0

    the normal to this trinagle would be..

    0,1,0 ( pointing straight up ). Normals usualy go from 0 to 1. Imagine it being a spike poking out of the centre of the face.


    For collision detection, you could see if a point is within a volume ( ie a building ). make the building from 6 faces, each with a normal.
    If you take any point on the face( one of its verts will do ), and dot product it with the planes normal, you get a value P. If you dot product your collision point ( one of the points on the collision box ) with the normal you get a value C. If C is less than P, the point is behind the plane. Do this for all the planes in your volume. If P is always less than C, the point is inside the volume and theres been a collision.


    To find the dot product of two vectors
    Vector v1;
    Vector v2;
    float dot;

    dot = (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);

    have fun :)












Sign In or Register to comment.