Subject: Gl Circles
From: Jay Cox <[email-masked]>
To: [email-masked]
Date: Wed, 28 Jan 1998 02:19:46 -0800

I would like to thank you for making your circle drawing code
available.  I never would have thought to use the font system to draw
circles quickly.  It was quite usefull in optomizing my particle system
flame.

  I'm not sure if you have any further interest in drawing circles, but
I thought I'd pass along my results in case you still find the topic
interesting.  I have found that using triangle meshes can be more than
twice as fast as  your optomized gl polygon routine (at least on my
100mhz r4k elan).  At the bottom of this message is code that can easily
be added to circ2.c

  It can be usefull to remove the call to swapbuffers when timing low
level primitives as it gives you much finer grain timings.  This is
because swapbufers must wait till the next vertical retrace before
executing.  From your published timings I would guess that kukui is set
to a 72Hz refresh rate, fireball 78hz(could it have been changed to 60hz
for the opengl tests?) and oreo 60hz.

void mesh_circle(vec3 *cen, vec3 *n, float r, int nsides) {
    /* doesn't assume n is a unit vector */
    /* I wrote a table look up version but it made only a negligble
speed diference */
    int i;
    float ang, cosang, sinang;
    vec3 u, v, pt;

    if (n->x*n->x < .33) VEC_SET(0, n->z, -n->y, &u);	/* n X (1,0,0) */
    else VEC_SET(-n->z, 0, n->x, &u);			/* n X (0,1,0) */
    vec_smul(r/VEC_LEN(&u), &u, &u);
    vec_cross(n, &u, &v);			/* v is another tangent vector*/
    vec_smul(r/VEC_LEN(&v), &v, &v);
    /* u, v, and n are mutually orthogonal, u and v have length r */

    /* draw a disk */
    if ((nsides & 1)) /* nsides must be even for this code to work
properly */
	nsides++;
    bgntmesh();
    for (i=0; i<nsides/2; i++) {
	ang = 2.*M_PI*(i+.5)/nsides;
	cosang = cosf(ang);
	sinang = sinf(ang);
	pt.x = cen->x + cosang*u.x + sinang*v.x;
	pt.y = cen->y + cosang*u.y + sinang*v.y;
	pt.z = cen->z + cosang*u.z + sinang*v.z;
	v3f(&pt.x);
	ang = -2.*M_PI*(i+.5)/nsides;
	sinang *= -1.0f;
	pt.x = cen->x + cosang*u.x + sinang*v.x;
	pt.y = cen->y + cosang*u.y + sinang*v.y;
	pt.z = cen->z + cosang*u.z + sinang*v.z;
	v3f(&pt.x);
    }
    endtmesh();
}

Thanks again,

Jay Cox
Digital 3D Corp.