www.pudn.com > stlreader.rar > twoimageDlg.cpp


// twoimageDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "twoimage.h" 
#include "twoimageDlg.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CAboutDlg dialog used for App About 
C3DModel m_Model; 
class CAboutDlg : public CDialog 
{ 
public: 
	CAboutDlg(); 
 
// Dialog Data 
	//{{AFX_DATA(CAboutDlg) 
	enum { IDD = IDD_ABOUTBOX }; 
	//}}AFX_DATA 
 
	// ClassWizard generated virtual function overrides 
	//{{AFX_VIRTUAL(CAboutDlg) 
	protected: 
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support 
	//}}AFX_VIRTUAL 
 
// Implementation 
protected: 
	//{{AFX_MSG(CAboutDlg) 
	//}}AFX_MSG 
	DECLARE_MESSAGE_MAP() 
}; 
 
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 
{ 
	//{{AFX_DATA_INIT(CAboutDlg) 
	//}}AFX_DATA_INIT 
} 
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAboutDlg) 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 
	//{{AFX_MSG_MAP(CAboutDlg) 
		// No message handlers 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CTwoimageDlg dialog 
 
CTwoimageDlg::CTwoimageDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CTwoimageDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CTwoimageDlg) 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CTwoimageDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CTwoimageDlg) 
	DDX_Control(pDX, IDC_ZSLIDER, m_Zslider); 
	DDX_Control(pDX, IDC_YSLIDER, m_Yslider); 
	DDX_Control(pDX, IDC_XSLIDER, m_Xslider); 
 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CTwoimageDlg, CDialog) 
	//{{AFX_MSG_MAP(CTwoimageDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_WM_HSCROLL() 
	ON_WM_VSCROLL() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CTwoimageDlg message handlers 
 
