Game Development Community

Sphere collisions

by Dylan Sale · in Torque Game Engine · 01/08/2004 (4:29 am) · 9 replies

Is there any way to check for sphere collisions, for balls and the like, without using a collision mesh (as they dont provide enough accuracy, and you get the ball sliding on its edges instead of rotating properly)?

I would have assumed torque had a way.. it seems fairly simple.. you would just check if a point/line/poly was within a certain radius of the sphere center right? I cant find it though.

I know you can do a radius search, but I need proper collision info for a sphere, not the actual objects.

#1
01/08/2004 (4:59 am)
If I understand your question correctly, you assume that your shape is always a perfect sphere, so rather than use a spherical collision mesh you wish to compute the sphereical collision values.

I'm a Torque noobie, but it would seem that since Torque treats all object collisions basically the same way, that you would have to create a new collision type, attatch it to the shapeBase, and then provide a means to determine which collision type is to be used for each instance.

From my understanding, that is not a small endeavour. Nine times out of ten I've found that any problem whose obvious solution is to make major additions to the code base has a less obvious alternative that turns out to be far more elegant.

Maybe if you went a little further into what effect you are trying to produce... I have to admit I'm curious as to what project requires such presise sphereical collision handling. :)
#3
01/08/2004 (5:19 am)
Yeah, I read your post with that stuff in it Matthew, and it helped, but I still have no idea how I would go about getting contact points from the Convex or polylist or whathaveyou.. Maybe im just tired now.

Ill give it a go tomorrow.

Thanks

Dylan
#4
01/08/2004 (5:42 am)
Whoops....sorry, I didn't look at who started the thread (hey is is still early in the morning and I haven't finished my caffeine fix =)

Let me think about this a bit...I have an inkling of an answer but I don't want to promise anything.

I would assume that the ball/sphere is an active moving object and not a passive one?
#5
01/08/2004 (5:44 am)
Yeah, its actually an ODE object ala www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5024, so very active ;)
#6
01/08/2004 (9:02 am)
Dylan,

I think your best bet might be just to up the friction a bunch and make a more detailed collision mesh for your ball. Also, you could play with ODEItem::buildPolyList to return a lower detail collision mesh for all the other object collisions so that you don't bog down the system too much. Torque collision list works in polys so it would be difficult to implement otherwise. I have a cleanup ODEItem release with your code as well as default and individual bounce and friction values that I'll try to post today.

That being said...It could be done: Create a new derived class from Convex. Then you could create your own version of getCollisionInfo that calls getFeatures on a potential collisionList and then calc's the collisions based on the sphere equation and the returned ConvexFeature. You would have to return some mesh though for getPolyList as most of the rest of torque doesn't use getFeatures.

I would try the first option and see it you get satisfactory results as the second might take some time.

-Pascal
#7
01/08/2004 (5:37 pm)
Thanks for the reply Pascal. Yeah, this was just a little side project that I wanted to do, but it wasnt quite working out right. I thought I would just ask, but seeing as it'd take a lot of work and messing around, I think I'll just focus on my main project for now.

Ill try upping the friction.

Thanks

Dylan
#8
01/08/2004 (5:40 pm)
I would simply write the sphere collision in.
it will be well worth it.
#9
01/08/2004 (5:42 pm)
Heh, I realise itd be worth it, but theres only a certain number of hours in the day and I'm working on 2 games already. If you wanted to give it a go, then by all means... ;)