//tamanho de posições que ocupam
#define SUBMARINO 3
#define BARCO     2
#define NAVIO     4

GLuint  barco;
GLuint  submarino;
GLuint  navio;

int EhDia=1;
//---------------------------------------------------------------------------
/*Esta função irá construir o modelo geométrico da bomba, usada para marcar o
local onde o usuário acertar os navios - */
void constroe_bomba(int x, int y)
{
   /*esfera da bomba*/
   glPushMatrix();
      glColor3f(1,0,0.1);
      glTranslatef(9-(2*y),-2,9-(2*x));
      //glutSolidSphere (raio, subdivisões em torno do eixo z, subdivisões ao longo do eixo z)
      glutSolidSphere(0.6, 10, 8);
   glPopMatrix();

    //cilíndro - detalhe da bomba
    glPushMatrix();
       glTranslatef(9-(2*y), -1.7,9-(2*x));
       glRotatef(90, 0.0, 1.0, 0.0); //rotacionando 90 graus em y
       glRotatef(270, 1.0, 0.0, 0.0); //rotacionando 270 graus em x
      //objeto quadrico(criado com gluNewQuadric), raio da base, raio do topo, altura,
      //subdivisões ao redor do eixo z, subdivisões ao longo do eixo z
       gluCylinder(gluNewQuadric(), 0.1, 0.1, 0.1, 5, 3);
    glPopMatrix();
}
//---------------------------------------------------------------------------
/*Esta função irá construir o modelo geométrico do submarino*/
void constroe_submarino(int intPosx, int intPosy)
{
   float x;

   /*inicia a composicao do submarino */
   submarino = glGenLists(0);
   glNewList(submarino, GL_COMPILE);

   glPushMatrix();
      glColor3f(0,0.9,0);
      //Formação da posição y
      if (intPosx >= 0 && intPosx <= 2)
         x = 5.9 - (2*intPosx);
      else if (intPosx == 3)
         x = -0.9;
      else if (intPosx > 3)
         x = -7.9+(2*(7-intPosx));

      glTranslatef(8.75-(2*intPosy), -1.5, x);

      /* corpo */
      gluCylinder(gluNewQuadric(), 0.5, 0.5, 3, 12, 3);  //raio base, raio topo, altura, slices, stacks

      //nariz do submarino
      glTranslatef(0,0,3);
      glutSolidSphere(0.49,10, 8);

      //final do corpo do submarino
      glTranslatef(0,0,-3);
      glPushMatrix();
         glScalef(1,1,2.0);
         //base para cauda (cone)
         glTranslatef(0,0,-0.41);
         gluCylinder(gluNewQuadric(), 0.2, 0.5, 0.4, 12, 3);   //raio base, raio topo, altura, slices, stacks
      glPopMatrix();

      //asa frontal
      glPushMatrix();
         glTranslatef(-0.8,0.0,2.5);
         glRotatef(90, 0.0,1.0,0.0);
         glScalef(1.2,0.5,1);
         gluCylinder(gluNewQuadric(), 0.1, 0.1, 1.6, 12, 3);   //raio base, raio topo, altura, slices, stacks
      glPopMatrix();

      //asa da cauda - vertical
      glTranslatef(0,0,-0.65);
      glBegin(GL_POLYGON);
         glVertex3f(0.0,0.8,0.0);
         glVertex3f(0.0,0.8,-0.1);
         glVertex3f(0.0,0.0,0.0);
         glVertex3f(0.0,0.0,0.3);
      glEnd();

      //asa da cauda - horizontal
      glTranslatef(0,0,0);
      glBegin(GL_TRIANGLES);
         glVertex3f(0.7,0.0,0);
         glVertex3f(-0.7,0.0,0);
         glVertex3f(0.0,0.0,0.7);
      glEnd();

      /* cabine - (arredondado)
	  glTranslatef(0,0.3,0.8);
	  glPushMatrix();
	  glScalef(0.8,0.8,1.0);
	  glutSolidSphere(0.4,20, 20);
	  glPopMatrix();*/

      // cilindro superior
      glTranslatef(0,0.3,0.8);
      glRotatef(240, 1.0, 1.0, 1.0);
      glPushMatrix();
         glScalef(1.2,0.8,1);
         gluCylinder(gluNewQuadric(), 0.3, 0.3, 0.3, 20, 10);  //raio base, raio topo, altura, slices, stacks
      glPopMatrix();

      glPushMatrix();
         //Iluminação da janela do submarino
         GLfloat especularidade[4]={0.0,0.0,0.0,1.0};  //capacidade de brilho do material
         if (EhDia == 0)
         {
            especularidade [0] = 2.0;
            especularidade [1] = 1.0;
            especularidade [2] = 1.0;
         }
         glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION, especularidade);
         //----------

		//Cor das janelas
		 glColor3f(0,0.2,0.8);
         
		 //Janelas Laterias
         glPushMatrix();
           //Lado Esquerdo
           glRotatef(90, 1.0, 0.0, 0.0);
           glTranslatef(0.4, -0.37, 0.50);
           glScalef(1.8,1,1);
           glutSolidTorus(0.03,0.03,2.5,150);

           glTranslatef(0.2, 0.0, 0.0);
           glutSolidTorus(0.03,0.03,2.5,150);

           glTranslatef(0.2, 0.0, 0.0);
           glutSolidTorus(0.03,0.03,2.5,150);

           glTranslatef(0.2, 0.0, 0.0);
           glutSolidTorus(0.03,0.03,2.5,150);

           glTranslatef(0.2, 0.0, 0.0);
           glutSolidTorus(0.03,0.03,2.5,150);
         glPopMatrix();

         //Janelas lado direito
         glPushMatrix();
           glTranslatef(0.0, 1.0, 0.00);
           glColor3f(0,0.0,1);
           glRotatef(90, 1.0, 0.0, 0.0);
           glTranslatef(0.4, -0.37, 0.50);
           glScalef(1.8,1,1);
           glutSolidTorus(0.03,0.03,2.5,150);

           glTranslatef(0.2, 0.0, 0.0);
           glutSolidTorus(0.03,0.03,2.5,150);

           glTranslatef(0.2, 0.0, 0.0);
           glutSolidTorus(0.03,0.03,2.5,150);

           glTranslatef(0.2, 0.0, 0.0);
           glutSolidTorus(0.03,0.03,2.5,150);

           glTranslatef(0.2, 0.0, 0.0);
           glutSolidTorus(0.03,0.03,2.5,150);
         glPopMatrix();
      //fim dos objetos a serem iluminados a noite
      glPopMatrix();

      //Voltando a especularidade para não ficar tudo branco
      especularidade [0] = 0.0;
      especularidade [1] = 0.0;
      especularidade [2] = 0.0;
      glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION, especularidade);

	glPopMatrix();

   /* termina a composicao do submarino*/
   glEndList();
}
//---------------------------------------------------------------------------
/*Esta função irá construir o modelo geométrico do barco - */
void constroe_barco(int intPosx, int intPosy)
{
   // inicia a composicao do submarino
   barco = glGenLists(0);
   glNewList(barco, GL_COMPILE);

   glPushMatrix();
      glColor3f(1,0,0.5);
      glRotatef(-90, 1.0, 0.0, 0.0);
      glRotatef(90, 0.0, 0.0, 1.0);
      //para movimentar em y e em x, soma sempre 2 em -8.95  e -9.5 respectivamente
      glTranslatef(-9.5+(2*intPosx),-8.95+(2*intPosy),-2.85);

      //Parede Lateral Esquerda
      glPushMatrix();
         glTranslatef(-1,0.5,2);
         glRotatef(90, 0.0, 1.0, 0.0);
         glRotatef(90, 1.0, 0.0, 0.0);
         glRotatef(-20, 0.0, 1.0, 0.0);
         glScalef(1.5, 5.0, 1.0);
         glBegin(GL_QUADS);
            glVertex3f (0.25, 0.25, 0.0);
            glVertex3f (0.75, 0.35, 0.0);
            glVertex3f (0.75, 0.65, 0.0);
            glVertex3f (0.25, 0.75, 0.0);
         glEnd();
      glPopMatrix();

      //Parede Lateral Direita
      glPushMatrix();
         glTranslatef(-1.0, -0.8, 2.0);
         glRotatef(90, 0.0, 1.0, 0.0);
         glRotatef(90, 1.0, 0.0, 0.0);
         glRotatef(20, 0.0, 1.0, 0.0);
         glScalef(1.5, 5.0, 1.0);
         glBegin(GL_QUADS);
            glVertex3f (0.25, 0.25, 0.0);
            glVertex3f (0.75, 0.35, 0.0);
            glVertex3f (0.75, 0.65, 0.0);
            glVertex3f (0.25, 0.75, 0.0);
         glEnd();
      glPopMatrix();

      //Parede Topo
      glPushMatrix();
         glTranslatef(4.0, -1.2, 1.65);
         glRotatef(90, 0.0, 0.0, 1.0);
         glScalef(2.1, 5.0, 1.0);
         glBegin(GL_QUADS);
            glVertex3f (0.25, 0.25, 0.0);
            glVertex3f (0.75, 0.25, 0.0);
            glVertex3f (0.75, 0.75, 0.0);
            glVertex3f (0.25, 0.75, 0.0);
         glEnd();
      glPopMatrix();

      //Parede fundo
      glPushMatrix();
         glTranslatef(3.0, -0.68, 0.94);
         glRotatef(90, 0.0, 0.0, 1.0);
         glScalef(1.05, 3.0, 1.0);
         glBegin(GL_QUADS);
            glVertex3f (0.25, 0.25, 0.0);
            glVertex3f (0.75, 0.25, 0.0);
            glVertex3f (0.75, 0.75, 0.0);
            glVertex3f (0.25, 0.75, 0.0);
         glEnd();
      glPopMatrix();

      //Parede Frente
      glPushMatrix();
         glTranslatef(1.75, -0.68, 0.21);
         glRotatef(-55.0, 0.0, 35.0, 1.0);
         glRotatef(1.0, 1.0, 0.0, 1.0);
         glScalef(1.20, 1.2, 1.0);
         glBegin(GL_QUADS);
            glVertex3f (1.46, 0.01, 0.0);
            glVertex3f (0.74, 0.23, 0.0);
            glVertex3f (0.74, 0.68, 0.0);
            glVertex3f (1.46, 0.91, 0.0);
         glEnd();
      glPopMatrix();

      //Parede fundo
      glPushMatrix();
         glTranslatef(1.25, -0.68, 0.22);
         glRotatef(-125.5, 0.0, 35.0, 1.0);
         glRotatef(1.0, 0.0, 0.0, 1.0);
         glRotatef(2.0, 1.0, 0.0, 0.0);
         glScalef(1.20, 1.15, 1.0);
         glBegin(GL_QUADS);
            glVertex3f (1.46, 0.01, 0.0);
            glVertex3f (0.74, 0.23, 0.0);
            glVertex3f (0.74, 0.68, 0.0);
            glVertex3f (1.46, 0.91, 0.0);
         glEnd();
      glPopMatrix();

      //Cabine
      glPushMatrix();
         glTranslatef(1.0, -0.15, 1.9);
         glScalef(-1.5, 1.0, 0.8);
         glutSolidCube(0.7);
      glPopMatrix();

      //Chaminé
      glPushMatrix();
         glTranslatef(1.0, -0.15, 2.15);
         gluCylinder(gluNewQuadric(), 0.1, 0.1, 0.5, 12, 3);  //raio base, raio topo, altura, slices, stacks
      glPopMatrix();


      glPushMatrix();
         //Iluminação da janela do barco
         GLfloat especularidade[4]={0.0,0.0,0.0,1.0};  //capacidade de brilho do material
         if (EhDia == 0)
         {
            especularidade [0] = 2.0;
            especularidade [1] = 1.0;
            especularidade [2] = 1.0;
         }
         glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION, especularidade);
		 
         //----------
         //janela frontal
         glPushMatrix();
		    glColor3f(0,0.2,0.9);  //azul claro da janela
            glScalef(0.5, 2.2, 1.9);
            glTranslatef(3.0, -0.07, 1.02);
            glutSolidCube(0.2);
         glPopMatrix();

         //janelas laterais
         glPushMatrix();
            glColor3f(0,0.2,0.9);
            glRotatef(90, 0.0, 0.0, 1.0);
            glScalef(7.5, 3.2, 2.9);
            glTranslatef(-0.021, -0.25, 0.68);
            glutSolidCube(0.1);
         glPopMatrix();

         //Porta
         glPushMatrix();
            glColor3f(0,0.2,0.9);
            glRotatef(90, 0.0, 0.0, 1.0);
            glScalef(0.45, 3.0, 4.5);
            glTranslatef(0.45, -0.42, 0.42);
            glutSolidCube(0.1);
         glPopMatrix();
      glPopMatrix();

      //Voltando a especularidade para não ficar tudo branco
      especularidade [0] = 0.0;
      especularidade [1] = 0.0;
      especularidade [2] = 0.0;
      glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION, especularidade);

   glPopMatrix();

   // termina a composicao do barco
   glEndList();
}

