Exemplo n.º 1
0
/*****************************************************************
関数名 : DrawMain
機能	: メイン画面の描画
引数	: なし
出力	: なし
*****************************************************************/
void DrawMain()
{
	SDL_FillRect(gMainWindow,NULL,0x101010);
	if(mState == MAIN_RESULT) //結果画面
		DrawResult();
	else
		DrawShip();

	if(mState == MAIN_COMMAND) //コマンド入力
		DrawCommand();
	else if(mState == MAIN_MOVE){ //コマンド適用
		DrawShot();
		boxColor(gMainWindow, 0, 0, F_WIDTH, HEIGHT, 0x00000040);
	}
	SDL_Flip(gMainWindow);
}
Exemplo n.º 2
0
void PasPlay::Draw(){
// 描画処理
	mBackground->Draw();					// 背景
	mUnitAdmin->Draw();						// ゲームオブジェクト
	DrawPlayerStatusBar(200);				// ステータスバー

	if(flgWarning)	{ DrawWarning();	}	// ワーニング

	BoardStatus tmpBoard;
	mScoreBoard->Draw(GetBoardStatus(&tmpBoard));	// スコアボード

	/*==  ================*/
	if(flgStart)	{ DrawStart();		}	// ミッションスタート
	if(flgClear)	{ DrawClear();		}	// ミッションクリア
	if(flgGameOver)	{ DrawGameOver();	}	// ゲームオーバー
	if(flgResult)	{ DrawResult();		}	// リザルト

//	DrawDebug();
}
Exemplo n.º 3
0
int Game::Draw(){
	ClearScreen();
	glLoadIdentity();
	camera->Update();

	//描画処理
	switch(phase){
	case MENU:
		DrawMenu();
		break;
	case PLAY:
		DrawPlay();
		break;
	case RESULT:
		DrawResult();
		break;
	}

	SwapScreen();
	return 0;
}
Exemplo n.º 4
0
CResult * CMarkovChain::OnCMarkovChain(CDataInterface *pDataInterface, string VO)
{
	CResult * pResult;
	pResult = new CResult("马尔可夫链");
	m_pResult = pResult;
	m_pDataInterface = pDataInterface;

	if (!GetValueFromVo(pDataInterface, VO))
	{
		CTString strWarning = "读取参数发生错误,请重新运行!";
		CRsltElementText * pWarningTextRslt = new CRsltElementText( "错误!" );
		pWarningTextRslt->AddString( strWarning );
		m_pResult->Add( pWarningTextRslt );
		return pResult;
	}
	
	CDWordArray indexary;
	CDoubleMatrix Data_Matrix;
	indexary.Add(m_nUserID);
	indexary.Add(m_nPath);
//	if (m_nTime > -1)
//		indexary.Add(m_nTime);

	m_nRow = pDataInterface->GetColsData(indexary, Data_Matrix, 0);//取回界面数据
//	if (m_nTime > -1)
//	{
//		CDoubleVector tempSort_vec = Data_Matrix(2);
//		CIntVector tempSort_id(m_nRow);
//		tempSort_vec.Sort(tempSort_id);
//		m_ID_vec.create(m_nRow);
//		m_Path_vec.create(m_nRow);
//		for (int j=0; j<m_nRow; j++)
//		{
//			m_ID_vec(j) = Data_Matrix(0, tempSort_id(j)-1);
//			m_Path_vec(j) = Data_Matrix(1, tempSort_id(j)-1);
//		}
//	}
//	else
	{
		m_ID_vec = Data_Matrix(0);
		m_Path_vec = Data_Matrix(1);
	}
	
	if (Main() )
	{
		DrawResult();
	}
	else
	{
		CTString strWarning = "数据无法计算,请重新运行!";
		CRsltElementText * pWarningTextRslt = new CRsltElementText( "错误!" );
		pWarningTextRslt->AddString( strWarning );
		m_pResult->Add( pWarningTextRslt );
		return pResult;
	}

//	if (m_bSaveModle)
//	{
//		...
//	}

	return pResult;
}
Exemplo n.º 5
0
CResult * CMarkovChain::OnMorkovChainPred(CDataInterface *pDataInterface, string VO)//外部调用预测函数
{
	m_pResult = new CResult("线性回归模型预测结果");
	m_pDataInterface = pDataInterface;
	if (!GetPredValueVo(pDataInterface, VO))//读参数及模型
	{
		CRsltElementText * pWarningTextRslt = new CRsltElementText( "错误!" );
		pWarningTextRslt->AddString( "模型参数有误,无法运行。" );
		m_pResult->Add( pWarningTextRslt );
		return m_pResult;
	}
//读取数据
	CDWordArray indexary;
	CDoubleMatrix Data_Matrix;
	indexary.Add(m_nUserID);
	indexary.Add(m_nPath);
	m_nRow = pDataInterface->GetColsData(indexary, Data_Matrix, 0);//取回界面数据
	m_ID_vec = Data_Matrix(0);
	m_Path_vec = Data_Matrix(1);
	CDoubleVector start_vec(m_nRow);
	CDoubleVector pairID_vec(m_nRow);
	CDoubleVector length_vec(m_nRow, 0);
	int i=0, L, id=0;
// 数据准备(Preprocessing) begin
//
	while (i < m_nRow) 
	{
		L=0;
		start_vec(id) = i;
		pairID_vec(id) = m_ID_vec(i);
		while (pairID_vec(id) == m_ID_vec(i)) 
		{
			length_vec(id)++;
			i++;
			if (i >= m_nRow) 
			{
				break;
			}
		}
		id++;
	}
	m_nTotalID = id;
    start_vec.resize(m_nTotalID);
	pairID_vec.resize(m_nTotalID);
	length_vec.resize(m_nTotalID);
//数据准备(Preprocessing) end

//开始计算
	int k, t;
	CDoubleMatrix responsibility(m_nTotalID, m_nCluster);
	for (i=0; i<m_nTotalID; i++)
	{
		L=length_vec(i);
		for (k=0; k<m_nCluster; k++)
		{
			double temp = 1;
			for (t=start_vec(i); t<start_vec(i)+L-1; t++)
			{
				temp *= m_Theta_Trans[k](m_Path_vec(t)-1,m_Path_vec(t+1)-1);
			}
			responsibility(i,k) = temp;
		}
	}
	for (i=0; i<m_nCluster; i++) // Normalization of the responsibilities
	{
		double s = 0;
		for (k=0; k<m_nCluster; k++)
		{
			s = s + responsibility(i,k);
		}
		for (k=0; k<m_nCluster; k++)
		{
			responsibility(i,k) = responsibility(i,k)/s;
		}
	}

	m_VecClus.create(m_nTotalID);
	for (i=0; i<m_nTotalID; i++)
	{
		int which = 0;
		for (k=0; k<m_nCluster; k++)
		{
			if (responsibility(i, which) > responsibility(i,k))
			{
				which = k;
			}
		}
		m_VecClus(i) = which;
	}
//完成计算
	DrawResult();
	return m_pResult;
}
Exemplo n.º 6
0
void  main()
{
	char message[100];
	cvNamedWindow("template");
	cvNamedWindow("sampling");
	cvNamedWindow("result");

	// initialize
	sprintf_s(message, IMAGE_SEQ_FILE_NAME, 0);
	IplImage* saveImage = cvLoadImage(message, 0);
	if(GAUSSIAN_BLUR > 0)
		cvSmooth(saveImage, saveImage, CV_GAUSSIAN, GAUSSIAN_BLUR, GAUSSIAN_BLUR);

	int width = saveImage->width;
	int height = saveImage->height;
	int startX = (width-TEMPLATE_WIDTH)/2;
	int startY = (height-TEMPLATE_HEIGHT)/2;
	float q = TEMPLATE_WIDTH * TEMPLATE_HEIGHT;
	
	IplImage* inputImage = NULL;
	IplImage* resultImage = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
	IplImage* templateImage = cvCreateImage(cvSize(TEMPLATE_WIDTH, TEMPLATE_HEIGHT), IPL_DEPTH_8U, 1);
	IplImage* samplingImage = NULL;

	// set template image
	CvRect rect = cvRect(startX, startY, TEMPLATE_WIDTH, TEMPLATE_HEIGHT);
	cvSetImageROI(saveImage, rect);
	cvCopyImage(saveImage, templateImage);
	cvShowImage("template", templateImage);
	cvResetImageROI(saveImage);
	cvReleaseImage(&saveImage);

	// initial homography
	windage::Matrix3 homography(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
	homography._13 = startX;
	homography._23 = startY;
	windage::Matrix3 e = homography;

	// Template based Tracking using Inverse Compositional
	windage::InverseCompositional* ic = new windage::InverseCompositional(TEMPLATE_WIDTH, TEMPLATE_HEIGHT);
	ic->AttatchTemplateImage(templateImage);
	ic->SetInitialHomography(e);
	ic->Initialize();

	// homography update stack
	std::vector<windage::Matrix3> homographyList;

	cvWaitKey();

	float sumTime = 0.0;
	int sumIter = 0;
	bool processing =true;
	int k = 0;
	while(processing)
	{
		if(k >= IMAGE_SEQ_COUNT)
			processing = false;

		// load image
		if(inputImage) cvReleaseImage(&inputImage);
		sprintf_s(message, IMAGE_SEQ_FILE_NAME, k);
		inputImage = cvLoadImage(message, 0);
		if(GAUSSIAN_BLUR > 0)
			cvSmooth(inputImage, inputImage, CV_GAUSSIAN, GAUSSIAN_BLUR, GAUSSIAN_BLUR);

		cvCvtColor(inputImage, resultImage, CV_GRAY2BGR);

		// processing
		int64 startTime = cvGetTickCount();
		
		float error = 0.0;
		float delta = 1.0;
		int iter = 0;
		homographyList.clear();
		for(iter=0; iter<MAX_ITERATION; iter++)
		{
			error = ic->UpdateHomography(inputImage, &delta);
			homography = ic->GetHomography();
			samplingImage = ic->GetSamplingImage();

			homographyList.push_back(homography);

//			if(delta < HOMOGRAPHY_DELTA)
//				break;
		}
		int64 endTime = cvGetTickCount();
		k++;
		sumIter+= iter;

		// draw result
		int count = homographyList.size();
		for(int i=0; i<count; i++)
 			DrawResult(resultImage, homographyList[i], CV_RGB(((count-i)/(float)count) * 255.0, (i/(float)count) * 255.0, 0), 1);
 		
		double processingTime = (endTime - startTime)/(cvGetTickFrequency() * 1000.0);
		sprintf_s(message, "%03d >> processing time : %.2lf ms (%02d iter), error : %.2lf", k, processingTime, iter, error);
		std::cout << message << std::endl;
		sumTime += processingTime;

		windage::Utils::DrawTextToImage(resultImage, cvPoint(5, 15), message, 0.6);

		// draw image
		cvShowImage("sampling", samplingImage);
		cvShowImage("result", resultImage);

		char ch = cvWaitKey(1);
		switch(ch)
		{
		case ' ':
			{
				char tempch = cvWaitKey(0);
				if(tempch == 's' || tempch == 'S')
				{
					cvSaveImage("ICAlgorithm.jpg", resultImage);
				}
			}
			break;
		case 'i':
		case 'I':
			k++;
			break;
		case 'o':
		case 'O':
			k-=5;
			break;
		case 'q':
		case 'Q':
			processing = false;
			break;
		}

	}

	std::cout << "average iteration : " << sumIter/(float)IMAGE_SEQ_COUNT << std::endl;
	std::cout << "average processing ime : " << sumTime/(float)IMAGE_SEQ_COUNT << " ms" << std::endl;

	cvReleaseImage(&resultImage);
	cvDestroyAllWindows();
}
Exemplo n.º 7
0
void  main()
{
	char message[100];
	cvNamedWindow("template");
	cvNamedWindow("sampling");
	cvNamedWindow("result");

	// initialize
	int width = WIDTH;
	int height = HEIGHT;
	int startX = (width-TEMPLATE_WIDTH)/2;
	int startY = (height-TEMPLATE_HEIGHT)/2;
	
	IplImage* inputImage = NULL;
	IplImage* grayImage = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
	IplImage* resultImage = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
	IplImage* templateImage = cvCreateImage(cvSize(TEMPLATE_WIDTH, TEMPLATE_HEIGHT), IPL_DEPTH_8U, 1);
	IplImage* samplingImage = NULL;

	// initial template & homography
	CvRect rect = cvRect(startX, startY, TEMPLATE_WIDTH, TEMPLATE_HEIGHT);
	windage::Matrix3 homography(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
	homography._13 = startX;
	homography._23 = startY;
	windage::Matrix3 e = homography;

	// Template based Tracking using Inverse Compositional
#if USE_IC
	windage::InverseCompositional* tracker = new windage::InverseCompositional(TEMPLATE_WIDTH, TEMPLATE_HEIGHT);
#endif
#if USE_ESM
	windage::HomographyESM* tracker = new windage::HomographyESM(TEMPLATE_WIDTH, TEMPLATE_HEIGHT);
#endif
	tracker->SetInitialHomography(e);

	// homography update stack
	std::vector<windage::Matrix3> homographyList;

	// camera
	CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);

	bool isTrained = false;
	bool processing =true;
	while(processing)
	{
		inputImage = cvRetrieveFrame(capture);
		cvResize(inputImage, resultImage);
		cvCvtColor(resultImage, grayImage, CV_BGR2GRAY);
		
		if(GAUSSIAN_BLUR > 0)
			cvSmooth(grayImage, grayImage, CV_GAUSSIAN, GAUSSIAN_BLUR, GAUSSIAN_BLUR);

		// processing
		int64 startTime = cvGetTickCount();
		
		float error = 0.0;
		float delta = 1.0;
		int iter = 0;
		homographyList.clear();
		for(iter=0; iter<MAX_ITERATION; iter++)
		{
			error = tracker->UpdateHomography(grayImage, &delta);
			homography = tracker->GetHomography();
			homographyList.push_back(homography);

//			if(delta < HOMOGRAPHY_DELTA)
//				break;
		}
		int64 endTime = cvGetTickCount();
		samplingImage = tracker->GetSamplingImage();

		// draw result
		int count = homographyList.size();
		for(int i=0; i<count; i++)
 			DrawResult(resultImage, homographyList[i], CV_RGB(((count-i)/(double)count) * 255.0, (i/(double)count) * 255.0, 0), 1);
 		
		double processingTime = (endTime - startTime)/(cvGetTickFrequency() * 1000.0);
		sprintf_s(message, "processing time : %.2lf ms (%02d iter), error : %.2lf", processingTime, iter, error);
		std::cout << message << std::endl;

#if USE_IC
		windage::Utils::DrawTextToImage(resultImage, cvPoint(5, 15), "Inverse Compositional", 0.6);
#endif
#if USE_ESM
		windage::Utils::DrawTextToImage(resultImage, cvPoint(5, 15), "Efficient Second-order Minimization", 0.6);
#endif
		windage::Utils::DrawTextToImage(resultImage, cvPoint(5, 35), message, 0.6);

		// draw image
		cvShowImage("sampling", samplingImage);
		cvShowImage("result", resultImage);

		char ch = cvWaitKey(1);
		switch(ch)
		{
		case ' ':
			cvSetImageROI(grayImage, rect);
			cvCopyImage(grayImage, templateImage);
			cvShowImage("template", templateImage);
			cvResetImageROI(grayImage);

			tracker->AttatchTemplateImage(templateImage);
			tracker->SetInitialHomography(e);
			tracker->Initialize();
			break;
		case 'r':
		case 'R':
			delete tracker;
			tracker = NULL;
#if USE_IC
			tracker = new windage::InverseCompositional(TEMPLATE_WIDTH, TEMPLATE_HEIGHT);
#endif
#if USE_ESM
			tracker = new windage::HomographyESM(TEMPLATE_WIDTH, TEMPLATE_HEIGHT);
#endif
			tracker->SetInitialHomography(e);
			break;
		case 'q':
		case 'Q':
			processing = false;
			break;
		}

	}

	cvReleaseCapture(&capture);

	cvReleaseImage(&grayImage);
	cvReleaseImage(&resultImage);
	cvDestroyAllWindows();
}
Exemplo n.º 8
0
//描画
int CSystem::Draw()
{
	int i;
	RECT rect;

	//ステージリザルト
	if( state == SYSTEM_RESULT ){
		switch( result_mode ) {
		case 0:
			DrawResult(200,100*(RESULT_COUNT-result_count),alpha(255));
			break;
		case 1:
			DrawResult(200,0,alpha(255));
			break;
		case 2:
			DrawResult(200,100*result_count,alpha(255));
			break;
		}
	}

	//システム背景
	if( draw_system ) {
		//上
		SetRect(&rect,0,0,256,48);
		imgSystem1.DrawRect(0,0,rect);

		SetRect(&rect,0,48,256,96);
		imgSystem1.DrawRect(256,0,rect);
		
		SetRect(&rect,0,96,128,144);
		imgSystem1.DrawRect(512,0,rect);

		//下
		SetRect(&rect,0,144,256,176);
		imgSystem1.DrawRect(0,448,rect);

		SetRect(&rect,0,176,256,208);
		imgSystem1.DrawRect(256,448,rect);

		SetRect(&rect,128,96,256,144);
		imgSystem1.DrawRect(512,448,rect);

		//左
		SetRect(&rect,0,0,24,256);
		imgSystem2.DrawRect(0,48,rect);

		SetRect(&rect,24,0,48,144);
		imgSystem2.DrawRect(0,304,rect);

		//右
		SetRect(&rect,48,0,88,256);
		imgSystem2.DrawRect(600,48,rect);

		SetRect(&rect,88,0,128,144);
		imgSystem2.DrawRect(600,304,rect);

		//ライフ
		for(i=0;i<life;++i){
			imgLife.Draw(93+i*24,7,alpha(255),1,(double)count/36*2);
		}
		//ボム
		for(i=0;i<bomb;++i){
			imgBomb.Draw(93+i*24,23,alpha(255),1.0+0.1*sin((double)count/36*10));
		}

		//魔法陣
		Sun3D.SetBlendingType(BLEND_ADD);
		imgMaho.Draw(414,440,alpha(255),0.8,(double)count/36);
		Sun3D.SetBlendingType(BLEND_NORMAL);

		//難易度
		SetRect(&rect,0,16+16*g_pGame->diff,88,32+16*g_pGame->diff);
		imgMoji.DrawRect(50,454,rect);

		//数値
		DrawNumber(480,7,score,8);
		DrawNumber(480,23,hiscore,8);
		if( power < 1000 ) {
			DrawNumber(340,7,power,3);
		}
		else {
			SetRect(&rect,208,0,248,16);
			imgMoji.DrawRect(340,7,rect);
		}
		DrawNumber(340,23,graze,3);

		//FPS
		DrawNumber(360,454,SunApp.m_obfps,2);

		//弾数
		DrawNumber(240,454,g_lTama.GetSize(),3);
		if( g_lTama.GetSize() > bullet )
			bullet = g_lTama.GetSize();

		//フルパワー
		if( fullpower_count > 0 ) {
			SetRect(&rect,0,72,190,96);
			imgMoji2.DrawRect(240,80,rect);
		}
		//スペルカードボーナス
		if( spellbonus_count > 0 ) {
			SetRect(&rect,0,96,120,120);
			imgMoji2.DrawRect(180,100,rect);
			if( spellbonus > 0 ) {
				SetRect(&rect,0,120,72,144);
				imgMoji2.DrawRect(320,100,rect,alpha(255));
				DrawNumber( 550,100,spellbonus,0,xrgb(255,255,255));
			}
			else {
				SetRect(&rect,72,120,144,144);
				imgMoji2.DrawRect(320,100,rect,alpha(255));
			}
		}
	}
	switch(state) {
	case SYSTEM_PAUSE:	//ポーズ中
		{
			SunEffectRect effect;
			SetRect(&effect.m_rect,GAME_LEFT,GAME_TOP,GAME_RIGHT,GAME_BOTTOM);
			effect.m_color = argb(200,0,0,0);
			effect.Draw();

			SetRect(&rect,0,128,96,160);
			imgMoji.DrawRect(250,130,rect);

			SetRect(&rect,0,160,216,191);
			imgMoji.DrawRect(200,200,rect,alpha(128+127*(pause_select==0)));

			SetRect(&rect,0,192,168,224);
			imgMoji.DrawRect(220,250,rect,alpha(128+127*(pause_select==1)));

			//リプレイモードでは「最初からやり直す」はなし
			if( g_pTitle->title_select != 3 ) {
				SetRect(&rect,0,224,254,255);
				imgMoji.DrawRect(200,300,rect,alpha(128+127*(pause_select==2)));
			}
		}
		break;
	case SYSTEM_GAMEOVER://ゲームオーバー
		{
			SunEffectRect effect;
			SetRect(&effect.m_rect,GAME_LEFT,GAME_TOP,GAME_RIGHT,GAME_BOTTOM);
			effect.m_color = argb(200,0,0,0);
			effect.Draw();

			SetRect(&rect,0,0,256,24);
			imgMoji2.DrawRect(200,130,rect);

			SetRect(&rect,0,24,216,48);
			imgMoji2.DrawRect(220,200,rect,alpha(128+127*(gameover_select==0)));

			SetRect(&rect,0,48,200,72);
			imgMoji2.DrawRect(220,250,rect,alpha(128+127*(gameover_select==1)));

			SetRect(&rect,144,120,224,144);
			imgMoji2.DrawRect(420,300,rect);
			DrawNumber(420+40,303,continue_rest,1);
		}
		break;
	case SYSTEM_REPLAY://リプレイ保存
		{
			SunEffectRect effect;
			SetRect(&effect.m_rect,GAME_LEFT,GAME_TOP,GAME_RIGHT,GAME_BOTTOM);
			effect.m_color = argb(200,0,0,0);
			effect.Draw();

			SetRect(&rect,0,144,256,168);
			imgMoji2.DrawRect(200,130,rect);

			if( continue_dirty == 0 ) {
				SetRect(&rect,120,96,200,120);
				imgMoji2.DrawRect(220,200,rect,alpha(128+127*(replay_select==0)));

				SetRect(&rect,200,96,256,120);
				imgMoji2.DrawRect(220,250,rect,alpha(128+127*(replay_select==1)));
			}else{
				SetRect(&rect,0,168,256,216);
				imgMoji2.DrawRect(220,200,rect);
			}
		}
		break;
	case SYSTEM_RESUME://ゲーム再開中
		{
			SunEffectRect effect;
			SetRect(&effect.m_rect,GAME_LEFT,GAME_TOP,GAME_RIGHT,GAME_BOTTOM);
			effect.m_color = argb(200,0,0,0);
			effect.Draw();
		}
		break;
	}
	return 1;
}