Menggerakan Bola Keatas dan Scaling Searah Sumbu X

#include
#include
#include
#define PI 3.14
double xpos, ypos, xdir;
int jumlah_titik =100;

void Lingkaran()
{
     GLint j;
     GLdouble sudut;
     glBegin(GL_POLYGON);
     for(j=0; j     {
      sudut=2*PI*j/jumlah_titik;
      glVertex2f(20*cos(sudut),10*sin(sudut));
     }
     glEnd();
}

void Display()
{
     glClear(GL_COLOR_BUFFER_BIT);
     glColor3f(1,0,0);
     ypos = ypos+xdir*0.01;
     if (ypos >=220)
     xdir=0;
     glLoadIdentity();
     glTranslatef(xpos+ypos+60,ypos,0);
     Lingkaran();

     glutSwapBuffers();
     glutPostRedisplay();
}
  
void reshape(int w, int h)
{
     glViewport(0,0,(GLsizei)w,(GLsizei)h);
     glMatrixMode(GL_PROJECTION);
     gluOrtho2D(0.0,320.0,0.0,240.0);
     glMatrixMode(GL_MODELVIEW);
}

void init()
{
     glClearColor(0.0,0.0,0.0,0.0);
     ypos=20;
     xpos=20;
     xdir=1;
}

int main(int argc,char*argv[])
{
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
    glutInitWindowSize(320,240);
    glutCreateWindow("Habibul Hakim [12111042]");
    init();
    glutDisplayFunc(Display);
    glutReshapeFunc(reshape);
    glutMainLoop();
}

Post a Comment

1. Jangan lupa tinggalkan Likenya ya
2. Berkomentarlah dengan baik dan sopan

[blogger]

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget