Exemple #1
0
void CDrawTextTextScene::Draw( CGraphics* pGraphic )
{
	CScene::Draw(pGraphic);
	pGraphic->DrawTextW(L"吴德宏",100,300,*sFontConfig.GetFont(3));	
	CPosition pts[5];
	pts[4] = CPosition(800,900);
	pts[3] = CPosition(600,500);
	pts[2] = CPosition(200,600);
	pts[1] = CPosition(200,300);
	pts[0] = CPosition(30,200);
	int a = GetTickCount();
	pGraphic->Polygon(pts,5,CRGB(255,124,122));
	DebugTrace(Trace_Info,"Polygon Time:%d\n",GetTickCount() - a);
	wchar_t* wcs = L"这是沿线绘制吴德宏啊伍德WoodHome";
	pGraphic->DrawTextW(wcs,pts,5,*sFontConfig.GetFont(2),50.0f);
	pGraphic->LineDDA(pts[0],pts[1],0,CRGB(255,124,122));
	pGraphic->LineDDA(pts[1],pts[2],0,CRGB(255,124,122));
	pGraphic->LineDDA(pts[2],pts[3],0,CRGB(255,124,122));
	pGraphic->LineDDA(pts[3],pts[4],0,CRGB(255,124,122));
	pts[0]=CPosition(600,20);
	pts[1]=CPosition(800,550);
	pGraphic->LineDDA(pts[0], 20 ,pts[1] ,10,CRGB(124,124,122));
	a = GetTickCount();
	pGraphic->DrawTextW(L"这是不等宽线",pts,2,*sFontConfig.GetFont(1),20);
	DebugTrace(Trace_Info,"不等宽线 Time:%d\n",GetTickCount() - a);
	pts[1]=CPosition(700,20);
	pts[0]=CPosition(200,120);
	a = GetTickCount();
	pGraphic->LineDDA(pts[0] ,pts[1] ,15,CRGB(124,124,122));
	pGraphic->DrawTextW(L"这是等宽线",pts,2,*sFontConfig.GetFont(1),20);
	DebugTrace(Trace_Info,"等宽线 Time:%d\n",GetTickCount() - a);
}
void CQueueMazeSln::Draw() //画出当前的slnMap
{
	if(slnMap.IsEmpty()){cout<<"Error:No Map Value."<<endl;}
	else 
	{
		//cout<<endl;
		cout<<"W-Speed Up;S-Speed Down;X-Pause;   Refresh Interval: "<<refreshInterval<<"ms"<<endl;
		cout<<"☆ is Entrance	★ is Exit	Steps: "<<round<<endl;
		if(refreshInterval!=0)
		{
			for(int h=0;h<slnMap.GetHeight();h++)
			{
				for(int w=0;w<slnMap.GetWidth();w++)
				{
					switch(slnMap.GetValue(CPosition(h,w)))
					{
						// ☆★▲△◇◆○●
						case MAPVALUE_WALL:	cout<<"■";break;
						case MAPVALUE_WAY:	cout<<"  ";break;
						case MAPVALUE_IN:	cout<<"☆";break;
						case MAPVALUE_OUT:	cout<<"★";break;
						case MAPVALUE_INPATH:	cout<<"●";break;
						case MAPVALUE_USED:	cout<<"○";break;  // u是表示踏足过的地方
						default:break;
					}
				}
				cout<<endl;
			}
			cout<<endl;
		}
	}
}
Exemple #3
0
void CGlutWindow::mouseMoveEvent(int x,int y) {
    
	if (m_bExternalMouseHandling) {
		if (handleMoveEvent(x,y)) {
			glutPostRedisplay();
		}
		return;
	}
    
	
	CArcBall *pArcball = NULL;
	switch(m_nInteractionMode) {
		default:
		case MOVE_CAMERA:
			pArcball = m_pCameraArcball;
			break;
		case MOVE_LIGHT:
			pArcball = m_pLightArcball;
			break;
	}
    
	CPosition pos(double(x)/double(m_nWidth),double(y)/double(m_nHeight));
    
	CPosition drag = pos-m_vecMouseDown;
    
	if ((m_bRotating) && (m_nMouseState & (MBUTTON_LEFT))) {
		pArcball->setMouse(CPosition(x, m_nHeight-1- y));
		glutPostRedisplay();
        
	} else if ((m_bDragging) && (m_nMouseState & MBUTTON_MIDDLE)) {
		
		m_dTranslateX +=  2.0 * drag[0];
		m_dTranslateY += -2.0 * drag[1];
        
		printf("%f %f\n",m_dTranslateX, m_dTranslateX/(1+dZoom));
		printf("%f %f\n",m_dTranslateY, m_dTranslateY/(1+dZoom));
		printf("%f \n",dZoom);
        
		if (m_dTranslateX >  (1+dZoom)) m_dTranslateX =  (1+dZoom);
		if (m_dTranslateX < -(1+dZoom)) m_dTranslateX = -(1+dZoom);
		if (m_dTranslateY >  (1+dZoom)) m_dTranslateY =  (1+dZoom);
		if (m_dTranslateY < -(1+dZoom)) m_dTranslateY = -(1+dZoom);
		glutPostRedisplay();
	} else if ((m_bZooming) && (m_nMouseState & MBUTTON_RIGHT )) {
		
		dZoom = 10.0*drag[0];
		
		camera->zoomIn(8*dZoom);
		
		glutPostRedisplay();
	} 
	m_vecMouseDown = pos;
}
Exemple #4
0
void CGlutWindow::resize(int width, int height) {
	m_nWidth = width; 
	m_nHeight = height;
	glViewport(0, 0, (GLsizei) width, (GLsizei) height);
    
	m_pCameraArcball->place(CPosition(width/2, height/2), 
                            0.5 * sqrt(double(width * width + height * height)));
    
	glViewport(0,0, (GLint) m_nWidth -1, (GLint) m_nHeight-1);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
    
	if ( 0 != camera ) {
		camera->resizeViewport(  m_nWidth / (isStereo ? 2 : 1), m_nHeight );
	}
	glMatrixMode(GL_MODELVIEW);
    
}
Exemple #5
0
void CGlutWindow::mouseButtonEvent(int button, int state,int x,int y) {
    
	if ((false == m_bDragging) && (false == m_bZooming) && (false == m_bRotating)) {
		if (handleButtonEvent(button, state,x,y)) {
			m_bExternalMouseHandling = true;		
			return;
		}
	}
    
	m_bExternalMouseHandling = false;	
    
	CArcBall *pArcball = NULL;
	switch(m_nInteractionMode) {
		default:
		case MOVE_CAMERA:
			pArcball = m_pCameraArcball;
			break;
		case MOVE_LIGHT:
			pArcball = m_pLightArcball;
			break;
	}
    
	switch(state) {
		case GLUT_DOWN:
        {
            m_vecMouseDown.set(double(x)/double(m_nWidth),double(y)/double(m_nHeight));
            
            switch (button) {
                case GLUT_LEFT_BUTTON:
                {
                    m_nMouseState |= (MBUTTON_LEFT);
                    pArcball->setMouse( CPosition(x, m_nHeight-1-y));
                    pArcball->startDragging();
                    m_bRotating = true;
                }
                    break;
                case GLUT_RIGHT_BUTTON:
                {
                    m_nMouseState |= (MBUTTON_RIGHT);	
                    m_bDragging = false;
                    m_bZooming = true;
                }
                    break;
                case GLUT_MIDDLE_BUTTON:
                {
                    m_nMouseState |= (MBUTTON_MIDDLE);	
#ifdef DISABLE_DRAGGING
                    m_bDragging = false;
#else
                    m_bDragging = true;
#endif
                    m_bZooming = false;
                }
                    break;
                default:
                    break;
            }
            break;
		case GLUT_UP:
			{
				switch (button) {
					case GLUT_LEFT_BUTTON:
						m_nMouseState ^= MBUTTON_LEFT;
						pArcball->finishDragging();
                        
						break;
					case GLUT_RIGHT_BUTTON:
						m_nMouseState ^= MBUTTON_RIGHT;
						break;
					case GLUT_MIDDLE_BUTTON:
						m_nMouseState ^= MBUTTON_MIDDLE;
						break;
					default:
						break;
				}
				m_bRotating = false;
				m_bDragging = false;
				m_bZooming  = false;
				m_bExternalMouseHandling = false;
            }
        }
            
            
	}
}
bool CQueueMazeSln::Run(int refInterval/*=100*/)
{
	if(!HasMap()) return false;

	refreshInterval=refInterval;


	int x = slnMap.GetInPos().GetW();
	int y = slnMap.GetInPos().GetH();


	path.InitQueue(x,y);
	QueuePtr M;//广度优先的上一层节点信息


	int (*dir)[2]; //指向数组的指针!
	int dir4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};  // 顺序:下右上左
	int dir8[8][2]={{1,1},{1,0},{0,1},{1,-1},{-1,1},{-1,0},{0,-1},{-1,-1}};  // 顺序:右下,下,右,左下,右上,上,左,左上
	if(slnMap.GetDirectionMode()==4){dir=dir4;}
	else {dir=dir8;}

	bool isFinished=false;
	bool findAccess=false;
	bool B;
	char v;
	int count = 0;



	system("cls");
	Draw();
	Sleep(refreshInterval);
	
		

		do
		{
			GetInput();
			M=path.Q.front;
			v=slnMap.GetValue(CPosition(y,x-1));
			if(x!=0 &&v!=MAPVALUE_WALL &&v!=MAPVALUE_USED && v!= MAPVALUE_IN)//上
			{
				if(v!=MAPVALUE_OUT)
				{
					slnMap.SetValue(CPosition(y,x-1),MAPVALUE_USED);
					path.EnQueue(x-1,y,M);
					system("cls");
					round++;
					Draw();
					
					Sleep(refreshInterval);
				}
				else
				{
					refreshInterval = 100;
					findAccess=true;
					break;
				}
			}
			//-----------------------------------------------------
			v=slnMap.GetValue(CPosition(y+1,x-1));
			if(x!=0&&y!= slnMap.GetHeight()  &&v!=MAPVALUE_WALL &&v!=MAPVALUE_USED && v!= MAPVALUE_IN)//上
			{
				if(v!=MAPVALUE_OUT)
				{
					slnMap.SetValue(CPosition(y+1,x-1),MAPVALUE_USED);
					path.EnQueue(x-1,y+1,M);
					system("cls");
					round++;
					Draw();
					
					Sleep(refreshInterval);
				}
				else
				{
					refreshInterval = 100;
					findAccess=true;
					break;
				}
			}
			//-----------------------------------------------------
			v=slnMap.GetValue(CPosition(y+1,x));
			if(y!= slnMap.GetHeight() &&v!=MAPVALUE_WALL &&v!=MAPVALUE_USED && v!= MAPVALUE_IN)//上
			{
				if(v!=MAPVALUE_OUT)
				{
					slnMap.SetValue(CPosition(y+1,x),MAPVALUE_USED);
					path.EnQueue(x,y+1,M);
					system("cls");
					round++;
					Draw();
					
					Sleep(refreshInterval);
				}
				else
				{
					refreshInterval = 100;
					findAccess=true;
					break;
				}
			}
			//------------------------------------------------------
			v=slnMap.GetValue(CPosition(y+1,x+1));
			if(x!=slnMap.GetWidth()&&y!= slnMap.GetHeight()  &&v!=MAPVALUE_WALL &&v!=MAPVALUE_USED && v!= MAPVALUE_IN)//上
			{
				if(v!=MAPVALUE_OUT)
				{
					slnMap.SetValue(CPosition(y+1,x+1),MAPVALUE_USED);
					path.EnQueue(x+1,y+1,M);
					system("cls");
					round++;
					Draw();
					
					Sleep(refreshInterval);
				}
				else
				{
					refreshInterval = 100;
					findAccess=true;
					break;
				}
			}
			//-----------------------------------------------------
			v=slnMap.GetValue(CPosition(y,x+1));
			if(x!=slnMap.GetWidth() &&v!=MAPVALUE_WALL &&v!=MAPVALUE_USED && v!= MAPVALUE_IN)//上
			{
				if(v!=MAPVALUE_OUT)
				{
					slnMap.SetValue(CPosition(y,x+1),MAPVALUE_USED);
					path.EnQueue(x+1,y,M);
					system("cls");
					round++;
					Draw();
					Sleep(refreshInterval);
				}
				else
				{
					refreshInterval = 100;
					findAccess=true;
					break;
				}
			}
			//------------------------------------------------------
			v=slnMap.GetValue(CPosition(y-1,x+1));
			if(x!=slnMap.GetWidth()&&y!= 0  &&v!=MAPVALUE_WALL &&v!=MAPVALUE_USED && v!= MAPVALUE_IN)//上
			{
				if(v!=MAPVALUE_OUT)
				{
					slnMap.SetValue(CPosition(y-1,x+1),MAPVALUE_USED);
					path.EnQueue(x+1,y-1,M);
					system("cls");
					round++;
					Draw();
					
					Sleep(refreshInterval);
				}
				else
				{
					refreshInterval = 100;
					findAccess=true;
					break;
				}
			}
			//------------------------------------------------------
			
			v=slnMap.GetValue(CPosition(y-1,x));
			if(y!=0 &&v!=MAPVALUE_WALL &&v!=MAPVALUE_USED && v!= MAPVALUE_IN)//上
			{
				if(v!=MAPVALUE_OUT)
				{
					slnMap.SetValue(CPosition(y-1,x),MAPVALUE_USED);
					path.EnQueue(x,y-1,M);
					system("cls");
					round++;
					Draw();
					Sleep(refreshInterval);
				}
				else
				{
					refreshInterval = 100;
					findAccess=true;
					break;
				}
			}
			//------------------------------------------------------
			v=slnMap.GetValue(CPosition(y-1,x-1));
			if(x!=0&&y!= 0  &&v!=MAPVALUE_WALL &&v!=MAPVALUE_USED && v!= MAPVALUE_IN)//上
			{
				if(v!=MAPVALUE_OUT)
				{
					slnMap.SetValue(CPosition(y-1,x-1),MAPVALUE_USED);
					path.EnQueue(x-1,y-1,M);
					system("cls");
					round++;
					Draw();
					
					Sleep(refreshInterval);
				}
				else
				{
					refreshInterval = 100;
					findAccess=true;
					break;
				}
			}
			B=path.DeQueue(x,y,M);
		}while(B==1);



		
	

	if(findAccess)
	{

		if(B==1)
		{
			while(path.MeQueue(x,y,M)==1)
			{
				count++;
				if(slnMap.GetValue(CPosition(y,x))!=MAPVALUE_OUT)
				{
					slnMap.SetValue(CPosition(y,x),MAPVALUE_INPATH);
					system("cls");
					Draw();
				}
				M=M->prier;
			}
		}
		cout<<"A path has been found, the length of the shortest path is "<<count<<endl<<endl;
	}
	else
	{
		cout<<"Sorry,no path can be found."<<endl<<endl;
		return false;
	}

}