// Play.cpp : 응용 프로그램에 대한 진입점을 정의합니다.
//

#include "stdafx.h"
#include "Play.h"
#include <windows.h>
#include "glm.h"
#include "materials.h"
#include <math.h>
#include <mmsystem.h>


#define MAX_LOADSTRING 100


HDC hdc;//DC
HDC p_hdc;//DC
HBITMAP  p_bit;//HBITMAP
HWND g_hWnd; //핸들값

HDC PlayDC;
HBITMAP hBmp ;
// 전역 변수:
HINSTANCE hInst;								// 현재 인스턴스입니다.
TCHAR szTitle[MAX_LOADSTRING];					// 제목 표시줄 텍스트입니다.
TCHAR szWindowClass[MAX_LOADSTRING];			// 기본 창 클래스 이름입니다.

typedef float vec3_t[3]; 

vec3_t color[] = {
	{1.0f, 0.0f, 0.0f},		//red
	{0.0f, 1.0f, 0.0f},		//green
	{0.0f, 0.0f, 1.0f},		//blue
	{1.0f, 1.0f, 0.0f},		//yellow
	{1.0f, 0.0f, 1.0f},		//magenta
	{0.0f, 1.0f, 1.0f},		//cyan
	{1.0f, 1.0f, 1.0f},		//white
	{.25f, .25f, .25f},		//dark gray
	{.75f, .75f, .75f},		//light gray
	{.60f, .40f, .12f},		//brown
	{.60f, .40f, .70f},		//barney purple
	{.98f, .625f, .12f},	//pumpkin orange
	{.98f, .04f, .70f}		//pastel pink
};

vec3_t rot = {0,0,0};
vec3_t eye = {0,0,0};
vec3_t center = {0,0,0};
///////////////피아노/////////////
GLfloat rotx[17];       //회전값
GLfloat Black_rotx[12];
bool BlackPiano[12];
bool Piano[17];         //건반변환
float x[17];            //흰건반이동값
float Black_x[12];      //검은건반이동값
int     ColorR = 10;  
int     ColorG = 10;    //흰건반테투리
int		ColorB = 10;
int     RectColorR = 0.0;
int     RectColorG = 0.0; //흰건반
int		RectColorB = 0.0;
int     BlackPianoR = 0.0;
int     BlackPianoG = 0.0; //검은건반
int     BlackPianoB = 0.0;
int     RectBlackColorR = 10.0;
int     RectBlackColorG = 10.0; //흰건반
int		RectBlackColorB = 10.0;
//int     pianoStart=0;    //피아노선택시생성

////////////드럼스틱//////////////////
GLfloat rstick[3];
GLfloat lstick[3];
GLint	rrstick[3];
GLint	rlstick[3];

/////////////////////////////////
float	size=3.;
float	theta=.0;
float	thetaDelta=.125;
float	eyeDelta=.5;
float	scale=4.0;
float	scaleDelta=1.125;
float   anitheta=.0;
float   anithetaDelta=.125;

int		mouseX = 0;
int		mouseY = 0;
int		mouseState = 0;
int		mouseButton = 0; 
int		projection = 0;
int		depthtest = 1;
int		frontface = 0;
int		displaymode = 1;
int		displayflag = GLM_SMOOTH|GLM_COLOR;
int		shade = 1;
int		cullface = 1;
int		localviewer = 0;
int		twoside = 0;
int		windowWidth;
int		windowHeight;
int		lighting=1;
int Select_Instrument;

//////////////////////////////////
//   사용자 정의 변수           //
//////////////////////////////////
int     SpaceKey[4];
bool	PianoState;
bool	DrumState;
bool    GuitarState;
bool    SelectState[3];
bool    GuitarButton[6];
//////////////////////////////////
//   사용자 정의 함수			//
//////////////////////////////////
void	keyInput(int Num, char* String, int _Time, int _val);		// 키입력 함수
void    PianoNum(int i); //버튼누르기
void	PianoNum1();     //건반 원상복구
//void	BlackPianoNum(int i);//버튼누르기
//void    BlackPianoNum1(); //건반 원상복구
void	OnIdle();
void	myIdle(int Value);
void	myidle();

GLMmodel *pmodel[3] = {NULL,NULL,NULL};
GLMmodel *hmodel[3] = {NULL};


//GLfloat mat_ambient[] = { 0.11, 0.6, 0.71, 1.0};
GLfloat mat_ambient[] = { 0.91, 0.1, 0.11, 1.0};
GLfloat mat_diffuse[] = { 0.4, 0.37, 0.57, 1.0 };
GLfloat mat_specular[] = { 0.33, 0.33, 0.52, 1.0 };
GLfloat mat_emission[] = { 0.02, 0.02, 0.02, 0.0 };
GLfloat mat_shininess[] = { 10.0 };

GLfloat light_Kambient[] = { 0.2, 0.2, 0.2, 1.0};
GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0};
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0};
GLfloat light_specular[] ={ 1.0, 1.0, 1.0, 1.0};
GLfloat light_spotDir[] = { -1.0, -1.0, -1.0 };

// 이 코드 모듈에 들어 있는 함수의 정방향 선언입니다.
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: 여기에 코드를 입력합니다.
	MSG msg;
	HACCEL hAccelTable;
	BOOL done = FALSE;

	// 전역 문자열을 초기화합니다.
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_PLAY, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// 응용 프로그램 초기화를 수행합니다.
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PLAY));
	hdc = GetDC(g_hWnd);

	p_hdc= CreateCompatibleDC(NULL);
	p_bit= LoadBitmap(hInst,
		MAKEINTRESOURCE(IDC_BMP));
	SelectObject(p_hdc, p_bit);

	 PlayDC = CreateCompatibleDC(NULL);
	 hBmp = LoadBitmap(hInst,MAKEINTRESOURCE(IDC_PLAY) );
	SelectObject(PlayDC, hBmp);

	// 기본 메시지 루프입니다.
	while(1)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
				if(msg.message == WM_QUIT) break;

				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			else //메세지가 없을 경우 게임 루프를 실행한다.
			{
				
				OnIdle();	
			} 
	}
	ReleaseDC(g_hWnd, hdc);	
	
	return (int) msg.wParam;
}



