Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Object Collisions?

 Post Reply Post Reply Page  12>
Author
Message
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Topic: Object Collisions?
    Posted: 2012 Sep 05 at 1:14pm

User Information:

Cinema 4D Version:   R13 
Platform:   Windows  ;   
Language(s):     C++  ;   

---------

I'm trying to learn how to do collisions. But the archives are a bit vague on this.
Lots of general discussions, but not a heck of a lot of actual code to learn from.

At first I thought I could use the bounding box (op->GetRad() )  values to check for collisions.
But that method needs to handle the +- of each vector. Which seems like a lot of repetitive code.
Then I thought about maybe sending out a ray from every polygon. But I'm worried that this might become very slow.

Is it possible to see the C++ code that's in the xpresso collision node?
That might help me get a better idea how to approach object-to-object collisions.

-ScottA
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2558
Post Options Post Options   Quote NiklasR Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 06 at 4:14am
Hello Scott,

this looks like an interesting document: http://zach.in.tu-clausthal.de/papers/deform_colldet_cgf.pdf
AFAIK, collision detection always relies on either bounding-volume computation and then checking those volumes for intersection, or filling the volume with particles and compute them. (I think the bullet engine uses this method, not quite sure though).

-Niklas


Edited by NiklasR - 2012 Sep 06 at 4:15am
Back to Top
spedler View Drop Down
Member
Member


Joined: 2008 Apr 19
Location: United Kingdom
Online Status: Offline
Posts: 673
Post Options Post Options   Quote spedler Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 06 at 4:22am
Collision detection is not something to undertake lightly, believe me. Although the SDK has a number of classes to handle it, IMHO you need a good grounding in the theory before trying to implement it.

Games programming sites are the best for this, I've found. Here's one useful collection of references: http://www.gamespp.com/algorithms/collisiondetection/

There are lots more such sites, best to search the net for 'collision detection' and 'games' - you should get a whole bunch of links.

Steve
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 06 at 8:11am
Thanks for the links guys.
I don't need a super accurate collision scheme at this point. All I need is the code that checks for bounding box collisions. Like in the xpresso collision node. I think it's called AABB collision.
But I'm having a very hard time finding code for that on the internet.

Everything I'm finding is for 2D, proprietary games, or OpenGL.
And on the rare occasion I do find a link to generic 3D bounding box collisions. The link is dead.Angry

-ScottA
Back to Top
Remotion4D View Drop Down
Member
Member
Avatar

Joined: 2010 Oct 20
Online Status: Offline
Posts: 172
Post Options Post Options   Quote Remotion4D Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 07 at 10:17am
May be you first try to use GeColliderEngine from C4D SDK !?

It can be used to reproduce function fom xpresso collision Node.
It is much easier to use GeColliderEngine instate of writing you own, especially if you do not have experience with it.

But if you want to know more about this collision detection then I would suggest to start from "Real-Time Collision Detection".

Remo
Remo
developer of SuperVoxels, SuperTracer, UniFlex, GeoTools, DiTools and more
www.remotion4d.net
www.c4dpp.org
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 07 at 12:50pm
Here's where my ignorance is showing about the GeColliderEngine.
I've only done some very basic ray collision stuff with python. And from what I gathered it sends out a ray( or a spline used as the ray in my example) from the center of a polygon.
But what happens if the collision occurs on the corners of the objects?
The ray shooting out will not hit the other object and generate a collision.

Snippet from my python spline ray casting plugin:
    rc = utils.GeRayCollider()
    rc. Init(obj)
    rc. Intersect(start_pos, direct, length)
   
    intersect_cnt = rc.GetIntersectionCount ()

I'm sure I'm not thinking about it correctly. And the GeColliderEngine will probably work. But I'm just so new and lost about how that class works that I'm struggling very badly with it.
If we had access to the code inside of the collision node. I thought it might help demystify how it works.

