tags:

views:

622

answers:

2

I am teaching myself OpenGL game programming from tutorials on the net. I want to draw a half torus, such that it can look like a gateway. How can I do this, does any one know the math involved? most tutorials online show how to draw a full torus.

+1  A: 

Set a clip plane appropriately ([0,0,1,0] ought to work, assuming +Z is 'up') and draw a full torus.

genpfault
A: 

Here's an answer that adapts the OpenGL Redbook torus.c tutorial

Here's their code for drawing a torus:

static void torus(int numc, int numt)
{
   int i, j, k;
   double s, t, x, y, z, twopi;

   twopi = 2 * PI_;
   for (i = 0; i < numc; i++) {
      glBegin(GL_QUAD_STRIP);
      for (j = 0; j <= numt; j++) {
         for (k = 1; k >= 0; k--) {
            s = (i + k) % numc + 0.5;
            t = j % numt;

            x = (1+.1*cos(s*twopi/numc))*cos(t*twopi/numt);
            y = (1+.1*cos(s*twopi/numc))*sin(t*twopi/numt);
            z = .1 * sin(s * twopi / numc);
            glVertex3f(x, y, z);
         }
      }
      glEnd();
   }
}

What this does is draws a volume of rotation. You can use this same idea, except stop this loop halfway through (i.e., for(i = 0; i < numc/2; i++) )

bkritzer