Chris Share

05-12-2005, 04:49 AM

Hi,

I'm trying to draw a series of ellipses that rotate about a point other than their centre. The ellipses are drawn as a series of points.

My problem is, that I can get the ellipses to rotate about their own centre point, however I can't figure out how to get them to rotate about a different point. Here's the basic code I've tried:

void drawEllipse()

{

float degInRad;

float xradius = 0;

float zradius = 4;

int i, j;

glColor3f(1.0, 1.0, 0.0); // Yellow.

glPushMatrix();

glTranslatef(x, 0, z - 4.4); // Ellipse centre.

glRotatef(180-angle*180.0/3.14, 0.0, 1.0, 0.0);

for(j = 0; j < NUM_ELLIPSES; j++)

{

for(i = 0; i < 360; i++)

{

// Convert degrees to radians.

degInRad = i * DEG2RAD;

glBegin(GL_POINTS);

glVertex3f(cos(degInRad) * xradius, y, sin(degInRad) * zradius);

glEnd();

}

xradius += 0.25f; // Distance between ellipses.

}

glPopMatrix();

}Do I need to draw each point in each ellipse with respect to the rotation point (rather than the centre point) or is there another way to do this?

Cheers,

Chris Share

I'm trying to draw a series of ellipses that rotate about a point other than their centre. The ellipses are drawn as a series of points.

My problem is, that I can get the ellipses to rotate about their own centre point, however I can't figure out how to get them to rotate about a different point. Here's the basic code I've tried:

void drawEllipse()

{

float degInRad;

float xradius = 0;

float zradius = 4;

int i, j;

glColor3f(1.0, 1.0, 0.0); // Yellow.

glPushMatrix();

glTranslatef(x, 0, z - 4.4); // Ellipse centre.

glRotatef(180-angle*180.0/3.14, 0.0, 1.0, 0.0);

for(j = 0; j < NUM_ELLIPSES; j++)

{

for(i = 0; i < 360; i++)

{

// Convert degrees to radians.

degInRad = i * DEG2RAD;

glBegin(GL_POINTS);

glVertex3f(cos(degInRad) * xradius, y, sin(degInRad) * zradius);

glEnd();

}

xradius += 0.25f; // Distance between ellipses.

}

glPopMatrix();

}Do I need to draw each point in each ellipse with respect to the rotation point (rather than the centre point) or is there another way to do this?

Cheers,

Chris Share