I did figure out how to do spherical collisions today. Which is at least a step in the right direction.
Here is a python example of spherical collisions:
import c4d
def main():

    text = doc.SearchObject("Text")          #A text object

    player = op.GetObject()                  #The object with the python tag on it
    playerpos = player.GetMg().off           #The object's global position
    pRad = player.GetRad()                   #The object's bounding box radius

    enemy = doc.SearchObject("enemy")        #The object that will collide with the player object
    enemypos = enemy.GetMg().off             #The object's global position
    eRad = enemy.GetRad()                    #The object's bounding box radius

    distvec = playerpos - enemypos           #The vector between the two objects
    length =  distvec.GetLength()            #The distance between the two objects

    if length < pRad.x + eRad.x:             #If the distance is less than the sum of the two obj radius
        text[c4d.PRIM_TEXT_TEXT]="Collision" #We have a collision so change the text in the text object
    else: text[c4d.PRIM_TEXT_TEXT]="None"    #Otherwise...Set the text to "None"

While this is great and fairly useful.
I would really like to learn how to do AABB collisons in C4D(in C++ or python). Or whatever the xpresso collision node is doing for it's collisions.

I tried to invent Bounding Box collisions from scratch. Breaking the scene into Right,Left,Front,Back,Top, Bottom quadrants relative to the player object's global position. Then checking positions between player and the enemy objects. But it's very buggy. And I'm positive I'm doing it wrong.
Meaning...I'm sure I'm asking the wrong questions in my code.

Anyway...Whenever the subject comes up. It tends to get brushed off quickly as being too complex. Or not a question that the support staff can answer. So I was hoping that we could maybe not try to tackle the super duper accurate collisions. And instead possibly share some code with each other for simpler collisions. Like the collision node.
Matthias sometimes shares xpresso code with us. So I was just wondering if Maxon would allow us to see the code for the collision node. And maybe we could learn from it.

-ScottA
Back to Top
kuroyume0161 View Drop Down
Member
Member
Avatar

Joined: 2002 Oct 29
Location: United States
Online Status: Offline
Posts: 3665
Post Options Post Options   Quote kuroyume0161 Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 07 at 3:12pm
There are basically three levels to Collision Detection:

1. Bounding Box
2. Polygon-Polygon Bounding Box
3. Ray-Triangle Intersection

Each of these represents a more accurate collision detection.

All you need for 1. is to GetRad() and GetMp() for the two objects to be tested.  Note that GetMp() returns the bounding box in LOCAL space.  You need to convert that to GLOBAL space like so to do the AABB collision test:


// Global-space Bounding-Box Center Point
Vector bbCenter = obj->GetMp() * obj->GetUpMg();
// Bounding-Box extents in X/Y/Z
Vector bbBounds = obj->GetRad();
// Bounding-Box minimum extents
Vector bbMin = bbCenter - bbBounds;
// Bounding-Box maximum extents
Vector bbMax = bbCenter + bbBounds;


These give you an AABB and not an OBB (I think). 

This is now very simple. Given world object A and another object B you can test for a collision simply by doing a number of checks e.g.

  • If the max x position of A is less than the min x position of B they do not collide
  • If the min x position of A is greater than the max x position of B they do not collide
  • and the same goes for y and z

If none of the checks find that no collision occurred then obviously a collision did occur. This does make sense - read it slowly :)

Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 07 at 4:57pm
Hi Robert,

