#include
#include
#include
#include
GLfloat angle =0.0;
GLfloat theta =0.0,vp=30.0;
GLfloat v[4][4],u[4][4];
typedef int edge[2];
typedef int face[4];
typedef GLfloat point3[3];
int myWin,w,h;
void myinit(void){
//int i,j;
glEnable(GL_DEPTH_TEST);
glClearColor(0.6,0.6,0.6,1.0);
}
point3 vertices[8]={
{-1.0,-1.0,-1.0},
{-1.0,-1.0,1.0},
{-1.0,1.0,-1.0},
{-1.0,1.0,1.0},
{1.0,-1.0,-1.0},
{1.0,-1.0,1.0},
{1.0,1.0,-1.0},
{1.0,1.0,1.0}
};
point3 nomals[6]={
{-1.0, 0.0,0.0},
{0.0, 0.0, 1.0},
{0.0, 1.0, 0.0},
{0.0, 0.0, -1.0},
{ 0.0, -1.0,0.0},
{1.0, 0.0, 0.0}
};
edge edges[24]={
{0,1},{1,3},{3,2},{2,0},
{0,4},{1,5},{3,7},{2,6},
{4,5},{5,7},{7,6},{6,4},
{1,0},{3,1},{2,3},{0,2},
{4,0},{5,1},{7,3},{6,2},
{5,4},{7,5},{6,7},{4,6}
};
face cubev[6]={
{0,1,2,3}, {5,9,18,13},
{14,6,10,19}, {7,11,16,15},
{4,8,17,12}, {22,21,20,23}
};
void cube(void){
int face,edge;
glBegin(GL_QUADS);
for (face=0;face<6;face++)
{glNormal3fv(nomals[face]);
for (edge=0;edge<4;edge++)
glVertex3fv(vertices[edges[cubev[face][edge]][0]]);}
glEnd();
}
void setColor(float t) {
float r,g,b;
r=t*0.01;
g=1-0.001*t*t;
b=1-r;
glColor3f(r,g,b);
}
void display(void){
#define SCALE 10,0
int i,j;GLfloat *p;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0,0,(GLsizei)w/2,(GLsizei)h);
printf("\n the matrixis:\t");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glGetFloatv(GL_PROJECTION_MATRIX,u);
gluPerspective(60.0,((float)w/2)/(float)h,1.0,300.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glGetFloatv(GL_MODELVIEW_MATRIX,v);
gluLookAt(vp,vp/2.,vp/4.,0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
glPushMatrix();
glRotatef(angle,0., 0., 1.0);
glScalef(5.0,5.0,5.0);
p=&v;
for(i=0;i<16;i++)printf("\t %f",*p++);printf("\t End ofthe matrixis!\n");
setColor(angle);
cube();
glPopMatrix();
glutSwapBuffers();
}
void reshape(int width ,int high){
w=width;h=high;
glutPostRedisplay();
}
void iterationStep(void){
if (angle>100)angle=0.0;
angle+=0.1;
}
void animate(void){
iterationStep();
glutPostRedisplay();
}
int main(int argc,char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB| GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(50,50);
myWin= glutCreateWindow("Temperature in bar");
myinit();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(animate);
glutMainLoop();
}
阅读(385) | 评论(0) | 转发(0) |