//---------------------------------------------------------------------------
/*Esta função irá construir o modelo geométrico do navio*/
void constroe_navio(int intPosx, int intPosy)
{
   // inicia a composicao do navio
   navio = glGenLists(2);
   glNewList(navio, GL_COMPILE);

   glPushMatrix();
	   //Posicionando na coordenada
	   glTranslatef(9-(2*intPosy),-2,8.5-(2*intPosx));

	   glRotatef(90,0.0, 1.0, 0.0);
      glRotatef(-90, 0.0, 0.0, 1.0);
	   glTranslatef(-0.8,0,0);  //deixando um pouco do casco imerso...
      glScalef(1,1.15,1);

      glPushMatrix();
         glColor3f(0,0.2,0.3);
		 
         //bico
         glBegin(GL_QUADS);
            glVertex3f (0.0, -1.0, 0.0);
            glVertex3f (1.0, 0.3, 0.0);
            glVertex3f (1, 0.5, -0.5);
            glVertex3f (0, 0.5, -0.5);
         glEnd();
         
         glBegin(GL_QUADS);
            glVertex3f (0.0, -1.0, 0.0);
            glVertex3f (1.0, 0.3, 0.0);
            glVertex3f (1, 0.5, 0.5);
            glVertex3f (0, 0.5, 0.5);
         glEnd();
   		//lateral
	   	glBegin(GL_QUADS);
            glVertex3f (0.3, 3.0, 0.5);
            glColor3f(0,0.2,0.3);  //cinza
			glVertex3f (0.0, 0.5, 0.5);
			glVertex3f (1.0, 0.5, 0.5);
			glColor3f(0,0.5,0.5);  //petroleo
	   		glVertex3f (1.0, 3.0, 0.5);
         glEnd();
         glBegin(GL_QUADS);
			glColor3f(0,0.2,0.3);  //cinza
            glVertex3f (0.3, 3.0, -0.5);
            glVertex3f (0.0, 0.5, -0.5);
			glVertex3f (1.0, 0.5, -0.5);
			glColor3f(0,0.5,0.5);  //petroleo
   			glVertex3f (1.0, 3.0, -0.5);
         glEnd();

         //'chão'
   		glBegin(GL_QUADS);
            glVertex3f (1.0, 3.0, -0.5);
            glVertex3f (1.0, 0.5, -0.5);
			glVertex3f (1.0, 0.5, 0.5);
   			glVertex3f (1.0, 3.0, 0.5);
         glEnd();

		   //sobe
   		glBegin(GL_QUADS);
			glVertex3f (1.0, 3.0, -0.5);  //1
			glVertex3f (0.7, 5.0, -0.5);  //2
			glVertex3f (0.7, 5.0, 0.5);  //3
            glVertex3f (1.0, 3.0, 0.5);  //4
         glEnd();
		
		 //fechamento lateral 1 (final)
		 glBegin(GL_QUADS);
            glColor3f(0,0.5,0.5);		 //petroleo
		    glVertex3f (1.0, 3.0, 0.5);  
			glColor3f(0,0.2,0.3);		 //cinza
			glVertex3f (0.3, 3.0, 0.5);  
			glVertex3f (0.4, 5.0, 0.5);  
			glVertex3f (0.7, 5.0, 0.5);  
         glEnd();

		 //fechamento lateral 2 (final)
		 glBegin(GL_QUADS);
		    glColor3f(0,0.5,0.5);  //petroleo
            glVertex3f (1.0, 3.0, -0.5); 
			glColor3f(0,0.2,0.3);  //cinza
			glVertex3f (0.3, 3.0, -0.5);  
			glVertex3f (0.4, 5.0, -0.5);  
			glVertex3f (0.7, 5.0, -0.5); 
         glEnd();


		   //Plano traseiro
         glBegin(GL_QUADS);
            glVertex3f (0.5, 0.5, -0.5);  //1
		    glVertex3f (0.5, 5.0, -0.5);  //2
		    glColor3f(0.2,0.2,0.2);  //cinza
			glVertex3f (0.5, 5.0, 0.5);  //3
            glVertex3f (0.5, 0.5, 0.5);  //4
         glEnd();

		   //fechamento traseiro
   		glBegin(GL_QUADS);
	   	   glVertex3f (0.7, 5.0, -0.5);  //2
            glVertex3f (0.5, 5.0, -0.5);  //4
			glVertex3f (0.5, 5.0, 0.5);  //1
   			glVertex3f (0.7, 5.0, 0.5);  //1
         glEnd();


		   //cabine
		glColor3f(0.4,0.4,0.4);  //cinza
		glTranslatef(0.2, 2.5, 0);
	   	glScalef(0.6, 2, 0.9);
        glutSolidCube(1);
      glPopMatrix();
	
	  

      //cabine menor
		glPushMatrix();
         glColor3f(0.8,0,0);
		   glTranslatef(-0.25, 2, 0);
		   glScalef(0.5, 1, 1);
         glutSolidCube(0.8);
      glPopMatrix();

      
	  glColor3f(0,0.2,0.5);  //azul da janela

		glPushMatrix();
         //Iluminação da janela do navio
         GLfloat especularidade[4]={0.0,0.0,0.0,1.0};  //capacidade de brilho do material
         if (EhDia == 0)
         {
            especularidade [0] = 2.0;
            especularidade [1] = 1.0;
            especularidade [2] = 1.0;
         }
         glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION, especularidade);

         //janela frontal
          glPushMatrix();
		    glTranslatef(0, -0.02, 0);
            glBegin(GL_QUADS);
		      glVertex3f (-0.15, 1.61, -0.35);
   		      glVertex3f (-0.40, 1.61, -0.35);
			  glColor3f(0.5,0.5,0.9);  //azul claro da janela
	   		  glVertex3f (-0.40, 1.61,  0.30);
		   	  glVertex3f (-0.15, 1.61,  0.30);
		    glEnd();
           glPopMatrix();
        glPopMatrix();

           //janelinhas laterais
           glPushMatrix();
		   glTranslatef(-0.3, 1.8, 0.4);   
		   glutSolidTorus(0.05,0.04,5,10);

		   glTranslatef(0, 0, -0.8);   
		   glutSolidTorus(0.05,0.04,5,10);

		   glTranslatef(0, 0.21, 0);   
		   glutSolidTorus(0.05,0.04,5,10);

		   glTranslatef(0, 0, 0.8);   
		   glutSolidTorus(0.05,0.04,5,10);

		   glTranslatef(0, 0.21, 0);  
		   glutSolidTorus(0.05,0.04,5,10);

		   glTranslatef(0, 0, -0.8);  
		   glutSolidTorus(0.05,0.04,5,10);

         glPopMatrix();

      //Voltando a especularidade para não ficar tudo branco
        especularidade [0] = 0.0;
        especularidade [1] = 0.0;
        especularidade [2] = 0.0;
        glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION, especularidade);

		//Bóia
		glPushMatrix();
		   glColor3f(1.0,0.5,0.0);
   		   glTranslatef(0.25, 3.56, 0);
	   	   glScalef(0.5,0.5,0.5);
		   glRotatef(90, 1, 0,0);
		   glutSolidTorus(0.10,0.20,5,10);
   		  glRotatef(-90, 1, 0,0);
        glPopMatrix();

       //torre da antena
		 glPushMatrix();
		 glColor3f(0.2,0.2,0.2);
		 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		 glTranslatef(0, 0, 0);
		 glBegin(GL_QUADS);
		    glVertex3f (-0.1, 3.00, -0.2);
            glVertex3f (-1.3, 3.05, -0.1);    //sup.esq.
            glVertex3f (-1.3, 3.20, -0.1);    //up. dir.
            glVertex3f (-0.1, 3.25, -0.2);
		 glEnd();
		 glBegin(GL_QUADS);
		    glVertex3f (-0.1, 3.00, 0.2);
            glVertex3f (-1.3, 3.05, 0.1);
            glVertex3f (-1.3, 3.20, 0.1);
            glVertex3f (-0.1, 3.25, 0.2);
		 glEnd();
         glBegin(GL_QUADS);
		    glVertex3f (-0.1, 3.00, -0.2);
            glVertex3f (-1.3, 3.05, -0.1);
            glVertex3f (-1.3, 3.05, 0.1);
            glVertex3f (-0.1, 3.00, 0.2);
		 glEnd();
         glBegin(GL_QUADS);
		    glVertex3f (-0.1, 3.25, -0.2);
            glVertex3f (-1.3, 3.20, -0.1);
            glVertex3f (-1.3, 3.20, 0.1);
            glVertex3f (-0.1, 3.25, 0.2);
		 glEnd();
		 //triângulo do topo + antena final
         glBegin(GL_TRIANGLE_FAN);
		    glVertex3f (-1.4, 3.15, 0);
            glVertex3f (-1.3, 3.05, -0.1);
			glVertex3f (-1.3, 3.05,  0.1);
			glVertex3f (-1.3, 3.20, -0.1);
			glVertex3f (-1.3, 3.20,  0.1);
		 glEnd();
         glBegin(GL_LINES);
		    glVertex3f (-1.4, 3.15, 0);
			glVertex3f (-1.55, 3.15, 0);
		 glEnd();
         //fios que atravessam o topo da antena
		 glBegin(GL_LINES);
		   glVertex3f (-1.2, 3.05, -0.3);
		   glVertex3f (-1.2, 3.05, 0.3);
           glVertex3f (-1.1, 3.05, -0.3);
		   glVertex3f (-1.1, 3.05, 0.3);
		   glVertex3f (-1.2, 3.20, -0.3);
		   glVertex3f (-1.2, 3.20, 0.3);
           glVertex3f (-1.1, 3.20, -0.3);
		   glVertex3f (-1.1, 3.20, 0.3);
		glEnd();
		//linhas do corpo da antena ('Z' dentro da antena)
        glBegin(GL_LINES);
		   glVertex3f (-0.1, 3.00, -0.2);
           glVertex3f (-0.4, 3.23, -0.18);
		   glVertex3f (-0.4, 3.23, -0.18);
		   glVertex3f (-0.4, 3.02, -0.18);

		   glVertex3f (-0.4, 3.02, -0.18);
           glVertex3f (-0.7, 3.21, -0.15);
		   glVertex3f (-0.7, 3.21, -0.15);
           glVertex3f (-0.7, 3.02, -0.15);

		   glVertex3f (-0.7, 3.02, -0.15);
           glVertex3f (-1.0, 3.21, -0.13);
		   glVertex3f (-1.0, 3.21, -0.13);
           glVertex3f (-1.0, 3.02, -0.13);

		   glVertex3f (-1.0, 3.02, -0.13);
           glVertex3f (-1.3, 3.21, -0.1);
		   glVertex3f (-1.3, 3.21, -0.1);
           glVertex3f (-1.3, 3.02, -0.1);

		   //'Z' da face 2
		   glVertex3f (-0.1, 3.00, 0.2);
           glVertex3f (-0.4, 3.23, 0.18);
		   glVertex3f (-0.4, 3.23, 0.18);
		   glVertex3f (-0.4, 3.02, 0.18);

		   glVertex3f (-0.4, 3.02, 0.18);
           glVertex3f (-0.7, 3.21, 0.15);
		   glVertex3f (-0.7, 3.21, 0.15);
           glVertex3f (-0.7, 3.02, 0.15);

		   glVertex3f (-0.7, 3.02, 0.15);
           glVertex3f (-1.0, 3.21, 0.13);
		   glVertex3f (-1.0, 3.21, 0.13);
           glVertex3f (-1.0, 3.02, 0.13);

		   glVertex3f (-1.0, 3.02, 0.13);
           glVertex3f (-1.3, 3.21, 0.1);
		   glVertex3f (-1.3, 3.21, 0.1);
           glVertex3f (-1.3, 3.02, 0.1);

		   //retas das outras duas faces da antena
		   glVertex3f (-0.4, 3.02, -0.18);
		   glVertex3f (-0.4, 3.02, 0.18);
		   glVertex3f (-0.7, 3.02, -0.18);
		   glVertex3f (-0.7, 3.02, 0.18);
		   glVertex3f (-1.0, 3.02, -0.18);
		   glVertex3f (-1.0, 3.02, 0.18);

		   glVertex3f (-0.4, 3.21, -0.18);
		   glVertex3f (-0.4, 3.21, 0.18);
		   glVertex3f (-0.7, 3.21, -0.18);
		   glVertex3f (-0.7, 3.21, 0.18);
		   glVertex3f (-1.0, 3.21, -0.18);
		   glVertex3f (-1.0, 3.21, 0.18);
         glEnd();

		 glPopMatrix();
		 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

      //Voltando a especularidade para não ficar tudo branco
     /* especularidade [0] = 0.0;
      especularidade [1] = 0.0;
      especularidade [2] = 0.0;
      glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION, especularidade);*/

   glPopMatrix();

   // termina a composicao do navio
   glEndList();
}