I'm not understanding your BB code. It's returning zeros (local coords. based on the object's matrix..not the the world?) no matter where the object is in the world.
    BaseObject *player = doc->SearchObject("player");             //The object to work on
    Vector playerPos = player->GetMg().off;                       //The player object's global position

 
    Vector playerbbCenter = player->GetMp() * player->GetUpMg();  //The BB Global or local position?
    GePrint(RealToString(playerbbCenter.x));                      //<---- Always prints zero
    GePrint(RealToString(playerbbCenter.y));                      //<---- Always prints zero
    GePrint(RealToString(playerbbCenter.z));                      //<---- Always prints zero


With playerbbCenter always returning (0,0,0) I don't understand how that is useful?

-ScottA
Back to Top
kuroyume0161 View Drop Down
Member
Member
Avatar

Joined: 2002 Oct 29
Location: United States
Online Status: Offline
Posts: 3665
Post Options Post Options   Quote kuroyume0161 Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 07 at 6:14pm
Try using player->GetMp() * player->GetMg();

Also, if you have a hierarchy of objects or are looking at a Null/HyperNURBS/Generator as parent of the object(s) then that might explain why you always get (0,0,0).  You will need to traverse the hierarchy of objects to get the BB radius and BB center.
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 07 at 7:02pm
Hurray!
I think I got it now Robert.
I didn't use the GetMp() function. But this seems to be working properly.
//This creates AABB collision checking between two objects
//Similar to the results from the xpresso collision node

    BaseObject *player = doc->SearchObject("player");               //One of the objects to check for collisions
    if(!player) return FALSE;
    Vector playerPos = player->GetMg().off;                         //The object's global position
    Vector playerbbCenter = playerPos;                              //The bounding box's position
    Vector playerbbBounds = player->GetRad();                       //Bounding-Box extents in X/Y/Z
    Vector playerbbMin = playerbbCenter - playerbbBounds;           //Bounding-Box minimum extents
    Vector playerbbMax = playerbbCenter + playerbbBounds;           //Bounding-Box maximum extents

    BaseObject *enemy = doc->SearchObject("enemy");                 //The other object to check for collisions
    if(!enemy) return FALSE;
    Vector enemyPos = enemy->GetMg().off;                           //The object's global position
    Vector enemybbCenter = enemyPos;                                //The bounding box's position
    Vector enemybbBounds = enemy->GetRad();                         //Bounding-Box extents in X/Y/Z
    Vector enemybbMin = enemybbCenter - enemybbBounds;              //Bounding-Box minimum extents
    Vector enemybbMax = enemybbCenter + enemybbBounds;              //Bounding-Box maximum extents


    LONG collision = 1;                   //The Collision value will be set to true before we check the two objects for collisions

    if(playerbbMax.x < enemybbMin.x)      //If the player's positive X bounds is less than the enemy's negative X bounds
    { collision = 0; }                    //We don't have a collison
    if(playerbbMin.x > enemybbMax.x)      //If the player's negative X bounds is more than the enemy's positive X bounds
    { collision = 0; }                    //We don't have a collison


    if(playerbbMax.y < enemybbMin.y)      //If the player's positive Y bounds is less than the enemy's negative Y bounds
    { collision = 0;  }                   //We don't have a collison
    if(playerbbMin.y > enemybbMax.y)      //If the player's negative Y bounds is more than the enemy's positive Y bounds
    { collision = 0; }                    //We don't have a collison   


    if(playerbbMax.z < enemybbMin.z)      //If the player's positive Z bounds is less than the enemy's negative Z bounds
    { collision = 0; }                    //We don't have a collison
    if(playerbbMin.z > enemybbMax.z)      //If the player's negative Z bounds is more than the enemy's positive Z bounds
    { collision = 0; }                    //We don't have a collison

    GePrint(LongToString(collision));


I will try out you suggestion with GetMp(). But I don't seem to need it.

Thanks a ton Robert.Beer
-ScottA
Back to Top
Remotion4D View Drop Down
Member
Member
Avatar

Joined: 2010 Oct 20
Online Status: Offline
Posts: 172
Post Options Post Options   Quote Remotion4D Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 08 at 3:50am
Collision Node probably uses internal GeColliderEngine.

If you want results from "Collision" output then use DoPolyPairs() then "Polygon Index 1" is GetId1() and "Polygon Index 2" GetId2().

If you want results from "Distance" output then use DoDistance() or DoTolerance() then "Point 1" is GetP1() and "Point 2" is GetP2().



Remo
developer of SuperVoxels, SuperTracer, UniFlex, GeoTools, DiTools and more
www.remotion4d.net
www.c4dpp.org
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 08 at 7:48am
Originally posted by Remotion4D

Collision Node probably uses internal GeColliderEngine.

The code I have now is working exactly like the collision node. So I'm just curious why you would you think that Remo?

I have almost no experience at all with the GeColliderEngine. So what you're saying is making no sense to me yet. But I would like to learn more about it. So I am going to try and learn how to use it today.
Can you offer any kind of code tips or something to help me get started with it?

We have a sphere collision example and an AABB collision example in this thread so far.
I would love it if we can post more of these collision examples in this thread. They are very useful.

-ScottA
BTW: Thanks for the link. That book looks like a very good collision book based on the errata.
Back to Top
Giblet View Drop Down
Member
Member


Joined: 2003 May 21
Online Status: Offline
Posts: 465
Post Options Post Options   Quote Giblet Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 08 at 9:43am
Hey Robert,

I was playing with this a bit the other day and I think you need to add/subtract the Rad() before multiplying by the global matrix (note that the bounding box is also in local space, so combine first, then multiply the results by the global matrix to get the whole thing into global space)...


Vector bbCenter = obj->GetMp();   // Local-space Bounding-Box Center Point
Vector bbBounds = obj->GetRad(); // Local-space Bounding-Box extents in X/Y/Z
Vector bbMin = (bbCenter - bbBounds) * obj->GetMg(); // Bounding-Box minimum extents (positioned and oriented in global-space)
Vector bbMax = (bbCenter + bbBounds) * obj->GetMg(); // Bounding-Box maximum extents (positioned and oriented in global-space)

// NOTE: multiplying by the global matrix (rotations) can negate some of the min/max values, so re-normalize...
MinMax mm;
mm.Init(bbMin1);
mm.AddPoint(bbMax1);
bbMin1 = mm.GetMin();
bbMax1 = mm.GetMax();


EDIT: Actually, the above code doesn't work and I kinda know why, but need to figure out the fix.
EDIT2: OK, the above addition (using a MinMax class) to re-normalize fixes it.
 
Scott,

You should not be using the 'position' of the objects (the player->GetMg().off), since that does not account for the 'midpoint' of the object, that you need for doing the spherical/bounding-box test.  Note that the object's position may be at 0/0/0, but the actual mesh may be offset by any amount from there (and thus the middle of the mesh would also be offset).

Using code similar to the above will account for this, as well as any rotations / scaling of the objects, which you're also not accounting for with the code you have.

Cheers.


Edited by Giblet - 2012 Sep 08 at 10:35am
Back to Top
Giblet View Drop Down
Member
Member


Joined: 2003 May 21
Online Status: Offline
Posts: 465
Post Options Post Options   Quote Giblet Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 08 at 10:44am
Here you go - just add some objects to scene and pass it doc->GetFirstObject() and it'll tell you if that object collides with any other object in the scene (using crude bounding box test only)...


void BBoxTest(BaseObject *op)
{
    if( op )
    {
        Vector bbCenter = op->GetMp();   // Local-space Bounding-Box Center Point
        Vector bbBounds = op->GetRad();  // Local-space Bounding-Box extents in X/Y/Z
        Vector bbMin1 = (bbCenter - bbBounds) * op->GetMgn(); // Bounding-Box minimum extents (positioned and oriented in global-space)
        Vector bbMax1 = (bbCenter + bbBounds) * op->GetMgn(); // Bounding-Box maximum extents (positioned and oriented in global-space)
        MinMax mm;
        mm.Init(bbMin1);
        mm.AddPoint(bbMax1);
        bbMin1 = mm.GetMin();
        bbMax1 = mm.GetMax();
//      GePrint(op->GetName()+" bbMin1: "+utVecToString(bbMin1)+" bbMax1: "+utVecToString(bbMax1));

        BaseObject *op2 = op->GetNext();
        while( op2 )
        {
            Vector bbMin2 = (op2->GetMp() - op2->GetRad()) * op2->GetMgn(); // Bounding-Box minimum extents (positioned and oriented in global-space)
            Vector bbMax2 = (op2->GetMp() + op2->GetRad()) * op2->GetMgn(); // Bounding-Box maximum extents (positioned and oriented in global-space)
            mm.Init(bbMin2);
            mm.AddPoint(bbMax2);
            bbMin2 = mm.GetMin();
            bbMax2 = mm.GetMax();
//            GePrint(op2->GetName()+" bbMin2: "+utVecToString(bbMin2)+" bbMax2: "+utVecToString(bbMax2));

            Bool xlap, ylap, zlap;
            if( bbMin2.x <= bbMax1.x && bbMax2.x >= bbMin1.x )    xlap = true;
            else                                                  xlap = false;
            if( bbMin2.y <= bbMax1.y && bbMax2.y >= bbMin1.y )    ylap = true;
            else                                                  ylap = false;
            if( bbMin2.z <= bbMax1.z && bbMax2.z >= bbMin1.z )    zlap = true;
            else                                                  zlap = false;
            String slap = op->GetName()+" / " + op2->GetName();
            slap += " xlap: ";
            slap += xlap ? "true" : "false";
            slap += " ylap: ";
            slap += ylap ? "true" : "false";
            slap += " zlap: ";
            slap += zlap ? "true" : "false";
            slap += " BBox Collision: ";
            slap += (xlap && ylap && zlap) ? "true" : "false";
            GePrint(slap);
            op2 = op2->GetNext();
        }
    }
}




Edited by Giblet - 2012 Sep 08 at 10:55am
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 08 at 11:24am
Thanks Giblet.

Using your custom method. The collisions between two non-rotated objects works good.
But I'm not getting proper collisions when the objects are rotated.
-Create two cubes
-Put the second cube above the first cube close...but not quite colliding

The only time I'm getting collisions is when I rotate either object in -B or +P

-ScottA
Back to Top
Giblet View Drop Down
Member
Member


Joined: 2003 May 21
Online Status: Offline
Posts: 465
Post Options Post Options   Quote Giblet Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 08 at 4:13pm
Yeah, I see that it's still not working.. and I know why, I'm just trying to come up with the best solution...
Back to Top
kuroyume0161 View Drop Down
Member
Member
Avatar

Joined: 2002 Oct 29
Location: United States
Online Status: Offline
Posts: 3665
Post Options Post Options   Quote kuroyume0161 Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 08 at 4:26pm
The problem with multiplying the global matrix after you get the minima and maxima bounds is that it is now an OBB.  The vector returned by GetRad() is simply a distance vector (relative) and is already aligned globally.
Back to Top
Giblet View Drop Down
Member
Member


Joined: 2003 May 21
Online Status: Offline
Posts: 465
Post Options Post Options   Quote Giblet Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 08 at 11:18pm
OBB?  (I'm not familiar with the term)

GetRad() returns a 'local-space' distance (radius) vector on each axis.  In other words, imagine a playing-cards pack, with a GetRad() vector of 20/40/10... if you rotate the object 90deg on the Y axis, the x and z axis swap, so you'd (effectively) have 10/40/20 in global-space, which is quite different - implying that you do indeed need to modify the GetRad() value by the global-space matrix.

The problem with doing that (erm, what I was doing above) is that you are effectively only rotating 2 pseudo-points - two actual points of the bounding box (ie. top/right/rear and bottom/left/front), but there are 6 others that make up that box, that aren't correctly accounted for.

I think the solution would be to (temporarily) actually generate all 8 points, rotate them (apply the global matrix), then feed all 8 back into the MinMax class to reduce it back to the bbMin and bbMax vectors.

Of course I could be going down the wrong path - there may be some other solution, which I'd love to hear.
Back to Top
Giblet View Drop Down
Member
Member


Joined: 2003 May 21
Online Status: Offline
Posts: 465
Post Options Post Options   Quote Giblet Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 09 at 8:23am
As mentioned, there may be other ways of doing this, but this now seems to work...


void BBoxTest(BaseObject *op)
{
    if( op )
    {
        Vector bbMin1 = op->GetMp() - op->GetRad(); // Bounding-Box minimum extents (Local-space)
        Vector bbMax1 = op->GetMp() + op->GetRad(); // Bounding-Box maximum extents (Local-space)
        Matrix opgm = op->GetMgn();

        // Generate (8) points of bounding box in Global-space and generate new min/max vectors
        MinMax mm;

        // bottom
        mm.Init(bbMin1 * opgm);
        mm.AddPoint(Vector(bbMin1.x, bbMin1.y, bbMax1.z) * opgm);
        mm.AddPoint(Vector(bbMax1.x, bbMin1.y, bbMax1.z) * opgm);
        mm.AddPoint(Vector(bbMax1.x, bbMin1.y, bbMin1.z) * opgm);

        // top
        mm.AddPoint(bbMax1 * opgm);
        mm.AddPoint(Vector(bbMax1.x, bbMax1.y, bbMin1.z) * opgm);
        mm.AddPoint(Vector(bbMin1.x, bbMax1.y, bbMin1.z) * opgm);
        mm.AddPoint(Vector(bbMin1.x, bbMax1.y, bbMax1.z) * opgm);

        bbMin1 = mm.GetMin();
        bbMax1 = mm.GetMax();
//        GePrint(op->GetName()+" bbMin1: "+utVecToString(bbMin1)+" bbMax1: "+utVecToString(bbMax1));

        BaseObject *op2 = op->GetNext();
        while( op2 )
        {
            Vector bbMin2 = op2->GetMp() - op2->GetRad(); // Bounding-Box minimum extents (Local-space)
            Vector bbMax2 = op2->GetMp() + op2->GetRad(); // Bounding-Box maximum extents (Local-space)
            opgm = op2->GetMgn();

            // Generate (8) points of bounding box in Global-space and generate new min/max vectors
            // bottom
            mm.Init(bbMin2 * opgm);
            mm.AddPoint(Vector(bbMin2.x, bbMin2.y, bbMax2.z) * opgm);
            mm.AddPoint(Vector(bbMax2.x, bbMin2.y, bbMax2.z) * opgm);
            mm.AddPoint(Vector(bbMax2.x, bbMin2.y, bbMin2.z) * opgm);

            // top
            mm.AddPoint(bbMax2 * opgm);
            mm.AddPoint(Vector(bbMax2.x, bbMax2.y, bbMin2.z) * opgm);
            mm.AddPoint(Vector(bbMin2.x, bbMax2.y, bbMin2.z) * opgm);
            mm.AddPoint(Vector(bbMin2.x, bbMax2.y, bbMax2.z) * opgm);

            bbMin2 = mm.GetMin();
            bbMax2 = mm.GetMax();
//            GePrint(op2->GetName()+" bbMin2: "+utVecToString(bbMin2)+" bbMax2: "+utVecToString(bbMax2));

            Bool xlap, ylap, zlap;
            if( bbMin2.x < bbMax1.x && bbMax2.x > bbMin1.x )    xlap = true;    else xlap = false;
            if( bbMin2.y < bbMax1.y && bbMax2.y > bbMin1.y )    ylap = true;    else ylap = false;
            if( bbMin2.z < bbMax1.z && bbMax2.z > bbMin1.z )    zlap = true;    else zlap = false;
            String slap = op->GetName()+" / " + op2->GetName();
            slap += " xlap: ";                slap += xlap ? "true" : "false";
            slap += " ylap: ";                slap += ylap ? "true" : "false";
            slap += " zlap: ";                slap += zlap ? "true" : "false";
            slap += " BBox Collision: ";    slap += (xlap && ylap && zlap) ? "true" : "false";
            GePrint(slap);
            op2 = op2->GetNext();
        }
    }
}


EDIT: replaced it with a slightly tidier version.
EDIT 9/11/12: Fixed a bug where I had too many mm.Init() calls


Edited by Giblet - 2012 Sep 11 at 10:43am
Back to Top
Remotion4D View Drop Down
Member
Member
Avatar

Joined: 2010 Oct 20
Online Status: Offline
Posts: 172
Post Options Post Options   Quote Remotion4D Quote  Post ReplyReply Direct Link To This Post Posted: 2012 Sep 10 at 5:54am
Well here helper class that help to use GeColliderEngine.
GeColliderHelper.h

Just look at GeColliderHelperTest() function.

It will calculate distance between two first object in the document.
It will also do collision detection and return ids of two first colliding polygons.

By the way why do you use MinMax and not proper AABBox class ?
Remo
developer of SuperVoxels, SuperTracer, UniFlex, GeoTools, DiTools and more
www.remotion4d.net
www.c4dpp.org
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.125 seconds.