PDA

View Full Version : Points rotation?



saibot
06-10-2010, 03:49 AM
Is there anyway to constant rotate some points?!


The code:
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glColor3d(0.0,0.0,1.0);
glPushMatrix();
glTranslatef(0.0,0.0,-5.0);
glRotatef(angle,1.0,0.0,0.0);

for(int i=1;i<=36;i++)
{
glBegin(GL_POINTS);
glVertex3f(sin(i),cos(i),0.0);
}


glPopMatrix();
angle++;
glutSwapBuffers();
}

But no results!!

Exoide
06-10-2010, 07:56 AM
Hi saibot,


Is there anyway to constant rotate some points?!

Of course you can do it.

If the code you showed here is the real code it can't give you any result because you have a lot of bugs there.

I'll try to fix it assuming you wanna rotate 36 points around the origin.



static void display(void)
{
const float PI = 3.1415; // It'll be needed to convert to radians
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glColor3d(0.0,0.0,1.0);
glPushMatrix();
glTranslatef(0.0,0.0,-5.0);
glRotatef(angle,1.0,0.0,0.0);

glBegin(GL_POINTS); // You must avoid if possible the inclusion of "glBegin" inside a loop
for (int i = 1; i <= 36; i++)
{
//glVertex3f(sin(i),cos(i),0.0); // Error!!! sin() and cos() expect the argument to be in radians not degrees
double radian = i * PI / 180; // You must declare "PI" as a constant
glVertex3f(sin(radian), cos(radian), 0); // In this case you can use glVertex2f instead. But it's ok like this.
}
glEnd(); // It was missing in your code.

glPopMatrix();
angle++;
glutSwapBuffers();
}

saibot
06-10-2010, 08:11 AM
Thanks very much for the tips!