www.pudn.com > final_6.rar > Frontview.cpp


// Frontview.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "CG.h" 
#include "Frontview.h" 
#include "Operation.h" 
#include "Base.h" 
#include "CGDoc.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CFrontview 
 
IMPLEMENT_DYNCREATE(CFrontview, CView) 
 
CFrontview::CFrontview() 
{ 
  g_pFrontView=this;  
  startPoint=new CGPoint(); 
  prePoint = NULL; 
} 
 
CFrontview::~CFrontview() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CFrontview, CView) 
	//{{AFX_MSG_MAP(CFrontview) 
	ON_WM_LBUTTONDOWN() 
	ON_WM_LBUTTONUP() 
	ON_WM_MOUSEMOVE() 
	ON_WM_RBUTTONDOWN() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CFrontview drawing 
 
void CFrontview::OnDraw(CDC* pDC) 
{ 
	CCGDoc* pDoc =(CCGDoc*)GetDocument(); 
	// TODO: add draw code here 
    CRect rc; 
	GetClientRect(&rc); 
   	pDC->FillRect(rc,backBrush); 
	pDC->TextOut(10,10,"Front 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->DrawFront(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->DrawFront(pDC); 
	} 
 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CFrontview diagnostics 
 
#ifdef _DEBUG 
void CFrontview::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CFrontview::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CFrontview message handlers 
 
void CFrontview::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	 switch (drawMode) 
	  { 
	     case dmNormal: 
			 { 
			     
				 break; 
			 } 
		 case dmMove: 
			 { 
			    if (MouseOn(point)) 
				{   
			      g_pDoc->UpdateAllViews(NULL); 
				  prePoint=point; 
				} 
			 } 
		 case dmRotate: 
			 { 
			    if (MouseOn(point)) 
				{   
			      g_pDoc->UpdateAllViews(NULL); 
				  prePoint=point; 
				} 
				break; 
			 } 
		case dmZoom: 
			 { 
			    if (MouseOn(point)) 
				{   
			      g_pDoc->UpdateAllViews(NULL); 
				  prePoint=point; 
				} 
				break; 
			 } 
		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,FRONT,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,FRONT,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,FRONT,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,FRONT); 
					 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,FRONT); 
					 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,FRONT)) 
			   { 
			      g_pDoc->UpdateAllViews(NULL); 
				  prePoint=point; 
			   }   
			 break; 
		 } 
		 default: 
		 { 
		  
		 } 
	  } 
 
 
 
	CView::OnLButtonDown(nFlags, point); 
} 
 
void CFrontview::OnLButtonUp(UINT nFlags, CPoint point)  
{ 
    selectNo=-1; 
	selectLight=-1; 
    g_pDoc->UpdateAllViews(NULL); 
  	CView::OnLButtonUp(nFlags, point); 
} 
 
void CFrontview::OnMouseMove(UINT nFlags, CPoint point)  
{ 
	switch (drawMode) 
	{ 
	   case dmNormal: 
		   { 
			   
			   break; 
		   } 
	   case dmMove: 
		   { 
			   if (selectNo!=-1) 
			   {        
					   COperation::MoveEntity(point,prePoint,FRONT); 
					   g_pDoc->UpdateAllViews(NULL); 
                       prePoint=point; 
			   } 
    	       break; 
		   } 
	   case dmRotate: 
		   { 
			    if (selectNo!=-1) 
			   {        
					   COperation::RotateEntity(point,prePoint,FRONT); 
					   g_pDoc->UpdateAllViews(NULL); 
                       prePoint=point; 
			   } 
					   break; 
		   } 
	case dmZoom: 
		   { 
		       if (selectNo!=-1) 
			   { 
				   COperation::ZoomEntity(point,prePoint,FRONT); 
				   g_pDoc->UpdateAllViews(NULL); 
                   prePoint=point; 
			   } 
		       break; 
		   } 
		case dmExtrude: 
		   { 
		       if (selectNo!=-1) 
			   { 
				   COperation::ExtrudeEntity(point,prePoint,FRONT); 
				   g_pDoc->UpdateAllViews(NULL); 
                   prePoint=point; 
			   } 
		       break; 
		   } 
       case dmMovePointL: 
		   {   
			   if (selectLight!=-1) 
			   { 
				   COperation::MoveLight(point,prePoint,FRONT); 
				   g_pDoc->UpdateAllViews(NULL); 
				   prePoint=point; 
			   } 
		       break; 
		   } 
	   default: 
		   {   
		    
		   } 
	} 
	 
	CView::OnMouseMove(nFlags, point); 
} 
 
BOOL CFrontview::MouseOn(CPoint point) 
{ 
    if (index>=1) 
	{   
	CGPoint *mousePoint=new CGPoint(); 
	COperation::ScreenToReal(mousePoint,point,FRONT); 
	vector mouseVector; 
	SetStartPoint(mousePoint); 
	COperation::CaculateVector(mouseVector,mousePoint,startPoint); 
   	if (COperation::Ray_Hit(startPoint,mouseVector,FRONT)) 
	{ 
   	 return TRUE; 
	} 
 	} 
     return FALSE; 
} 
 
void CFrontview::SetStartPoint(CGPoint *mousePoint) 
{ 
    startPoint->x=mousePoint->x; 
	startPoint->y=mousePoint->y; 
	startPoint->z=300; 
} 
 
void CFrontview::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)  
{ 
    Invalidate(FALSE); 
} 
 
void CFrontview::OnRButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	if(opOn) 
	{ 
		opOn = false; 
	} 
	if(loftSampleOn) 
	{ 
		loftSampleOn = false; 
	} 
	if(loftTrackOn) 
	{ 
		loftTrackOn = false; 
	} 
	selectNo = -1; 
	opPointIndex = 0; 
	CView::OnRButtonDown(nFlags, point); 
}