Membuat Lampu Kristal 3D

Coding

#include
#include
#include
#define PI 3.14
GLint circle_points = 50;
void MyTone(GLfloat radius1, GLfloat radius2)
{
     GLint i,j;
     GLdouble theta, ntheta;
     for(i=0; i
     {
        glBegin(GL_POLYGON);
        theta = (2*PI*i/circle_points);
        ntheta = (2*PI*(i+1)/circle_points);
        glVertex3f(0,0,0);
        glVertex3f(radius1*cos(theta), 1, radius1*sin(theta));      
        glVertex3f(radius1*cos(theta), 2, radius1*sin(theta)); 
        glVertex3f(radius1*cos(ntheta), 3.5, radius1*sin(ntheta));
        glVertex3f(radius1*cos(ntheta), 2, radius1*sin(ntheta));       
        glVertex3f(radius1*cos(theta), 1.5, radius2*sin(theta));       
        glVertex3f(radius2*cos(theta), 1.5, radius2*sin(theta));             
        glVertex3f(radius1*cos(theta), 0.5, radius1*sin(theta));
        glEnd();
     }
}
void Lingkaran(GLfloat radius)
{
     GLdouble inc=PI/10;
     GLdouble theta,phi;
    
     for(theta=-PI/2;theta<(PI/2+inc);theta+=inc)
     {
         for(phi=0;phi<2 inc="" phi="" span="">
         {
             glBegin(GL_POLYGON);
             glVertex3f(radius*cos(theta)*cos(phi),radius*sin(theta),radius*cos(theta) *sin(phi));
             glVertex3f(radius*cos(theta+inc)*cos(phi),radius*sin(theta+inc),radius*cos(theta+inc) *sin(phi));
             glVertex3f(radius*cos(theta+inc)*cos(phi+inc),radius*sin(theta+inc),radius*cos(theta+inc) *sin(phi+inc));
             glVertex3f(radius*cos(theta)*cos(phi+inc),radius*sin(theta),radius*cos(theta) *sin(phi+inc));
         glEnd();
         }
     }
     glFlush();
}
void Display()
{
     glClear(GL_COLOR_BUFFER_BIT);
     glColor3f(-1,0,0);    
     MyTone(0.5,1); 
     Lingkaran(0.1);
     glEnd();
    
     glBegin(GL_POLYGON);
     glVertex2f(0,0.1);
     glVertex2f(0,5.5);
     glVertex2f(-0.01,0.1);
     glVertex2f(-0.01,5.5);
     glVertex2f(0.01,0.1);
     glVertex2f(0.01,5.5);
     glEnd();
    
     glBegin(GL_POLYGON);
     glColor3f(0,0,1);
     glVertex2f(-0.08,5.5);
     glVertex2f(-0.08,5.8);
     glVertex2f(0.08,5.8);
     glVertex2f(0.08,5.5);
     glVertex2f(-0.08,5.5);
     glVertex2f(-0.08,5.8);
     glVertex2f(0.08,5.8);
     glVertex2f(0.08,5.5);
     glEnd();    
     glFlush();
}
    
void reshape(int w, int h)
{
     glViewport(0,0,(GLsizei)w,(GLsizei)h);
     glMatrixMode(GL_PROJECTION);
     glFrustum (-(GLfloat)w/h,(GLfloat)w/h, -2,2, 1,30);
     gluLookAt(0,2,2.3,0,0,-100,0,1,0);
}
void init()
{
     glPolygonMode(GL_FRONT,GL_LINE);
     glPolygonMode(GL_BACK,GL_LINE);
     glEnable (GL_LINE_SMOOTH);
    
     glEnable (GL_BLEND);
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     glHint(GL_LINE_SMOOTH_HINT | GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);
     glClearColor(1,1,1,1);
     glPointSize(3);
     glLineWidth(1.2);
}
int main(int argc,char*argv[])
{
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowSize(500,500);
    glutCreateWindow("Habibul Hakim | 12111042 [LAMPU KRISTAL]");
    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