Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <windows.h>
- #include<math.h>
- #include<iostream>
- using namespace std;
- const int width = 500;
- const int height = 400;
- const float rat = 1.0 * width / height;
- GLfloat eyeX = 0;
- GLfloat eyeY = 18;
- GLfloat eyeZ = 30;
- GLfloat lookX = 0;
- GLfloat lookY = 5;
- GLfloat lookZ = 0;
- float light_height = 20;
- float light_width = -29.5;
- float light_length = -30;
- float light1_height = 20;
- float light1_width = 29.5;
- float light1_length = -30;
- float light2_height = 28;
- float light2_width = -15;
- float light2_length = -20;
- float spt_cutoff = 30;
- float rot = 0, f_spin = 0.0, d_spin = 0.0, c_spin1 = 360.0, c_spin2 = 360.0;
- bool t = true, t1 = true, t2 = false;
- bool flagRot = false, flagDoor = true, flagClock=false;
- static GLfloat v_cube[8][3] =
- {
- {0,0,0},
- {0,0,1},
- {0,1,0},
- {0,1,1},
- {1,0,0},
- {1,0,1},
- {1,1,0},
- {1,1,1}
- };
- static GLubyte c_ind[6][4] =
- {
- {0,2,6,4},
- {1,5,7,3},
- {0,4,5,1},
- {2,3,7,6},
- {0,1,3,2},
- {4,6,7,5}
- };
- static void getNormal3p(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2, GLfloat x3, GLfloat y3, GLfloat z3)
- {
- GLfloat Ux, Uy, Uz, Vx, Vy, Vz, Nx, Ny, Nz;
- Ux = x2-x1;
- Uy = y2-y1;
- Uz = z2-z1;
- Vx = x3-x1;
- Vy = y3-y1;
- Vz = z3-z1;
- Nx = Uy*Vz - Uz*Vy;
- Ny = Uz*Vx - Ux*Vz;
- Nz = Ux*Vy - Uy*Vx;
- glNormal3f(Nx,Ny,Nz);
- }
- void cube(float R=0.5, float G=0.5, float B=0.5, bool em=false , bool l = false)
- {
- GLfloat mat_no[] = {0, 0, 0, 1.0};
- GLfloat mat_amb[] = {R,G,B,1};
- GLfloat mat_diff[] = {R,G,B,1};
- GLfloat mat_spec[] = {1,1,1,1};
- GLfloat mat_sh[] = {30};
- GLfloat mat_em[] = {1,1,1,1};
- glMaterialfv(GL_FRONT, GL_AMBIENT, mat_amb);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diff);
- glMaterialfv(GL_FRONT, GL_SPECULAR, mat_spec);
- glMaterialfv(GL_FRONT, GL_SHININESS, mat_sh);
- if(em && l)
- {
- glMaterialfv(GL_FRONT, GL_EMISSION, mat_em);
- }
- else
- {
- glMaterialfv(GL_FRONT, GL_EMISSION, mat_no);
- }
- glBegin(GL_QUADS);
- for (GLint i = 0; i <6; i++)
- {
- getNormal3p(v_cube[c_ind[i][0]][0], v_cube[c_ind[i][0]][1], v_cube[c_ind[i][0]][2],
- v_cube[c_ind[i][1]][0], v_cube[c_ind[i][1]][1], v_cube[c_ind[i][1]][2],
- v_cube[c_ind[i][2]][0], v_cube[c_ind[i][2]][1], v_cube[c_ind[i][2]][2]);
- for (GLint j=0; j<4; j++)
- {
- glVertex3fv(&v_cube[c_ind[i][j]][0]);
- }
- }
- glEnd();
- }
- void tube1()
- {
- float t_length = 16;
- float t_width = 1;
- glPushMatrix();
- glTranslatef(-29.5,20,0);
- glPushMatrix();
- glScalef(t_width,t_width,t_length);
- glTranslatef(-0.5,0,-0.5);
- cube(1,1,1,true,t);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,0,t_length/2+t_width/2);
- glScalef(t_width,t_width,t_width);
- glTranslatef(-0.5,0,-0.5);
- cube(0.2,0.2,0.2);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,0,-t_length/2-t_width/2);
- glScalef(t_width,t_width,t_width);
- glTranslatef(-0.5,0,-0.5);
- cube(0.2,0.2,0.2);
- glPopMatrix();
- glPopMatrix();
- }
- void tube2()
- {
- float t_length = 16;
- float t_width = 1;
- glPushMatrix();
- glTranslatef(29.5,20,0);
- glPushMatrix();
- glScalef(t_width,t_width,t_length);
- glTranslatef(-0.5,0,-0.5);
- cube(1,1,1,true,t1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,0,t_length/2+t_width/2);
- glScalef(t_width,t_width,t_width);
- glTranslatef(-0.5,0,-0.5);
- cube(0.2,0.2,0.2);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,0,-t_length/2-t_width/2);
- glScalef(t_width,t_width,t_width);
- glTranslatef(-0.5,0,-0.5);
- cube(0.2,0.2,0.2);
- glPopMatrix();
- glPopMatrix();
- }
- void light()
- {
- GLfloat light_no[] = {0, 0, 0, 1.0};
- GLfloat light_amb[] = {0.1, 0.1, 0.1, 1.0};
- GLfloat light_dif[] = {1,1,1,1};
- GLfloat light_spec[] = {1,1,1,1};
- GLfloat light_pos[] = {light_width,light_height,light_length,1.0};
- glEnable(GL_LIGHT0);
- if(t)
- {
- glLightfv(GL_LIGHT0, GL_AMBIENT, light_amb);
- }
- else
- {
- glLightfv(GL_LIGHT0, GL_AMBIENT, light_no);
- }
- if(t)
- {
- glLightfv(GL_LIGHT0, GL_DIFFUSE, light_dif);
- }
- else
- {
- glLightfv(GL_LIGHT0, GL_DIFFUSE, light_no);
- }
- if(t)
- {
- glLightfv(GL_LIGHT0, GL_SPECULAR, light_spec);
- }
- else
- {
- glLightfv(GL_LIGHT0, GL_SPECULAR, light_no);
- }
- glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
- }
- void light1()
- {
- GLfloat light1_no[] = {0, 0, 0, 1.0};
- GLfloat light1_amb[] = {0.1, 0.1, 0.1, 1.0};
- GLfloat light1_dif[] = {1,1,1,1};
- GLfloat light1_spec[] = {1,1,1,1};
- GLfloat light1_pos[] = {light1_width,light1_height,light1_length,1.0};
- glEnable(GL_LIGHT1);
- if(t1)
- {
- glLightfv(GL_LIGHT1, GL_AMBIENT, light1_amb);
- }
- else
- {
- glLightfv(GL_LIGHT1, GL_AMBIENT, light1_no);
- }
- if(t1)
- {
- glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_dif);
- }
- else
- {
- glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_no);
- }
- if(t1)
- {
- glLightfv(GL_LIGHT1, GL_SPECULAR, light1_spec);
- }
- else
- {
- glLightfv(GL_LIGHT1, GL_SPECULAR, light1_no);
- }
- glLightfv(GL_LIGHT1, GL_POSITION, light1_pos);
- }
- void light2()
- {
- GLfloat light2_no[] = {0, 0, 0, 1.0};
- GLfloat light2_amb[] = {0.1, 0.1, 0.1, 1.0};
- GLfloat light2_dif[] = {1,1,1,1};
- GLfloat light2_spec[] = {1,1,1,1};
- GLfloat light2_pos[] = {light2_width,light2_height,light2_length,1.0};
- glEnable(GL_LIGHT2);
- if(t2)
- {
- glLightfv(GL_LIGHT2, GL_AMBIENT, light2_amb);
- }
- else
- {
- glLightfv(GL_LIGHT2, GL_AMBIENT, light2_no);
- }
- if(t2)
- {
- glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_dif);
- }
- else
- {
- glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_no);
- }
- if(t2)
- {
- glLightfv(GL_LIGHT2, GL_SPECULAR, light2_spec);
- }
- else
- {
- glLightfv(GL_LIGHT2, GL_SPECULAR, light2_no);
- }
- glLightfv(GL_LIGHT2, GL_POSITION, light2_pos);
- GLfloat spt_dir[] = {1,0,-1,1};
- GLfloat spt_ct[] = {spt_cutoff};
- glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, spt_dir);
- glLightfv(GL_LIGHT2, GL_SPOT_CUTOFF, spt_ct);
- }
- void spot_light()
- {
- float s_height = 2;
- float s_width = 5;
- float s_length = 5;
- glPushMatrix();
- glTranslatef(-15,24,-15);
- glPushMatrix();
- glScalef(s_width,s_height,s_length);
- glTranslatef(-0.5,0,-0.5);
- cube(1,1,1,true,t2);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,0,s_length/2+0.1);
- glScalef(4.5,1.5,0.1);
- glTranslatef(-0.5,0.1,-0.5);
- cube(0.7,0.7,0.8);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-1.8,1.3,s_length/2+0.2);
- glScalef(0.5,0.2,0.2);
- glTranslatef(-0.5,0,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-1,1.3,s_length/2+0.2);
- glScalef(0.5,0.2,0.2);
- glTranslatef(-0.5,0,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-1,0.8,s_length/2+0.2);
- glScalef(0.5,0.2,0.2);
- glTranslatef(-0.5,0,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-1.8,0.8,s_length/2+0.2);
- glScalef(0.5,0.2,0.2);
- glTranslatef(-0.5,0,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-0.3,0.8,s_length/2+0.2);
- glScalef(0.2,0.2,0.2);
- glTranslatef(-0.5,0,-0.5);
- cube(1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0.2,0.8,s_length/2+0.2);
- glScalef(0.2,0.2,0.2);
- glTranslatef(-0.5,0,-0.5);
- cube(1,1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-0.3,1.3,s_length/2+0.2);
- glScalef(0.2,0.2,0.2);
- glTranslatef(-0.5,0,-0.5);
- cube(0,1,0.9);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0.2,1.3,s_length/2+0.2);
- glScalef(0.2,0.2,0.2);
- glTranslatef(-0.5,0,-0.5);
- cube(0.7,0.7,0.7);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(1.8,0.5,s_length/2+0.2);
- glScalef(0.8,0.3,0.2);
- glTranslatef(-0.5,0,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,s_height,0);
- glScalef(0.7,4,0.7);
- glTranslatef(-0.5,0,-0.5);
- cube(0.8,0.8,0.8);
- glPopMatrix();
- glPopMatrix();
- }
- void axes()
- {
- float length = 10;
- float width = 0.3;
- // X-axis
- glPushMatrix();
- glTranslatef(length/2,0,0);
- glScalef(length,width,width);
- glTranslatef(-0.5,-0.5,-0.5);
- cube(0.8,0.1,0.1);
- glPopMatrix();
- // Y-axis
- glPushMatrix();
- glTranslatef(0,length/2,0);
- glScalef(width,length,width);
- glTranslatef(-0.5,-0.5,-0.5);
- cube(0.1,0.8,0.1);
- glPopMatrix();
- // Z-axis
- glPushMatrix();
- glTranslatef(0,0,length/2);
- glScalef(width,width,length);
- glTranslatef(-0.5,-0.5,-0.5);
- cube(0.1,0.1,0.8);
- glPopMatrix();
- }
- void walll()
- {
- float length = 60;
- float width = 1;
- float height = 30;
- //floor
- glPushMatrix();
- glScalef(length,width,length);
- glTranslatef(-0.5,-1,-0.5);
- cube(0.9,0.9,0.9);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(length/2,-width,0);
- glScalef(width,height,length);
- glTranslatef(0,0,-0.5);
- cube(0.741, 0.718, 0.420);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-length/2-1,-width,0);
- glScalef(width,height,length);
- glTranslatef(0,0,-0.5);
- cube(0.741, 0.718, 0.420);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,-width,-length/2-1);
- glScalef(length,height,width);
- glTranslatef(-0.5,0,0);
- cube(0.741, 0.718, 0.420);
- glPopMatrix();
- //blackboard
- glPushMatrix();
- glTranslatef(0,height/4,-length/2);
- glScalef(length/2,height/3,width);
- glTranslatef(-0.5,0,0);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- //top
- glPushMatrix();
- glTranslatef(0,height,0);
- glScalef(length,width,length);
- glTranslatef(-0.5,-1,-0.5);
- cube(0.941, 0.902, 0.54);
- glPopMatrix();
- }
- void chair()
- {
- float height=5;
- float width=8;
- float length=4;
- float base_height=0.8;
- float leg_height=height-base_height;
- float leg_width=0.7;
- glPushMatrix();
- glTranslatef(0,leg_height,0);
- glPushMatrix();
- glScalef(width,base_height,length);
- glTranslatef(-0.5,0,-0.5);
- cube(0.53,0.39,0.28);
- glPopMatrix();
- //legs
- glPushMatrix();
- glTranslatef(width/2-leg_width/2,0,length/2-leg_width/2);
- glScalef(leg_width,leg_height,leg_width);
- glTranslatef(-0.5,-1,-0.5);
- cube(1,0.8,0);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(width/2-leg_width/2,0,-(length/2-leg_width/2));
- glScalef(leg_width,leg_height,leg_width);
- glTranslatef(-0.5,-1,-0.5);
- cube(1,0.8,0);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-(width/2-leg_width/2),0,-(length/2-leg_width/2));
- glScalef(leg_width,leg_height,leg_width);
- glTranslatef(-0.5,-1,-0.5);
- cube(1,0.8,0);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-(width/2-leg_width/2),0,(length/2-leg_width/2));
- glScalef(leg_width,leg_height,leg_width);
- glTranslatef(-0.5,-1,-0.5);
- cube(1,0.8,0);
- glPopMatrix();
- //chair
- glPushMatrix();
- glTranslatef(0,-leg_height/2,length);
- glScalef(width/2,base_height,length/2);
- glTranslatef(-0.5,0,-0.5);
- cube(1.0,0,0);
- glPopMatrix();
- //legs
- glPushMatrix();
- glTranslatef(width/4-leg_width/4,-leg_height/2,length+(length/4-leg_width/4));
- glScalef(leg_width/2,leg_height/2,leg_width/2);
- glTranslatef(-0.5,-1,-0.5);
- cube(1,0.8,0);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(width/4-leg_width/4,-leg_height/2,length-(length/4-leg_width/4));
- glScalef(leg_width/2,leg_height/2,leg_width/2);
- glTranslatef(-0.5,-1,-0.5);
- cube(1,0.8,0);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-(width/4-leg_width/4),-leg_height/2,length+(length/4-leg_width/4));
- glScalef(leg_width/2,leg_height/2,leg_width/2);
- glTranslatef(-0.5,-1,-0.5);
- cube(1,0.8,0);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-(width/4-leg_width/4),-leg_height/2,length-(length/4-leg_width/4));
- glScalef(leg_width/2,leg_height/2,leg_width/2);
- glTranslatef(-0.5,-1,-0.5);
- cube(1,0.8,0);
- glPopMatrix();
- //
- glPushMatrix();
- glTranslatef((width/4-leg_width/4)/2,-leg_height/2,length-(length/4-leg_width/4)+length/2.5);
- glScalef(leg_width/2,leg_height/4,leg_width/2);
- glTranslatef(-0.5,0.4,-0.5);
- cube(0,0.2,0);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-(width/4-leg_width/4)/2,-leg_height/2,length-(length/4-leg_width/4)+length/2.5);
- glScalef(leg_width/2,leg_height/4,leg_width/2);
- glTranslatef(-0.5,0.4,-0.5);
- cube(0,0.2,0);
- glPopMatrix();
- //
- glPushMatrix();
- glTranslatef(0,-leg_height/1.3,length-(length/4-leg_width/4)+length/2.5);
- glScalef(width/2,leg_height/2.5,leg_width/2);
- glTranslatef(-0.5,1.5,-0.5);
- cube(1,1,0);
- glPopMatrix();
- glPopMatrix();
- }
- void chair_table()
- {
- for (float i = -25 ; i<24 ; i = i + 12)
- {
- for (float j = 23 ; j>-5 ; j = j - 9)
- {
- glPushMatrix();
- glTranslatef(i,0,j);
- chair();
- glPopMatrix();
- }
- }
- }
- void fan()
- {
- float height = 30;
- float m_width = 4;
- float m_height = 2;
- float angle = 0;
- float s_width = 2.0;
- float s_height = 20.0;
- for(int i=0; i<=360 ; i=i+10)
- {
- glPushMatrix();
- glTranslatef(0,height-1.5,0);
- glRotatef(i,0,1,0);
- glScalef(m_width,m_height/8,m_height);
- glTranslatef(-0.5,0,-0.5);
- cube(0.753, 0.753, 0.753);
- glPopMatrix();
- }
- glPushMatrix();
- glTranslatef(0,height-m_width-m_height/8,0);
- glScalef(1,m_width,1);
- glTranslatef(-0.5,0,-0.5);
- cube(1,0,0);
- glPopMatrix();
- glPushMatrix();
- glRotatef(f_spin,0,1,0);
- for(int i=0; i<=360 ; i=i+10)
- {
- glPushMatrix();
- glTranslatef(0,height-m_width-m_height/8-m_height,0);
- glRotatef(i,0,1,0);
- glScalef(m_width,m_height,m_height);
- glTranslatef(-0.5,0,-0.5);
- cube(0.000, 0.749, 1.000);
- glPopMatrix();
- }
- glPushMatrix();
- glTranslatef(0,height-m_width-m_height/8-m_height+1,0);
- glScalef(s_height,0.5,s_width);
- glTranslatef(-0.5,0,-0.5);
- cube(0.196, 0.804, 0.196);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,height-m_width-m_height/8-m_height+1,0);
- glScalef(s_width,0.5,s_height);
- glTranslatef(-0.5,0,-0.5);
- cube(0.196, 0.804, 0.196);
- glPopMatrix();
- glPopMatrix();
- }
- void desk()
- {
- float height=2;
- float width=25;
- float length=8;
- float base_height=0.8;
- float leg_height=height-base_height;
- float leg_width=0.7;
- glPushMatrix();
- glTranslatef(0,0,-(30-length/2)+1);
- glPushMatrix();
- glTranslatef(0,leg_height,0);
- glPushMatrix();
- glScalef(width,base_height,length);
- glTranslatef(-0.5,0,-0.5);
- cube(0.53,0.39,0.28);
- glPopMatrix();
- //legs
- glPushMatrix();
- glTranslatef(width/2-leg_width/2,0,length/2-leg_width/2);
- glScalef(leg_width,leg_height,leg_width);
- glTranslatef(-0.5,-1,-0.5);
- cube(0.502, 0.502, 0.000);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(width/2-leg_width/2,0,-(length/2-leg_width/2));
- glScalef(leg_width,leg_height,leg_width);
- glTranslatef(-0.5,-1,-0.5);
- cube(0.502, 0.502, 0.000);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-(width/2-leg_width/2),0,-(length/2-leg_width/2));
- glScalef(leg_width,leg_height,leg_width);
- glTranslatef(-0.5,-1,-0.5);
- cube(0.502, 0.502, 0.000);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-(width/2-leg_width/2),0,(length/2-leg_width/2));
- glScalef(leg_width,leg_height,leg_width);
- glTranslatef(-0.5,-1,-0.5);
- cube(0.502, 0.502, 0.000);
- glPopMatrix();
- glPopMatrix();
- //
- glPushMatrix();
- glTranslatef(0,0,length);
- glScalef(width/3,length*1.5,length/2);
- glTranslatef(-0.5,0,-0.5);
- cube(0.53,0.39,0.28);
- glPopMatrix();
- glPopMatrix();
- }
- void wardrobe()
- {
- float war_hieght = 15;
- float war_width = 7;
- float war_length = 10;
- glPushMatrix();
- glTranslatef(30-war_width/2,0,-(30-war_length/2)+2);
- glPushMatrix();
- glScalef(war_width,war_hieght,war_length);
- glTranslatef(-0.5,0,-0.5);
- cube(0.824, 0.412, 0.118);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-war_width/2,0,war_length/2);
- glScalef(war_width/25,war_hieght,war_length/25);
- glTranslatef(-0.5,0,-0.5);
- cube(0.545, 0.271, 0.075);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-war_width/2,0,-war_length/2);
- glScalef(war_width/25,war_hieght,war_length/25);
- glTranslatef(-0.5,0,-0.5);
- cube(0.545, 0.271, 0.075);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-war_width/2,0,0);
- glScalef(war_width/25,war_hieght,war_length/25);
- glTranslatef(-0.5,0,-0.5);
- cube(0.545, 0.271, 0.075);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(war_width/2,0,war_length/2);
- glScalef(war_width/25,war_hieght,war_length/25);
- glTranslatef(-0.5,0,-0.5);
- cube(0.545, 0.271, 0.075);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-war_width/2,war_hieght/2,war_length/13);
- glScalef(0.3,2.5,0.3);
- glTranslatef(-0.5,0,-0.5);
- cube(0.439, 0.502, 0.565);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-war_width/2,war_hieght/2,-war_length/13);
- glScalef(0.3,2.5,0.3);
- glTranslatef(-0.5,0,-0.5);
- cube(0.439, 0.502, 0.565);
- glPopMatrix();
- glPopMatrix();
- }
- void door()
- {
- float d_height = 15;
- float d_length = 8;
- float d_width = 0.8;
- glPushMatrix();
- glTranslatef(-30+d_width/2+0.5,0,-25);
- glPushMatrix();
- glRotatef(d_spin,0,1,0);
- glPushMatrix();
- glScalef(d_width,d_height,d_length);
- glTranslatef(-0.5,0,0);
- cube(0.737, 0.561, 0.561);
- glPopMatrix();
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-d_width/2,0,0);
- glScalef(d_width,d_height,d_length);
- glTranslatef(-0.5,0,0);
- cube(1, 1, 1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,0,d_length);
- glScalef(d_width+0.1,d_height,d_length/20);
- glTranslatef(-0.5,0,0);
- cube(0.824, 0.706, 0.549);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,0,-0.3);
- glScalef(d_width,d_height,d_length/20);
- glTranslatef(-0.5,0,0);
- cube(0.824, 0.706, 0.549);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,15,-0.4);
- glScalef(d_width,d_height/35,d_length+1);
- glTranslatef(-0.5,0,0);
- cube(0.824, 0.706, 0.549);
- glPopMatrix();
- glPopMatrix();
- }
- void clock()
- {
- float c_length = 1;
- float c_width = 7;
- float c_height = 7;
- glPushMatrix();
- glTranslatef(0,20,-30+c_length/2);
- glPushMatrix();
- glScalef(c_width*1.5,c_height,c_length);
- glTranslatef(-0.5,0,-0.5);
- cube(1.000, 0.855, 0.725);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,c_height/2,c_length/2);
- glRotatef(c_spin1,0,0,1);
- glScalef(c_width/2-0.2,0.3,c_length/4);
- glTranslatef(0,-0.5,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,c_height/2,c_length/2);
- glRotatef(c_spin2,0,0,1);
- glScalef(c_width/3,0.3,c_length/4);
- glTranslatef(0,-0.5,-0.5);
- cube(1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,c_height-1.5,c_length/2);
- glScalef(0.4,0.9,c_length/4);
- glTranslatef(-0.5,0,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(c_width/2+1,c_height/2,c_length/2);
- glScalef(0.9,0.4,c_length/4);
- glTranslatef(-0.5,0,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-c_width/2-1,c_height/2,c_length/2);
- glScalef(0.9,0.4,c_length/4);
- glTranslatef(-0.5,0,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,-c_height/2+4,c_length/2);
- glScalef(0.4,0.9,c_length/4);
- glTranslatef(-0.5,0,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPopMatrix();
- }
- void grid()
- {
- float grid_length = 60;
- float grid_width = 0.06;
- float floor_width = 24;
- for (int i=-floor_width; i<=floor_width; i+=8)
- {
- glPushMatrix();
- glTranslatef(i,0,0);
- glScalef(grid_width,grid_width,grid_length);
- glTranslatef(-0.5,0,-0.5);
- cube(0,0,0);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,0,i);
- glScalef(grid_length,grid_width,grid_width);
- glTranslatef(-0.5,0,-0.5);
- cube(0,0,0);
- glPopMatrix();
- }
- }
- void sphere()
- {
- GLfloat m_amb[] = {1,1,0,1};
- GLfloat m_diff[] = {1,1,0,1};
- GLfloat m_spec[] = {1,1,1,1};
- GLfloat m_sh[] = {30};
- GLfloat m_em[] = {1,1,1,1};
- glMaterialfv(GL_FRONT, GL_AMBIENT, m_amb);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, m_diff);
- glMaterialfv(GL_FRONT, GL_SPECULAR, m_spec);
- glMaterialfv(GL_FRONT, GL_SHININESS, m_sh);
- glPushMatrix();
- glTranslatef(27,15,-23);
- glPushMatrix();
- glTranslatef(0,5,0);
- glutSolidSphere( 3, 30.0, 30.0);
- glPopMatrix();
- glPushMatrix();
- glScalef(0.5,2,0.5);
- glTranslatef(-0.5,0,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(0,0,0);
- glScalef(4,0.5,4);
- glTranslatef(-0.5,0,-0.5);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- glPopMatrix();
- }
- static void key(unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 27 :
- case 'q':
- exit(0);
- break;
- case 't':
- t=1-t;
- break;
- case 'y':
- t1=1-t1;
- break;
- case 'u':
- t2=1-t2;
- break;
- case ',':
- rot+=2;
- break;
- case '.':
- rot-=2;
- break;
- case 'a':
- eyeX--;
- lookX--;
- break;
- case 'd':
- eyeX++;
- lookX++;
- break;
- case 'w':
- eyeY--;
- lookY--;
- break;
- case 's':
- eyeY++;
- lookY++;
- break;
- case '+':
- eyeZ--;
- lookZ--;
- break;
- case '-':
- eyeZ++;
- lookZ++;
- break;
- case 'c':
- flagClock=true;
- break;
- case 'x':
- flagRot=true;
- break;
- case 'z':
- flagRot=false;
- flagClock=false;
- break;
- case 'k':
- if (flagDoor==true)
- {
- d_spin++;
- flagDoor = true;
- if(d_spin>90)
- flagDoor=false;
- }
- break;
- case 'l':
- if (flagDoor==false)
- {
- d_spin--;
- flagDoor = false;
- if(d_spin<0)
- flagDoor=true;
- }
- }
- glutPostRedisplay();
- }
- static void idle(void)
- {
- if (flagRot == true)
- {
- f_spin = f_spin + 0.1;
- if(f_spin > 360)
- f_spin = 0;
- }
- if (flagClock == true)
- {
- c_spin1 = c_spin1 - 0.05;
- if(c_spin1 < 0)
- c_spin1 = 360;
- }
- if (flagClock == true)
- {
- c_spin2 = c_spin2 - 0.0008;
- if(c_spin2 < 0)
- c_spin2 = 360;
- }
- glutPostRedisplay();
- }
- static void resize(int width, int height)
- {
- glViewport(width/2-height*rat/2,0,height*rat,height);
- }
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-3, 3, -3, 3, 3.0, 100.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(eyeX,eyeY,eyeZ, lookX,lookY,lookZ, 0,1,0);
- glRotatef(rot, 0,1,0);
- axes();
- walll();
- desk();
- sphere();
- chair_table();
- fan();
- door();
- wardrobe();
- clock();
- grid();
- light();
- tube1();
- light1();
- tube2();
- light2();
- spot_light();
- glutSwapBuffers();
- }
- int main(int argc, char *argv[])
- {
- glutInit(&argc, argv);
- glutInitWindowSize(width,height);
- glutInitWindowPosition(10,10);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("GLUT Shapes");
- glutDisplayFunc(display);
- glutKeyboardFunc(key);
- glutIdleFunc(idle);
- glutReshapeFunc(resize);
- glEnable(GL_DEPTH_TEST);
- glShadeModel( GL_SMOOTH );
- glEnable(GL_NORMALIZE);
- glEnable(GL_BLEND);
- glEnable(GL_LIGHTING);
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement