PDA

View Full Version : ellipse rotation



nebula
05-16-2014, 01:36 AM
hello i have this code and i want to ass more ellipses around the circle which will be rotated (45 degrees an do on)
is there an easy way to do it in the ellipse equation in the for loop
maybe do i have to add glRotate?
what would you recommend?

thank yoU!


#include <stdio.h>
#include <math.h>
#include <GL/glut.h>

#define PI 3.1415926535897932384626433832795

static double radius = 0.2;
static double xradius=1.5;
static double yradius=0.4;

void init()
{
glClearColor(1.0, 1.0, 1.0,0.0);
gluOrtho2D(0.0,100,0.0,100);
}

void myEllipse1()
{
glColor3f(0.2, 0.3, 0.5);
glBegin(GL_LINE_LOOP);
for(double i = 0; i < 2 * PI; i += PI / 24)
{
glVertex2f(20*cos(i) * xradius+50,20* sin(i) * yradius+50);
}
glEnd();

}

void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glBegin(GL_POLYGON);
for(double i=0;i<2*PI;i+=PI/24)
{
glVertex2f(20*cos(i)*radius+50,20*sin(i)*radius+50 );
}
glEnd();
myEllipse1();

glFlush();
}

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
glutInitWindowSize(500,500);
glutInitWindowPosition(50,50);
glutCreateWindow("meh");
init();
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}