SceneObject::buldPolyList / Collision questions
by Eric Roberts · in Torque Game Engine · 02/28/2006 (5:33 pm) · 7 replies
I'm uncertain to exactly what SceneObject::buildPolyList is supposed to achieve or even when it's called. As far as I know, most (if not all) objects that require a polyList get it from the object's convex (Convex::getPolyList()).
So why implement a SceneObject::buildPolyList, and not just use a convex (and maybe impliment your own derived functionality)?
buildPolyList isn't even mentioned in the collision tutorial object resource, and the description given on TDN I don't find very helpful.
And a slightly more specific question:
I've been recently trying to implement a sceneobject that has collision. Right now I'm working with a simple SceneObject that renders a triangle. I could easily implement a derived object from Convex to build a polyList (of one poly), but the problem I have is with castRay. How can I check to see if castRay intersected with a triangle? All castRay examples I've seen check against a plane - but this will cover the whole area of the shape, and not just the triangle alone. Right now I'm using a BoxConvex, and my castRay checks for an intesection with the plane the vertices lie in. This will make projectiles collide with the entire enclosed plane - not just the triangle. Something I'm missing or misunderstanding?
Thanks,
- Eric
So why implement a SceneObject::buildPolyList, and not just use a convex (and maybe impliment your own derived functionality)?
buildPolyList isn't even mentioned in the collision tutorial object resource, and the description given on TDN I don't find very helpful.
And a slightly more specific question:
I've been recently trying to implement a sceneobject that has collision. Right now I'm working with a simple SceneObject that renders a triangle. I could easily implement a derived object from Convex to build a polyList (of one poly), but the problem I have is with castRay. How can I check to see if castRay intersected with a triangle? All castRay examples I've seen check against a plane - but this will cover the whole area of the shape, and not just the triangle alone. Right now I'm using a BoxConvex, and my castRay checks for an intesection with the plane the vertices lie in. This will make projectiles collide with the entire enclosed plane - not just the triangle. Something I'm missing or misunderstanding?
Thanks,
- Eric
About the author
#2
From my original post:
But my second question is still there.
If I have a sceneObject that's simple a triangle poly - how would I perform a castRay? Does castRay depend on convexes at all? I'm currently using a BoxConvex and if I do a check against a plane the vertices make, I get a collision with the entire enclosed plane - not just the half the triangle takes up.
Any ideas?
Thanks,
- Eric
03/01/2006 (5:18 am)
@Matt:From my original post:
Quote:So yes, I have. It wasn't mentioned that it was used for shadow rendering - but it is mentioned on TDN under a collision article. Thank you for clearing that up for me.
buildPolyList isn't even mentioned in the collision tutorial object resource, and the description given on TDN I don't find very helpful.
But my second question is still there.
If I have a sceneObject that's simple a triangle poly - how would I perform a castRay? Does castRay depend on convexes at all? I'm currently using a BoxConvex and if I do a check against a plane the vertices make, I get a collision with the entire enclosed plane - not just the half the triangle takes up.
Any ideas?
Thanks,
- Eric
#3
03/01/2006 (2:04 pm)
There are a ton of examples of ray->triangle intersection code out on the internet. Just Google for them. My favorite technique (little slower than some but simple) is to find the plane/ray intersection point and then walk the edges of the triangle creating planes and make sure that the point is inside all of the them. There is an example of this around line 399 of interior\interiorCollision.cc (in Interior::castRay_r()).
#4
Ah thanks for pointing the example code to me. I was under the impression that Torque had already had some intersection routines I was unaware of - but I've simply implemented my own routine myself with help from your kind direction.
In fact - I've already tried two different algorithms. Both seem to work fine except...
When I shoot a projectile at it, around the edges of the triangle - the projectile seems to be hitting when it shouldn't. In fact when I had developed the first algorithm, I simply switched to the algorithm used in the Interior::castRay_r() and modified it to my needs. But the same problem creeps up. I wonder if there's a slight precision issue going on. I've been trying to track it down - but it's difficult to debug since castRay is constantly being called.
Thanks again,
- Eric
03/01/2006 (6:33 pm)
@Matt:Ah thanks for pointing the example code to me. I was under the impression that Torque had already had some intersection routines I was unaware of - but I've simply implemented my own routine myself with help from your kind direction.
In fact - I've already tried two different algorithms. Both seem to work fine except...
When I shoot a projectile at it, around the edges of the triangle - the projectile seems to be hitting when it shouldn't. In fact when I had developed the first algorithm, I simply switched to the algorithm used in the Interior::castRay_r() and modified it to my needs. But the same problem creeps up. I wonder if there's a slight precision issue going on. I've been trying to track it down - but it's difficult to debug since castRay is constantly being called.
Thanks again,
- Eric
#5
How finely are you checking? You're going to get some "odd" results if you zoom way in. :)
If it's a projectile doing the castRay, you could try either noting each line segment it tests into a vector and drawing the lines so you can see what it's doing, or setting a global on/off around the relevant query to active more detailed logging.
03/01/2006 (8:39 pm)
TSE has a port of Moeller's excellent ray-tri intersection code that Atlas uses.How finely are you checking? You're going to get some "odd" results if you zoom way in. :)
If it's a projectile doing the castRay, you could try either noting each line segment it tests into a vector and drawing the lines so you can see what it's doing, or setting a global on/off around the relevant query to active more detailed logging.
#6
I build my object ( a derived class of SceneObject ) and I use a right triangle that's 5 units by 5 units. I shoot projectiles along the edge of the right triangle. Some areas along the edges seem to perform better than others. the middle and the corners tseem to be the worst as far as I can tell.
Is a 5x5 right triangle too big?
I'll try out drawing the line segments / global flag debugging later when I grab some time. Right now the algorithm depends on whether or not the dot product is < 0.0f for no collision (checking the plane normal with the normal to the edge/point-vertex). So I may try fiddling around and making the tolerence a little higher than simply just being negative.
Thanks,
- Eric
03/02/2006 (8:28 am)
Here's how I'm testing the collsion:I build my object ( a derived class of SceneObject ) and I use a right triangle that's 5 units by 5 units. I shoot projectiles along the edge of the right triangle. Some areas along the edges seem to perform better than others. the middle and the corners tseem to be the worst as far as I can tell.
Is a 5x5 right triangle too big?
I'll try out drawing the line segments / global flag debugging later when I grab some time. Right now the algorithm depends on whether or not the dot product is < 0.0f for no collision (checking the plane normal with the normal to the edge/point-vertex). So I may try fiddling around and making the tolerence a little higher than simply just being negative.
Thanks,
- Eric
#7
Ben's suggestion of storing the line segments for later rendering would be useful.
if the segments are in fact outside the triangle, you probably want to rethink your collision algorythm rather than raising tolerance.
side note -
in the method Matt described, i'm wondering if it's possible to account for projectile size (eg a basketball versus a pebble) by pushing the edges of the triangle out along their normal by say the projectile's radius.
- i wish i had a need for this in my project right now so i could spend time fiddling around !
@ben - thanks for pointing out the Moeller method. fascinating to see how different slight alterations to the code run better and worse on various processors..
03/02/2006 (9:21 am)
Strange that you would get false-positive intersections near the middle of the diagonal edge.Ben's suggestion of storing the line segments for later rendering would be useful.
if the segments are in fact outside the triangle, you probably want to rethink your collision algorythm rather than raising tolerance.
side note -
in the method Matt described, i'm wondering if it's possible to account for projectile size (eg a basketball versus a pebble) by pushing the edges of the triangle out along their normal by say the projectile's radius.
- i wish i had a need for this in my project right now so i could spend time fiddling around !
@ben - thanks for pointing out the Moeller method. fascinating to see how different slight alterations to the code run better and worse on various processors..
Associate Matt Fairfax
PopCap