void tree(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height, GLfloat theight)
{
/* function tree()
중심 x, y, z 좌표를 받아 사각뿔의 밑면 길이가 width이고 사각뿔 높이가 height이고 줄기 부분 높이가 theight인 나무 생성
x : x 좌표
y : y 좌표
z : z 좌표
width : 나무 잎 부분 사각뿔 밑면 길이
eight : 나무 잎 부분 사각뿔 높이 길이
theight : 나무 줄기 부분 원기둥 높이
*/
float v[3][3];
float out[3];
v[0][0]= x; v[0][1]=y; v[0][2]=z;
v[1][0] = x-width; v[1][1] = y-height; v[1][2] = z-width;
v[2][0] = x-width; v[2][1] = y-height; v[2][2] = z+width;
glPushMatrix();
glTranslated(x, y+height+theight, z);
glColor3ub(34, 139, 34);
glBegin(GL_TRIANGLE_FAN); //나무 윗부분 사각뿔
calcNormal(v, out);
glNormal3f(0.0f, 1.0f, 0.0f);
glVertex3f(x, y, z);
glNormal3fv(out);
glVertex3f(x-width, y-height, z-width);
glNormal3fv(out);
glVertex3f(x-width, y-height, z+width);
v[1][0] = x-width; v[1][1] = y-height; v[1][2] = z+width;
v[2][0] = x+width; v[2][1] = y-height; v[2][2] = z-width;
calcNormal(v, out);
glNormal3fv(out);
glVertex3f(x+width, y-height, z+width);
v[1][0] = x+width; v[1][1] = y-height; v[1][2] = z+width;
v[2][0] = x+width; v[2][1] = y-height; v[2][2] = z-width;
calcNormal(v, out);
glNormal3fv(out);
glVertex3f(x+width, y-height, z-width);
v[1][0] = x+width; v[1][1] = y-height; v[1][2] = z-width;
v[2][0] = x-width; v[2][1] = y-height; v[2][2] = z-width;
calcNormal(v, out);
glNormal3fv(out);
glVertex3f(x-width, y-height, z-width);
glEnd();
glBegin(GL_QUADS); //사각뿔 밑면
glNormal3f(0.0f, -1.0f, 0.0f);
glVertex3f(x-width, y-height, z-width);
glVertex3f(x+width, y-height, z-width);
glVertex3f(x+width, y-height, z+width);
glVertex3f(x-width, y-height, z+width);
glEnd();
glTranslatef(x, y-height, z);
glRotated(90.0f, 1.0f, 0.0f, 0.0f);
treebottom(0.0f, 0.0f, 0.0f, 10.0f, theight); //나무 원기둥 함수
glPopMatrix();
}