////////////////////////////////////
//	  OpenGLによる描画関数
//注：「表示」の「2D/3D」メニューに
//	対応するDrawNoを設定し、それに
//	対応するGLLoop関数のスイッチ文
//	から呼び出します。
////////////////////////////////////
///////////////////
//描画関数Draw2D01
///////////////////
void Draw2D01() {

	static float theta = 0.0f;		//シータ値
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT); 	//ウィンドウを塗りつぶす
	glPushMatrix();
		glRotatef(theta, 0.0f, 0.0f, 1.0f);
		glBegin(GL_TRIANGLES);
			glColor3f(1.0f, 0.0f, 0.0f);	glVertex3f(0.0f, 0.7f, 0.0);	//0.8 x (1.73 / 2)
			glColor3f(0.0f, 1.0f, 0.0f);	glVertex3f(0.7f, -0.4f, 0.0);
			glColor3f(0.0f, 0.0f, 1.0f);	glVertex3f(-0.7f, -0.4f, 0.0);
		glEnd();
	glPopMatrix();
	//ダブルバッファリング
	SwapBuffers(g_hDC);
	theta += 1.0f;
	Sleep(1);
}

void Draw2D02() {

	static float theta = 0.0f;		//シータ値
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT); 	//ウィンドウを塗りつぶす
	glRotatef(theta, 0.0f, 0.0f, 1.0f);
	glPushMatrix();
		glBegin(GL_POLYGON);
			glColor3d(1.0, 0.0, 0.0);	glVertex3d(-0.5, -0.5, 0.0);
			glColor3d(0.0, 1.0, 0.0);	glVertex3d(0.5, -0.5, 0.0);
			glColor3d(0.0, 0.0, 1.0);	glVertex3d(0.5, 0.5, 0.0);
			glColor3d(1.0, 1.0, 0.0);	glVertex3d(-0.5, 0.5, 0.0);
		glEnd();
	glPopMatrix();
	//ダブルバッファリング
	SwapBuffers(g_hDC);
	theta += 0.1f;
	Sleep(1);
}

void Draw2D03() {

	static float theta = 0.0f;		//シータ値
	double offset = 0.5;
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT); 	//ウィンドウを塗りつぶす
	glRotatef(theta, 0.0f, 0.0f, 1.0f);
	double radius = 0.5;
	glPushMatrix();					//左側に線描画の円
		glTranslated(offset, 0, 0);
		glColor3d(1, 1, 0);
		for(double rad = -PAI; rad <= PAI;  rad += 0.1) {
			glBegin(GL_LINES);
				glVertex3d(radius * cos(rad), radius * sin(rad), 0.0);
				glVertex3d(radius * cos(rad + 0.1), radius * sin(rad + 0.1), 0.0);
			glEnd();
		}
	glPopMatrix();					//右側に塗潰し描画の円
	glPushMatrix();
		glTranslated(-offset, 0, 0);
		for(radius = 0.5; radius > 0; radius -= 0.001) {	//半径
			glColor3d(1 - radius, radius, radius / 2);
			for(double rad = -PAI; rad <= PAI;  rad += 0.1) {
				glBegin(GL_LINES);
					glVertex3d(radius * cos(rad), radius * sin(rad), 0.0);
					glVertex3d(radius * cos(rad + 0.1), radius * sin(rad + 0.1), 0.0);
				glEnd();
			}
		}
	glPopMatrix();
	theta += 0.1f;
	//ダブルバッファリング
	SwapBuffers(g_hDC);
}

void Draw2D04() {
}

void Draw2D05() {
}

void Draw3D01() {

	//中心を（0, 0, 0)とする一辺1.0の直方体の頂点
	GLdouble vertex[][3] = {
		{-0.4, -0.4, -0.4},	/* A */
		{0.4, -0.4, -0.4},	/* B */
		{0.4, 0.4, -0.4},	/* C */
		{-0.4, 0.4, -0.4},	/* D */
		{-0.4, -0.4, 0.4},	/* E */
		{0.4, -0.4, 0.4},	/* F */
		{0.4, 0.4, 0.4},	/* G */
		{-0.4, 0.4, 0.4}	/* H */
	};
	//上記頂点の連結線
	int edge[][2] = {
		{0, 1},	/* ア (A-B) */
		{1, 2},	/* イ (B-C) */
		{2, 3},	/* ウ (C-D) */
		{3, 0},	/* エ (D-A) */
		{4, 5},	/* オ (E-F) */
		{5, 6},	/* カ (F-G) */
		{6, 7},	/* キ (G-H) */
		{7, 4},	/* ク (H-E) */
		{0, 4},	/* ケ (A-E) */
		{1, 5},	/* コ (B-F) */
		{2, 6},	/* サ (C-G) */
		{3, 7}	/* シ (D-H) */
	};
	static float theta = 0.0f;			//シータ値
	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();
	/* 図形の回転 */
	glRotated(theta, 0.0, 1.0, 1.0);
	theta += 0.01;
	/* 図形の描画 */
	glColor3d(1.0, 1.0, 0.0);
	glBegin(GL_LINES);
		for (int i = 0; i < 12; i++) {
			glVertex3dv(vertex[edge[i][0]]);
			glVertex3dv(vertex[edge[i][1]]);
		}
	glEnd();
	glFlush();
	//ダブルバッファリング
	SwapBuffers(g_hDC);
}

