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;
- double Txval=0,Tyval=0,Tzval=0;
- double windowHeight=500, windowWidth=500;
- GLfloat alpha = 0.0, theta = 0.0, axis_x=0.0, axis_y=0.0 , f_spin=0.0;
- GLboolean bRotate = false, uRotate = false;
- bool flagRot = 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 quadIndices[6][4] =
- {
- {3, 1, 5, 7},
- {2, 0, 4, 6},
- {2, 0, 1, 3},
- {6, 4, 5, 7},
- {2, 3, 7, 6},
- {0, 1, 5, 4}
- };
- void cube(float cr = 0.5, float cg = 0.5, float cb = 0.5)
- {
- glBegin(GL_QUADS);
- for(GLint i = 0; i<6; i++)
- {
- glColor3f(cr,cg,cb);
- //cr+=0.6;
- //cg+=0.4;
- //cb+=0.2;
- for(GLint j=0; j<4; j++)
- {
- glVertex3fv(&v_cube[quadIndices[i][j]][0]);
- }
- }
- glEnd();
- }
- 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 wall()
- {
- float length = 45;
- float width = 1;
- //floor
- glPushMatrix();
- glScalef(length,width,length);
- glTranslatef(-0.5,-1,-0.5);
- cube(0.9,0.9,0.9);
- glPopMatrix();
- //left
- glPushMatrix();
- glTranslatef(length/2,-width,0);
- glScalef(width,length,length);
- glTranslatef(0,0,-0.5);
- cube(03,0.7,0.7);
- glPopMatrix();
- //right
- glPushMatrix();
- glTranslatef(-length/2-1,-width,0);
- glScalef(width,length,length);
- glTranslatef(0,0,-0.5);
- cube(03,0.7,0.7);
- glPopMatrix();
- //front
- glPushMatrix();
- glTranslatef(0,-width,length/2);
- glScalef(length,length,width);
- glTranslatef(-0.5,0,0);
- cube(1,1,0.8);
- glPopMatrix();
- //black board
- glPushMatrix();
- glTranslatef(0,length/3,length/2-1);
- glScalef(length/2,length/3,width);
- glTranslatef(-0.5,0,0);
- cube(0.1,0.1,0.1);
- glPopMatrix();
- //top
- glPushMatrix();
- glTranslatef(0,length,0);
- glScalef(length,width,length);
- glTranslatef(-0.5,-1,-0.5);
- cube(1,1,1);
- glPopMatrix();
- }
- void fan()
- {
- float height = 43;
- float m_width = 4;
- float m_height = 2;
- float angle = 0;
- float s_width = 2.0;
- float s_height = 20.0;
- glPushMatrix();
- glTranslatef(0,0,10);
- for(int i=0; i<=360 ; i=i+10)
- {
- glPushMatrix();
- glTranslatef(0,height,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.863, 0.078, 0.235);
- 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.000, 0.749, 1.000);
- 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.000, 0.749, 1.000);
- glPopMatrix();
- glPopMatrix();
- glPopMatrix();
- }
- void chair()
- {
- float height=5;
- float width=6;
- float length=3.5;
- float base_height=0.5;
- 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));
- 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));
- 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/2,-length-(length/4-leg_width/4));
- glScalef(width/1.5,leg_height/4,leg_width/2);
- glTranslatef(-0.5,1.5,-0.5);
- cube(1,1,0);
- glPopMatrix();
- glPopMatrix();
- }
- void chair_table()
- {
- float length = 12;
- float chair_length = 3.5;
- float chair_width = 6;
- float width = 19;
- for (float i=-17 ; i<length; i= i+ 2*chair_length)
- {
- for (float j =-19 ; j<width; j= j+ 2*chair_width)
- {
- if(i==11 && j==-19)
- {
- }
- else
- {
- glPushMatrix();
- glTranslatef(j,0,i);
- chair();
- glPopMatrix();
- }
- }
- }
- }
- void wardrobe()
- {
- glPushMatrix();
- glTranslatef(-18,0,16);
- glScalef(8,18,12);
- glTranslatef(-0.5,0,-0.5);
- cube(0.824, 0.412, 0.118);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-14,0,10);
- glScalef(0.3,18,0.5);
- glTranslatef(-0.5,0,-0.5);
- cube(0.545, 0.271, 0.075);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-14,0,22);
- glScalef(0.3,18,0.5);
- glTranslatef(-0.5,0,-0.5);
- cube(0.545, 0.271, 0.075);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-14,0,16);
- glScalef(0.3,18,0.5);
- glTranslatef(-0.5,0,-0.5);
- cube(0.545, 0.271, 0.075);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-22,0,10);
- glScalef(0.5,18,0.3);
- glTranslatef(-0.5,0,-0.5);
- cube(0.545, 0.271, 0.075);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-14,0,15);
- glScalef(0.3,3,0.3);
- glTranslatef(-0.5,2.5,-0.5);
- cube(0.439, 0.502, 0.565);
- glPopMatrix();
- glPushMatrix();
- glTranslatef(-14,0,17);
- glScalef(0.3,3,0.3);
- glTranslatef(-0.5,2.5,-0.5);
- cube(0.439, 0.502, 0.565);
- glPopMatrix();
- }
- void grid()
- {
- }
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- glFrustum(-5,5,-5,5, 4, 70);
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- gluLookAt(10,10,-28, 1,5,1, 0,1,0);
- glViewport(0, 0, windowHeight, windowWidth);
- glRotatef(theta,axis_x,axis_y,0);
- //axes();
- wall();
- wardrobe();
- chair_table();
- fan();
- glFlush();
- glutSwapBuffers();
- }
- static void key(unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 27 :
- case 'q':
- exit(0);
- break;
- case ',':
- theta++;
- axis_y=1;
- axis_x=0;
- break;
- case '.':
- theta--;
- axis_y=1;
- axis_x=0;
- break;
- case 'n':
- theta++;
- axis_x=1;
- axis_y=0;
- break;
- case 'm':
- theta--;
- axis_x=1;
- axis_y=0;
- case 'z':
- flagRot=true;
- break;
- case 'x':
- flagRot=false;
- break;
- }
- glutPostRedisplay();
- }
- static void idle(void)
- {
- if (flagRot == true)
- {
- f_spin = f_spin + 0.1;
- if(f_spin > 360)
- f_spin = 0;
- }
- glutPostRedisplay();
- }
- int main(int argc, char**argv)
- {
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowPosition(200,200);
- glutInitWindowSize(500,500);
- glutCreateWindow("Rectangle");
- glShadeModel(GL_SMOOTH);
- glEnable(GL_DEPTH_TEST);
- glutDisplayFunc(display);
- glutKeyboardFunc(key);
- glutIdleFunc(idle);
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement