MEMBUAT DONAT 3D BERGERAK OPENGL VS 2008




#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>
#include <math.h>

GLfloat xRotated, yRotated, zRotated;
GLdouble innerRaidus=0.5;
GLdouble outterRaidus=1;
GLint sides =30;
GLint rings =30;
int i=0;
int a=0;
float j=0;
float k=0;
bool ket = true;

void donat(void)
{

    glMatrixMode(GL_MODELVIEW);
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0,0.0,-4.5);
    glColor3f(0.8, 0.6, 0.8);
    glRotatef(xRotated,1.0,0.0,0.0);
    glRotatef(yRotated,0.0,1.0,0.0);
    glRotatef(zRotated,0.0,0.0,1.0);
    glScalef(1.0,1.0,1.0);

    glutSolidTorus(innerRaidus,outterRaidus,sides,rings);
    glFlush();   
}

void tengil(int x, int y)
{
    if (y == 0 || x == 0) return;
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity();
    gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);
    glViewport(0,0,x,y);
}

void idleTorus(){
     glPushMatrix();
        glRotated(i, 8, 1, 0);

        donat();
      
      i = i + 0.1;
    a = a + 0.1;
     yRotated += 0.08;
}


void geser(){
glPushMatrix();
    glRotated(90,1,0,0);
    //glTranslated(k,0,0);
    donat();
    glPopMatrix();
}


int main (int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 
    glutInitWindowSize(400,350);
    glutCreateWindow("1500018153");
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    xRotated = yRotated = zRotated = 10.0;
    xRotated=33;
    yRotated=40;
    glClearColor(0.0,0.0,0.0,0.0);

    glutDisplayFunc(donat);
    glutReshapeFunc(tengil);
    glutIdleFunc(idleTorus);

    glutMainLoop();
    return 0;
}

0 komentar: