www.pudn.com > final_6.rar > PerView.cpp
// PerView.cpp : implementation file
//
#include "stdafx.h"
#include "CG.h"
#include "PerView.h"
#include"Shape.h"
#include"CGDoc.h"
#include "Operation.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPerView
IMPLEMENT_DYNCREATE(CPerView, CView)
CPerView::CPerView()
{
bOpView = false;
g_pPerView=this;
}
CPerView::~CPerView()
{
}
BEGIN_MESSAGE_MAP(CPerView, CView)
//{{AFX_MSG_MAP(CPerView)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPerView drawing
void CPerView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
// pDC->TextOut(10,10,"Perspective View");
CRect rc;
GetClientRect(&rc);
pDC->FillRect(rc,backBrush);
pDC->TextOut(10,10,"Perspective View");
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
pDC->SelectObject(frame);
// pDC->MoveTo(0,0);pDC->LineTo(0,1000);
// pDC->MoveTo(0,0);pDC->LineTo(1000,0);
// pDC->MoveTo(0,0);pDC->LineTo(-1000,0);
// pDC->MoveTo(0,0);pDC->LineTo(0,-1000);
// pDC->MoveTo(0,0);pDC->LineTo(500,-500);
// pDC->MoveTo(0,0);pDC->LineTo(-500,500);
//Íø¸ñ
{
double startx = -500;
double startz = -500;
double deltax = -startx/10;
double deltaz = -startz/10;
CGPoint net[21][21];
SPoint netview[21][21];
for(int i=0;i<21;i++)
for(int j=0;j<21;j++)
{
net[i][j].x = startx + i*deltax;
net[i][j].y = 0;
net[i][j].z = startz + j*deltaz;
COperation::PerspectiveCal(&net[i][j],&netview[i][j]);
}
for(i=0;i<20;i++)
for(int j=0;j<20;j++)
{
pDC->MoveTo((int)netview[i][j].x,(int)netview[i][j].y);
pDC->LineTo((int)netview[i+1][j].x,(int)netview[i+1][j].y);
pDC->MoveTo((int)netview[i][j].x,(int)netview[i][j].y);
pDC->LineTo((int)netview[i][j+1].x,(int)netview[i][j+1].y);
}
}
int x;
for (x=0;xSelectObject(bePointed);
else
pDC->SelectObject(shape);
CShape* mShape;
mShape=(CShape*)g_pDoc->m_ShapeArray[x];
COperation::PerViewPoints(mShape);
mShape->DrawPer(pDC,&rc);
}
CPen light(PS_DASH,2,RGB(255,100,100));
CPen *pOldPen=pDC->SelectObject(&light);
for (x=0;xSelectObject(bePointed);
else pDC->SelectObject(light);
CGLight *mLight;
mLight=(CGLight *)g_pDoc->m_LightArray[x];
mLight->DrawPer(pDC);
}
}
/////////////////////////////////////////////////////////////////////////////
// CPerView diagnostics
#ifdef _DEBUG
void CPerView::AssertValid() const
{
CView::AssertValid();
}
void CPerView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPerView message handlers
void CPerView::OnLButtonDown(UINT nFlags, CPoint point)
{
switch (drawMode)
{
case dmZoomView:
{
prePoint = point;
bOpView = true;
break;
}
case dmRotateView:
{
prePoint = point;
bOpView = true;
break;
}
case dmAddPointL:
{
g_pDoc->m_LightArray.Add((CObject *)new CGLight((point.x-395/2+14.16),(point.y-160-14.16),40));
lightIndex++;
g_pDoc->UpdateAllViews(NULL);
break;
}
default:
{
}
}
CView::OnLButtonDown(nFlags, point);
}
void CPerView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
Invalidate(FALSE);
}
void CPerView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
switch(drawMode)
{
case dmZoomView:
{
if(bOpView)
{
d += 2*(prePoint.x - point.x);
if(d<0)
d = 1;
g_pDoc->UpdateAllViews(NULL);
}
prePoint = point;
break;
}
case dmRotateView:
{
if(bOpView)
{
Oe->x += (prePoint.x - point.x);
Oe->y += (prePoint.y - point.y);
Oe->z = sqrt(680000 - Oe->x*Oe->x - Oe->y*Oe->y);
g_pDoc->UpdateAllViews(NULL);
}
prePoint = point;
break;
}
}
CView::OnMouseMove(nFlags, point);
}
void CPerView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
bOpView = false;
CView::OnLButtonUp(nFlags, point);
}