void Draw3D02() {

	glEnable(GL_DEPTH_TEST);		//陰面消去を行う為の深度処理有効化
	//画面クリア
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	static float theta = 0.0f;			//シータ値
	//ポリゴン描画
	glPushMatrix();
		glRotated(theta, 0.0, 1.0, 0.0);
		theta += 0.05;
		glBegin(GL_TRIANGLES);
			//奥の面
			glColor3f(1.0f, 0.0f, 0.0f);
			glVertex3f(-0.5f, -0.25f, -0.25f);	glVertex3f(0.5f, -0.25f, -0.25f);	glVertex3f(0.0f, 0.616f, 0.0f);
			//右手前面
			glColor3f(0.0f, 1.0f, 0.0f);
			glVertex3f(0.5f, -0.25f, -0.25f);		glVertex3f(0.0f, -0.25f, 0.616f);	glVertex3f(0.0f, 0.616f, 0.0f);
			//左手前面
			glColor3f(0.0f, 0.0f, 1.0f);
			glVertex3f(0.0f, -0.25f, 0.616f);		glVertex3f(-0.5f, -0.25f, -0.25f);	glVertex3f(0.0f, 0.616f, 0.0f);
			//底面
			glColor3f(1.0f, 1.0f, 1.0f);
			glVertex3f(0.5f, -0.25f, -0.25f);	glVertex3f(0.5f, -0.25f, -0.25f);	glVertex3f(0.0f, -0.25f, 0.616f);
		glEnd();
	glPopMatrix();
  	//描画処理を実行
	glFlush();
	//ダブルバッファリング
	SwapBuffers(g_hDC);
	glDisable(GL_DEPTH_TEST);		//陰面消去を行う為の深度処理有効化
}

void Draw3D03() {

	glEnable(GL_DEPTH_TEST);		//陰面消去を行う為の深度処理有効化
	static float theta = 0.0f;		//シータ値
	//画面クリア
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//モデルビュー変換行列の初期化
	glMatrixMode(GL_MODELVIEW);		//描画コマンド設定https://learn.microsoft.com/ja-jp/windows/win32/opengl/glmatrixmode
	glLoadIdentity();
	glPushMatrix();
		glRotated(theta, 0.0, 1.0, 0.0);
		glRotated(theta, 1.0, 0.0, 0.0);
		//描画処理
		/* 図形の回転 */
		glBegin(GL_QUADS);
			//手前正面
			glColor3d(0.0, 0.0, 1.0);
			glVertex3d(-0.5, -0.5, 0.5);
			glVertex3d(0.5, -0.5, 0.5);
			glVertex3d(0.5, 0.5, 0.5);
			glVertex3d(-0.5, 0.5, 0.5);
			//右側面
			glColor3d(0.0, 1.0, 1.0);
			glVertex3d(0.5, -0.5, -0.5);
			glVertex3d(0.5,- 0.5, 0.5);
			glVertex3d(0.5, 0.5, 0.5);
			glVertex3d(0.5, 0.5, -0.5);
			//奥正面
			glColor3d(1.0, 0.0, 0.0);
			glVertex3d(-0.5, -0.5, -0.5);
			glVertex3d(0.5, -0.5, -0.5);
			glVertex3d(0.5, 0.5, -0.5);
			glVertex3d(-0.5, 0.5, -0.5);
			//左側面
			glColor3d(0.0, 1.0, 0.0);
			glVertex3d(-0.5, -0.5, -0.5);
			glVertex3d(-0.5, 0.5, -0.5);
			glVertex3d(-0.5, 0.5, 0.5);
			glVertex3d(-0.5, -0.5, 0.5);
			//天面
			glColor3d(1.0, 0.0, 1.0);
			glVertex3d(-0.5, 0.5, -0.5);
			glVertex3d(-0.5, 0.5, 0.5);
			glVertex3d(0.5, 0.5, 0.5);
			glVertex3d(0.5, 0.5, -0.5);
			//底面
			glColor3d(1.0, 1.0, 0.0);
			glVertex3d(-0.5, -0.5, -0.5);
			glVertex3d(-0.5, -0.5, 0.5);
			glVertex3d(0.5, -0.5, 0.5);
			glVertex3d(0.5, -0.5, -0.5);
		glEnd();
		theta += 0.1;
	glPopMatrix();
	//命令処理
	glFlush();
	//ダブルバッファリング
	SwapBuffers(g_hDC);
	glDisable(GL_DEPTH_TEST);		//陰面消去を行う為の深度処理有効化
}

void Draw3D04() {
}

void Draw3D05() {
}

/////////////////////////
//描画関数を選択する変数
/////////////////////////
void DrawObjects(int num) {

	switch(num) {
	case IDM_2D01:
		Draw2D01();		//2D－Sample01
		break;
	case IDM_2D02:
		Draw2D02();		//2D－Sample02
		break;
	case IDM_2D03:
		Draw2D03();		//2D－Sample03
		break;
	case IDM_2D04:
		Draw2D04();		//2D－Sample04
		break;
	case IDM_2D05:
		Draw2D05();		//2D－Sample05
		break;
	case IDM_3D01:
		Draw3D01();		//3D－Sample01
		break;
	case IDM_3D02:
		Draw3D02();		//3D－Sample02
		break;
	case IDM_3D03:
		Draw3D03();		//3D－Sample03
		break;
	case IDM_3D04:
		Draw3D04();		//3D－Sample04
		break;
	case IDM_3D05:
		Draw3D05();		//3D－Sample05
		break;
	default:
		break;
	}
}
