07063257_GLView.cpp
资源名称:aa.rar [点击查看]
上传用户:kuqidezhu
上传日期:2022-07-18
资源大小:4151k
文件大小:23k
源码类别:
3D图形编程
开发平台:
Visual C++
- // 07063257_GLView.cpp : implementation of the CMy07063257_GLView class
- //
- #include "stdafx.h"
- #include "07063257_GL.h"
- #include "07063257_GLDoc.h"
- #include "07063257_GLView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMy07063257_GLView
- IMPLEMENT_DYNCREATE(CMy07063257_GLView, CView)
- BEGIN_MESSAGE_MAP(CMy07063257_GLView, CView)
- //{{AFX_MSG_MAP(CMy07063257_GLView)
- ON_COMMAND(ID_ADDDATA, OnAdddate)
- ON_COMMAND(ID_TieTu, OnTieTu)
- ON_WM_CREATE()
- ON_WM_DESTROY()
- ON_WM_PAINT()
- ON_WM_SIZE()
- ON_COMMAND(ID_LEFT, OnLeft)
- ON_COMMAND(ID_RIGHT, OnRight)
- ON_COMMAND(ID_UP, OnUp)
- ON_COMMAND(ID_DOWN, OnDown)
- ON_COMMAND(ID_LROTAEF, OnLrotaef)
- ON_COMMAND(ID_RROTATEF, OnRrotatef)
- ON_COMMAND(ID_ZOOMOUT, OnZoomout)
- ON_COMMAND(ID_ZOOMIN, OnZoomin)
- ON_COMMAND(ID_FRONT, OnFront)
- ON_COMMAND(ID_BACK, OnBack)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMy07063257_GLView construction/destruction
- CMy07063257_GLView::CMy07063257_GLView()
- {
- // TODO: add construction code here
- m_Rotateangle=0;
- MAX=624;
- IsOpen=0;
- n=0;
- }
- CMy07063257_GLView::~CMy07063257_GLView()
- {
- }
- BOOL CMy07063257_GLView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- cs.style |= (WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMy07063257_GLView drawing
- void CMy07063257_GLView::OnDraw(CDC* pDC)
- {
- CMy07063257_GLDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CClientDC dc(this);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMy07063257_GLView printing
- BOOL CMy07063257_GLView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMy07063257_GLView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMy07063257_GLView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMy07063257_GLView diagnostics
- #ifdef _DEBUG
- void CMy07063257_GLView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CMy07063257_GLView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CMy07063257_GLDoc* CMy07063257_GLView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy07063257_GLDoc)));
- return (CMy07063257_GLDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMy07063257_GLView message handlers
- void CMy07063257_GLView::OnAdddate()
- {
- twc=1;
- // TODO: Add your command handler code here
- Invalidate(true);
- CAddData d1;
- CChooseTexture d2;
- BeginWaitCursor();
- if (d1.DoModal()==1)
- {
- FILE *mm_vertexFile;
- CFileDialog location(true);
- location.DoModal();
- mm_vertexFile=fopen(location.GetPathName(),"r");
- MAXX=0.0;
- MINX=10.0;
- MAXY=0.0;
- MINY=10.0;
- for (int i=0;i<MAX;i++)
- {
- float a,b,c;
- a=b=c=0.0;
- m_vertex[i].x=0.0;
- fscanf(mm_vertexFile,"%f%f%f",&a ,&b,&c);
- (m_vertex[i].x)=(a-87500)*1.5;
- // (m_vertex[i].x)=(a-87500)*1.5 ;
- (m_vertex[i].y)=(b-12800)*1.5;
- // (m_vertex[i].y)=(b-12800);
- (m_vertex[i].z)=c*1.5;
- if (m_vertex[i].x>MAXX) {MAXX=m_vertex[i].x;}
- if (m_vertex[i].x<MINX) {MINX=m_vertex[i].x;}
- if (m_vertex[i].y<MINY) {MINY=m_vertex[i].y;}
- if (m_vertex[i].y>MAXY) {MAXY=m_vertex[i].y;}
- }
- fclose(mm_vertexFile);
- glClear(GL_COLOR_BUFFER_BIT);
- glClearColor(0.0,0.0,0.0,1.0);
- // glTranslatef(0,0,-2);
- glShadeModel(GL_SMOOTH );
- glTranslatef( 0, 0,-500);
- glPointSize(2);
- glColor4f(0,0.4,1,1);
- BuildTIN();
- }
- EndWaitCursor();
- }
- void CMy07063257_GLView::OnTieTu()
- {
- twc=2;
- // TODO: Add your command handler code here
- n=1;
- CChooseTexture d2;
- d2.DoModal();
- CFileDialog mOpen(true);
- if (mOpen.DoModal()==IDOK)
- {
- AUX_RGBImageRec *Image=auxDIBImageLoad(mOpen.GetPathName());
- glTexImage2D(GL_TEXTURE_2D, 0, 3, Image->sizeX,Image->sizeY,
- 0, GL_RGB, GL_UNSIGNED_BYTE,Image->data);
- }
- }
- void CMy07063257_GLView::BuildTIN()
- {
- if (MAX > 2)
- {
- for(int i=0;i<MAX-1;i++) //确定基线
- {
- // glBegin(GL_LINE_LOOP);
- // glVertex3f(m_vertex[i].x,m_vertex[i].y,m_vertex[i].z);
- // glEnd();
- for(int j=i+1;j<MAX;j++)
- {
- if(m_vertex[i].x>m_vertex[j].x)
- {
- Vertex temp;
- temp.x=m_vertex[i].x;
- temp.y=m_vertex[i].y;
- temp.z=m_vertex[i].z;
- m_vertex[i].x=m_vertex[j].x;
- m_vertex[i].y=m_vertex[j].y;
- m_vertex[i].z=m_vertex[j].z;
- m_vertex[j].x=temp.x;
- m_vertex[j].y=temp.y;
- m_vertex[j].z=temp.z;
- }
- }
- }
- if(m_vertex[0].y>m_vertex[1].y) //沿基线固定方向
- this->TriDelaunay(m_vertex[0],m_vertex[1]);//调用边扩展算法构网delaunay
- else
- this->TriDelaunay(m_vertex[1],m_vertex[0]);//调用边扩展算法构网delaunay
- }
- }
- //DEL void CMy07063257_GLView::CalculateNormal()
- //DEL {
- //DEL
- //DEL }
- BOOL CMy07063257_GLView::CreateViewGLContext(HDC hDC)
- {
- m_hGLContext = wglCreateContext(hDC);
- if (m_hGLContext == NULL)
- return FALSE;
- if (wglMakeCurrent(hDC, m_hGLContext)==FALSE) return FALSE;
- return TRUE;
- }
- Vertex CMy07063257_GLView::GetThirdPoint(Vertex p1, Vertex p2)
- {
- bool sign=true;
- Edge edge;
- edge.p1.x=p1.x;
- edge.p1.y=p1.y;
- edge.p1.z=p1.z;
- edge.p2.x=p2.x;
- edge.p2.y=p2.y;
- edge.p2.z=p2.z;
- for(int i=0;i<m_edges.size();i++)
- {
- if(edge.p1.x==m_edges[i].p1.x &&
- edge.p1.y==m_edges[i].p1.y&&
- edge.p1.z==m_edges[i].p1.z&&
- edge.p2.x==m_edges[i].p2.x&&
- edge.p2.y==m_edges[i].p2.y&&
- edge.p2.z==m_edges[i].p2.z)
- sign=false;
- }
- double temp=1; //采用最大张角,即最小余弦的判别准则
- int j=0;
- for( i=0;i<MAX;i++)
- {
- double equation;
- equation = ((p1.y - p2.y) * (m_vertex[i].x - p2.x))
- - ((m_vertex[i].y - p2.y) * (p1.x - p2.x));//确定基线的方向
- if(equation<=0) continue; //沿基线>0固定方向
- double a=sqrt(pow(p1.x-m_vertex[i].x,2)+pow(p1.y-m_vertex[i].y,2));
- double b=sqrt(pow(p2.x-m_vertex[i].x,2)+pow(p2.y-m_vertex[i].y,2));
- double c=sqrt(pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2));
- double d=(a*a+b*b-c*c)/(2*a*b);
- if(d<temp && equation>0 && sign)
- {
- temp=d;
- j=i;
- }
- }
- if(j!=0)
- return m_vertex[j];
- else
- {
- Vertex temp_vertex;
- temp_vertex.x=0;
- temp_vertex.y=0;
- temp_vertex.z=0;
- return temp_vertex;
- }
- }
- void CMy07063257_GLView::initial()
- {
- int i;
- for (i=0;i<m_edges.size();i++)
- {
- m_edges[i].no=i+1;
- m_edges[i].length=1.0;
- m_edges[i].usetimes=0;
- m_edges[i].p1.x=0;
- m_edges[i].p1.y=0;
- m_edges[i].p1.z=0;
- m_edges[i].p2.x=0;
- m_edges[i].p2.y=0;
- m_edges[i].p2.z=0;
- }
- /////////////////////////////////////////////////////////////
- for (i=0;i<m_triangles.size();i++)
- {
- m_triangles[i].no=i+1;
- m_triangles[i].edgeno[0]=-1;
- m_triangles[i].edgeno[1]=-1;
- m_triangles[i].edgeno[2]=-1;
- m_triangles[i].Normal[0]=-1;
- m_triangles[i].Normal[1]=-1;
- m_triangles[i].Normal[2]=-1;
- }
- }
- int CMy07063257_GLView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- // TODO: Add your specialized creation code here
- HWND hWnd = GetSafeHwnd();
- HDC hDC = ::GetDC(hWnd);
- if (SetWindowPixelFormat(hDC)==FALSE) return 0;
- if (CreateViewGLContext(hDC)==FALSE) return 0;
- return 0;
- }
- void CMy07063257_GLView::OnDestroy()
- {
- if(wglGetCurrentContext()!=NULL)
- wglMakeCurrent(NULL, NULL) ;
- if (m_hGLContext!=NULL)
- {
- wglDeleteContext(m_hGLContext);
- m_hGLContext = NULL;
- }
- CView::OnDestroy();
- }
- void CMy07063257_GLView::OnGetVertex()
- {
- IsOpen=1;
- // TODO: Add your command handler code here
- FILE *mm_vertexFile;
- CFileDialog location(true);
- location.DoModal();
- mm_vertexFile=fopen(location.GetPathName(),"r");
- for (int i=0;i<MAX;i++)
- {
- float a,b,c;
- a=b=c=0.0;
- m_vertex[i].x=0.0;
- fscanf(mm_vertexFile,"%f%f%f",&a ,&b,&c);
- (m_vertex[i].x)=(a-87500)*1.5;
- // (m_vertex[i].x)=(a-87500)*1.5 ;
- (m_vertex[i].y)=(b-12800)*1.5;
- // (m_vertex[i].y)=(b-12800);
- (m_vertex[i].z)=c*1.5;
- }
- fclose(mm_vertexFile);
- }
- void CMy07063257_GLView::OnOpenglLighting()
- {
- Invalidate(true);
- }
- void CMy07063257_GLView::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- glColor3f(0,0.4,0.3);
- glClear(GL_COLOR_BUFFER_BIT);
- switch(twc)
- {
- case 1:
- {
- GLfloat light_ambient0[]= { 1.0,1.0,1.0, 1.0 };
- GLfloat light_position0[]={500,-500,60,1.0f};
- GLfloat light_specular0[]={1,1,1,1};
- GLfloat light_diffuse0[]={1.0f,0.0f,1.0f,1.0f};
- GLfloat spot_direction0[]={ -1.0,1.0,0.0,1.0};
- glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient0);
- glLightfv(GL_LIGHT0,GL_POSITION,light_position0);
- glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular0);
- glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse0);
- glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION,spot_direction0);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_FALSE);
- this->OPenGL_Lighting();
- float dVector1[3],dVector2[3],norm[3];
- for (int i=0; i<m_triangles.size(); i++)
- {
- dVector1[0] = m_triangles[i].ptr[1].x - m_triangles[i].ptr[0].x;
- dVector1[1] = m_triangles[i].ptr[1].y - m_triangles[i].ptr[0].y;
- dVector1[2] = m_triangles[i].ptr[1].z - m_triangles[i].ptr[0].z;
- dVector2[0] = m_triangles[i].ptr[2].x - m_triangles[i].ptr[0].x;
- dVector2[1] = m_triangles[i].ptr[2].y - m_triangles[i].ptr[0].y;
- dVector2[2] = m_triangles[i].ptr[2].z - m_triangles[i].ptr[0].z;
- norm[0]=dVector1[1]*dVector2[2]-dVector1[2]*dVector2[1];
- norm[1]=dVector1[2]*dVector2[0]-dVector1[0]*dVector2[2];
- norm[2]=dVector1[0]*dVector2[1]-dVector1[1]*dVector2[0];
- float dNormalLength=sqrt(norm[0]*norm[0] + norm[1]*norm[1] + norm[2]*norm[2]);
- aa=norm[0]/dNormalLength;
- bb=norm[1]/dNormalLength;
- cc=norm[2]/dNormalLength;
- glNormal3f(aa,bb,cc); //三角面法向量
- }
- }
- case 2:
- GLfloat light_ambient0[]= { 1.0,1.0,1.0, 1.0 };
- GLfloat light_position0[]={500,-500,60,1.0f};
- GLfloat light_specular0[]={1,1,1,1};
- GLfloat light_diffuse0[]={1.0f,0.0f,1.0f,1.0f};
- GLfloat spot_direction0[]={ -1.0,1.0,0.0,1.0};
- glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient0);
- glLightfv(GL_LIGHT0,GL_POSITION,light_position0);
- glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular0);
- glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse0);
- glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION,spot_direction0);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_FALSE);
- this->OPenGL_Lighting();
- glPushMatrix();
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_DECAL); //在此处更改映射模式,选择GL_DECAL、GL_MODULATE、GL_BLEND分别察看演示效果
- glEnable(GL_TEXTURE_2D);
- glShadeModel(GL_SMOOTH); //更改GL_SMOOTH、GL_FLAT进行试验,察看效果
- /* 设置纹理坐标和物体几何坐标 */
- glRotatef(m_Rotateangle, 1, 1, 1);
- //纹理坐标的定义与演示效果,该图位于左下,纹理与图形表面吻合
- for (int i=0; i<m_triangles.size(); i++)
- {
- float dVector1[3],dVector2[3],norm[3];
- Vertex Point1,Point3,Point2;
- Point1.x=m_triangles[i].ptr[0].x;
- Point1.y=m_triangles[i].ptr[0].y;
- Point1.z=0.0;
- Point2.x=m_triangles[i].ptr[1].x;
- Point2.y=m_triangles[i].ptr[1].y;
- Point2.z=0.0;
- Point3.x=m_triangles[i].ptr[2].x;
- Point3.y=m_triangles[i].ptr[2].y;
- Point3.z=0.0;
- dVector1[0] = m_triangles[i].ptr[1].x - m_triangles[i].ptr[0].x;
- dVector1[1] = m_triangles[i].ptr[1].y - m_triangles[i].ptr[0].y;
- dVector1[2] = m_triangles[i].ptr[1].z - m_triangles[i].ptr[0].z;
- dVector2[0] = m_triangles[i].ptr[2].x - m_triangles[i].ptr[0].x;
- dVector2[1] = m_triangles[i].ptr[2].y - m_triangles[i].ptr[0].y;
- dVector2[2] = m_triangles[i].ptr[2].z - m_triangles[i].ptr[0].z;
- norm[0]=dVector1[1]*dVector2[2]-dVector1[2]*dVector2[1];
- norm[1]=dVector1[2]*dVector2[0]-dVector1[0]*dVector2[2];
- norm[2]=dVector1[0]*dVector2[1]-dVector1[1]*dVector2[0];
- float dNormalLength=sqrt(norm[0]*norm[0] + norm[1]*norm[1] + norm[2]*norm[2]);
- aa=norm[0]/dNormalLength;
- bb=norm[1]/dNormalLength;
- cc=norm[2]/dNormalLength;
- glBegin(GL_TRIANGLES);
- glTexCoord2f(CalTexture(Point1.x,Point1.y,Point1.z).x, CalTexture(Point1.x, Point1.y, Point1.z).y);
- glVertex3f(m_triangles[i].ptr[0].x, m_triangles[i].ptr[0].y, m_triangles[i].ptr[0].z);
- glTexCoord2f(CalTexture(Point2.x,Point2.y, Point2.z).x, CalTexture(Point2.x, Point2.y, Point2.z).y);
- glVertex3f(m_triangles[i].ptr[1].x, m_triangles[i].ptr[1].y, m_triangles[i].ptr[1].z);
- glTexCoord2f(CalTexture(Point3.x, Point3.y, Point3.z).x, CalTexture(Point3.x, Point3.y,Point3.z).y);
- glVertex3f(m_triangles[i].ptr[2].x, m_triangles[i].ptr[2].y, m_triangles[i].ptr[2].z);
- glNormal3f(aa,bb,cc);
- glEnd();
- }
- }
- glFlush();
- glDisable(GL_TEXTURE_2D);
- glPopMatrix();
- }
- void CMy07063257_GLView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- glViewport(0,0,cx,cy);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- if(cx<=cy)
- glOrtho(-500.0,500.0,-500.0*(GLfloat)cy/(GLfloat)cx,
- 500.0*(GLfloat)cy/(GLfloat)cx,-500.0,500.0);
- else
- glOrtho(-500.0*(GLfloat)cx/(GLfloat)cy,
- 500.0*(GLfloat)cx/(GLfloat)cy,-500.0,500.0,-500.0,500.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- // TODO: Add your message handler code here
- }
- void CMy07063257_GLView::OPenGL_Lighting()
- {
- glPushMatrix();
- GLfloat mat_diffuse[]={0.0f,1.0f,0.4f,1.0f};
- GLfloat mat_specular[]={0.0f,1.0f,0.4f,1.0f};
- GLfloat mat_shininess[]={80.0f};
- glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diffuse);
- glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
- glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
- glClearColor(0.0,0.0,0.0,0.0);
- glShadeModel(GL_SMOOTH);
- glPolygonMode(GL_FRONT,GL_FILL);
- glColor3f(0.0f,0.4f,1.0f);
- for(int i=0;i<m_triangles.size();i++)
- {
- double dNormal[3];
- dNormal[0] = m_triangles[i].Normal[0];
- dNormal[1] = m_triangles[i].Normal[1];
- dNormal[2] = m_triangles[i].Normal[2];
- glBegin(GL_POLYGON);
- glNormal3dv(dNormal);
- glVertex3f(m_triangles[i].ptr[0].x, m_triangles[i].ptr[0].y, m_triangles[i].ptr[0].z);
- glVertex3f(m_triangles[i].ptr[1].x, m_triangles[i].ptr[1].y, m_triangles[i].ptr[1].z);
- glVertex3f(m_triangles[i].ptr[2].x, m_triangles[i].ptr[2].y, m_triangles[i].ptr[2].z);
- glEnd();
- glFlush();
- }
- glPopMatrix();
- }
- BOOL CMy07063257_GLView::SetWindowPixelFormat(HDC hDC)
- {
- PIXELFORMATDESCRIPTOR pixelDesc;
- pixelDesc.nSize = sizeof(PIXELFORMATDESCRIPTOR); pixelDesc.nVersion = 1;
- pixelDesc.dwFlags = PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI | PFD_STEREO_DONTCARE; pixelDesc.iPixelType = PFD_TYPE_RGBA; pixelDesc.cColorBits = 32;
- pixelDesc.cRedBits = 8;
- pixelDesc.cRedShift = 16;
- pixelDesc.cGreenBits = 8;
- pixelDesc.cGreenShift = 8;
- pixelDesc.cBlueBits = 8;
- pixelDesc.cBlueShift = 0;
- pixelDesc.cAlphaBits = 0;
- pixelDesc.cAlphaShift = 0;
- pixelDesc.cAccumBits = 64;
- pixelDesc.cAccumRedBits = 16;
- pixelDesc.cAccumGreenBits = 16;
- pixelDesc.cAccumBlueBits = 16;
- pixelDesc.cAccumAlphaBits = 0;
- pixelDesc.cDepthBits = 32;
- pixelDesc.cStencilBits = 8;
- pixelDesc.cAuxBuffers = 0;
- pixelDesc.iLayerType = PFD_MAIN_PLANE;
- pixelDesc.bReserved = 0;
- pixelDesc.dwLayerMask = 0;
- pixelDesc.dwVisibleMask = 0;
- pixelDesc.dwDamageMask = 0;
- m_GLPixelIndex = ChoosePixelFormat( hDC, &pixelDesc);
- if (m_GLPixelIndex==0) // Let's choose a default index.
- { m_GLPixelIndex = 1;
- if (DescribePixelFormat(hDC, m_GLPixelIndex, sizeof(PIXELFORMATDESCRIPTOR),&pixelDesc)==0)
- return FALSE;
- }
- if (SetPixelFormat( hDC, m_GLPixelIndex,&pixelDesc)==FALSE) return FALSE;
- return TRUE;
- }
- void CMy07063257_GLView::TriDelaunay(Vertex p1, Vertex p2)
- {
- CClientDC dc(this);
- Vertex ThirdPoint;
- ThirdPoint.x=(GetThirdPoint(p1,p2)).x;
- ThirdPoint.y=(GetThirdPoint(p1,p2)).y;
- ThirdPoint.z=(GetThirdPoint(p1,p2)).z;
- if (ThirdPoint.x!=0 && ThirdPoint.y!=0)
- {
- glBegin(GL_LINE_LOOP);
- glVertex3f(p1.x,p1.y,p1.z);
- glVertex3f(p2.x,p2.y,p2.z);
- glVertex3f(ThirdPoint.x,ThirdPoint.y,ThirdPoint.z);
- glEnd();
- Edge l1;
- l1.p1.x=p1.x;
- l1.p1.y=p1.y;
- l1.p1.z=p1.z;
- l1.p2.x=p2.x;
- l1.p2.y=p2.y;
- l1.p2.z=p2.z;
- m_edges.push_back(l1);
- Triangle triangle;
- triangle.ptr[0].x=p1.x;
- triangle.ptr[0].y=p1.y;
- triangle.ptr[0].z=p1.z;
- triangle.ptr[1].x=p2.x;
- triangle.ptr[1].y=p2.y;
- triangle.ptr[1].z=p2.z;
- triangle.ptr[2].x=ThirdPoint.x;
- triangle.ptr[2].y=ThirdPoint.y;
- triangle.ptr[2].z=ThirdPoint.z;
- m_triangles.push_back(triangle);
- }
- else
- return;//储存已构成的直线
- TriDelaunay(p1,ThirdPoint) ;
- TriDelaunay(ThirdPoint,p2) ; //标记已构三角形的边,对尚未构三角形的边用算法进行递归调用
- }
- void CMy07063257_GLView::OnLeft()
- {
- IsOpen++;
- type=IsOpen%4;
- switch(type)
- {
- case 0:
- {
- glTranslatef (-50.0, 0.0, 0.0);
- OnPaint();
- break;
- }
- case 1:
- {
- glTranslatef (-50.0, 0.0, 0.0);
- OnPaint();
- break;
- }
- case 2:
- {
- glTranslatef (-50.0, 0.0, 0.0);
- OnPaint();
- break;
- }
- case 3:
- glTranslatef (-50.0, 0.0, 0.0);
- OnPaint();
- }
- }
- void CMy07063257_GLView::OnRight()
- {
- IsOpen++;
- type=IsOpen%4;
- switch(type)
- {
- case 0:
- {
- glTranslatef (50.0, 0.0, 0.0);
- OnPaint();
- break;
- }
- case 1:
- {
- glTranslatef (50.0, 0.0, 0.0);
- OnPaint();
- break;
- }
- case 2:
- {
- glTranslatef (50.0, 0.0, 0.0);
- OnPaint();
- break;
- }
- case 3:
- glTranslatef (50.0, 0.0, 0.0);
- OnPaint();
- }
- }
- void CMy07063257_GLView::OnUp()
- {
- // TODO: Add your command handler code here
- IsOpen++;
- type=IsOpen%4;
- switch(type)
- {
- case 0:
- {
- glTranslatef (0.0, 50.0, 0.0);
- OnPaint();
- break;
- }
- case 1:
- {
- glTranslatef (0.0, 50.0, 0.0);
- OnPaint();
- break;
- }
- case 2:
- {
- glTranslatef (0.0, 50.0, 0.0);
- OnPaint();
- break;
- }
- case 3:
- glTranslatef (0.0, 50.0, 0.0);
- OnPaint();
- }
- }
- void CMy07063257_GLView::OnDown()
- {
- // TODO: Add your command handler code here
- IsOpen++;
- type=IsOpen%4;
- switch(type)
- {
- case 0:
- {
- glTranslatef (0.0, -50.0, 0.0);
- OnPaint();
- break;
- }
- case 1:
- {
- glTranslatef (0.0, -50.0, 0.0);
- OnPaint();
- break;
- }
- case 2:
- {
- glTranslatef (0.0, -50.0, 0.0);
- OnPaint();
- break;
- }
- case 3:
- glTranslatef (0.0, -50.0, 0.0);
- OnPaint();
- }
- }
- void CMy07063257_GLView::OnLrotaef()
- {
- // TODO: Add your command handler code here
- IsOpen++;
- type=IsOpen%4;
- switch(type)
- {
- case 0:
- {
- glRotatef (10.0, 0.0, 0.0, 1.0);
- OnPaint();
- break;
- }
- case 1:
- {
- glRotatef (10.0, 0.0, 0.0, 1.0);
- OnPaint();
- break;
- }
- case 2:
- {
- glRotatef (10.0, 0.0, 0.0, 1.0);
- OnPaint();
- break;
- }
- case 3:
- glRotatef (10.0, 0.0, 0.0, 1.0);
- OnPaint();
- }
- }
- void CMy07063257_GLView::OnRrotatef()
- {
- // TODO: Add your command handler code here
- IsOpen++;
- type=IsOpen%4;
- switch(type)
- {
- case 0:
- {
- glRotatef (-10.0, 0.0, 0.0, 1.0);
- OnPaint();
- break;
- }
- case 1:
- {
- glRotatef (-10.0, 0.0, 0.0, 1.0);
- OnPaint();
- break;
- }
- case 2:
- {
- glRotatef (-10.0, 0.0, 0.0, 1.0);
- OnPaint();
- break;
- }
- case 3:
- glRotatef (-10.0, 0.0, 0.0, 1.0);
- OnPaint();
- }
- }
- void CMy07063257_GLView::OnZoomout()
- {
- // TODO: Add your command handler code here
- IsOpen++;
- type=IsOpen%4;
- switch(type)
- {
- case 0:
- {
- glScalef (1.2, 1.2, 1.2);
- OnPaint();
- break;
- }
- case 1:
- {
- glScalef (1.2, 1.2, 1.2);
- OnPaint();
- break;
- }
- case 2:
- {
- glScalef (1.2, 1.2, 1.2);
- OnPaint();
- break;
- }
- case 3:
- glScalef (1.2, 1.2, 1.2);
- OnPaint();
- }
- }
- void CMy07063257_GLView::OnZoomin()
- {
- // TODO: Add your command handler code here
- IsOpen++;
- type=IsOpen%4;
- switch(type)
- {
- case 0:
- {
- glScalef (0.8, 0.8, 0.8);
- OnPaint();
- break;
- }
- case 1:
- {
- glScalef (0.8, 0.8, 0.8);
- OnPaint();
- break;
- }
- case 2:
- {
- glScalef (0.8, 0.8, 0.8);
- OnPaint();
- break;
- }
- case 3:
- glScalef (0.8, 0.8, 0.8);
- OnPaint();
- }
- }
- void CMy07063257_GLView::OnFront()
- {
- // TODO: Add your command handler code here
- IsOpen++;
- type=IsOpen%4;
- switch(type)
- {
- case 0:
- {
- glRotatef (-10.0, 1.0, 0.0, 0.0);
- OnPaint();
- break;
- }
- case 1:
- {
- glRotatef (-10.0, 1.0, 0.0, .0);
- OnPaint();
- break;
- }
- case 2:
- {
- glRotatef (-10.0, 1.0, 0.0, 0.0);
- OnPaint();
- break;
- }
- case 3:
- glRotatef (-10.0, 1.0, 0.0, 0.0);
- OnPaint();
- }
- }
- void CMy07063257_GLView::OnBack()
- {
- // TODO: Add your command handler code here
- IsOpen++;
- type=IsOpen%4;
- switch(type)
- {
- case 0:
- {
- glRotatef (10.0, 1.0, 0.0, 0.0);
- OnPaint();
- break;
- }
- case 1:
- {
- glRotatef (10.0, 1.0, 0.0, .0);
- OnPaint();
- break;
- }
- case 2:
- {
- glRotatef (10.0, 1.0, 0.0, 0.0);
- OnPaint();
- break;
- }
- case 3:
- glRotatef (10.0, 1.0, 0.0, 0.0);
- OnPaint();
- }
- }
- Vertex CMy07063257_GLView::CalTexture(float xx, float yy, float zz)
- {
- Vertex CalTexture1;
- CalTexture1.x=(MAXX-xx)/(MAXX-MINX);
- CalTexture1.y=(MAXY-yy)/(MAXY-MINY);
- CalTexture1.z=0.0;
- return CalTexture1;
- }