//
//  함수: MyRegisterClass()
//
//  목적: 창 클래스를 등록합니다.
//
//  설명:
//
//    Windows 95에서 추가된 'RegisterClassEx' 함수보다 먼저
//    해당 코드가 Win32 시스템과 호환되도록
//    하려는 경우에만 이 함수를 사용합니다. 이 함수를 호출해야
//    해당 응용 프로그램에 연결된
//    '올바른 형식의' 작은 아이콘을 가져올 수 있습니다.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PLAY));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_PLAY);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	return RegisterClassEx(&wcex);
}

//
//   함수: InitInstance(HINSTANCE, int)
//
//   목적: 인스턴스 핸들을 저장하고 주 창을 만듭니다.
//
//   설명:
//
//        이 함수를 통해 인스턴스 핸들을 전역 변수에 저장하고
//        주 프로그램 창을 만든 다음 표시합니다.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // 인스턴스 핸들을 전역 변수에 저장합니다.
   RECT rect;//윈도 화면크기 조정
   rect.left = 0; 	rect.top = 0;
   rect.right = 800; rect.bottom = 600;
   AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);

   g_hWnd = hWnd = CreateWindow(szWindowClass, 
	   szTitle, 
	   WS_OVERLAPPEDWINDOW,
	   CW_USEDEFAULT, 0, 
	   rect.right - rect.left, 
	   rect.bottom - rect.top,
	   NULL, NULL, hInstance, NULL);
   if (!hWnd)
   {
      return FALSE;
   }
   //////////피아노 초기화///////////
   for(int i = 1; i< 17 ; i++)
   {
	   x[0]=-0.85f;
	   x[1]=-0.75f;
	   x[i]=0.1f+x[i-1];

   }

   Black_x[0]=-0.8f;
   Black_x[1]=-0.7f;
   Black_x[2]=-0.5f;
   Black_x[3]=-0.4f;
   Black_x[4]=-0.3f;
   Black_x[5]=-0.1f;
   Black_x[6]= 0.0f;
   Black_x[7]= 0.2f;
   Black_x[8]= 0.3f;
   Black_x[9]= 0.4f;
   Black_x[10]= 0.6f;
   Black_x[11]= 0.7f;

   for(int a = 0; a < 16; a++)
   {
	   Piano[a]=false;
   }

   for(int a = 0; a < 12; a++)
   {
	   BlackPiano[a]=false;
   }
   //////////////////////////////////
	rstick[0]=0;
	rstick[1]=-0.2;
	rstick[2]=0.5;

	lstick[0]=0.1;
	lstick[1]=-0.2;
	lstick[2]=0.5;

	rrstick[0]=90;
	rrstick[1]=1;
	rrstick[2]=0;

	rlstick[0]=90;
	rlstick[1]=1;
	rlstick[2]=0;
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  함수: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  목적: 주 창의 메시지를 처리합니다.
//
//  WM_COMMAND	- 응용 프로그램 메뉴를 처리합니다.
//  WM_PAINT	- 주 창을 그립니다.
//  WM_DESTROY	- 종료 메시지를 게시하고 반환합니다.
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_CREATE:
		hdc = GetDC(g_hWnd);
		break;
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// 메뉴의 선택 영역을 구문 분석합니다.
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:
		{
			hdc = BeginPaint(hWnd, &ps);

			// TODO: 여기에 그리기 코드를 추가합니다.
			EndPaint(hWnd, &ps);
		}
		
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

// 정보 대화 상자의 메시지 처리기입니다.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
		{
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}

void new_material(float* material)
{
	mat_ambient[0] = material[0];
	mat_ambient[1] = material[1];
	mat_ambient[2] = material[2];
	mat_ambient[3] = material[3];
	mat_diffuse[0] = material[4];
	mat_diffuse[1] = material[5];
	mat_diffuse[2] = material[6];
	mat_diffuse[3] = material[7];
	mat_specular[0] = material[8];
	mat_specular[1] = material[9];
	mat_specular[2] = material[10];
	mat_specular[3] = material[11];
	mat_shininess[0] = material[12];
	glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
	glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
	glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
	glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
}

void myInit(void)
{    
	glClearColor(0.25, 0.25, 0.25, 1.0);
	glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER,localviewer);
	glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,twoside);
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,light_Kambient);
	glLightfv(GL_LIGHT0,GL_POSITION,light_position);
	glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);
	glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
	glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);
	glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,light_spotDir);
	glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,180.0f);
	glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,30.0f);	
	glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
	glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
	glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
	glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
	glMaterialfv(GL_FRONT,GL_EMISSION,mat_emission);
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_CULL_FACE);		
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_NORMALIZE);
}

