PDA

View Full Version : Triangle fans problem???



nexusone
07-22-2000, 04:22 AM
I am working on creating a routine that will create a 3D object based on the number of sides. 3 sides = pyramid, 4 sides = cube, etc.

I am trying to use the TRIANGLE_FAN option to create a side of the 3D object.

glBegin(GL_TRIANGLE_FAN)
glColor3f( 1.0f, 0.0f, 1.0f )
glVertex3f( 0.0f, 0.0f, 0.0f)
for(i=sides; i < sides; i++)
{
radi = ((360/sides)/360)* PI // convert rad to deg
mx=1*(float)cos(radi)
my=1*(float)sin(radi)
glVertex3f(mx, my, 0.0f)
}
glEnd()

The thing is after the routine run's there is nothing drawn.... Is there something missing? in order to use Triangle_fan?

flashp
07-22-2000, 05:02 AM
Maybe there are just typos in the code you've written here, but I guess the loop is at least very strange. It should better look like this, if I understand right what you want to do:

for(i=0; i<sides; i++) {
radi = ((2*PI)/sides)*i;
mx = radius*cos(radi);
my = radius*sin(radi);
glVertex2f(mx, my);
}

Flash

nexusone
07-23-2000, 04:43 AM
I guess that it was the long way around but I wanted to use degree's but maybe to simplify that routine I should just stick to rad.
Yea, I believe you got the idea of what I am trying ot do.
One other question is a triangle fan need's a min. of 3 points, to create one triangle?


Originally posted by flashp:
Maybe there are just typos in the code you've written here, but I guess the loop is at least very strange. It should better look like this, if I understand right what you want to do:

for(i=0; i<sides; i++) {
radi = ((2*PI)/sides)*i;
mx = radius*cos(radi);
my = radius*sin(radi);
glVertex2f(mx, my);
}

Flash

shawge
07-24-2000, 07:27 AM
Three points for the first triangle and one point for every triangle after that. The initial point (ex. 0) and the previous point (n-1) are used with the last point (n)
to create the next tri in the fan. Here's a cheezy ascii diagram

1 __2__ 3
\ | /|
\ | / |
0 __4
\ |
\ |
5

0 is the initial point, 4 is n-1, and 5 is n. Clear as mud?? http://www.opengl.org/discussion_boards/ubb/smile.gif

nexusone
07-24-2000, 07:43 AM
Thank's for the reply.
1. I found that triangle was being drawn out side the viewport, correct it with a translate command.
2. I am now just using the rad's for the point calculation and not degree's.
3. My next step is the make the routine, figure out the location of each face. Been thinking about the math to do that.