BOOL CTwoimageDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Add "About..." menu item to system menu. 
 
	// IDM_ABOUTBOX must be in the system command range. 
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 
	ASSERT(IDM_ABOUTBOX < 0xF000); 
 
	CMenu* pSysMenu = GetSystemMenu(FALSE); 
	if (pSysMenu != NULL) 
	{ 
		CString strAboutMenu; 
		strAboutMenu.LoadString(IDS_ABOUTBOX); 
		if (!strAboutMenu.IsEmpty()) 
		{ 
			pSysMenu->AppendMenu(MF_SEPARATOR); 
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 
		} 
	} 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	m_Xslider.SetRange(0,360); 
	m_Yslider.SetRange(0,360); 
	m_Zslider.SetRange(0,360); 
	m_Xslider.SetPos(0); 
    m_Yslider.SetPos(0); 
    m_Zslider.SetPos(0); 
	// TODO: Add extra initialization here 
	CString sfile1,sfile2; 
	sfile1.Format("%s","res\\xie2.bmp"); 
    sfile2.Format("%s","res\\xie1.bmp"); 
	m_foot.Init(sfile1,sfile2); 
	m_Model.InitModel(); 
	m_Model.ScaleFoot(m_foot.m_Heigth,m_foot.m_Width,1); 
	 
	m_paint1 =0; 
	CRect rect(100,100,400,400); 
	D3Window.Create(WS_CHILD| WS_VISIBLE, rect, this, IDC_IW_INRIGHT); 
    D3Window.ShowWindow(SW_SHOW); 
	D3Window.initOpengl(); 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CTwoimageDlg::OnSysCommand(UINT nID, LPARAM lParam) 
{ 
	if ((nID & 0xFFF0) == IDM_ABOUTBOX) 
	{ 
		CAboutDlg dlgAbout; 
		dlgAbout.DoModal(); 
	} 
	else 
	{ 
		CDialog::OnSysCommand(nID, lParam); 
	} 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void CTwoimageDlg::OnPaint()  
{ 
    if(m_paint1 ==0) 
	{ 
		 
		m_paint1++; 
		return; 
	} 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
		 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
	} 
		 
	//PaintFoot(m_xaxi,m_yaxi,m_zaxi); 
	//Drawgg(); 
	//paintsurface(); 
	 
	 
 
	 
	//::glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 
	/*float size=100.0f; 
	glLineWidth(3.0f);  //  
	// axis -- x 
	glColor3f(1,0,0); 
	glBegin(GL_LINES);  
	glVertex3f(-size,0,0); 
	glVertex3f(size,0,0); 
	glEnd(); 
	// axis -- y 
	glColor3f(0,1,0); 
	glBegin(GL_LINES);  
	glVertex3f(0,-size,0); 
	glVertex3f(0,size,0); 
	glEnd(); 
	// axis -- z 
	glColor3f(0,0,1); 
	glBegin(GL_LINES);  
	glVertex3f(0,0,-size); 
	glVertex3f(0,0,size); 
	glEnd(); 
	*/// 
	//glLineWidth(1.0f); // ssj  
	//::glFinish();  
	//SwapBuffers( m_hDC );  
	 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CTwoimageDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
 
 
void CTwoimageDlg::initopengl() 
{ 
	//m_pDC = new CClientDC(this); 
	CWnd *p = (CWnd*) GetDlgItem(IDC_IW_INRIGHT); 
    m_pDC =p->GetDC(); 
	m_hDC=m_pDC->GetSafeHdc(); 
	PIXELFORMATDESCRIPTOR pfd = {  
		sizeof(PIXELFORMATDESCRIPTOR),    // pfd结构的大小  
			1,                                // 版本号  
			PFD_DRAW_TO_WINDOW |              // 支持在窗口中绘图  
			PFD_SUPPORT_OPENGL |              // 支持 OpenGL  
			PFD_DOUBLEBUFFER,                 // 双缓存模式  
			PFD_TYPE_RGBA,                    // RGBA 颜色模式  
			24,                               // 24 位颜色深度  
			0, 0, 0, 0, 0, 0,                 // 忽略颜色位  
			0,                                // 没有非透明度缓存  
			0,                                // 忽略移位位  
			0,                                // 无累加缓存  
			0, 0, 0, 0,                       // 忽略累加位  
			32,                               // 32 位深度缓存      
			0,                                // 无模板缓存  
			0,                                // 无辅助缓存  
			PFD_MAIN_PLANE,                   // 主层  
			0,                                // 保留  
			0, 0, 0                           // 忽略层,可见性和损毁掩模  
	}; 	 
	int pixelformat; 
     
	 
	glEnable(GL_TEXTURE_2D);                   // 启用纹理映射(新增) 
	glShadeModel(GL_SMOOTH);                   // 启用阴影平滑 
	 
	// 设置深度缓存// 启用深度测试 
	glClearDepth(1.0f); 
    glEnable(GL_DEPTH_TEST); 
	// 所作深度测试的类型// 真正精细的透视修正 
	glDepthFunc(GL_LEQUAL);                                          
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);               
	 
	glEnable(GL_NORMALIZE); 
	glShadeModel(GL_SMOOTH); 
	 
	glEnable(GL_LIGHTING); 
	 
	glLineWidth(0.25f); 
	glPointSize(2.25f); 
	int   m_PixelFormat; 
	pixelformat = ::ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);//选择像素格式 
	::SetPixelFormat(m_pDC->GetSafeHdc(), pixelformat, &pfd);	//设置像素格式 
   
	m_hRC = ::wglCreateContext( m_hDC );  
	wglMakeCurrent( m_hDC, m_hRC );  
	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; 
	 
	GLfloat mat_shininess[] = { 90.0 }; 
	 
	GLfloat light_position[] = { 1.0, 1.0, 1.0, 1.0 }; 
	 
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 
	 
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 
	 
	glLightfv(GL_LIGHT0, GL_POSITION, light_position); 
	 
	//glEnable(GL_LIGHTING); 
	 
	//glEnable(GL_LIGHT0); 
	 
	glDepthFunc(GL_LEQUAL); 
	 
	glEnable(GL_DEPTH_TEST); 
	 
 
} 
 
