Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10641
  • 博文数量: 8
  • 博客积分: 335
  • 博客等级: 一等列兵
  • 技术积分: 90
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-26 20:11
文章分类

全部博文(8)

文章存档

2008年(8)

我的朋友
最近访客

分类: C/C++

2008-10-25 20:21:28

#include
#include
#include
#include

GLfloat angle =0.0;
GLfloat theta =0.0,vp=30.0;
GLfloat v[4][4],u[4][4];
#define Xsize 80
#define Ysize 80
int Vertices[Xsize][Ysize];

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);
    
   
}
void setColor(float t) {
    float r,g,b;
    r=0.110;
    g=0.5;
      
    b=1-t*0.008;
    glColor3f(r,g,b);
}

void wsurface(){
    int i,j;
    for (i=0;i        for(j=0;j        Vertices[i][j]=1.85*(cos(i*i+j*j+angle)+sin(i*i-j*j+0.5*angle));
    }


}
 
void drawing(){
   
    int i,j;
    wsurface();
        glEnable(GL_POLYGON_SMOOTH);
    glBegin(GL_TRIANGLE_STRIP);
    for (i=0;i       
        for(j=0;j        setColor(angle+i-j);
        glVertex3f(3*i,3*j,Vertices[i][j]);
        glVertex3f(3*(i+1),3*j,Vertices[i+1][j]);
        glVertex3f(3*i,3*(j+1),Vertices[i][j+1]);
        glVertex3f(3*(i+1),3*(j+1),Vertices[i+1][j+1]);
        }
    }
    glEnd();

}





void display(void){
    #define SCALE 10,0
    int i,j;
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glViewport(0,0,(GLsizei)w,(GLsizei)h);   
   
        glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    //glOrtho(-100.,200.,-100.,200.,10.0,400.0);
    gluPerspective(75.0,((float)w)/(float)h,10.0,450.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(-210.,35.,150.0,0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
    //gluLookAt(vp*4,vp*4,vp,0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
    glPushMatrix();
         glTranslatef(-150.,-150.,0.0);
    //glRotatef(angle, 1.0,  0.0, 0.0);
    //glScalef(1.0,1.0,1.0);
   
    //setColor(angle);
    glPushMatrix();
    drawing();
   
    glPopMatrix();
    glPopMatrix();
   
   
   
    glutSwapBuffers();


   
}


void reshape(int width ,int high){
   
         w=width;h=high;
    glutPostRedisplay();
}




void iterationStep(void){
    if (angle>500) 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(10,10);
    myWin= glutCreateWindow("Waterwave");
    myinit();
       


    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutIdleFunc(animate);
    glutMainLoop();
}
 
阅读(348) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~