void drawWavefrontModel(void)
{
	if(pmodel[0]){
		glPushMatrix();
		glRotatef(130,1.0f,0,0);
		glBegin(GL_POLYGON);
		if(SpaceKey[0] == 0){glColor3f(0.2, 0.2, 0.2);}
		else if(SpaceKey[0] ==1){glColor3f(0.1f, 0.2f, 0.1f);}
		else if(SpaceKey[0] ==2){glColor3f(0.2f, 0.0f, 0.1f);}
		else if(SpaceKey[0] ==3){glColor3f(0.0f, 0.1f, 0.2f);}
		else if(SpaceKey[0] ==4){glColor3f(0.3f, 0.6f, 0.1f);}
		else if(SpaceKey[0] ==5){glColor3f(0.1f, 0.4f, 0.2f);}
		else if(SpaceKey[0] ==6){glColor3f(0.2f, 0.1f, 0.6f);}
		else if(SpaceKey[0] ==7){glColor3f(0.0f, 0.3f, 0.2f);}
		else if(SpaceKey[0] ==8){glColor3f(0.0f, 0.3f, 0.0f);}
		else if(SpaceKey[0] ==9){glColor3f(0.6f, 0.6f, 0.6f);}
	
		glmDraw(pmodel[0], displayflag);//GLM_WIREFRAME
		glEnd();
		glPopMatrix();
	}
	if(pmodel[1]){ 
		glPushMatrix();
		glRotatef(130,1.0f,0,0);
		glRotatef(-90,0,1.0f,0);
		glTranslatef(-2.5f, 0.0f, 0.0f);
		glBegin(GL_POLYGON);
		if(SpaceKey[1] == 0){glColor3f(0.4, 0.2, 0.2);}
		else if(SpaceKey[1] ==1){glColor3f(0.1f, 0.2f, 0.1f);}
		else if(SpaceKey[1] ==2){glColor3f(0.2f, 0.0f, 0.1f);}
		else if(SpaceKey[1] ==3){glColor3f(0.0f, 0.1f, 0.2f);}
		else if(SpaceKey[1] ==4){glColor3f(0.3f, 0.6f, 0.1f);}
		else if(SpaceKey[1] ==5){glColor3f(0.1f, 0.4f, 0.2f);}
		else if(SpaceKey[1] ==6){glColor3f(0.2f, 0.1f, 0.6f);}
		else if(SpaceKey[1] ==7){glColor3f(0.0f, 0.3f, 0.2f);}
		else if(SpaceKey[1] ==8){glColor3f(0.0f, 0.3f, 0.0f);}
		else if(SpaceKey[1] ==9){glColor3f(0.6f, 0.6f, 0.6f);}

	
		glmDraw(pmodel[1], displayflag);//GLM_WIREFRAME
		glEnd();
		glPopMatrix();
	}
	if(pmodel[2]){
		glPushMatrix();
		
		glRotatef(-90,1.0f,0,0);
		glRotatef(90,0,1.0f,0);
		glTranslatef(0.0f, 0.0f, 2.5f);
		glBegin(GL_POLYGON);
		if(SpaceKey[2] == 0){glColor3f(0.3, 0, 0.3);}
		else if(SpaceKey[2] ==1){glColor3f(0.1f, 0.2f, 0.1f);}
		else if(SpaceKey[2] ==2){glColor3f(0.2f, 0.0f, 0.1f);}
		else if(SpaceKey[2] ==3){glColor3f(0.0f, 0.1f, 0.2f);}
		else if(SpaceKey[2] ==4){glColor3f(0.3f, 0.6f, 0.1f);}
		else if(SpaceKey[2] ==5){glColor3f(0.1f, 0.4f, 0.2f);}
		else if(SpaceKey[2] ==6){glColor3f(0.2f, 0.1f, 0.6f);}
		else if(SpaceKey[2] ==7){glColor3f(0.0f, 0.3f, 0.2f);}
		else if(SpaceKey[2] ==8){glColor3f(0.0f, 0.3f, 0.0f);}
		else if(SpaceKey[2] ==9){glColor3f(0.6f, 0.6f, 0.6f);}
		
		glmDraw(pmodel[2], displayflag);//GLM_WIREFRAME
		glEnd();
		glPopMatrix();

		glPushMatrix();
		glRotatef(-90,1.0f,0,0);
		glRotatef(90,0,1.0f,0);
		glTranslatef(0.0f, 0.0f, -2.5f);
		glBegin(GL_POLYGON);
		if(SpaceKey[3] == 0){glColor3f(0.3, 0, 0.3);}
		else if(SpaceKey[3] ==1){glColor3f(0.1f, 0.2f, 0.1f);}
		else if(SpaceKey[3] ==2){glColor3f(0.2f, 0.0f, 0.1f);}
		else if(SpaceKey[3] ==3){glColor3f(0.0f, 0.1f, 0.2f);}
		else if(SpaceKey[3] ==4){glColor3f(0.3f, 0.6f, 0.1f);}
		else if(SpaceKey[3] ==5){glColor3f(0.1f, 0.4f, 0.2f);}
		else if(SpaceKey[3] ==6){glColor3f(0.2f, 0.1f, 0.6f);}
		else if(SpaceKey[3] ==7){glColor3f(0.0f, 0.3f, 0.2f);}
		else if(SpaceKey[3] ==8){glColor3f(0.0f, 0.3f, 0.0f);}
		else if(SpaceKey[3] ==9){glColor3f(0.6f, 0.6f, 0.6f);}
		
		glmDraw(pmodel[2], displayflag);//GLM_WIREFRAME
		glEnd();
		glPopMatrix();
	}
	//for(i=0; i<22; i++)
	//	if(hmodel[i]) glmDraw(hmodel[i], displayflag);
	
}
void myLookAt(int key)
{
	if(key == GLUT_KEY_UP) {
		eye[2] = eye[2]-cos(theta)*eyeDelta;
		eye[0] = eye[0]+sin(theta)*eyeDelta;
	}else if(key == GLUT_KEY_DOWN) {
		eye[2] = eye[2]+cos(theta)*eyeDelta;
		eye[0] = eye[0]-sin(theta)*eyeDelta;
	}else if(key == GLUT_KEY_LEFT){
		theta-=thetaDelta;
	}else if(key == GLUT_KEY_RIGHT){
		theta+=thetaDelta;
	}
	center[2] = eye[2]-cos(theta);
	center[0] = eye[0]+sin(theta);
}

