#include <glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159
#define StartLength 15.0

float PI2, PI5,Dtheta, Length_Scale, neck = 5.0, lighting = 1.0;
GLfloat zdisp=-5.0,lightx=2.0;
GLfloat Ax,Bx,Cx,Dx,Ay,By,Cy,Dy,Az,Bz,Cz,Dz,x1,k,l,x2,y2,z2,t,p,constx1,consty1,constz1;
int i, spin = 0, m = 0;

// This window is mapped to the viewport
void setWindow(float left, float right, float bottom , float top)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(left,right,bottom,top);
}

// Viewport inside the screen window
void setViewport(int left, int right, int bottom, int top)
{
	glViewport(left,bottom, right-left, top-bottom);
}

// DrawRiver Routine
void DrawRiver(float firstx1,float firsty1,float firstz1,float lastx2,float lasty2,float lastz2,float conx1, float cony1,float conz1,float conx2,float cony2,float conz2)
{
Ax =lastx2 -firstx1-3*conx2+3*conx1;
Bx = 3*firstx1 -6*conx1 +3*conx2;
Cx=-3*firstx1+3*conx1;
Dx=firstx1;
Ay =lasty2 -firsty1-3*cony2+3*cony1;
By = 3*firsty1 -6*cony1 +3*cony2;
Cy=-3*firsty1+3*cony1;
Dy=firsty1;
Az =lastz2 -firstz1-3*conz2+3*conz1;
Bz = 3*firstz1 -6*conz1 +3*conz2;
Cz=-3*firstz1+3*conz1;
Dz=firstz1;
// Curve
glPushMatrix();
for (t=0.0;t<=1.0 ; t=t+0.05)
{
	x1=Ax*t*t*t +Bx*t*t + Cx*t + Dx;
	k =Ay*t*t*t +By*t*t + Cy*t + Dy;
	l =Az*t*t*t +Bz*t*t + Cz*t + Dz;
	p=t+0.05;
    x2=Ax*p*p*p +Bx*p*p + Cx*p + Dx;
	y2=Ay*p*p*p +By*p*p + Cy*p + Dy;
	z2=Az*p*p*p +Bz*p*p + Cz*p + Dz;

	if (t< 0.01) constx1=x1; 
	if (t< 0.01) consty1=k;

    glBegin(GL_TRIANGLE_FAN); // Fills the bezier curve using triangle fan constant z = 1.0
	glColor3f(0.2,0,0.6);
	glVertex3f(constx1,consty1,1.0);
	glVertex3f(x1,k,1.0);
	glVertex3f(x2,y2,1.0);
	glEnd();

	glBegin(GL_TRIANGLE_FAN); // Second layer of bezier at constant z = 25.0
	glColor3f(0.0,0.2,0.6);
	glVertex3f(constx1,consty1,20.5);
	glVertex3f(x1,k,20.5);
	glVertex3f(x2,y2,20.5);
	glEnd();  

    glBegin(GL_QUADS);
	glColor3f(0.0,0,0.6); // Stich the layers  together
	glVertex3f(x1,k,1.0);  
	glVertex3f(x2,y2,1.0);
	glVertex3f(x2,y2,20.5);
	glVertex3f(x1,k,20.5);
	glEnd();

}
glPopMatrix();
}

//River
void river()
{
glTranslated(-5,-21,0);
glRotatef(160,1,1,0);
DrawRiver(30,-50,1,   -50,0,1,   20,100,1,    6,-10,1);
}

// Mountain
void Mountain(float x1,float y1,float x2,float y2,float range, int div)
{
  
 float midx;
 float midy;
 // Mid value of x coordinates and
 // Mid value of y coordinates + random value
 midx = (x1+x2)/2;
 midy =(y1+y2)/2 + (range*(rand()%5+1)/2);
 // # of divisions
 if (div < 6) 
 { Mountain(x1,y1,midx,midy,(range*(rand()%5+1)/2),div +1);
   Mountain(midx,midy,x2,y2,(range*(rand()%5 +1)/2),div +1);
 } 
  else
  {
	glBegin(GL_LINES);
	glColor3f(0.58,0.39,0.0);
	glVertex2f(x1,y1);
	glVertex2f(x2,y2);
	glEnd();
	} 
}

