|
|
- #include <gl/glaux.h>
- #include <gl/glut.h>
- #include <math.h>
- #include "qgl.h"
- #define D_PI 3.141592653
- #pragma comment(lib, "opengl32.lib")
- #pragma comment(lib, "GLu32.lib")
- #pragma comment(lib, "GLaux.lib")
- AUX_RGBImageRec *Water_img;
- int rx=0,ry=0,rz=0;
- struct cvPoint
- {
- float x,y,z; //点的坐标
- };
- //矢量相乘C=A*B (方向符合右手定则)
- void vect_mult(struct cvPoint *A, struct cvPoint *B, struct cvPoint *C)
- {
- C->x=A->y * B->z -A ->z * B->y;
- C->y=A->z * B->x -A ->x * B->z;
- C->z=A->x * B->y -A ->y * B->x;
- }
- double t=0.0;//相位
- double sf(double x,double y)
- {
- return cos(sqrt(x*x+y*y)+t);
- }
- float ver[21][21][3];
- GLvoid initVer()
- {
- int i,j;
- float dx=D_PI*8/20.0,dy=D_PI*8/20.0;
- for(i=0;i<=20;i++)
- for(j=0;j<=20;j++)
- {
- ver[j][0]=i*dx-D_PI*4;
- ver[j][1]=j*dy-D_PI*4;
- ver[j][2]=(float)sf(ver[j][0],ver[j][1]);
- }
- }
- int HUD_VidInit(void)
- {
- QGL_Init();
- Water_img = auxDIBImageLoadA( "esf/water.bmp" );
- // 创建线性滤波纹理[]
- qglBindTexture(GL_TEXTURE_2D, 9000);
- qglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- qglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- qglTexImage2D(GL_TEXTURE_2D, 0, 3, Water_img->sizeX, Water_img->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, Water_img->data);
- free( Water_img );
- return gExportfuncs.HUD_VidInit();
- }
- void HUD_DrawNormalTriangles(void)
- {
- qglDisable( GL_CULL_FACE );// 禁止剔除表面
- qglEnable(GL_TEXTURE_2D);
- qglRotatef(float(rx),1.0,0.0,0.0);
- qglRotatef(float(ry),0.0,1.0,0.0);
- qglRotatef(float(rz),0.0,0.0,1.0);
- qglBindTexture(GL_TEXTURE_2D, 9000);
- initVer();//重新赋值[]
- cvPoint pa,pb,pc;
- qglPushMatrix();
- qglScalef(100.0,100.0,100.0);
- qglTranslatef(-D_PI/2,-D_PI/2,30.0f);
- qglRotatef(0,1,0,0);
- qglRotatef(0,0,0,1);
- for(int i=0;i<20;i++)
- for(int j=0;j<20;j++)
- {
- //第一条对角线
- pa.x=ver[i+1][j+1][0]-ver[j][0];
- pa.y=ver[i+1][j+1][1]-ver[j][1];
- pa.z=ver[i+1][j+1][2]-ver[j][2];
- //第二条对角线
- pb.x=ver[j+1][0]-ver[i+1][j][0];
- pb.y=ver[j+1][1]-ver[i+1][j][1];
- pb.z=ver[j+1][2]-ver[i+1][j][2];
- vect_mult(&pa,&pb,&pc);//计算法向,注意顺序[]
- qglNormal3f(pc.x,pc.y,pc.z);
- qglBegin(GL_QUADS);
- qglTexCoord2f(0.05*i,0.05*j);
- qglVertex3f(ver[j][0],ver[j][1],ver[j][2]);
- qglTexCoord2f(0.05*(i+1),0.05*j);
- qglVertex3f(ver[i+1][j][0],ver[i+1][j][1],ver[i+1][j][2]);
- qglTexCoord2f(0.05*(i+1),0.05*(j+1));
- qglVertex3f(ver[i+1][j+1][0],ver[i+1][j+1][1],ver[i+1][j+1][2]);
- qglTexCoord2f(0.05*i,0.05*(j+1));
- qglVertex3f(ver[j+1][0],ver[j+1][1],ver[j+1][2]);
- qglEnd();
- }
- qglPopMatrix();
- t+=0.01;//改变相位
- qglDisable(GL_TEXTURE_2D);
- return gExportfuncs.HUD_DrawNormalTriangles();
- }
复制代码 |
|