void myResize (int width, int height)
{
	if (!height) return;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	if(projection) {
		glOrtho(-size, size, -size, size, -size, size); 
		eye[2] = 0.;
	}
	else {
		gluPerspective(60., (float)width/height, .01, 1000.);
		eye[2] = 10.;
		myLookAt(0);
	}
	glEnable(GL_DEPTH_TEST);
	windowWidth=width;
	windowHeight=height;
}
void myDisplay (void)
{
	BitBlt(hdc, 0,0,800,600,PlayDC, 0,0,SRCCOPY);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glEnable(GL_DEPTH_TEST);
	glLoadIdentity();
	if(!projection)
	gluLookAt(eye[0], eye[1], eye[2], center[0], center[1], center[2], 0, 1, 0);
	glRotatef(rot[0], 1.0f, 0.0f, 0.0f);
	glRotatef(rot[1], 0.0f, 1.0f, 0.0f);
	glRotatef(rot[2], 0.0f, 0.0f, 1.0f);
	glScalef(scale, scale, scale);
	glRotatef(-90., 1., 0., 0.);

	
	if(PianoState == true){
		for(int i = 0; i < 17 ; i++)
		{
			glDisable(GL_CULL_FACE);
			/////////////건반//////////////////
			glPushMatrix();
			glColor3f(ColorR, ColorG, ColorB);
			glRotatef(rotx[i]+130, 0.1f, 0.0f, 0.0f);
			glTranslatef(x[i], 0.3f, 0.05f);
			glBegin(GL_POLYGON );
			
			glVertex3f(.0, .0, .0);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f(0.1f, .0, .0);
			glEnd();
			//////////뒤////////////
			glBegin(GL_POLYGON );
			glVertex3f(.0, .0, 0.2f);
			glVertex3f( .0, 0.1f, 0.2f);
			glVertex3f( 0.1f, 0.1f, 0.2f);
			glVertex3f(0.1f, .0, 0.2f);
			glEnd();
			/////왼쪽면///////////
			glBegin(GL_POLYGON );
			glVertex3f( .0, 0.1f, 0.2f);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( .0, .0, .0);
			glVertex3f(.0, .0, 0.2f);
			glEnd();
			////////////오른쪽면////////
			glBegin(GL_POLYGON );
			glVertex3f( 0.1f, 0.1f, 0.2f);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f( 0.1f, .0, .0);
			glVertex3f( 0.1f, .0, 0.2f);
			glEnd();
			/////////위/////////////
			glBegin(GL_POLYGON );
			glVertex3f(.0, .0, 0.2f);
			glVertex3f( .0, .0, .0);
			glVertex3f( 0.1f, .0, .0);
			glVertex3f(0.1f, .0, 0.2f);
			glEnd();
			/////////////아래////////////
			glBegin(GL_POLYGON );
			glVertex3f(.0, 0.1f, 0.2f);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f(0.1f, 0.1f, 0.2f);
			glEnd();
			glPopMatrix();
		}
		/////////////////////건반라인//////////////
		for(int i = 0; i < 17 ; i++)
		{
			glDisable(GL_CULL_FACE);
			/////////////건반테두리//////////////////
			glPushMatrix();
			glColor3f(RectColorR, RectColorG, RectColorB);
			glRotatef(rotx[i]+130, 0.1f, 0.0f, 0.0f);
			glTranslatef(x[i], 0.3f, 0.05f);
			glBegin(GL_LINE_STRIP );
			
			glVertex3f(.0, .0, .0);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f(0.1f, .0, .0);
			glEnd();
			//////////뒤////////////
			glBegin(GL_LINE_STRIP );
			//glColor3f(RectColorR, RectColorG, RectColorB);
			glVertex3f(.0, .0, 0.2f);
			glVertex3f( .0, 0.1f, 0.2f);
			glVertex3f( 0.1f, 0.1f, 0.2f);
			glVertex3f(0.1f, .0, 0.2f);
			glEnd();
			/////왼쪽면///////////
			glBegin(GL_LINE_STRIP );
			//glColor3f(RectColorR, RectColorG, RectColorB);
			glVertex3f( .0, 0.1f, 0.2f);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( .0, .0, .0);
			glVertex3f(.0, .0, 0.2f);
			glEnd();
			////////////오른쪽면////////
			glBegin(GL_LINE_STRIP );
			//glColor3f(RectColorR, RectColorG, RectColorB);
			glVertex3f( 0.1f, 0.1f, 0.2f);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f( 0.1f, .0, .0);
			glVertex3f( 0.1f, .0, 0.2f);
			glEnd();
			/////////위/////////////
			glBegin(GL_LINE_STRIP );
			//glColor3f(RectColorR, RectColorG, RectColorB);
			glVertex3f(.0, .0, 0.2f);
			glVertex3f( .0, .0, .0);
			glVertex3f( 0.1f, .0, .0);
			glVertex3f(0.1f, .0, 0.2f);
			glEnd();
			/////////////아래////////////
			glBegin(GL_LINE_STRIP );
			//glColor3f(RectColorR, RectColorG, RectColorB);
			glVertex3f(.0, 0.1f, 0.2f);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f(0.1f, 0.1f, 0.2f);
			glEnd();
			glPopMatrix();
		}

		for(int i = 0; i < 12 ; i++)
		{
			glDisable(GL_CULL_FACE);
			/////////////건반테두리//////////////////
			glPushMatrix();
			glColor3f(RectBlackColorR, RectBlackColorG, RectBlackColorB);
			glRotatef(Black_rotx[i]+130, 0.1f, 0.0f, 0.0f);
			glTranslatef(Black_x[i], 0.32f, 0.05f);
			glBegin(GL_LINE_STRIP );
			glVertex3f(.0, .0, .0);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f(0.1f, .0, .0);
			glEnd();
			//////////뒤////////////
			glBegin(GL_LINE_STRIP );
			//glColor3f(RectBlackColorR, RectBlackColorG, RectBlackColorB);
			glVertex3f(.0, .0, 0.12f);
			glVertex3f( .0, 0.1f, 0.12f);
			glVertex3f( 0.1f, 0.1f, 0.12f);
			glVertex3f(0.1f, .0, 0.12f);
			glEnd();
			/////왼쪽면///////////
			glBegin(GL_LINE_STRIP );
			//glColor3f(RectBlackColorR, RectBlackColorG, RectBlackColorB);
			glVertex3f( .0, 0.1f, 0.12f);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( .0, .0, .0);
			glVertex3f(.0, .0, 0.12f);
			glEnd();
			////////////오른쪽면////////
			glBegin(GL_LINE_STRIP );
			//glColor3f(RectBlackColorR, RectBlackColorG, RectBlackColorB);
			glVertex3f( 0.1f, 0.1f, 0.12f);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f( 0.1f, .0, .0);
			glVertex3f( 0.1f, .0, 0.12f);
			glEnd();
			/////////위/////////////
			glBegin(GL_LINE_STRIP );
			//glColor3f(RectBlackColorR, RectBlackColorG, RectBlackColorB);
			glVertex3f(.0, .0, 0.12f);
			glVertex3f( .0, .0, .0);
			glVertex3f( 0.1f, .0, .0);
			glVertex3f(0.1f, .0, 0.12f);
			glEnd();
			/////////////아래////////////
			glBegin(GL_LINE_STRIP );
			//glColor3f(RectBlackColorR, RectBlackColorG, RectBlackColorB);
			glVertex3f(.0, 0.1f, 0.12f);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f(0.1f, 0.1f, 0.12f);
			glEnd();
			glPopMatrix();

		}

		for(int i = 0; i < 12 ; i++)
		{
			glDisable(GL_CULL_FACE);
			/////////////검은건반//////////////////
			glPushMatrix();
			glColor3f(BlackPianoR, BlackPianoG, BlackPianoB);
			glRotatef(Black_rotx[i]+130, 0.1f, 0.0f, 0.0f);
			glTranslatef(Black_x[i], 0.32f, 0.05f);
			glBegin(GL_POLYGON );
		
			glVertex3f(.0, .0, .0);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f(0.1f, .0, .0);
			glEnd();
			//////////뒤////////////
			glBegin(GL_POLYGON );
			//glColor3f(BlackPianoR, BlackPianoG, BlackPianoB);
			glVertex3f(.0, .0, 0.12f);
			glVertex3f( .0, 0.1f, 0.12f);
			glVertex3f( 0.1f, 0.1f, 0.12f);
			glVertex3f(0.1f, .0, 0.12f);
			glEnd();
			/////왼쪽면///////////
			glBegin(GL_POLYGON );
			//glColor3f(BlackPianoR, BlackPianoG, BlackPianoB);
			glVertex3f( .0, 0.1f, 0.12f);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( .0, .0, .0);
			glVertex3f(.0, .0, 0.12f);
			glEnd();
			////////////오른쪽면////////
			glBegin(GL_POLYGON );
			//glColor3f(BlackPianoR, BlackPianoG, BlackPianoB);
			glVertex3f( 0.1f, 0.1f, 0.12f);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f( 0.1f, .0, .0);
			glVertex3f( 0.1f, .0, 0.12f);
			glEnd();
			/////////위/////////////
			glBegin(GL_POLYGON );
			//glColor3f(BlackPianoR, BlackPianoG, BlackPianoB);
			glVertex3f(.0, .0, 0.12f);
			glVertex3f( .0, .0, .0);
			glVertex3f( 0.1f, .0, .0);
			glVertex3f(0.1f, .0, 0.12f);
			glEnd();
			/////////////아래////////////
			glBegin(GL_POLYGON );
			//glColor3f(BlackPianoR, BlackPianoG, BlackPianoB);
			glVertex3f(.0, 0.1f, 0.12f);
			glVertex3f( .0, 0.1f, .0);
			glVertex3f( 0.1f, 0.1f, .0);
			glVertex3f(0.1f, 0.1f, 0.12f);
			glEnd();
			glPopMatrix();

		}

	}
	if(DrumState == true)	
	{
		GLUquadricObj *c;
		c=gluNewQuadric();
		gluQuadricDrawStyle(c, GLU_FILL);

		glPushMatrix();
		glTranslatef(rstick[0], rstick[1]+2.0, rstick[2]+1.8);
		glRotatef(rrstick[0],rrstick[1],rrstick[2],0);
		gluCylinder(c, 0.01,0.01, 0.4,10, 3);
		glEnd();
		glPopMatrix();

		glPushMatrix();
		glTranslatef(lstick[0], lstick[1]+2.0, lstick[2]+1.8);
		glRotatef(rlstick[0],rlstick[1],rlstick[2],0);
		gluCylinder(c, 0.01,0.01, 0.4,10, 3);
		glEnd();
		glPopMatrix();
	}
		
	if(GuitarState == true){
		glPushMatrix();
		glTranslatef(1.6, -0.1,-0.02);
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.0f);
		glVertex3f(1.5, 0.0f, .0);
		glEnd();
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.01f);
		glVertex3f(1.5, 0.0f, .01);
		glEnd();
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.02f);
		glVertex3f(1.5, 0.0f, .02);
		glEnd();
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.03f);
		glVertex3f(1.5, 0.0f, .03);
		glEnd();
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.04f);
		glVertex3f(1.5, 0.0f, .04);
		glEnd();
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.05f);
		glVertex3f(1.5, 0.0f, .05);
		glEnd();
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.06);
		glVertex3f(1.5, 0.0f, .06);
		glEnd();
		glPopMatrix();

		glPushMatrix();
		glTranslatef(-3.4, -0.1,-0.02);
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.0f);
		glVertex3f(1.5, 0.0f, .0);
		glEnd();
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.01f);
		glVertex3f(1.5, 0.0f, .01);
		glEnd();
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.02f);
		glVertex3f(1.5, 0.0f, .02);
		glEnd();
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.03f);
		glVertex3f(1.5, 0.0f, .03);
		glEnd();
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.04f);
		glVertex3f(1.5, 0.0f, .04);
		glEnd();
		glBegin(GL_LINES);
		glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.05f);
		glVertex3f(1.5, 0.0f, .05);
		glEnd();
		glBegin(GL_LINES);
			glColor3f(0.4f, 0.4f, 0.4f);
		glVertex3f(0.0, 0.0f, 0.06);
		glVertex3f(1.5, 0.0f, .06);
		glEnd();
		glPopMatrix();
		if(GuitarButton[0] == true){
			glPushMatrix();
			glTranslatef(2.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(1.0f, 0.0f, 0.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();

			glPushMatrix();
			glTranslatef(-3.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(3.0f, 0.0f, 0.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();
		}else if(GuitarButton[1] == true){
			glPushMatrix();
			glTranslatef(2.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(0.0f, 3.0f, 0.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();

			glPushMatrix();
			glTranslatef(-3.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(0.0f, 3.0f, 0.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();
		}else if(GuitarButton[2] == true){
			glPushMatrix();
			glTranslatef(2.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(0.0f, 0.0f, 2.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();

			glPushMatrix();
			glTranslatef(-3.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(0.0f, 0.0f, 2.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();

		}else if(GuitarButton[3] == true){
			glPushMatrix();
			glTranslatef(2.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(3.0f, 3.0f, 0.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();

			glPushMatrix();
			glTranslatef(-3.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(3.0f, 3.0f, 0.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();
		}else if(GuitarButton[4] == true){
			glPushMatrix();
			glTranslatef(2.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(0.0f, 3.0f, 3.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();

			glPushMatrix();
			glTranslatef(-3.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(0.0f, 3.0f, 3.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();
		}else if(GuitarButton[5] == true){
			glPushMatrix();
			glTranslatef(2.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(3.0f, 0.0f, 3.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();

			glPushMatrix();
			glTranslatef(-3.0,0.0,0.0);
			glBegin(GL_POLYGON);
			glColor3f(3.0f, 0.0f, 3.0f);
			glutSolidSphere(.1,3,3);
			glEnd();
			glPopMatrix();
		}
	}


	drawWavefrontModel();
  
	glPushMatrix();
	glFlush();
	glutSwapBuffers();
	glPopMatrix();
}

void mySKeyboard (int key, int x, int y)
{
	if(DrumState == true){
		if(key == GLUT_KEY_INSERT){
			rstick[0]=-0.4;
			rstick[1]=0.3;
			rstick[2]=0.5;

			rrstick[0]=135;
			rrstick[2]=0;
			sndPlaySoundA("wav\\drum\\drum.wav",SND_ASYNC);
			glutTimerFunc(140, myIdle, 1);
		}
		if(key == GLUT_KEY_HOME){
			lstick[0]=0.4;
			lstick[1]=0.3;
			lstick[2]=0.55;

			rlstick[0]=135;
			rlstick[2]=0;
			sndPlaySoundA("wav\\drum\\snare.wav",SND_ASYNC);
			glutTimerFunc(140, myIdle, 1);
		}
		if(key == GLUT_KEY_PAGE_UP){
			sndPlaySoundA("wav\\drum\\base.wav",SND_ASYNC);
		}
		if(key == GLUT_KEY_END){
			lstick[0]=0.4;
			lstick[1]=0;
			lstick[2]=1;

			rlstick[0]=135;
			rlstick[2]=5;
			sndPlaySoundA("wav\\drum\\hat.wav",SND_ASYNC);
			glutTimerFunc(140, myIdle, 1);
		}
		if(key == GLUT_KEY_PAGE_DOWN){
			rrstick[0]=135;
			rrstick[2]=-5;

			rstick[0]=-0.4;
			rstick[1]=0;
			rstick[2]=0.9;
			sndPlaySoundA("wav\\drum\\sim.wav",SND_ASYNC);
			glutTimerFunc(140, myIdle, 1);
		}
	}
	myLookAt(key);
	glutPostRedisplay();
}
void myKeyboard (unsigned char key, int x, int y)
{
	if(PianoState == true){
		if(key == 'z'){keyInput(0, "wav\\piano\\do.wav", 140, 1);}
		if(key == 'x'){keyInput(1, "wav\\piano\\re.wav", 140, 1);}
		if(key == 'c'){keyInput(2, "wav\\piano\\me.wav", 140, 1);}
		if(key == 'v'){keyInput(3, "wav\\piano\\pa.wav", 140, 1);}
		if(key == 'b'){keyInput(4, "wav\\piano\\sol.wav", 140, 1);}
		if(key == 'n'){keyInput(5, "wav\\piano\\ra.wav", 140, 1);}
		if(key == 'm'){keyInput(6, "wav\\piano\\si.wav", 140, 1);}
		if(key == 'a'){keyInput(7, "wav\\piano\\ddo.wav", 140, 1);}
		if(key == 's'){keyInput(8, "wav\\piano\\re.wav", 140, 1);}
		if(key == 'd'){keyInput(9, "wav\\piano\\me.wav", 140, 1);}
		if(key == 'f'){keyInput(10, "wav\\piano\\pa.wav", 140, 1);}
		if(key == 'g'){keyInput(11, "wav\\piano\\sol.wav", 140, 1);}
		if(key == 'h'){keyInput(12, "wav\\piano\\ra.wav", 140, 1);}
		if(key == 'j'){keyInput(13, "wav\\piano\\si.wav", 140, 1);}
		if(key == 'k'){keyInput(14, "wav\\piano\\ddo.wav", 140, 1);}
		if(key == 'l'){keyInput(15, "wav\\piano\\re.wav", 140, 1);}
		if(key == ';'){keyInput(16, "wav\\piano\\mi.wav", 140, 1);}
		if(key == 'q'){keyInput(17, NULL, 140, 1);}
		if(key == 'w'){keyInput(18, NULL, 140, 1);}
		if(key == 'e'){keyInput(19, NULL, 140, 1);}
		if(key == 'r'){keyInput(20, NULL, 140, 1);}
		if(key == 't'){keyInput(21, NULL, 140, 1);}
		if(key == 'y'){keyInput(22, NULL, 140, 1);}
		if(key == 'u'){keyInput(23, NULL, 140, 1);}
		if(key == 'i'){keyInput(24, NULL, 140, 1);}
		if(key == 'o'){keyInput(25, NULL, 140, 1);}
		if(key == 'p'){keyInput(26, NULL, 140, 1);}
		if(key == '['){keyInput(27, NULL, 140, 1);}
		if(key == ']'){keyInput(28, NULL, 140, 1);}
	}
	if(GuitarState == true){
		if(key == '1' ){
			sndPlaySoundA("wav\\gita\\통기타Am.wav",SND_ASYNC);
			GuitarButton[0] = true;
		}
		else if(key == '2' ){
			sndPlaySoundA("wav\\gita\\통기타C.wav",SND_ASYNC);
			GuitarButton[1] = true;
		}
		else if(key == '3' ){
			sndPlaySoundA("wav\\gita\\통기타D.wav",SND_ASYNC);
			GuitarButton[2] = true;
		}
		else if(key == '4' ){
			sndPlaySoundA("wav\\gita\\통기타E6.wav",SND_ASYNC);
			GuitarButton[3] = true;
		}
		else if(key == '5' ){
			sndPlaySoundA("wav\\gita\\통기타F.wav",SND_ASYNC);
			GuitarButton[4] = true;
		}
		else if(key == '6' ){
			sndPlaySoundA("wav\\gita\\통기타G7.wav",SND_ASYNC);
			GuitarButton[5] = true;
		}
	}

	if(key == '-'){
		SpaceKey[3]++;
		if(SpaceKey[3] > 9){
			SpaceKey[3] = 0;
		}
	}

	if(key == '0'){
		SpaceKey[2]++;
		if(SpaceKey[2] > 9){
			SpaceKey[2] = 0;
		}
	}

	if(key == '9'){
		SpaceKey[1]++;
		if(SpaceKey[1] > 9){
			SpaceKey[1] = 0;
		}
	}

	if(key == '8'){
		SpaceKey[0]++;
		if(SpaceKey[0] > 9){
			SpaceKey[0] = 0;
		}
	}



	glutPostRedisplay();
}

void myKeyboardup(unsigned char key, int x, int y){
	if(GuitarState == true){
		if(key == '1' ){
			GuitarButton[0] = false;
		}
		else if(key == '2' ){
			GuitarButton[1] = false;
		}
		else if(key == '3' ){
			GuitarButton[2] = false;
		}
		else if(key == '4' ){
			GuitarButton[3] = false;
		}
		else if(key == '5' ){
			GuitarButton[4] = false;
		}
		else if(key == '6' ){
			GuitarButton[5] = false;
		}
	}
}

void myMouse(int btn, int state, int x, int y)
{
	if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
		mouseState=state;
		mouseButton=btn;
		mouseX=x;
		mouseY=y;
	}
	else if(btn==GLUT_LEFT_BUTTON && state == GLUT_UP) {
		mouseState=-1;
	}
	else return;
	glutPostRedisplay();
}

void myMotion(int x, int y)
{
	if(mouseButton == GLUT_LEFT_BUTTON && mouseState == GLUT_DOWN) {
		rot[1] -= (mouseX - x)/5.;
		rot[0] -= (mouseY - y)/5.;
		glutPostRedisplay();
		mouseX=x;
		mouseY=y;
	}
}

void material_menu(int value)
{
	switch (value) {
	case 1:
		new_material(Brass);
		break;
	case 2:
		new_material(Bronze);
		break;
	case 3:
		new_material(Polished_Bronze);
		break;
	case 4:
		new_material(Chrome);
		break;
	case 5:
		new_material(Copper);
		break;
	case 6:
		new_material(Polished_Copper);
		break;
	case 7:
		new_material(Gold);
		break;
	case 8:
		new_material(Polished_Gold);
		break;
	case 9:
		new_material(Pewter);
		break;
	case 10:
		new_material(Silver);
		break;
	case 11:
		new_material(Polished_Silver);
		break;
	case 12:
		new_material(Emerald);
		break;
	case 13:
		new_material(Jade);
		break;
	case 14:
		new_material(Obsidian);
		break;
	case 15:
		new_material(Pearl);
		break;
	case 16:
		new_material(Ruby);
		break;
	case 17:
		new_material(Turquoise);
		break;
	case 18:
		new_material(Black_Plastic);
		break;
	case 19:
		new_material(Black_Rubber);
		break;
	}
	glutPostRedisplay();
}

void screen_menu(int value)
{
	int ObjectNum = 0;
	char *name[3];

	switch (value) {
	case '1': //피아노 오브젝트를 부른다
		{
			if(PianoState == false){
				PianoState = true;
				SelectState[0] = true;
			}
			else{
				PianoState = false;
				SelectState[0] = false;
			}
		}	
		break;
	case '2': // 드럼 오브젝트를 부른다
		{
			if(DrumState == false){
				DrumState = true;
				SelectState[1] = true;
			}
			else{
				DrumState = false;
				SelectState[1] = false;
			}
		}
		break;
	case '3': // 기타 오브젝트를 부른다
		{
			if(GuitarState == false){
				GuitarState = true;
				SelectState[2] = true;
			}
			else{
				GuitarState = false;
				SelectState[2] = false;
			}
		}	
		break;
	}
	if(PianoState == true){
		name[0] = "data/piano.obj";
		displayflag = GLM_SMOOTH;
		new_material(Polished_Gold);
	}
	if(DrumState == true){
		name[1] = "data/drum.obj";
		displayflag = GLM_SMOOTH;
		new_material(Polished_Gold);
	}
	if(GuitarState == true){
		name[2] = "data/gita.obj";
		displayflag = GLM_SMOOTH;
		new_material(Polished_Gold);
		glDisable(GL_CULL_FACE);
	}
	
	for(int j = 0 ; j < 3 ; j++){
		if(SelectState[j] == true){
			pmodel[j] = glmReadOBJ(name[j]);
			if (!pmodel[j]) exit(0);
			glmUnitize(pmodel[j]);
			glmFacetNormals(pmodel[j]);
			glmVertexNormals(pmodel[j], 90.0);
			for(int i=0; i<3; i++) if(hmodel[i]) hmodel[i]=NULL;
		}else{
			pmodel[j] = NULL;
		}
	}

	glutPostRedisplay();
}
void OnIdle()
{
	
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitWindowSize(500,500);
	glutCreateWindow("lab21 by lbg@dongseo.ac.kr");
	glutDisplayFunc(myDisplay);
	glutReshapeFunc(myResize);
	glutKeyboardFunc(myKeyboard);
	glutKeyboardUpFunc(myKeyboardup);
	glutSpecialFunc(mySKeyboard);
	glutMouseFunc(myMouse);
	glutMotionFunc(myMotion);
	glutCreateMenu(material_menu);
	glutAddMenuEntry("Brass", 1);
	glutAddMenuEntry("Bronze", 2);
	glutAddMenuEntry("Polished_Bronze", 3);
	glutAddMenuEntry("Chrome", 4);
	glutAddMenuEntry("Copper", 5);
	glutAddMenuEntry("Polished_Copper", 6);
	glutAddMenuEntry("Gold", 7);
	glutAddMenuEntry("Polished_Gold", 8);
	glutAddMenuEntry("Pewter", 9);
	glutAddMenuEntry("Silver", 10);
	glutAddMenuEntry("Polished_Silver", 11);
	glutAddMenuEntry("Emerald", 12);
	glutAddMenuEntry("Jade", 13);
	glutAddMenuEntry("Obsidian", 14);
	glutAddMenuEntry("Pearl", 15);
	glutAddMenuEntry("Ruby", 16);
	glutAddMenuEntry("Turquoise", 17);
	glutAddMenuEntry("Black_Plastic", 18);
	glutAddMenuEntry("Black_Rubber", 19);
	glutAttachMenu(GLUT_MIDDLE_BUTTON);
	glutCreateMenu(screen_menu);
	glutAddMenuEntry("Piano", '1');
	glutAddMenuEntry("Drum", '2');
	glutAddMenuEntry("Guiter", '3');
	glutAttachMenu(GLUT_RIGHT_BUTTON);
	glutTimerFunc(40, myIdle, 1);
	glutIdleFunc(myidle);
	
	myInit();
	glutMainLoop();

}
//////////////////////////////////피아노흰건반///////////////////////////////
void PianoNum(int i)
{
	if (Piano[i]==false)
	{
		for(int num = 0 ; num <5 ; num++)
		{
			rotx[i]+=1.0f;
			if(rotx[i]>=5.0f)
			{

				Piano[i] = true;

			}
		}
	}
}
void PianoNum1()
{	for(int i = 0 ; i < 17 ; i++)
	{
		if(Piano[i]==true)
		{
			for(int num = 0 ; num <5 ; num++)
			{
				rotx[i]-=1.0f;
				if(rotx[i]<=0.0f)
				{
					Piano[i] = false;
				}
			}
		}
	}
};
/*///////////////////////////////검은 건반///////////////////////////////
void BlackPianoNum(int i)
{
	if (BlackPiano[i]==false)
	{
		for(int num = 0 ; num <5 ; num++)
		{
			Black_rotx[i]+=1.0f;
			if(Black_rotx[i]>=5.0f)
			{

				BlackPiano[i] = true;

			}
		}
	}
}*//*
void BlackPianoNum1()
{	for(int i = 0 ; i < 12 ; i++)
	{
		if(BlackPiano[i]==true)
		{
			for(int num = 0 ; num <5 ; num++)
			{
				Black_rotx[i]-=1.0f;
				if(Black_rotx[i]<=0.0f)
				{
					BlackPiano[i] = false;
				}
			}
		}
	}
};*/
//////////////////////////////////////////////////////////////////////////////
void myIdle(int Value)
{
	rstick[0]=0;
	rstick[1]=-0.2;
	rstick[2]=0.5;

	lstick[0]=0.1;
	lstick[1]=-0.2;
	lstick[2]=0.5;

	rrstick[0]=90;
	rrstick[1]=1;
	rrstick[2]=0;

	rlstick[0]=90;
	rlstick[1]=1;
	rlstick[2]=0;
	PianoNum1();
	//BlackPianoNum1();
	
}
void myidle()
{
	void myDisplay (void);
	glutPostRedisplay();
}




/////////////////////
//사용자 정의 함수 //
/////////////////////
void keyInput(int Num, char* String, int _Time, int _val){
	PianoNum(Num);
	sndPlaySoundA(String,SND_ASYNC);
	glutTimerFunc(_Time, myIdle, _val);
}