⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 primitiveview.cpp

📁 visual c++数字图像与图形处理中的光盘内容
💻 CPP
字号:
// PrimitiveView.cpp : implementation of the CPrimitiveView class
//

#include "stdafx.h"
#include "Primitive.h"

#include "PrimitiveDoc.h"
#include "PrimitiveView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#include "BTriangle.h"

/////////////////////////////////////////////////////////////////////////////
// CPrimitiveView

IMPLEMENT_DYNCREATE(CPrimitiveView, CView)

BEGIN_MESSAGE_MAP(CPrimitiveView, CView)
	//{{AFX_MSG_MAP(CPrimitiveView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPrimitiveView construction/destruction

CPrimitiveView::CPrimitiveView()
{
	// TODO: add construction code here
}

CPrimitiveView::~CPrimitiveView()
{
}

BOOL CPrimitiveView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CPrimitiveView drawing

void CPrimitiveView::OnDraw(CDC* pDC)
{
	CRect rect;
	GetClientRect(&rect);
	int nClientWidth = rect.Width();
	int nClientHeight = rect.Height();

	CColorBuffer* pCB = new CColorBuffer(nClientWidth, nClientHeight);
	CZBuffer* pZB = new CZBuffer(nClientWidth, nClientHeight);
	pZB->InitAllDepth(500.0f);

	CBTriangle bt;
	
	//顶点
	POINT pts[12] = {
		{60,  60}, {210, 60}, {210, 80},  {60,  80}, 
		{80,  40}, {100, 40}, {190, 210}, {170, 210},
		{190, 40}, {170, 40}, {80,  210}, {100, 210}};

	//颜色,三个四边形的颜色分别为红色、绿色和蓝色
	FLOATCOLORRGBA red = {1.0f, 0.0f, 0.0f, 1.0f};
	FLOATCOLORRGBA green = {0.0f, 1.0f, 0.0f, 1.0f};
	FLOATCOLORRGBA blue = {0.0f, 0.0f, 1.0f, 1.0f};

	//四边形顶点深度
	float z[12] = {0.5f, 0.5f, 0.4f, 0.4f,
				   0.2f, 0.2f, 0.9f, 0.9f,
				   0.6f, 0.6f, 0.1f, 0.1f};
	
	//绘制
	//注意,绘制顺序无关

	//红色条带
	bt.Draw(pts[0], pts[1], pts[2], z[0], z[1], z[2], red, red, red, pCB, pZB);	
	bt.Draw(pts[0], pts[3], pts[2], z[0], z[3], z[2], red, red, red, pCB, pZB);	

	//绿色条带
	bt.Draw(pts[4], pts[5], pts[6], z[4], z[5], z[6], green, green, green, pCB, pZB);
	bt.Draw(pts[4], pts[7], pts[6], z[4], z[7], z[6], green, green, green, pCB, pZB);	

	//蓝色条带
	bt.Draw(pts[8], pts[9], pts[10], z[8], z[9], z[10], blue, blue, blue, pCB, pZB);	
	bt.Draw(pts[8], pts[10],pts[11], z[8], z[10],z[11], blue, blue, blue, pCB, pZB);	

	//将后台颜色缓冲区的内容显示在屏幕上
	pCB->SwapBuffer(pDC);
	
	delete pCB;
	delete pZB;
}

/////////////////////////////////////////////////////////////////////////////
// CPrimitiveView diagnostics

#ifdef _DEBUG
void CPrimitiveView::AssertValid() const
{
	CView::AssertValid();
}

void CPrimitiveView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CPrimitiveDoc* CPrimitiveView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPrimitiveDoc)));
	return (CPrimitiveDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPrimitiveView message handlers

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -