#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include "glm.h"

typedef float vec3_t[3];

vec3_t rot = {0.0, 0.0, 0.0};
vec3_t eye = {0.0, 0.0, 0.0};
vec3_t center = {0.0, 0.0, 0.0};

float scale = 1.0;
float scaleDelta = 1.125;
float size = 3.0;
float theta = 0.0;
float thetaDelta = 0.125;
float eyeDelta = 0.125;

int anitheta = 0;
int anithetaDelta = 50;

float the = 0.0;

int mouseX = 0;
int mouseY = 0;
int mouseState = 0;
int mouseButton = 0;
int projection = 0;
int aniOn = 0;
int windowWidth, windowHeight;

GLUquadricObj *c;

GLMmodel *body = glmReadOBJ("data/carbody.obj");
GLMmodel *tire = glmReadOBJ("data/tireA.obj");
GLMmodel *tree_1 = glmReadOBJ("data/tree1.obj");
GLMmodel *tree_2 = glmReadOBJ("data/tree2.obj");
GLMmodel *tree_3 = glmReadOBJ("data/tree3.obj");
GLMmodel *al = glmReadOBJ("data/al.obj");

void drawCar(void)
{
	glmDraw(body, GLM_WIREFRAME);
	
	glColor3f(0, 0, 0);

	glTranslatef(0, 0, 0);
	glmDraw(tire, GLM_WIREFRAME);

	glTranslatef(-37, 0, 0);	
	glmDraw(tire, GLM_WIREFRAME);
	
	glTranslatef(0, 0, 63.5);	
	glmDraw(tire, GLM_WIREFRAME);

	glTranslatef(37, 0, 0);	
	glmDraw(tire, GLM_WIREFRAME);
}
void Street1()
{
	glPushMatrix();
	glTranslatef(0, 0, -17.0);
	glScalef(70.0, 1000.5, 0.1);
	glColor3f(.70f, .60f, .60f);
	//if(fillOn) glutSolidCube(1.0);
	glutSolidCube(1.0);
	//else glutWireCube(1.0); 
	glPopMatrix();
}

void Street2()
{
	glPushMatrix();
	glTranslatef(0, 0, -17.0);
	glScalef(70.0, 500.5, 0.1);
	glColor3f(.70f, .60f, .60f);
	//if(fillOn) glutSolidCube(1.0);
	glutSolidCube(1.0);
	//else glutWireCube(1.0); 
	glPopMatrix();
}

//중앙선
void center1()
{
	glPushMatrix();
	glTranslatef(0, 0, -16.9);
	glScalef(10.0, 750.5, 0.1);
	glColor3f(1.0f, 1.0f, 0.0f);
	//if(fillOn) 
	glutSolidCube(1.0);
	//else glutWireCube(1.0); 
	glPopMatrix();
}

void corner1()
{
	glPushMatrix();
	glTranslatef(-125, -490, -17.1);
	glScalef(320.0, 320, 0.1);
	glColor3f(.70f, .60f, .60f);
	//if(fillOn) 
	glutSolidSphere(0.5, 100,100);
	//glutWireSphere(0.5, 20,20);		
	//else glutWireCube(1.0); 
	glPopMatrix();
}

void black1()
{
	glPushMatrix();
	glTranslatef(-125, -370, -16.9);
	glScalef(179.0, 179, 0.1);
	glColor3f(0.0f, 0.6f, 0.0f);
	//if(fillOn) 
	glutSolidSphere(0.5, 200,200);
	//glutWireSphere(0.5, 20,20);		
	//else glutWireCube(1.0); 
	glPopMatrix();
}

void black2()
{
	glPushMatrix();
	glTranslatef(-125, -370, -16.9);
	glScalef(179.0, 179, 0.1);
	glColor3f(0.0f, 0.6f, 0.0f);
	//if(fillOn) 
	glutSolidSphere(1.1, 1000,1000);
	//glutWireSphere(0.5, 20,20);		
	//else glutWireCube(1.0); 
	glPopMatrix();
}

//나무1
void tree()
{
	glPushMatrix();
	glTranslatef(0, 0, 0.0);
	glScalef(200.0, 200, 150.1);
	glColor3f(0.6f, 0.3f, 0.0f);
	//if(fillOn) 
	glmDraw(tree_1, GLM_WIREFRAME);
	//glutWireSphere(0.5, 20,20);		
	//else glutWireCube(1.0); 
	glPopMatrix();
}

void tree2()
{
	glPushMatrix();
	glTranslatef(0, 0, 0.0);
	glScalef(130.0, 130, 150.1);
	glColor3f(0.6f, 0.3f, 0.0f);
	//if(fillOn) 
	glmDraw(tree_2, GLM_WIREFRAME);
	//glutWireSphere(0.5, 20,20);		
	//else glutWireCube(1.0); 
	glPopMatrix();
}

void stand()
{
	glPushMatrix();
	glTranslatef(-110, 9, -16.9);
	glScalef(1700, 50, 250.1);
	glColor3f(.75, .75, .75);
	//if(fillOn) 
	glutSolidCube(1.0);
	glColor3f(0.1, 0.1, 0.1);
	glutWireCube(1.0); 
	glPopMatrix();
}

void stand2()
{
	glPushMatrix();
	glTranslatef(-110, 9, -16.9);
	glScalef(1700, 50, 170.1);
	glColor3f(.75, .75, .75);
	//if(fillOn) 
	glutSolidCube(1.0);
	glColor3f(0.1, 0.1, 0.1);
	glutWireCube(1.0); 
	glPopMatrix();
}

void stand3()
{
	glPushMatrix();
	glTranslatef(-110, 9, -16.9);
	glScalef(1700, 50, 90.1);
	glColor3f(.75, .75, .75);
	//if(fillOn) 
	glutSolidCube(1.0);
	glColor3f(0.1, 0.1, 0.1);
	glutWireCube(1.0); 
	glPopMatrix();
}

void map()
{
	glPushMatrix();
	glTranslatef(-110, -20, 220.9);
	glScalef(3000, 2, 3000.1);
	glColor3f(0.0f, 0.6f, 0.0f);
	//if(fillOn) 
	glutSolidCube(1.0);
	//glColor3f(0.0f, 1.0f, 0.0f);
	//glutWireCube(1.0); 
	glPopMatrix();
}

void wall()
{
	glPushMatrix();
	glTranslatef(0, 180, 0);
	glScalef(2900, 400, 70.1);
	glColor3f(.75, .75, .75);
	//if(fillOn) 
	glutSolidCube(1.0);
	glColor3f(0.1, 0.1, 0.1);
	glutWireCube(1.0); 
	glPopMatrix();
}

void myDisplay(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	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);


	glPushMatrix();
	glRotatef(-90, 1,0,0);
	glRotatef(0, 0,1,0);
	glRotatef(0, 0,0,1);
	Street1();//도로



	glPushMatrix();
	glTranslatef(-250, 0, 0.0);
	Street1();//도로
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-500, 0, 0.0);
	Street1();//도로
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-750, 0, 0.0);
	Street1();//도로
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-1000, 0, 0.0);
	Street1();//도로
	glPopMatrix();


	glPushMatrix();
	glTranslatef(-1000, -500, 0.0);
	Street1();//도로
	glPopMatrix();

	glPushMatrix();
	glTranslatef(749, -500, 0.0);
	Street1();//도로
	glPopMatrix();

	glPushMatrix();
	glTranslatef(749, 0, 0.0);
	Street1();//도로
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-400, -1100, 0.0);
	glRotatef(0, 1,0,0);
	glRotatef(0, 0,1,0);
	glRotatef(90, 0,0,1);
	Street1();//도로
	glPopMatrix();

	glPushMatrix();
	glTranslatef(100, -1100, 0.0);
	glRotatef(0, 1,0,0);
	glRotatef(0, 0,1,0);
	glRotatef(90, 0,0,1);
	Street1();//도로
	glPopMatrix();

	glPushMatrix();
	glTranslatef(410, 635, 0.0);
	glRotatef(0, 1,0,0);
	glRotatef(0, 0,1,0);
	glRotatef(90, 0,0,1);
	Street2();//도로
	glPopMatrix();

	glPushMatrix();
	center1();//중앙선
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-250, 0, 0.0);
	center1();//중앙선
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-500, 0, 0.0);
	center1();//중앙선
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-750, 0, 0.0);
	center1();//중앙선
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-1000, 0, 0.0);
	center1();//중앙선
	glPopMatrix();

	glPushMatrix();
	corner1();//코너
	glTranslatef(-250, 1000, 0.0);
	corner1();
	glTranslatef(-250, -1000, 0.0);
	corner1();
	glTranslatef(-250, 1000, 0.0);
	corner1();
	glTranslatef(0, -1485, 0.0);
	corner1();
	glTranslatef(1500, 0, 0.0);
	corner1();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(250, 1000, 0.0);
	corner1();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(750, 1000, 0.0);
	corner1();
	glPopMatrix();


	glPushMatrix();
	black1();//가리기
	glTranslatef(-250,  750, 0.0);
	black1();
	glTranslatef(-250,  -750, 0.0);
	black1();
	glTranslatef(-250,  750, 0.0);
	black1();
	glTranslatef(105,  -1248, 0.0);
	//glutSolidSphere(10, 200,200);
	//glScalef(200.0, 200, 0.1);
	black2();
	glTranslatef(1290,  0, 0.0);
	//glutSolidSphere(10, 200,200);
	//glScalef(200.0, 200, 0.1);
	black2();

	glTranslatef(0,  1270, 0.0);
	black2();
	glTranslatef(-290,  0, 0.0);
	black2();
	glPopMatrix();



	glPopMatrix();

	glPushMatrix();
	glTranslatef(-125, -17, 360.0);
	tree();// 나무1
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-125, -17, 220.0);
	tree2();//나무2
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-125, -17, 80.0);
	tree();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-125, -17, -60.0);
	tree2();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-125, -17, -200.0);
	tree();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-125, -17, -340.0);
	tree2();
	glPopMatrix();

	//----------------------

	glPushMatrix();
	glTranslatef(-380, -17, 360.0);
	tree();// 나무1
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-380, -17, 220.0);
	tree2();//나무2
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-380, -17, 80.0);
	tree();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-380, -17, -60.0);
	tree2();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-380, -17, -200.0);
	tree();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-380, -17, -340.0);
	tree2();
	glPopMatrix();

	//------------------------

	glPushMatrix();
	glTranslatef(-635, -17, 360.0);
	tree();// 나무1
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-635, -17, 220.0);
	tree2();//나무2
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-635, -17, 80.0);
	tree();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-635, -17, -60.0);
	tree2();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-635, -17, -200.0);
	tree();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-635, -17, -340.0);
	tree2();
	glPopMatrix();

	//---------------------

	glPushMatrix();
	glTranslatef(-890, -17, 360.0);
	tree();// 나무1
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-890, -17, 220.0);
	tree2();//나무2
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-890, -17, 80.0);
	tree();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-890, -17, -60.0);
	tree2();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-890, -17, -200.0);
	tree();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-890, -17, -340.0);
	tree2();
	glPopMatrix();

	glPushMatrix();

	glTranslatef(0, 0, -900);
	stand();//스탠드
	glTranslatef(0, 51, -40);
	stand2();
	glTranslatef(0, 51, -40);
	stand3();
	glPopMatrix();

	glPushMatrix();

	glTranslatef(0, 0, 1400);
	stand();//스탠드
	glTranslatef(0, 51, 40);
	stand2();
	glTranslatef(0, 51, 40);
	stand3();
	glPopMatrix();	

	glPushMatrix();
	glTranslatef(-1300, 0, 120);
	glRotatef(0, 1,0,0);
	glRotatef(90, 0,1,0);
	glRotatef(0, 0,0,1);
	stand();
	glTranslatef(0, 51, -40);
	stand2();
	glTranslatef(0, 51, -40);
	stand3();
	glPopMatrix();	

	glPushMatrix();
	glTranslatef(1000, 0, 120);
	glRotatef(0, 1,0,0);
	glRotatef(90, 0,1,0);
	glRotatef(0, 0,0,1);
	stand();
	glTranslatef(0, 51, 40);
	stand2();
	glTranslatef(0, 51, 40);
	stand3();
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-1300, -16, -850.0);
	glScalef(2.5, 2.5, 2.5);
	glColor3f(0.6f, 0.3f, 0.0f);
	glmDraw(tree_3, GLM_WIREFRAME);
	glPopMatrix();


	glPushMatrix();
	glTranslatef(-1300, -16, 1300.0);
	glScalef(2.5, 2.5, 2.5);
	glColor3f(0.6f, 0.3f, 0.0f);;
	glmDraw(tree_3, GLM_WIREFRAME);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(950, -16, -850.0);
	glScalef(2.5, 2.5, 2.5);
	glColor3f(0.6f, 0.3f, 0.0f);
	glmDraw(tree_3, GLM_WIREFRAME);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(950, -16, 1300.0);
	glScalef(2.5, 2.5, 2.5);
	glColor3f(0.6f, 0.3f, 0.0f);
	glmDraw(tree_3, GLM_WIREFRAME);
	glPopMatrix();

	//--------사람
	glPushMatrix();
	glTranslatef(-700, 70, -820);
	glScalef(10,10,10);
	glColor3f(0.1f, .1f, .1f);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(20, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(10, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(22, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(16, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(5, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(23, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(38, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(7, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-780, 120, -900);
	glScalef(10,10,10);
	glColor3f(.1, .1f, .1f);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(5, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(13, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(8, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(20, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(11, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(18, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(16, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(13, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(7, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(18, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(9, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-800, 170, -980);
	glScalef(10,10,10);
	glColor3f(.1f, .1f, .1f);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(32, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(22, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(43, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(30, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(11, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glPopMatrix();


	glPushMatrix();

	glTranslatef(-750, 70, 1300);
	glRotatef(0, 1,0,0);
	glRotatef(180, 0,1,0);
	glRotatef(0, 0,0,1);
	glScalef(10,10,10);
	glColor3f(.1, .1f, .1f);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-9, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-12, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-14, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-5, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-20, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-14, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-11, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-15, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-11, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-19, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-6, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glTranslatef(-4, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-790, 120, 1380);
	glRotatef(0, 1,0,0);
	glRotatef(180, 0,1,0);
	glRotatef(0, 0,0,1);
	glScalef(10,10,10);
	glColor3f(.1, .1f, .1f);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-6, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-3, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-7, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-2, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-10, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-22, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-8, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-4, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-15, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-9, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-790, 170, 1460);
	glRotatef(0, 1,0,0);
	glRotatef(180, 0,1,0);
	glRotatef(0, 0,0,1);
	glScalef(10,10,10);
	glColor3f(.1, .1f, .1f);
	glmDraw(al, GLM_WIREFRAME);
		//glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-9, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-22, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-12, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-3, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-6, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-8, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-14, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-19, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-7, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-6, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-11, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
		glTranslatef(-4, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
			glTranslatef(-10, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
			glTranslatef(-10, 0, 0);
	glmDraw(al, GLM_WIREFRAME);
			glTranslatef(-5, 0, 0);
	glmDraw(al, GLM_WIREFRAME);

	glPopMatrix();

	glPushMatrix();
	map();//밑에 깔리는거
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-750, 0, 990);
	glScalef(60,60,60);
	glColor3f(0.6f, 0.3f, 0.0f);
	glmDraw(tree_2, GLM_WIREFRAME);
	glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);
	glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);

		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);

		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);

		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);

		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);

		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);

		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);

		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);

		glTranslatef(1, 0, 0 );
	glmDraw(tree_2, GLM_WIREFRAME);

	glPopMatrix();


	glPushMatrix();
	glTranslatef(-100, 0, -1315 );
	
	wall();
	glPopMatrix();

	glPushMatrix();

	if(anitheta <=460)
	{
		glTranslatef(0, 0, anitheta);
	}

	else if(anitheta <=550)
	{
		glTranslatef((-anitheta%460), 0, anitheta);
		glRotatef(-anitheta%460, 0, 1, 0);
	}

	else if(anitheta <=590)
	{
		glTranslatef((-anitheta%460)-9, 0, 550);
		glRotatef(-90, 0, 1, 0);
	}
	
	else if(anitheta <=680)
	{
		glTranslatef((-anitheta%460)-18, 0, 590-(anitheta%550));
		glRotatef(-anitheta%590-90, 0, 1, 0);
	}

	else if(anitheta <=1600)
	{
		glTranslatef(-250, 0, 460-(anitheta-680));
		glRotatef(180, 0, 1, 0);
	}

	else if(anitheta <=1690)
	{
		glTranslatef(-250+(-anitheta%1600), 0, 460-(anitheta-680));
		glRotatef(anitheta%1600 + 180, 0, 1, 0);
	}

	else if(anitheta <=1730)
	{
		glTranslatef(-250+(-anitheta%1600)-9, 0, -550);
		glRotatef(-90, 0, 1, 0);
	}
	
	else if(anitheta <=1820)
	{
		glTranslatef(-250+(-anitheta%1600)-18, 0, -550+(anitheta%1730));
		glRotatef(anitheta%1730-90, 0, 1, 0);
	}

	else if(anitheta <=2740)
	{
		glTranslatef(-500, 0, -460+(anitheta-1820));
	}

	else if(anitheta <=2830)
	{
		glTranslatef(-500+(-anitheta%2740), 0, 460+(anitheta%2740));
		glRotatef(-anitheta%2740, 0, 1, 0);
	}

	else if(anitheta <=2870)
	{
		glTranslatef(-500+(-anitheta%2740)-9, 0, 550);
		glRotatef(-90, 0, 1, 0);
	}
	
	else if(anitheta <=2960)
	{
		glTranslatef(-500+(-anitheta%2740)-18, 0, 550-(anitheta%2870));
		glRotatef(-anitheta%2870-90, 0, 1, 0);
	}

	else if(anitheta <=3880)
	{
		glTranslatef(-750, 0, 460-(anitheta-2960));
		glRotatef(180, 0, 1, 0);
	}

	else if(anitheta <=3970)
	{
		glTranslatef(-750+(-anitheta%3880), 0, 460-(anitheta-2960));
		glRotatef(anitheta%3880 + 180, 0, 1, 0);
	}

	else if(anitheta <=4010)
	{
		glTranslatef(-750+(-anitheta%3880)-9, 0, -550);
		glRotatef(-90, 0, 1, 0);
	}
	
	else if(anitheta <=4100)
	{
		glTranslatef(-750+(-anitheta%3880)-18, 0, -550+(anitheta%4010));
		glRotatef(anitheta%4010-90, 0, 1, 0);
	}

	else if(anitheta <=5520)
	{
		glTranslatef(-1000, 0, -460+(anitheta-4100));
	}

	else if(anitheta <=5610)
	{
		glTranslatef(-1000+(anitheta%5520), 0, -460+(anitheta-4100)+15);
		glRotatef(anitheta%5520, 0, 1, 0);
	}

	else if(anitheta <=7160)
	{
		glTranslatef(-1000+(anitheta%5520), 0, 1095);
		glRotatef(90, 0, 1, 0);
	}

	else if(anitheta <=7250)
	{
		glTranslatef(-1000+(anitheta%5520)+10, 0, 1095-(anitheta%7160));
		glRotatef(anitheta%7160+90, 0, 1, 0);
	}

	else if(anitheta <=8750)
	{
		glTranslatef(740, 0, 1100-(anitheta%7160));
		glRotatef(180, 0, 1, 0);
	}

	else if(anitheta <=8840)
	{
		glTranslatef(740-(anitheta%8750), 0, 1100-(anitheta%7160)-15);
		glRotatef(anitheta%8750+180, 0, 1, 0);
	}

	else if(anitheta <=9390)
	{
		glTranslatef(650-(anitheta%8840), 0, -630);
		glRotatef(-90, 0, 1, 0);
	}

	else if(anitheta <=9480)
	{
		glTranslatef(90-(anitheta%9390), 0, -630+(anitheta%9390));
		glRotatef(-90+(anitheta%9390), 0, 1, 0);
	}
	
	else if(anitheta <=10010)
	{
		glTranslatef(0, 0, -550+(anitheta%9480));
	}
	
	glColor3f(0, 0.1, 0.9);	
	drawCar();

	glPopMatrix();

	glFlush();
	glutSwapBuffers();
}

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;
	}
	center[2] = eye[2] - cos(theta);
	center[0] = eye[0] + sin(theta);
}

void myResize(int width, int height)
{
	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.0, (float)width/height, 0.1, 100.);
		eye[2] = 10;
		myLookAt(0);
	}
	glEnable(GL_DEPTH_TEST);
	windowWidth = width;
	windowHeight = height;
}

void myIdle(void)
{
	if(anitheta < 10000)
	{
		anitheta += anithetaDelta;
	}
	else
	{
		anitheta = 0;
	}
	glutPostRedisplay();
}

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;
		if(aniOn)
			glutIdleFunc(myIdle);
	}
	else
		return;
	glutPostRedisplay();
}

void myKeyboard(unsigned char key, int x, int y)
{
	switch (key) 
	{
		case ' ':
					aniOn = !aniOn;
					if(aniOn)
						glutIdleFunc(myIdle);
					else
						glutIdleFunc(NULL);
					break;
		case 'a':
					if(anithetaDelta < 101)
						anithetaDelta+=10;
					break;
		case 'd':
					if(anithetaDelta > 11)
						anithetaDelta-=10;
					break;
		case 'z':
					scale *= scaleDelta;
					break;
		case 'x':
					scale /= scaleDelta;
					break;
	}
	glutPostRedisplay();
}

void mySKeyboard (int key, int x, int y)
{
	switch (key) {
		case GLUT_KEY_UP : 
		break;
		case GLUT_KEY_DOWN : 
		break;
		case GLUT_KEY_LEFT : 
			theta-=thetaDelta; 
		break;
		case GLUT_KEY_RIGHT : 
			theta+=thetaDelta; 
		break;
		default : return;
    	}
	myLookAt(key);
	glutPostRedisplay();
}

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

void myInit(void)
{
	c = gluNewQuadric();
	gluQuadricDrawStyle(c, GLU_LINE);
}

void main()
{
	myInit();
	printf("a -> 속도 업, d -> 속도 다운, z -> 확대, x -> 축소 \n각 방향키 카메라 조절");
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitWindowSize(1000, 800);
	glutCreateWindow("Car");
	glutDisplayFunc(myDisplay);
	glutReshapeFunc(myResize);
	glutKeyboardFunc(myKeyboard);
	glutSpecialFunc(mySKeyboard);
	glutMouseFunc(myMouse);
	glutMotionFunc(myMotion);
	glutMainLoop();
}