void CTwoimageDlg::PaintFoot(int xaxi,int yaxi,int zaxi) 
{ 
   //int length =m_foot.m_footlength; 
   int i,j,k; 
 
	 
//	glutInitDisplayModel(GLUT_SINGLE|GLUT_RGB); 
	//glutInitWindowSize(500,500); 
//	glutInitWindowPosition(100,100); 
	glClearColor(0.2,0.2,0.2,0.8); 
	glShadeModel(GL_FLAT); 
	::glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 
	 
	glLoadIdentity(); 
	//gluLookAt(0,0,5,0,0,0,0,1,0); 
	//gluLookAt(0,0,5/100,0.04,0,0,0,1/100*yaxi,0.03*xaxi); 
	glScalef(0.003,0.003,0.003); 
	glRotatef(xaxi,1,0,0); 
    glRotatef(yaxi,0,1,0); 
	glRotatef(zaxi,0,0,1); 
	glColor3f (0.5,0.8,1.0); 
    //glBegin(GL_POINTS); 
   //glVertex3f( 0.4f, 0.5f, 0.0f); 
   //glColor3f(1.0f,0.0f,0.0f); 
   //glVertex3f(-0.4f,-0.5f, 0.0f); 
   //画出第一只脚 
	/*glBegin(GL_POINTS); 
   for(i=0;i=m_foot.m_maxY[i]) 
	    continue; 
		for( k=m_foot.m_minY[i];k<=m_foot.m_maxY[i];k++) 
		{  
			//j =i; 
			GLfloat x1,x2; 
			GLfloat y1,y2; 
			GLfloat z1,z2; 
			z1 =(GLfloat)(k)/1; 
			x1 =(GLfloat)(i-m_foot.m_origey2)/1; 
			y1 =(GLfloat)j/1; 
			glVertex3f(z1,x1,0); 
			 
			//glVertex3f(-0.4f,-0.5f,0.0f); 
			 
		} 
	} 
	glEnd(); 
	*/ 
   //glVertex3f( 1.0f,-1.0f, 1.0f); 
    
	   //glVertex3f(-100,-100,0); 
       //glVertex3f( 100,100,0); 
   //ReadData(); 
   
   /*for (i=0;i<10000;i++) 
	    
   { 
	   glVertex3f(m_Model.m_nTrueList[i][0],m_Model.m_nTrueList[i][1],m_Model.m_nTrueList[i][2]); 
	   //glVertex3f(0.4,0.5,0); 
       //glVertex3f(-0.4,-0.5,0); 
   }*/ 
	//m_Model.DrawNurbs(0); 
    m_Model.Draw3DModel(0); 
 
   //glViewport(100,100,500,500); 
    
   glFlush(); 
   glEnd(); 
 
   ::glFinish(); 
   //glRotatef(100,0.0f,1.0f,0.0f); 
   //glLoadIdentity(); 
   //glTranslatef(0,0.0f,0.5f); 
   //glRotatef(0.5,0.0f,1.0f,0.0f); 
   //glViewport(0,0,500,400); 
    
   //设置投影方式 
   /*glMatrixMode(GL_PROJECTION); 
   glLoadIdentity(); 
    
    
   //透视投影 
   gluPerspective(45.0f,1.0f,0.01f,1000.0f); 
    
    
    
   //设置观察方式 
   glMatrixMode(GL_MODELVIEW); 
   glLoadIdentity(); 
   // glColor3f(0,1,0); 
   glColor3f (0.5,0.8,1.0); 
   const GLfloat white[]={ 1.0,1.0,1.0,1.0}; 
   glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,white); 
   //gluLookAt(70.0,50.0,70.0,0.0,0.0,0.0,0.0,1.0,0.0); 
   */ 
   //gluLookAt(70.0,50.0,70.0,0.0,0.0,0.0,0.0,1.0,0.0); 
    
   glLineWidth(1.0f); // ssj  
     
   SwapBuffers( m_hDC ); 
 
 
} 
 
 
 
 
 
 
 
 
 
void CTwoimageDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)  
{ 
	// TODO: Add your message handler code here and/or call default 
	 
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar); 
    m_xaxi =m_Xslider.GetPos(); 
	this ->Invalidate(true); 
	 
} 
 
void CTwoimageDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)  
{ 
	// TODO: Add your message handler code here and/or call default 
	 
	CDialog::OnVScroll(nSBCode, nPos, pScrollBar); 
 
    m_zaxi =m_Zslider.GetPos(); 
    m_yaxi =m_Yslider.GetPos(); 
	this ->Invalidate(true); 
}