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

📄 空间曲面view.cpp

📁 这是树上的代码
💻 CPP
字号:
// 空间曲面View.cpp : implementation of the CMyView class
//

#include "stdafx.h"
#include "空间曲面.h"
#include "INPUT.h"
#include "math.h"
#include "空间曲面Doc.h"
#include "空间曲面View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//extern double a[20],m_fx[20],m_fy[20],m_fz[20];
//extern int m_m,m_n;
boolean Num;
/////////////////////////////////////////////////////////////////////////////
// CMyView

IMPLEMENT_DYNCREATE(CMyView, CView)

BEGIN_MESSAGE_MAP(CMyView, CView)
	//{{AFX_MSG_MAP(CMyView)
	ON_COMMAND(ID_INPUT, OnInput)
	ON_COMMAND(ID_INPUTDRAW, OnInputdraw)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction

CMyView::CMyView()
{
	// TODO: add construction code here
    Num=false;
}

CMyView::~CMyView()
{
}

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

	return CView::PreCreateWindow(cs);
}


/////////////////////////////////////////////////////////////////////////////
// CMyView printing

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers

void CMyView::OnInput() 
{
	// TODO: Add your command handler code here
	CMyDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
    INPUT Input;
	//Num=true;
	//Invalidate();
	a=Input.DoModal();
    angle1=Input.m_Int1;
    angle2=Input.m_Int2;
	OK=Input.m;
	if(a==IDOK)
	{
		for(i=1;i<=Input.m;i++)
		{
		  x[i]=Input.x[i];
	      y[i]=Input.y[i];
          z[i]=Input.z[i];
		}
	}
}