// Mountain Floor 1
void mountainFloor()
{
glBegin(GL_LINES);
	glColor3f(0.6,0.4,0.0);
	glVertex2f(60,10);
	glVertex2f(0,10);
	glEnd();
}

// Mountain Floor 2
void mountainFloor2()
{
glBegin(GL_LINES);
	glColor3f(0.6,0.4,0.0);
	glVertex2f(-90,10);
	glVertex2f(0,10);
	glEnd();
}

// DrawAxis Routine for X Y Z
void drawaxis(void)
{ 
  // x coordinates to draw the x axis
  GLdouble x1[3] = {-100.0, 0.0, 0.0}; // Define coordinates as an array
  GLdouble x2[3] = {50.0, 0.0, 0.0};  // GLdouble opengl varaible for storing doubles

  // y coordinates to draw the y axis
  GLdouble y1[3] = {0.0, -100.0, 0.0};
  GLdouble y2[3] = {0.0, 50.0, 0.0};

  // z coordinates to draw the z axis
  GLdouble z1[3] = {0.0, 0.0, -100.0};
  GLdouble z2[3] = {0.0, 0.0, 50.0};


  glBegin(GL_LINES);
  glColor3f(1.0, 0.0, 0.0); // Red X axis
  glVertex3dv(x1);
  glVertex3dv(x2);
  glColor3f(0.0, 1.0, 0.0); // Green y axis
  glVertex3dv(y1);
  glVertex3dv(y2);
  glColor3f(1.0, 1.0, 1.0); // White z axis
  glVertex3dv(z1);
  glVertex3dv(z2);
  glEnd();

}

//Define Binary Tree Function 
void DrawBinary(float level,float x,float y,float length,float theta)
{
float x1;
float y1;
	x1= x +length*sin(theta);
	y1= y + length*cos(theta);
	glBegin(GL_LINES);
	glColor3f(0.0,0.6,0.2);
	glVertex2f(x,y);
	glVertex2f(x1,y1);
	glEnd();
// If level >1 draw the attached branches - note use of recursion
// Call DrawBinary Routine
if (level > 1)
	{
	DrawBinary(level-1, x1,y1, length*Length_Scale,theta+Dtheta);
	DrawBinary(level-1, x1,y1, length*Length_Scale,theta-Dtheta);
	}
}

// DrawBezier Routine
void DrawBezier(float firstx1,float firsty1,float firstz1,float lastx2,float lasty2,float lastz2,float conx1, float cony1,float conz1,float conx2,float cony2,float conz2)
{
Ax =lastx2 -firstx1-3*conx2+3*conx1;
Bx = 3*firstx1 -6*conx1 +3*conx2;
Cx=-3*firstx1+3*conx1;
Dx=firstx1;
Ay =lasty2 -firsty1-3*cony2+3*cony1;
By = 3*firsty1 -6*cony1 +3*cony2;
Cy=-3*firsty1+3*cony1;
Dy=firsty1;
Az =lastz2 -firstz1-3*conz2+3*conz1;
Bz = 3*firstz1 -6*conz1 +3*conz2;
Cz=-3*firstz1+3*conz1;
Dz=firstz1;
// Curve
for (t=0.0;t<=1.0 ; t=t+0.05)
{
	x1=Ax*t*t*t +Bx*t*t + Cx*t + Dx;
	k =Ay*t*t*t +By*t*t + Cy*t + Dy;
	l =Az*t*t*t +Bz*t*t + Cz*t + Dz;
	p=t+0.05;
    	x2=Ax*p*p*p +Bx*p*p + Cx*p + Dx;
	y2=Ay*p*p*p +By*p*p + Cy*p + Dy;
	z2=Az*p*p*p +Bz*p*p + Cz*p + Dz;

	glLineWidth(5);
//  	glBegin(GL_LINES);
//	glColor3f(1.0,0.5,0.0);
//	glVertex3f(x1,k,l);
//	glVertex3f(x2,y2,z2);

	glPushMatrix();
	glTranslatef(x1,k,l);
	glColor3f(1.0,0.4,0.4);
	glutSolidSphere(1,25,25);
	glPopMatrix();
	glEnd();
	}
}

