KTĐH Chính
KTĐH Chính
h>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include<math.h>
namespace vd10 {
GLfloat alpha = 0.0, theta = 0.0, axis_x = 0.0, axis_y = 0.0, Calpha = 360.0, C_hr_alpha = 360.0;
GLboolean bRotate = false, fRotate = true, cRotate = true, xz_rotate = false, l_on = true;
GLfloat eyeX = 5;
GLfloat lookX = 0;
GLfloat lookY = 0;
GLfloat lookZ = 0;
{
{0.0, 0.0, 0.0},
};
{1, 4, 7, 6},
{7, 4, 2, 5},
{3, 5, 2, 0},
{3, 6, 7, 5},
{0, 2, 4, 1},
{1, 6, 3, 0}
};
(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;
GLfloat cube_sh[] = { 10 };
glBegin(GL_QUADS);
glVertex3fv(&v_Cube[quadIndices[i][j]][0]);
glEnd();
void flooor()
{
glPushMatrix();
glScalef(50, 1, 50);
glPopMatrix();
void table()
GLfloat table_width = 5;
glPushMatrix();
glPopMatrix();
glPushMatrix();
glPopMatrix();
glPushMatrix();
glPopMatrix();
glPushMatrix();
glPopMatrix();
glPushMatrix();
glPopMatrix();
}
void chair()
glPushMatrix();
GLfloat chair_width = 3;
glPushMatrix(); //upper_base
glPopMatrix();
glPushMatrix();
glScalef(chair_width, chair_length, chair_height); //base
glPopMatrix();
glPushMatrix();
glPopMatrix();
glPushMatrix();
glPopMatrix();
glPushMatrix();
glPopMatrix();
glPushMatrix();
glPopMatrix();
glPopMatrix();
void full_set()
glPushMatrix();
table();
glPopMatrix();
glPushMatrix();
chair();
glPopMatrix();
}
void nine_full_set_chair_table()
glPushMatrix();
full_set();
glPopMatrix();
glPushMatrix();
glTranslatef(15, 0, 0);
full_set();
glPopMatrix();
glPushMatrix();
glTranslatef(0, 0, 20);
full_set();
glPopMatrix();
glPushMatrix();
glTranslatef(0, 0, -20);
full_set();
glPopMatrix();
glPushMatrix();
glTranslatef(-15, 0, 20);
full_set();
glPopMatrix();
glPushMatrix();
glTranslatef(15, 0, -20);
full_set();
glPopMatrix();
glPushMatrix();
glTranslatef(15, 0, 20);
full_set();
glPopMatrix();
glPushMatrix();
glTranslatef(-15, 0, -20);
full_set();
glPopMatrix();
glPushMatrix();
glTranslatef(-15, 0, 0);
full_set();
glPopMatrix();
}
void wall(GLfloat col1, GLfloat col2, GLfloat col3)
glPushMatrix();
glScalef(50, 1, 50);
glPopMatrix();
void fan_leg()
glPushMatrix();
glPopMatrix();
void fan_face()
glPushMatrix();
glPopMatrix();
void fan_stand()
glPushMatrix();
glScalef(0.3, 6, 0.3);
glPopMatrix();
void fan_set()
glPushMatrix();
glPushMatrix();
fan_face();
glPopMatrix();
glPushMatrix();
fan_leg();
glPopMatrix();
glPushMatrix();
glPopMatrix();
glPushMatrix();
glRotatef(90, 0, 1, 0);
fan_leg();
glPopMatrix();
glPushMatrix();
glRotatef(90, 0, 1, 0);
fan_leg();
glPopMatrix();
void fan()
glPushMatrix();
glRotatef(0, 0, 1, 0);
fan_set();
glPopMatrix();
glPushMatrix();
fan_stand();
glPopMatrix();
void door()
glPushMatrix(); // door_lock
glTranslatef(44, 2, 13);
glRotatef(90, 0, 1, 0);
glTranslatef(-0.6, 5, 4.5);
cube(0, 0, 0);
glPopMatrix();
glPushMatrix(); //door
glTranslatef(49, 6, 20);
glRotatef(90, 0, 1, 0);
void room()
glPushMatrix();//front wall
glTranslatef(0, 0, 45);
glRotatef(270, 1, 0, 0);
glTranslatef(3, 2, 36);
glRotatef(90, 1, 0, 0);
glPopMatrix();
glPushMatrix(); //blackboard
glTranslatef(0, 1, 18);
glPopMatrix();
glPushMatrix();//clock
glPushMatrix();
glTranslatef(3, 1, 31);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(0.0, 0, -50);
glRotatef(90, 1, 0, 0);
glPopMatrix();
glRotatef(90, 0, 1, 0);
glScalef(12, 1, 0.8);
glPopMatrix();
glPushMatrix();
door();
glPopMatrix();
glTranslatef(50.0, 0, -1);
glRotatef(90, 0, 0, 1);
wall(1.000, 0.894, 0.882);
glRotatef(90, 0, 1, 0);
glScalef(12, 1, 0.8);
glPopMatrix();
glTranslatef(-50.0, 0, -1);
glRotatef(90, 0, 0, 1);
glPushMatrix();
glScalef(0.8, 1, 1);
fan();
glPopMatrix();
glTranslatef(0, 40, -5);
glRotatef(90, 0, 1, 0);
glPopMatrix();
glPushMatrix();//floor
glTranslatef(-40, 2, 25);
glScaled(40, 1, 10);
glPopMatrix();
flooor();
glPopMatrix();
void classRoom()
glPushMatrix();
room();
glPopMatrix();
glScalef(1.5, 1, 1);
glRotatef(180, 0, 1, 0);
glTranslatef(15, 4, -30);
full_set();
glPopMatrix();
glPushMatrix();
glTranslatef(5, 0, -5);
glScalef(1.2, 1, 1.2);
nine_full_set_chair_table();
glPopMatrix();
/*
glPushMatrix();
glPopMatrix();
*/
void light()
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
void display(void)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/*
*/
light();
classRoom();
glFlush();
glutSwapBuffers();
switch (key)
case 'R':
case 'r':
bRotate = !bRotate;
axis_x = 0.0;
axis_y = 1.0;
break;
case 'F':
fRotate = !fRotate;
axis_x = 0.0;
axis_y = 1.0;
break;
eyeZ++;
lookZ++;
break;
eyeZ--;
lookZ--;
break;
eyeY++;
lookY++;
break;
eyeY--;
lookY--;
break;
case 'x':
eyeX++;
lookX++;
break;
case 'z':
eyeX--;
lookX--;
break;
case 27: // Escape key
exit(1);
void animate()
if (bRotate == true)
theta += 0.1;
if (fRotate == true)
alpha += 0.8;
glutPostRedisplay();
}
glutInit(&argc, argv);
glutInitWindowPosition(0, 0);
glutInitWindowSize(vd10::height, vd10::width);
glutCreateWindow("ClassRoom");
glutReshapeFunc(vd10::resize);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
glutKeyboardFunc(vd10::myKeyboardFunc);
glutDisplayFunc(vd10::display);
glutIdleFunc(vd10::animate);
printf("Use 'a' to on/off the light ambient property for all lights.\n");
printf("Use 'd' to on/off the light diffuse property for all lights.\n");
printf("Use 's' to on/off the light Specular property for all lights.\n");
printf("Use 'r' to rotate the scene. \n");
printf("Use '*' to look up, '/' to look down, 'z' to look right, and 'x' to look left.\n");
glutMainLoop();
return 0;