//---------------------------------------------------------------------------
/*Esta função irá construir o modelo geométrico da bandeira, usada para marcar o
local onde o usuário errar os navios - */
void constroe_bandeira(int x, int y)
{
   //array de pontos da grid que formará a onda
   float pontos[45][45][3];
   int i, j;

   glPushMatrix();
      glTranslatef(9.7-(2*y),0.0,9.7-(2*x));

      //mastro da bandeira
      glPushMatrix();
	     glColor3f(0.5,0.5,0.3);
         glRotatef(90,1.0,0.0,0.0);
         gluCylinder(gluNewQuadric(), 0.1, 0.1, 2.0, 12, 3);  //raio base, raio topo, altura, slices, stacks
      glPopMatrix();

      //bandeira
      glPushMatrix();
         glColor3f(1,1,1);
		 glScalef(0.5,0.5,0.5);
         glRotatef(-90,0.0,1.0,0.0); //rotacionando no sentido horário em y
         glTranslatef(2.3,2.5,0.8);
         for(i=0; i<45; i++) // Loop em x
         {
            for(j=0; j<45; j++) // Loop em y
            {
               //Gerando os pontos da malha
               pontos[i][j][0] = float((i/5.0f)-4.5f);
               pontos[i][j][1] = float((j/5.0f)-4.5f);
               pontos[i][j][2] = float(sin((((i+2/1.0f)*40.0f)/360.0f)*3.141592654*1.2f));
            }
         }
         glBegin(GL_QUADS);
            //gerando os quadrados utilizando os pontos gerados
            for(i=0; i<10; i++)
            {
               for(j=0; j<10; j++)
               {
                  glVertex3f(pontos[i][j][0], pontos[i][j][1], pontos[i][j][2]);
                  glVertex3f(pontos[i][j+1][0], pontos[i][j+1][1], pontos[i][j+1][2]);
                  glVertex3f(pontos[i+1][j+1][0], pontos[i+1][j+1][1], pontos[i+1][j+1][2]);
                  glVertex3f(pontos[i+1][j][0], pontos[i+1][j][1], pontos[i+1][j][2]);
               }
            }
         glEnd();
      glPopMatrix();
   glPopMatrix();
}
