📄 opengltestview.cpp
字号:
// OpenGLtestView.cpp : implementation of the COpenGLtestView class
//
#include "stdafx.h"
#include "math.h"
#include "OpenGLtest.h"
#include "Plane.h"
#include "CARM.h"
#include "OpenGLtestDoc.h"
#include "OpenGLtestView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CTransf item;
CCARM newCARM;
/////////////////////////////////////////////////////////////////////////////
// COpenGLtestView
IMPLEMENT_DYNCREATE(COpenGLtestView, CView)
BEGIN_MESSAGE_MAP(COpenGLtestView, CView)
//{{AFX_MSG_MAP(COpenGLtestView)
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_DESTROY()
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_TrX, OnTrX)
ON_COMMAND(ID_TrY, OnTrY)
ON_COMMAND(ID_TrZ, OnTrZ)
ON_COMMAND(ID_Zoom, OnZoom)
ON_COMMAND(ID_TrYD, OnTrYD)
ON_COMMAND(ID_TrXL, OnTrXL)
ON_COMMAND(ID_TrZO, OnTrZO)
ON_COMMAND(ID_ZoomOut, OnZoomOut)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// COpenGLtestView construction/destruction
COpenGLtestView::COpenGLtestView()
{
// TODO: add construction code here
m_dAspectRatio=1.0;
X_Angle=0;
Y_Angle=0;
m_TrX=0;
m_TrY=0;
m_TrZ=0;
m_Zoom=0.2;
abc=cde=0;
}
COpenGLtestView::~COpenGLtestView()
{
}
BOOL COpenGLtestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
// these styles are meant for a use of this class in a MDI application
cs.lpszClass = AfxRegisterWndClass(CS_OWNDC | CS_HREDRAW | CS_VREDRAW);
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// COpenGLtestView drawing
void COpenGLtestView::OnDraw(CDC* pDC)
{
COpenGLtestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
static BOOL bBusy = FALSE;
// use the semaphore to enter this critic section
if(bBusy) return;
bBusy = TRUE;
wglMakeCurrent(m_pCDC->GetSafeHdc(), m_hRC);
// clear background
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glScaled(m_Zoom,m_Zoom,m_Zoom);
glTranslated(m_TrX,m_TrY,m_TrZ);
glRotated(X_Angle,1.0,0.0,0.0);
glRotated(Y_Angle,0.0,1.0,0.0);
//禸
ShowAxis();
POSITION pos = pDoc->m_EntityList.GetHeadPosition();
while(pos)
{
CEntity* pEntity = pDoc->m_EntityList.GetNext(pos);
pEntity->Draw(m_pCDC,m_hRC);
}
glPopMatrix();
// execute OGL commands (flush the OGL graphical pipeline)
glFinish();
// if double buffering is used it's time to swap the buffers
SwapBuffers(m_pCDC->GetSafeHdc());
// turn the semaphore "green"
bBusy = FALSE;
// free the target DeviceContext (window)
wglMakeCurrent(NULL,NULL);
}
/////////////////////////////////////////////////////////////////////////////
// COpenGLtestView printing
BOOL COpenGLtestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void COpenGLtestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void COpenGLtestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// COpenGLtestView diagnostics
#ifdef _DEBUG
void COpenGLtestView::AssertValid() const
{
CView::AssertValid();
}
void COpenGLtestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
COpenGLtestDoc* COpenGLtestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COpenGLtestDoc)));
return (COpenGLtestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// COpenGLtestView message handlers
BOOL COpenGLtestView::bSetupPixelFormat()
{
// define default desired video mode (pixel format)
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
16, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
// let the user change some parameters if he wants
//set the changes
pfd.dwFlags=PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |PFD_DOUBLEBUFFER;
pfd.cColorBits=24;
pfd.cDepthBits=16;
// ask the system for such video mode
ASSERT(m_pCDC != NULL);
int pixelformat;
if ( (pixelformat = ChoosePixelFormat(m_pCDC->GetSafeHdc(), &pfd)) == 0 )
{
AfxMessageBox("ChoosePixelFormat failed");
return FALSE;
}
// try to set this video mode
if (SetPixelFormat(m_pCDC->GetSafeHdc(), pixelformat, &pfd) == FALSE)
{
// the requested video mode is not available so get a default one
pixelformat = 1;
if (DescribePixelFormat(m_pCDC->GetSafeHdc(), pixelformat, sizeof(PIXELFORMATDESCRIPTOR), &pfd)==0)
{
// neither the requested nor the default are available: fail
AfxMessageBox("SetPixelFormat failed (no OpenGL compatible video mode)");
return FALSE;
}
}
return TRUE;
}
void COpenGLtestView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if ( 0 < cx && 0 < cy )
{
// update the rect and the aspect ratio
m_dAspectRatio=double(cx)/double(cy);
// specify the target DeviceContext of the subsequent OGL calls
wglMakeCurrent(m_pCDC->GetSafeHdc(), m_hRC);
// call the virtual sizing procedure (to be overridden by user)
glViewport(0,0,cx,cy);
// 砞﹚泊氟
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -