VC将灰度图转化为三维图.docx_第1页
VC将灰度图转化为三维图.docx_第2页
VC将灰度图转化为三维图.docx_第3页
VC将灰度图转化为三维图.docx_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

将灰度图的X、Y坐标作为三维图的X、Y坐标,将灰度图中各点灰度值作为Z坐标代码:/* L6.c OpenGL Framework using GLUT 3.7 Rob Fletcher 2001 Draw a quad and apply various transformations.*/#include #include /* For exit prototype */#include /* Header File For The GLUT Library */* ASCII code for the escape key. */#define ESCAPE 27GLint window; /* The number of our GLUT window */GLint Xsize=400;GLint Ysize=400;GLfloat xs=1.0,ys=1.0,zs=1.0; /* scale */* Simple window transformation routine */GLvoid Transform(GLfloat Width, GLfloat Height) glViewport(0, 0, Width, Height); /* Set the viewport */ glMatrixMode(GL_PROJECTION); /* Select the projection matrix */ glLoadIdentity();/* Reset The Projection Matrix */ gluPerspective(45.0,Width/Height,0.1,100.0); /* Calculate The Aspect Ratio Of The Window */ glMatrixMode(GL_MODELVIEW); /* Switch back to the modelview matrix */* A general OpenGL initialization function. Sets all of the initial parameters. */GLvoid InitGL(GLfloat Width, GLfloat Height) glClearColor(0.0, 0.0, 0.0, 0.0);/* This Will Clear The Background Color To Black */ glShadeModel(GL_SMOOTH); Transform( Width, Height ); /* Perform the transformation */* The function called when our window is resized */GLvoid ReSizeGLScene(GLint Width, GLint Height) if (Height=0) Height=1; /* Sanity checks */ if (Width=0) Width=1; Transform( Width, Height ); /* Perform the transformation */* The main drawing function In here we put all the OpenGL and calls to routines which manipulate the OpenGL state and environment. This is the function which will be called when a redisplay is requested.*/GLvoid DrawGLScene() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);/* Clear The Screen And The Depth Buffer */ glPushMatrix(); glLoadIdentity(); glTranslatef(0.0,0.0,-6.0); glScalef(xs,ys,zs); glBegin(GL_QUADS); glColor3f(1.0,1.0,0.0); glVertex3f( 1.0, 1.0, 1.0); glColor3f(1.0,0.0,0.0); glVertex3f(-1.0, 1.0, 1.0); glColor3f(1.0,1.0,0.0); glVertex3f(-1.0,-1.0, 1.0); glColor3f(1.0,0.0,0.0); glVertex3f( 1.0,-1.0, 1.0); glEnd(); glPopMatrix(); glFlush(); /* The function called whenever a normal key is pressed. */void NormalKey(GLubyte key, GLint x, GLint y) switch ( key ) case ESCAPE : printf(escape pressed. exit.n);glutDestroyWindow(window);/* Kill our window */exit(0); /* Very dirty exit */ break;/* Do we need this? */ case x: /* Scale x up */ xs += 0.2; glutPostRedisplay(); break; case X: xs -= 0.2; /* Scale x down */ glutPostRedisplay(); break; case y: /* Scale y up */ ys += 0.2; glutPostRedisplay(); break; case Y: ys -= 0.2; /* Scale y down */ glutPostRedisplay(); break; case z: /* Scale z up */ zs += 0.2; glutPostRedisplay(); break; case Z: zs -= 0.2; /* Scale z down */ glutPostRedisplay(); break; default:break; /* Main */int main(int argc, char *argv) /* Initialisation and window creation */ glutInit(&argc, argv); /* Initialize GLUT state. */ glutInitDisplayMode(GLUT_RGBA | /* RGB and Alpha */ GLUT_SINGLE| /* Single buffer */ GLUT_DEPTH); /* Z buffer (depth) */ glutInitWindowSize(Xsize,Ysize); /* set initial window size. */ glutInitWindowPosition(0,0); /* upper left corner of the screen. */ window = glutCreateWindow(L6); /* Open a window with a title. */ InitGL(Xsize,Ysize); /* Initialize our window. */* Now register the various callback functions */ glutDisplayFunc(DrawGLScene); /* Function to do all our OpenGL drawing. */ glutReshapeFunc(ReSizeGLScene); gl

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论