Sign in to follow this  
monchito

Horzontal or vertical triangles

Recommended Posts

Hi In a (Quake3) mesh loaded in a 3d engine (irrlicht 1.4) composed of all triangles. I can get the triangles but how can I test for horizontal and vertical triangles?

Share this post


Link to post
Share on other sites
I'm not sure what you are asking exactly, but you might test for the main triangle axis: you get the triangle borders by calculating the difference of the vertices, then you take the biggest component (x,y or z).

Share this post


Link to post
Share on other sites
Ok
What i mean is that the triangles formed by the vertices are horizontal aligned like the floor (plane x,z in irrlicht 3d)or vertical aligned (plane y,x)like a wall. Can i get the data from the normal or something else? Not the way its facing, but if horizontal or vertical. Don't know if test the 'y' of each 3 points
to test for sane height or any thing else.

Share this post


Link to post
Share on other sites
I am not sure why you need to know if a triangle belongs to the floor or to the walls. Your collision detection should handle general triangles no matter what. But to answer the question: Take the triangles normal and compare its angle to the normal of waht you belive to be the floot plane such as (0,1,0). If the angle is smaller than x degree it is a triangle that belongs to what you believe should be tagged as floor.

However, note that there could be triangles belongign to "the ceiling" as well as there could be triangles that have quite a slope and are either "floor" or "walls". So you have to define at which angle a triangle is still floor or already wall which in turn should be up to your collision detection system which leads us back to the introduction of this post :)

Share this post


Link to post
Share on other sites
Thanks a lot, that's the answer to what I'm searching for.
And yes i'm aware of triangles not fitting to horizontal or vertical but almost
90% or more are of this 2 types. I'm trying to ease the burden of the collision
detection by pre-selecting the triangles that must be tested. Currently my entities stay above the floor by tracing a vertical line from their origins to 200 units below, then do a line collision with all the triangle selector of the environment (Quake3 mesh). The idea is to speed up the time of testing, gain a couple of fps, it's only my theory don't know if will work...
If any one knows a better way by experience ....i'm all ears....

Note: the same test for horizontal movement, trace a horizontal line from origin to 100 units in front. Test for collision with all triangle generated by the selector...etc..etc...

[Edited by - monchito on March 17, 2009 6:39:05 AM]

Share this post


Link to post
Share on other sites
Use a different model.
Collision is expensive due to lots of branching and the like, so just cut down on the work.
Most games don't couple the graphics with the collision. The collision is usually a significantly more simplistic mesh.

Besides, while you need per-pixel resolution for drawing, you need per-smallest-object resolution in collision.
If your game character is 1m around and 2m tall, you can't resolve collisions with detail triangles smaller than 1m. (think of a picket fence,
there is no point in collision PER fencepost. Your character is going to collide at a much larger scale.)

Secondly, spatial partitioning of one form or another (hash, octtree), will help you significantly cut down on the number of triangles in a level that you need to collide with.

Share this post


Link to post
Share on other sites
Thanks for the reply
Actually I'm using the engine provisions like the addOctTreeSceneNode() and the
getCollisionPoint() functions like engine tutotials. The Quake3 mesh are 5000 and 10000 (triangles counted) in size. With the following function i only use 245 triangles for the collision point from the 5000 triangle mesh.

void TriangleFilter()
{
s32 HorTriangleCounter = 0;
ITriangleSelector* selector = irrWorld->getTriangleSelector();
triangle3df * triangles = 0;
if(selector)
{
s32 triangleCount = selector->getTriangleCount();

if(!triangles)
triangles = new triangle3df[triangleCount];

s32 total_found;
selector->getTriangles(triangles, triangleCount, total_found);

// setup an horizontal plane for normals compare
plane3d<f32> horz_plane;
horz_plane.setPlane(vector3df(1,0,0), vector3df(0,0,1), vector3df(0,0,0));
vector3df plane_normal = horz_plane.Normal;
plane_normal.normalize();

while(--total_found >= 0)
{ // get the normal of triangle
triangle3df &tri = triangles[total_found];
if(tri.pointA.Y < 400) // consider triangles below this height
{
vector3df tri_normal = tri.getNormal().normalize();
if(tri_normal == plane_normal) // yes is an horizontal triangle
{
HorTriangleCounter++;
}
}
}
delete[] triangles;
}
}

Note: I will try your ideas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this