Problem With Loading Map files using Intersection
I am unable to get the following code below to work correctly. I
am unable to render the data directly to a display list. If i compile with GL_POINTS instead of GL_QUADS I can see the vertices that make up the level, in the correct places. But when I render the faces properly it dosen''t work the geometry is messed up!!
This is because the loop renders all combinations of intersections and dosen''t do so in a specific order. How do I get the loop to render the data in the right order?
I would appreciate it if you could tell me whats wrong with the code below
Thanks alot. Sorry if the code is crap but i am new to 3D Coding and OpenGL.
void DisplayMap()
{
vert Vert;
level = glGenLists(1);
glNewList(level,GL_COMPILE);
glBegin(GL_QUADS);
for (int i=0; i.GetIntersection(plane[j], plane[k], ‖) == true)
{
for (int faces=0; faces < 6; faces++)
{
if (dotProduct(plane[faces].normal, Vert) + plane[faces].d > 0)
{
illegal = true;
}
}
if (illegal == false)
glVertex3f(Vert.x, Vert.y, Vert.z);
}
}
}
}
glEnd();
glEndList();
}
Thanks Alot
~Steve~
Hi again!! 
Well, first you can''t render using GL_QUADS because the polygons generated by the algorithm can have any number of sides. Use GL_POLYGON. But that won''t fix your problem. What you are seeing is the drawing of unsorted vertices. You need to sort them into clockwise order so you can render with GL_POLYGON. This is harder than it first appears. You can do it by getting the center of the polygon and comparing all angles between the vertices using DotProduct(). This has a few problems I think but it seems to work alright for me.
Doing the above will mean that you will have to store the vertices in some sort of polygon class, rather than just creating th display list. This is a much better way of doing it, especially when you need to be able to work with the vertices, and if you ever add CSG then the change now will come in handy.
How I showed you with creating a polygon for each face then adding it to the current planes you are testing for intersection, is exactly what you should be doing here. You can create your display list afterwards quite easily.
Let me know how you get on,
FatalXC

Well, first you can''t render using GL_QUADS because the polygons generated by the algorithm can have any number of sides. Use GL_POLYGON. But that won''t fix your problem. What you are seeing is the drawing of unsorted vertices. You need to sort them into clockwise order so you can render with GL_POLYGON. This is harder than it first appears. You can do it by getting the center of the polygon and comparing all angles between the vertices using DotProduct(). This has a few problems I think but it seems to work alright for me.
Doing the above will mean that you will have to store the vertices in some sort of polygon class, rather than just creating th display list. This is a much better way of doing it, especially when you need to be able to work with the vertices, and if you ever add CSG then the change now will come in handy.
How I showed you with creating a polygon for each face then adding it to the current planes you are testing for intersection, is exactly what you should be doing here. You can create your display list afterwards quite easily.
Let me know how you get on,
FatalXC
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement