www.pudn.com > final_6.rar > LeftView.cpp
// LeftView.cpp : implementation file
//
#include "stdafx.h"
#include "CG.h"
#include "LeftView.h"
#include "Shape.h"
#include "CGDoc.h"
#include "Operation.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLeftView
IMPLEMENT_DYNCREATE(CLeftView, CView)
CLeftView::CLeftView()
{
g_pLeftView=this;
startPoint=new CGPoint();
prePoint = NULL;
}
CLeftView::~CLeftView()
{
}
BEGIN_MESSAGE_MAP(CLeftView, CView)
//{{AFX_MSG_MAP(CLeftView)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_RBUTTONDOWN()
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLeftView drawing
void CLeftView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
CRect rc;
GetClientRect(&rc);
pDC->FillRect(rc,backBrush);
pDC->TextOut(10,10,"Left 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->SelectObject(shape);
int x;
for (x=0;xSelectObject(bePointed);
else
pDC->SelectObject(shape);
CShape* mShape;
mShape=(CShape*)g_pDoc->m_ShapeArray[x];
mShape->DrawLeft(pDC,&rc);
}
CPen light(PS_DASH,2,RGB(255,100,100));
for (x=0;xSelectObject(bePointed);
else pDC->SelectObject(light);
CGLight *mLight;
mLight=(CGLight *)g_pDoc->m_LightArray[x];
mLight->DrawLeft(pDC);
}
/*switch (drawMode)
{
case dmCuboid:
{
// AfxMessageBox("HI");
g_pDoc->test.DrawLeft(pDC,&rc);
break;
}
case dmCuboid1:
{
g_pDoc->test.DrawLeft(pDC,&rc);
break;
}
default:
{
}
}*/
}
/////////////////////////////////////////////////////////////////////////////
// CLeftView diagnostics
#ifdef _DEBUG
void CLeftView::AssertValid() const
{
CView::AssertValid();
}
void CLeftView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLeftView message handlers
void CLeftView::OnLButtonDown(UINT nFlags, CPoint point)
{
switch (drawMode)
{
case dmNormal:
{
break;
}
case dmMove:
{
if (MouseOn(point))
{
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
break;
}
case dmRotate:
{
if (MouseOn(point))
{
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
break;
}
case dmZoom:
{
if (MouseOn(point))
{
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
}
case dmExtrude:
{
if (MouseOn(point))
{
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
break;
}
case dmLatheX:
{
if (opOn)
{
CShape *pColumn;
pColumn = (CShape*)g_pDoc->m_ShapeArray[opEntityIndex];
CRect rc;
GetClientRect(&rc);
CPoint point_org;
point_org.x = point.x - rc.right/2;
point_org.y = point.y - rc.bottom/2;
COperation::LatheEntity(pColumn,point_org,LEFT,LATHEX);
pColumn->SetBodyFace();
opPointIndex++;
selectNo = opEntityIndex;
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
if(opPointIndex>=LATI)
{
opOn = false;
opPointIndex = 0;
selectNo = -1;
}
break;
}
case dmLatheY:
{
if (opOn)
{
CShape *pColumn;
pColumn = (CShape*)g_pDoc->m_ShapeArray[opEntityIndex];
CRect rc;
GetClientRect(&rc);
CPoint point_org;
point_org.x = point.x - rc.right/2;
point_org.y = point.y - rc.bottom/2;
COperation::LatheEntity(pColumn,point_org,LEFT,LATHEY);
pColumn->SetBodyFace();
opPointIndex++;
selectNo = opEntityIndex;
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
if(opPointIndex>=LATI)
{
opOn = false;
opPointIndex = 0;
selectNo = -1;
}
break;
}
case dmLatheZ:
{
if (opOn)
{
CShape *pColumn;
pColumn = (CShape*)g_pDoc->m_ShapeArray[opEntityIndex];
CRect rc;
GetClientRect(&rc);
CPoint point_org;
point_org.x = point.x - rc.right/2;
point_org.y = point.y - rc.bottom/2;
COperation::LatheEntity(pColumn,point_org,LEFT,LATHEZ);
pColumn->SetBodyFace();
opPointIndex++;
selectNo = opEntityIndex;
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
if(opPointIndex>=LATI)
{
opOn = false;
opPointIndex = 0;
selectNo = -1;
}
break;
}
case dmLoftSample:
{
if (loftSampleOn)
{
CShape *pColumn;
pColumn = (CShape*)g_pDoc->m_ShapeArray[opEntityIndex];
CRect rc;
GetClientRect(&rc);
CPoint point_org;
point_org.x = point.x - rc.right/2;
point_org.y = point.y - rc.bottom/2;
COperation::LoftSampleEntity(pColumn,point_org,LEFT);
opPointIndex++;
selectNo = opEntityIndex;
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
if(opPointIndex>=LONG)
{
loftSampleOn = false;
opPointIndex = 0;
selectNo = -1;
}
break;
}
case dmLoftTrack:
{
if(loftTrackOn && opEntityIndex!=-1)
{
CShape *pColumn;
pColumn = (CShape*)g_pDoc->m_ShapeArray[opEntityIndex];
CRect rc;
GetClientRect(&rc);
CPoint point_org;
point_org.x = point.x - rc.right/2;
point_org.y = point.y - rc.bottom/2;
COperation::LoftTrackEntity(pColumn,point_org,prePoint,LEFT);
pColumn->SetBodyFace();
opPointIndex++;
selectNo = opEntityIndex;
g_pDoc->UpdateAllViews(NULL);
prePoint=point_org;
}
if(opPointIndex>=LATI)
{
loftTrackOn = false;
opPointIndex = 0;
selectNo = -1;
}
break;
}
case dmMovePointL:
{
if (COperation::PointOnLight(point,LEFT))
{
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
break;
}
default:
{
}
}
CView::OnLButtonDown(nFlags, point);
}
void CLeftView::OnMouseMove(UINT nFlags, CPoint point)
{
switch (drawMode)
{
case dmNormal:
{
break;
}
case dmMove:
{
if (selectNo!=-1)
{
COperation::MoveEntity(point,prePoint,LEFT);
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
break;
}
case dmRotate:
{
if (selectNo!=-1)
{
COperation::RotateEntity(point,prePoint,LEFT);
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
break;
}
case dmZoom:
{
if (selectNo!=-1)
{
COperation::ZoomEntity(point,prePoint,LEFT);
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
break;
}
case dmExtrude:
{
if (selectNo!=-1)
{
COperation::ExtrudeEntity(point,prePoint,LEFT);
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
break;
}
case dmMovePointL:
{
if (selectLight!=-1)
{
COperation::MoveLight(point,prePoint,LEFT);
g_pDoc->UpdateAllViews(NULL);
prePoint=point;
}
break;
}
default:
{
}
}
CView::OnMouseMove(nFlags, point);
}
void CLeftView::OnLButtonUp(UINT nFlags, CPoint point)
{
selectNo=-1;
selectLight=-1;
g_pDoc->UpdateAllViews(NULL);
/*switch(drawMode)
{
case dmSelectEntity:
{
drawMode=dmNormal;
selectNo=-1;
g_pDoc->UpdateAllViews(NULL);
break;
}
default:
{
drawMode=dmNormal;
}
}*/
CView::OnLButtonUp(nFlags, point);
}
BOOL CLeftView::MouseOn(CPoint point)
{
if (index>=1)
{
CGPoint *mousePoint=new CGPoint();
COperation::ScreenToReal(mousePoint,point,LEFT);
vector mouseVector;
SetStartPoint(mousePoint);
COperation::CaculateVector(mouseVector,mousePoint,startPoint);
if (COperation::Ray_Hit(startPoint,mouseVector,LEFT))
{
return TRUE;
}
}
return FALSE;
}
void CLeftView::SetStartPoint(CGPoint *mousePoint)
{
startPoint->x=300;
startPoint->y=mousePoint->y;
startPoint->z=mousePoint->z;
}
void CLeftView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
Invalidate(FALSE);
}
void CLeftView::OnRButtonDown(UINT nFlags, CPoint point)
{
if(opOn)
{
opOn = false;
}
if(loftSampleOn)
{
loftSampleOn = false;
}
if(loftTrackOn)
{
loftTrackOn = false;
}
selectNo = -1;
opPointIndex = 0;
CView::OnRButtonDown(nFlags, point);
}