Game Development Community

Collision Depth, and I don't get it

by Gary "ChunkyKs" Briggs · in Torque Game Builder · 05/19/2005 (6:24 pm) · 9 replies

I'm probably being pretty stupid, but I don't get a couple things about collisions in T2D:

1) what does "%contacts" do in fxSceneObject2D::onCollision contain?
2) How do I get the depth of the collision?

Notably, what I need in onCollision is:
1) a Normal between the two objects at the surface where they collide
2) The depth of the collision
3) A position in the global world of where that collision is.

I don't get how to get those. I'm probably being pretty dumb, but can anyone explain it to me?

King Tut Bob, if you read this, a tutorial on collisions that actually makes use of all the parameters to fxSceneObject2D::onCollision would rock :-)

Gary (-;

#1
05/19/2005 (7:22 pm)
Ever get the feeling you're pretty damn stupid?

The normal one is pretty easy to answer; it's the parameter "%normal"

Hmmm.

Gary (-;
#2
05/19/2005 (8:17 pm)
In other news, BOO YA

function fxSceneObject2D::onCollision( %srcObj, %dstObj, %srcRef,
        %dstRef, %time, %normal, %contactCount, %contacts ) {

        %c = new tdContact();
        %c.SetNormal(getWord(%normal,0), getWord(%normal,1), 0);
        %c.SetPos(getWord(%contacts,0), getWord(%contacts,1), 0);

        %j = new tdJoint();
        %j.CreateContact($odeworld, $odecollisionjg, %c);
        %j.Attach(%srcObj.odeobj, %dstObj.odeobj);
}

ODE<->T2D collisions working almost perfectly in six lines of code. Now to just get the depth, and most of my problems will be fixed.

Gary (-;
#3
05/19/2005 (11:31 pm)
Cool! Let us see some screens of what you do with this. :)
#4
05/20/2005 (12:29 am)
icculus.org/~chunky/stuff/odescript/t2dodecoll.png

Like that?

I tried to post a .plan just now, but the stupid website ate it and I can't be bothered to re-write it.

Just to clarify, that's 100% T2D collision code. The "rope" is a chain of 100 or so ODE objects, tethered at the right hand end. Gravity currently points down. The spaceship and it's T2D collision code is copied verbatim from the spacescrollerdemo. That's 100% T2D's collision library doing all the hard work.

Which, basically, means that if you want ODE bodies and T2D Physics bodies interacting at the same time on the same screen, knock yourself out; it's trivial!

Gary (-;
#5
05/20/2005 (1:47 am)
That's pretty cool!

Be interesting to see what you do to take it further :)
#6
05/20/2005 (9:14 am)
You should post it as a resource. Then you should hook up Newton physics, too! :)
#7
05/20/2005 (9:43 am)
I'm planning on posting as a resource as soon as I'm happy with it actually working. Currently, that means I want to work out the collision depth, then I'll be releasing it.

Gary (-;
#8
05/20/2005 (10:16 am)
Oooh... constraints ?

I am very interested in this if it supports good constraints in T2D :)
#9
05/20/2005 (2:32 pm)
For constraints, ode.org/ode-latest-userguide.html#sec_7_5_1

I already support those function calls. :-)

Gary (-;