All tutorials in one place.

Saturday, July 9, 2016

4. Vizatimi i rrethit

Te gjithe primitivat e meparshme qe kemi permendur realizojne ndertimet nepermjet vijave te drejta. Ekzistojne algoritme si Algoritmi I Pikes se Mesit qe mund te konvertoje forma si rrethi dhe figura te tjera hiporbelike.

Theta eshte nje kend 0-360 grad, keshtu qe ne mund te marrim kordinatat (x,y) te pikes pergjate rrethit, pra vetem duke caktuar nje sasi te madhe pikash dhe vizatojme segmente qe i bashkojne, figura do te ngjaje tamam si rreth. Ne shembullin e meposhtem kemi percaktuar 100 pika per vizatimin e rrethit. 

#define PI 3.14
GLint circle_points=100;
void MyCircle2f(GLfloat centerx, GLfloat centery, GLfloat radius){
GLint i;
GLdouble theta;
glBegin(GL_POLYGON);
for(i=0;i<circle_points;i++){
theta=2*PI*i/circle_points; //kendi ne radian
glVertex2f(centerx+radius*cos(theta), centery+radius*sin(theta));
}
glEnd();
}
Shembull:
void Display(void){
glClear(GL_COLOR_BUFFER_BIT); //fshijme te gjitha pixelat me ngjyren e specifikuar
glColor3f(1.0,0.8,0.1);
MyCircle2f(80.,85.,10.);
//vizatojme syte
glBegin(GL_POINTS);
glColor3f(0.0,0.0,0.0);
glVertex2f(77.,88.);
glVertex2f(83.,88.);
glEnd();
//vizatojme trupin poligonal
glColor3f(0.8,0.0,0.9);
glBegin(GL_POLYGON);
glVertex2f(75.,75.);
glVertex2f(85.,75.);
glVertex2f(100.,30.);
glVertex2f(60.,30.);
glEnd();
//vizatojme kembet
glColor3f(1.0,0.0,0.1);
glRectf(70.,5.,75.,30.);
glRectf(80.,5.,90.,30.);
//vizatojme vijat per krahet
glBegin(GL_LINES);
glVertex2f(74.,70.);
glVertex2f(50.,50.);
glEnd();
glBegin(GL_LINES);
glVertex2f(86.,70.);
glVertex2f(110.,50.);
glEnd();
glFlush();
} void init()
{
glClearColor(1.0,0.0,0.0,1.0);
glPointSize(5.0); //percaktojme madhesine e pikave 5 pixela
glViewport(0,0,320,240);
gluOrtho2D(0.0,160.0,0.0,120.0);
}
int main(int argc, char* argv[])
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(320,240);
glutCreateWindow("Figure");
init();
glutDisplayFunc(Display);
glutMainLoop();
}

Rezultati i shembullit te mesiperm:


Share:

0 comments:

Post a Comment

Popular Posts

Categories

Tutorials House. Powered by Blogger.

Labels