void CMyView::OnInputdraw() 
{
	// TODO: Add your command handler code here
	CClientDC *pDC=new CClientDC(this);
    CPen Pen1(PS_SOLID,1,RGB(255,0,255));
    CPen Pen2(PS_SOLID,1,RGB(0,0,255));
    for(u1=1;u1<=10;u1++)
	{
	  u=u1/10.;
	  for(v1=1;v1<=10;v1++)
	  { 
        v=v1/10.;
		a1=x[1]*(u*u*u+3*u*u-3*u+1)+x[5]*(3*u*u*u-6*u*u+4)+x[9]*(3*u*u-3*u*u*u+3*u+1)+x[13]*u*u*u;
        b1=x[2]*(u*u*u+3*u*u-3*u+1)+x[6]*(3*u*u*u-6*u*u+4)+x[10]*(3*u*u-3*u*u*u+3*u+1)+x[14]*u*u*u;
        c1=x[3]*(u*u*u+3*u*u-3*u+1)+x[7]*(3*u*u*u-6*u*u+4)+x[11]*(3*u*u-3*u*u*u+3*u+1)+x[15]*u*u*u;
        d1=x[4]*(u*u*u+3*u*u-3*u+1)+x[8]*(3*u*u*u-6*u*u+4)+x[12]*(3*u*u-3*u*u*u+3*u+1)+x[16]*u*u*u;
		e=((a1+3*b1-3*c1+d1)*v*v*v+(3*a1-6*b1+3*c1)*v*v+(3*c1-3*a1)*v+(a1+4*b1+c1))/36;
        a2=y[1]*(u*u*u+3*u*u-3*u+1)+y[5]*(3*u*u*u-6*u*u+4)+y[9]*(3*u*u-3*u*u*u+3*u+1)+y[13]*u*u*u;
        b2=y[2]*(u*u*u+3*u*u-3*u+1)+y[6]*(3*u*u*u-6*u*u+4)+y[10]*(3*u*u-3*u*u*u+3*u+1)+y[14]*u*u*u;
        c2=y[3]*(u*u*u+3*u*u-3*u+1)+y[7]*(3*u*u*u-6*u*u+4)+y[11]*(3*u*u-3*u*u*u+3*u+1)+y[15]*u*u*u;
        d2=y[4]*(u*u*u+3*u*u-3*u+1)+y[8]*(3*u*u*u-6*u*u+4)+y[12]*(3*u*u-3*u*u*u+3*u+1)+y[16]*u*u*u;
		f=((a2+3*b2-3*c2+d2)*v*v*v+(3*a2-6*b2+3*c2)*v*v+(3*c2-3*a2)*v+(a2+4*b2+c2))/36;
        a3=z[1]*(u*u*u+3*u*u-3*u+1)+z[5]*(3*u*u*u-6*u*u+4)+z[9]*(3*u*u-3*u*u*u+3*u+1)+z[13]*u*u*u;
        b3=z[2]*(u*u*u+3*u*u-3*u+1)+z[6]*(3*u*u*u-6*u*u+4)+z[10]*(3*u*u-3*u*u*u+3*u+1)+z[14]*u*u*u;
        c3=z[3]*(u*u*u+3*u*u-3*u+1)+z[7]*(3*u*u*u-6*u*u+4)+z[11]*(3*u*u-3*u*u*u+3*u+1)+z[15]*u*u*u;
        d3=z[4]*(u*u*u+3*u*u-3*u+1)+z[8]*(3*u*u*u-6*u*u+4)+z[12]*(3*u*u-3*u*u*u+3*u+1)+z[16]*u*u*u;
		g=((a3+3*b3-3*c3+d3)*v*v*v+(3*a3-6*b3+3*c3)*v*v+(3*c3-3*a3)*v+(a3+4*b3+c3))/36;
        //l[u1][v1]=(e*0.717+g*0.717+40)*100/(e*0.717*0.717-f*0.717-g*0.717*0.717+300-20);
		//m[u1][v1]=(e*0.717*0.717+f*0.717-g*0.717*0.717+30)*100/(e*0.717*0.717-f*0.717-g*0.717*0.717+300-20); 
        l[u1][v1]=e+g*tan(angle1)*cos(angle2);
        m[u1][v1]=f+g*tan(angle1)*sin(angle2);
	  }
	}
    pDC->SelectObject(Pen1);
	for(u1=1;u1<10;u1++)
	{
	  for(v1=1;v1<10;v1++)
	  { 
         pDC->MoveTo((int)(90*l[u1][v1]-200),(int)(80*m[u1][v1]-520));
		 pDC->LineTo((int)(90*l[u1][v1+1]-200),(int)(80*m[u1][v1+1]-520));
	  }
	}
    for(v1=1;v1<10;v1++)
	{ 
       pDC->MoveTo((int)(90*l[10][v1]-200),(int)(80*m[10][v1]-520));
	   pDC->LineTo((int)(90*l[10][v1+1]-200),(int)(80*m[10][v1+1]-520));
	}
    pDC->SelectObject(Pen1);
    for(v1=1;v1<10;v1++)
	{
	  for(u1=1;u1<10;u1++)
	  { 
         pDC->MoveTo((int)(90*l[u1][v1]-200),(int)(80*m[u1][v1]-520));
		 pDC->LineTo((int)(90*l[u1+1][v1]-200),(int)(80*m[u1+1][v1]-520));
	  }
	}
    for(u1=1;u1<10;u1++)
	{ 
       pDC->MoveTo((int)(90*l[u1][10]-200),(int)(80*m[u1][10]-520));
	   pDC->LineTo((int)(90*l[u1+1][10]-200),(int)(80*m[u1+1][10]-520));
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMyView drawing

void CMyView::OnDraw(CDC* pDC)
{
	CMyDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
    //CClientDC *pDC=new CClientDC(this);
    //新建图件时,填充默认底色
	CRect rcClient;
	pDC->GetClipBox(rcClient);			//获取需刷新的逻辑坐标区域
	rcClient.NormalizeRect();
	if (rcClient.IsRectEmpty())			//不需刷新时直接返回
		return;

	//绘制客户区的底色
	CBrush	brush;
	//brush.CreateSolidBrush(0x808080);
    brush.CreateSolidBrush(RGB(230,230,235));

	pDC->FillRect(rcClient, &brush);
	brush.DeleteObject();

	//绘制3D文字Logo
	CFont m_LogoFont;
	CString sLogoString;
		
	m_LogoFont.CreateFont(46, 0, 0, 0, FW_BOLD, 1, FALSE, FALSE,
			DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
			FIXED_PITCH | FF_ROMAN, "楷体_GB2312");
		
	sLogoString="By HuaWei Studio";
	
		
	RECT rect,m_rDataBox;
	GetClientRect(&rect);
	CopyRect(&m_rDataBox,&rect);
		
	TEXTMETRIC tm;
	pDC->GetTextMetrics(&tm);
	CFont* oldFont=pDC->SelectObject(&m_LogoFont);
	CSize sz = pDC->GetTextExtent(sLogoString, sLogoString.GetLength());
	// 用GetTextExtent来计算字体logo大小,依靠于设备环境,使用logo位于右下角
	m_rDataBox.left=m_rDataBox.right-sz.cx-tm.tmAveCharWidth/2;
	m_rDataBox.top=m_rDataBox.bottom-sz.cy-tm.tmHeight/5;
	pDC->SetBkMode(TRANSPARENT);
	// 用3D字体显示,先黑后白,最后再用默认色
	
	COLORREF oldColor=pDC->SetTextColor(RGB(0,0,0));
	pDC->DrawText(sLogoString, sLogoString.GetLength(), &m_rDataBox, DT_VCENTER | DT_SINGLELINE | DT_CENTER);
	m_rDataBox.left-=3*tm.tmAveCharWidth/5;
	pDC->SetTextColor(RGB(255,255,255));
	pDC->DrawText(sLogoString, sLogoString.GetLength(), &m_rDataBox, DT_VCENTER | DT_SINGLELINE | DT_CENTER);
	m_rDataBox.left+=tm.tmAveCharWidth/5;
	pDC->SetTextColor(GetSysColor(COLOR_BTNFACE));
	pDC->DrawText(sLogoString, sLogoString.GetLength(), &m_rDataBox, DT_VCENTER | DT_SINGLELINE | DT_CENTER);
		
	//释放资源
	pDC->SelectObject(oldFont);
	pDC->SetTextColor(oldColor);   
	m_LogoFont.DeleteObject();

}

⌨️ 快捷键说明

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