// Bushes
void bush1()
{

	PI2=PI/12;
	PI5=PI/8;
	Dtheta=PI5;
	Length_Scale=0.99;

	glPushMatrix();

	glScaled(0.1,0.1,0.1);

	//first tree
	glPushMatrix();
	glTranslated(-775,-800,0); //translate along the x axis to coincide with the origin
	glRotatef(70, 0,1,0); // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);	
	glPopMatrix();

	//second tree
	glPushMatrix();
	glTranslated(-775,-800,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(10.0,0.0,-10.0,StartLength,8/10);

	//third tree
	glPopMatrix();
	glPushMatrix();
	glTranslated(-775,-800,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
	glPopMatrix();

  
	//fourth tree
	glPushMatrix();
	glTranslated(-775,-800,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
	glPopMatrix();

	glPopMatrix();
}
void bush2()
{

	PI2=PI/12;
	PI5=PI/8;
	Dtheta=PI5;
	Length_Scale=0.99;

	glPushMatrix();

	glScaled(0.1,0.1,0.1);

	//first tree
	glPushMatrix();
	glTranslated(-700,-800,0); //translate along the x axis to coincide with the origin
	glRotatef(70, 0,1,0); // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);	
	glPopMatrix();

	//second tree
	glPushMatrix();
	glTranslated(-700,-800,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(10.0,0.0,-10.0,StartLength,8/10);

	//third tree
	glPopMatrix();
	glPushMatrix();
	glTranslated(-700,-800,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
	glPopMatrix();

  
	//fourth tree
	glPushMatrix();
	glTranslated(-700,-800,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
	glPopMatrix();

	glPopMatrix();
}

// Trees
void tree()
{
  // Center Tree
  PI2=PI/8;
  PI5=PI/6;
  Dtheta=PI5;
  Length_Scale=0.55;
  // First Tree Ting
  glPushMatrix();
  glRotatef(-spin, 0, 1, 0); // Spinning in the clockwise direction
  glColor3f(0.0,0.8,0.0);
  DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
  glPopMatrix();

  // 2nd Tree Ting
  glPushMatrix();
  glRotatef(-spin, 0, 1, 0); // Spinning in the clockwise direction
  glRotatef(-90, 0.0, 1.0, 0.0);
  glColor3f(0.0,0.8,0.0);
  DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
  glPopMatrix();

  // 3rd Tree Ting
  glPushMatrix();
  glRotatef(-spin, 0, 1, 0); // Spinning in the clockwise direction
  glRotatef(-120, 0.0, 1.0, 0.0);
  glColor3f(0.0,0.8,0.0);
  DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
  glPopMatrix();

  // 4th Tree Ting
  glPushMatrix();
  glRotatef(-spin, 0, 1, 0); // Spinning in the clockwise direction
  glRotatef(-200, 0.0, 1.0, 0.0);
  glColor3f(0.0,0.8,0.0);
  DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
  glPopMatrix();
  }

void tree2()
{
  // First Tree Ting
  glPushMatrix();
  glTranslatef(0,0,0);
  glRotatef(-spin, 0, 1, 0); // Spinning in the clockwise direction
  DrawBinary(15.0,20.0,-10.0,StartLength,8/10);
  glPopMatrix();

  glPushMatrix();
  glTranslatef(0,0,0);
  glRotatef(-spin, 0, 1, 0); // Spinning in the clockwise direction
  glRotatef(-90, 0.0, 1.0, 0.0);
  DrawBinary(15.0,20.0,-10.0,StartLength,8/10);
  glPopMatrix();

  glPushMatrix();
  glTranslatef(0,0,0);
  glRotatef(-spin, 0, 1, 0); // Spinning in the clockwise direction
  glRotatef(-120, 0.0, 1.0, 0.0);
  DrawBinary(15.0,20.0,-10.0,StartLength,8/10);
  glPopMatrix();

  glPushMatrix();
  glTranslatef(0,0,0);
  glRotatef(-spin, 0, 1, 0); // Spinning in the clockwise direction
  glRotatef(-200, 0.0, 1.0, 0.0);
  DrawBinary(15.0,20.0,-10.0,StartLength,8/10);
  glPopMatrix();
  }

void tree3()
{
	// Smallest, furthest tree.
	PI2=PI/12;
	PI5=PI/4;
	Dtheta=PI5;
	Length_Scale=0.4;

	glPushMatrix();
	glScaled(0.3,0.3,0.3);

	// First tree
	glPushMatrix();
	glTranslated(30,20,0); //translate along the x axis to coincide with the origin
	glRotatef(70, 0,1,0); // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);	
	glPopMatrix();

	// Second tree
	glPushMatrix();
	glTranslated(30,10,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(10.0,0.0,-10.0,StartLength,8/10);

	// Third tree
	glPopMatrix();
	glPushMatrix();
	glTranslated(30,20,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
	glPopMatrix();

  
	// Fourth tree
	glPushMatrix();
	glTranslated(30,20,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
	glPopMatrix();

	glPopMatrix();
}
void tree4()
	{
	//Far left tree
	PI2=PI/12;
	PI5=PI/8;
	Dtheta=PI5;
	Length_Scale=0.66;

	glPushMatrix();

	glScaled(0.5,0.5,0.5);

	// First tree
	glPushMatrix();
	glTranslated(-80,10,0); //translate along the x axis to coincide with the origin
	glRotatef(70, 0,1,0); // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);	
	glPopMatrix();

	// Second tree
	glPushMatrix();
	glTranslated(-80,10,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(10.0,0.0,-10.0,StartLength,8/10);

	// Third tree
	glPopMatrix();
	glPushMatrix();
	glTranslated(-80,10,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
	glPopMatrix();

  
	// Fourth tree
	glPushMatrix();
	glTranslated(-80,10,0);
	glRotatef(70, 0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
	glPopMatrix();

	glPopMatrix();
}
void tree5()
{
	//Far right tree (off corner of screen)
	PI2=PI/12;
	PI5=PI/7;
	Dtheta=PI5;
	Length_Scale=0.7;

	glPushMatrix();

	glScaled(0.7,0.7,0.7);

	// First tree
	glPushMatrix();
	glTranslated(50,-10,0); // Translate along the x axis to coincide with the origin
	glRotatef(70,0,1,0); // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);	
	glPopMatrix();

	// Second tree
	glPushMatrix();
	glTranslated(50,-20,0);
	glRotatef(70,0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(10.0,0.0,-10.0,StartLength,8/10);

	// Third tree
	glPopMatrix();
	glPushMatrix();
	glTranslated(50,-10,0);
	glRotatef(70,0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
	glPopMatrix();

  
	// Fourth tree
	glPushMatrix();
	glTranslated(50,-10,0);
	glRotatef(70,0,1,0);  // Spinning in the clockwise direction
	glTranslated(0.0,0.0,0.0);  // Translate back to the original position
	DrawBinary(15.0,0.0,-10.0,StartLength,8/10);
	glPopMatrix();

	glPopMatrix();
}

void dinomain()
{

  // Head
  glPushMatrix();
  //glRotatef(spin,a,b,c);
  DrawBezier(1,neck,2.5,  5,-5,2.5,  5,5,2.5,  5,2.5,2.5);
  glPopMatrix();

  // Torso
  glPushMatrix();
  //glRotatef(spin,a,b,c);
  DrawBezier(5,-5,2.5,  20,-10,2.5,  10,-10,2.5,  15,-15,2.5);
  glPopMatrix();

  // Tail
  glPushMatrix();
  //glRotatef(spin,a,b,c);
  DrawBezier(20,-10,2.5,  24,-5,2.5,  20,-6,2.5,  20,-8,2.5);
  glPopMatrix();

  // Legs
  glPushMatrix();
  //glRotatef(spin,a,b,c);
  DrawBezier(10,-10,2.5,  15,-20,-1.5,  10,-15,1.5,  10,-15,0.5);
  glPopMatrix();
  glPushMatrix();
  //glRotatef(spin,a,b,c);
  DrawBezier(10,-10,2.5,  15,-20,5.5,  10,-15,3.5,  10,-15,4.5);
  glPopMatrix();

  // Claw
  glPushMatrix();
  //glRotatef(spin,a,b,c);
  DrawBezier(5,-5,2.5,  2,-15,1.0,  6,-8,2.0,  6,-10,1.5);
  glPopMatrix();
  glPushMatrix();
  //glRotatef(spin,a,b,c);
  DrawBezier(5,-5,2.5,  2,-15,4.0,  6,-8,3.0,  6,-10,3.5);
  glPopMatrix();
  }
void dino2()
{

  // Head
  glPushMatrix();
  glTranslated(-50,-10,1);
  glRotatef(70,0,1,0);
  DrawBezier(1,5,2.5,  5,-5,2.5,  5,5,2.5,  5,2.5,2.5);
  glPopMatrix();

  // Torso
  glPushMatrix();
  glTranslated(-50,-10,1);
  glRotatef(70,0,1,0);
  DrawBezier(5,-5,2.5,  20,-10,2.5,  10,-10,2.5,  15,-15,2.5);
  glPopMatrix();

  // Tail
  glPushMatrix();
  glTranslated(-50,-10,1);
  glRotatef(70,0,1,0);
  DrawBezier(20,-10,2.5,  24,-5,2.5,  20,-6,2.5,  20,-8,2.5);
  glPopMatrix();

  // Legs
  glPushMatrix();
  glTranslated(-50,-10,1);
  glRotatef(70,0,1,0);
  DrawBezier(10,-10,2.5,  15,-20,-1.5,  10,-15,1.5,  10,-15,0.5);
  glPopMatrix();

  glPushMatrix();
  glTranslated(-50,-10,1);
  glRotatef(70,0,1,0);
  DrawBezier(10,-10,2.5,  15,-20,5.5,  10,-15,3.5,  10,-15,4.5);
  glPopMatrix();

  // Claws
  glPushMatrix();
  glTranslated(-50,-10,1);
  glRotatef(70,0,1,0);
  DrawBezier(5,-5,2.5,  2,-15,1.0,  6,-8,2.0,  6,-10,1.5);
  glPopMatrix();

  glPushMatrix();
  glTranslated(-50,-10,1);
  glRotatef(70,0,1,0);
  DrawBezier(5,-5,2.5,  2,-15,4.0,  6,-8,3.0,  6,-10,3.5);
  glPopMatrix();
  }
void dino3()
{

  // Head
  glPushMatrix();
  glTranslated(-70,-10,1);
  glRotatef(180,0,1,0);
  DrawBezier(1,5,2.5,  5,-5,2.5,  5,5,2.5,  5,2.5,2.5);
  glPopMatrix();

  // Torso
  glPushMatrix();
  glTranslated(-70,-10,1);
  glRotatef(180,0,1,0);
  DrawBezier(5,-5,2.5,  20,-10,2.5,  10,-10,2.5,  15,-15,2.5);
  glPopMatrix();

  // Tail
  glPushMatrix();
  glTranslated(-70,-10,1);
  glRotatef(180,0,1,0);
  DrawBezier(20,-10,2.5,  24,-5,2.5,  20,-6,2.5,  20,-8,2.5);
  glPopMatrix();

  // Legs
  glPushMatrix();
  glTranslated(-70,-10,1);
  glRotatef(180,0,1,0);
  DrawBezier(10,-10,2.5,  15,-20,-1.5,  10,-15,1.5,  10,-15,0.5);
  glPopMatrix();

  glPushMatrix();
  glTranslated(-70,-10,1);
  glRotatef(180,0,1,0);
  DrawBezier(10,-10,2.5,  15,-20,5.5,  10,-15,3.5,  10,-15,4.5);
  glPopMatrix();

  // Claws
  glPushMatrix();
  glTranslated(-70,-10,1);
  glRotatef(180,0,1,0);
  DrawBezier(5,-5,2.5,  2,-15,1.0,  6,-8,2.0,  6,-10,1.5);
  glPopMatrix();

  glPushMatrix();
  glTranslated(-70,-10,1);
  glRotatef(180,0,1,0);
  DrawBezier(5,-5,2.5,  2,-15,4.0,  6,-8,3.0,  6,-10,3.5);
  glPopMatrix();
  }

// Reshape the callback function when window is moved or resized
void reshape(int width, int height)
{
   glViewport(0, 0, width, height);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluPerspective(50.0,1.0,15.0,350.0);  // Perspective
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
}


// Display Routine
void display(void)
{
	/*Lighting
   GLfloat mat_ambient[] = {0.8f, 0.5f, 0.0f, 1.0f}; 
   GLfloat mat_diffuse[] = {1.0f, 0.0f, 0.0f, 1.0f};
   GLfloat mat_specular[] = {1.0f, 0.0f, 0.0f, 1.0f};
   GLfloat mat_shininess[] = {150.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);
   GLfloat lightIntensity[] = {0.5f, 0.5f, 0.5f, 1.0f}; // Colours
   GLfloat light_position[] = {2.0f, lighting, 3.0f, 0.0f}; // Lighting direction
   glLightfv(GL_LIGHT0, GL_POSITION, light_position); // Lighting location
   glLightfv(GL_LIGHT0, GL_DIFFUSE, lightIntensity);
*/

   // Clear Window
   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

  gluLookAt(50.0, 20.0, 50.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);  // Position of the eye
  glPolygonMode(GL_FRONT,GL_FILL); // Draw the polygon in line mode
  glPolygonMode(GL_BACK,GL_FILL);

  // Mountains
  glPushMatrix();
  Mountain(0,10,   35,10,   3,3);
  mountainFloor();
  glPopMatrix();
  glPushMatrix();
  Mountain(0,10,   -90,10,   3,3);
  mountainFloor2();
  glPopMatrix();

  // River
  glPushMatrix();
  river();
  glPopMatrix();

  // Dinosaurs
  dinomain();
  dino2();
  dino3();

  // Trees & Bushes
  glPushMatrix();
  tree();
  //tree2();
  tree3();
  tree4();
  tree5();
  bush1();
  bush2();
  glPopMatrix();

  glutSwapBuffers();
  glFlush();
}

/* graphics initialisation */ 
void init(void)
{
   glClearColor (0.2, 0.2, 0.2, 1);   // Background colour
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_CULL_FACE);  // Enable back culling
   glCullFace(GL_BACK);     // Cull back faces
   setWindow(0.0,1024.0,0.0,768.0);          // Resolution

}

// Keyboard
void keyboard(unsigned char key, int x, int y) 
{
   switch (key) {


 case 'y':
            spin = (spin + 10) % 360;
			glutPostRedisplay(); // Use display function with new value of spin
         break;

 case 't':
            neck = (neck + 0.5);
			glutPostRedisplay();
         break;

 case 'r':
            neck = (neck - 0.5);
			glutPostRedisplay();
         break;
 case 's':
            lighting = (lighting + 0.3);
            glutPostRedisplay();
         break;

 case 'l':
            lighting = (lighting - 0.3);
            glutPostRedisplay();
         break;

 case 'c':
            neck = 5;
			glutPostRedisplay();
         break;

   }
}
int main(int argc, char** argv)
{
   /* window management code ... */
   /* initialises GLUT and processes any command line arguments */  
   glutInit(&argc, argv);
   /* use single-buffered window and RGBA colour model */
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
   /* enable the depth test */
   glEnable(GL_DEPTH_TEST);
   // Resolution
   glutInitWindowSize (1024, 768);
   /* window upper left corner at (0, 0) */
   glutInitWindowPosition (0, 0);
   // Window Title
   glutCreateWindow ("Jurasic Park");  

   /*Lighting
   glEnable(GL_LIGHTING);	
   glEnable(GL_LIGHT0);  
   glShadeModel(GL_SMOOTH);
   glEnable(GL_NORMALIZE);
*/
   init();

   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutKeyboardFunc(keyboard);
   glutMainLoop();
   return 0;
}

