/**************************Desenho do mundo************************************/
void display(void){
 
  int i;
  glClear(GL_COLOR_BUFFER_BIT);
  glColor3f (1.0, 1.0, 1.0);
 
//girar o objeto
 glRotatef((GLfloat) eixoxObjeto, 1.0, 0.0, 0.0);
 glRotatef((GLfloat) eixoyObjeto, 0.0, 1.0, 0.0);
 glRotatef((GLfloat) eixozObjeto, 0.0, 0.0, 1.0);
 
 

//  glPushMatrix();
 
  /*parte da frentde do barquinho*/
  glBegin(GL_POLYGON);
  glColor3f (0.0, 1.0, 0.0);// VERDE
  glVertex3f(15.0, 0.0,0.0);
  glVertex3f(5.0, 5.0,0.0);
  glVertex3f(40.0, 5.0,0.0);
  glVertex3f(30.0, 0.0,0.0);
  glEnd();
 
  /*parte de trás do barquinho*/
  glBegin(GL_POLYGON);
  glColor3f (0.0, 1.0, 0.0);// AMARELO
  glVertex3f(15.0, 0.0,-10.0);
  glVertex3f(5.0, 5.0,-10.0);
  glVertex3f(40.0, 5.0,-10.0);
  glVertex3f(30.0, 0.0,-10.0);
  glEnd();
 
   /*parte de baixo do barquinho*/
  glBegin(GL_POLYGON);
  glColor3f (0.0, 1.0, 0.0);// VERDE
  glVertex3f(15.0, 0.0,-10.0);
  glVertex3f(15.0, 0.0,0.0);
  glVertex3f(30.0, 0.0,0.0);
  glVertex3f(30.0, 0.0,-10.0);
  glEnd();
 
 
 /*parte esquerda do barquinho*/
  glBegin(GL_POLYGON);
  glColor3f (0.0, 1.0, 1.0);// AZUL
  glVertex3f(15.0, 0.0,0.0);
  glVertex3f(15.0, 0.0,-10.0);
  glVertex3f(5.0, 5.0,-10.0);
  glVertex3f(5.0, 5.0,0.0);
  glEnd();

 
 /*parte direita do barquinho*/
  glBegin(GL_POLYGON);
  glColor3f (0.0, 1.0, 0.0);//
  glVertex3f(30.0, 0.0,0.0);
  glVertex3f(30.0, 0.0,-10.0);
  glVertex3f(40.0, 5.0,-10.0);
  glVertex3f(40.0, 5.0,0.0);
  glEnd();
 
/**************************PARTE DO SALVA VIDAS**************************************/

   /* PRIMEIRO salva Vidas do barquinho*/
   glPushMatrix();
        glColor3f (1.5, 0.5, 0.5);// NAO SEI Q COR EH ESSA
        glTranslated(15.0,3.5,-6);
        glutSolidTorus(0.5,1,20,20);
    glPopMatrix();
    
    /* SEGUNDO salva Vidas do barquinho*/
   glPushMatrix();
        glColor3f (1.5, 0.5, 0.5);// NAO SEI Q COR EH ESSA
        glTranslated(20.0,3.5,-6);
        glutSolidTorus(0.5,1,20,20);
    glPopMatrix();
    
    /* TERCEIRO salva Vidas do barquinho*/
   glPushMatrix();
        glColor3f (1.5, 0.5, 0.5);// NAO SEI Q COR EH ESSA
        glTranslated(25.0,3.5,-6);
        glutSolidTorus(0.5,1,20,20);
    glPopMatrix();
   
   /* QUARTO salva Vidas do barquinho*/
   glPushMatrix();
        glColor3f (1.5, 0.5, 0.5);// NAO SEI Q COR EH ESSA
        glTranslated(30.0,3.5,-6);
        glutSolidTorus(0.5,1,20,20);
    glPopMatrix();

  /*************************Mastro do barquinho***************************/
  glBegin(GL_LINES);
  glColor3f (0.0, 0.0, 0.0);// PRETO
  glVertex3f(23.0, 5.0,0.0);
  glVertex3f(23.0, 15.0,0.0);
  glEnd();
   

  /*************************Bandeirinha do barquinho********************************/
     glPushMatrix();
          glColor3f (0.5, 0.7, 1.0);
          glTranslatef(23.0,12.0,0.0);
          glRotatef(-270,0,1,0);
          glScalef(1.0,3.0,1.0);
          glutSolidCone(1.0,5.0, 15.0, 15.0);        
          glPopMatrix();
 
  /***************************desenho de mar*******************************************/
  glBegin(GL_LINE_STRIP);
  glColor3f (0.0, 0.0, 1.0);
      for (i = 0; i <= 30; i++)
         glEvalCoord1f((GLfloat) i/30.0);
   glEnd();
  /* `mostragem dos pontos de controle  */
  glPointSize(5.0);
   glColor3f(0.0, 0.0, 1.0);
   
   glBegin(GL_POINTS);
      for (i = 0; i < 4; i++)
         glVertex3fv(&ctrlpoints[i][0]);
   glEnd();
   
   
  desenhaSol();
 
  glFlush();
  glutSwapBuffers();
}
示例#2
0
void display(void)	
{
	// Buffer clearen
	glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// View Matrix erstellen
	glLoadIdentity();
	float x = distance * sin(theta) * cos(phi);
	float y = distance * cos(theta);
	float z = distance * sin(theta) * sin(phi);
	gluLookAt(x, y, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

	// Teekanne rendern.
	glutSolidTeapot(1);

	// Den Matrix-Stack sichern.
	glPushMatrix();
	
		// Zeichnen der Kugelkreisbahn.	
			drawCircle(10.0f, 50);
		// Zeichnen der Kugel.
			// Wenden Sie eine Translation und eine Rotation an, bevor sie die Kugel zeichnen. Sie können die Variable 'angle' für die Rotation verwenden.
			// Bedenken Sie dabei die richtige Reihenfolge der beiden Transformationen.
			glRotated(angle, 0, 1.0f, 0);
			glTranslatef(10.0f, 0, 0);
			glutSolidSphere(1.0f, 32, 32);
		// Zeichnen der Würfelkreisbahn.
			// Hinweis: Der Ursprung des Koordinatensystems befindet sich nun im Zentrum des Würfels.
			// Drehen Sie das Koordinatensystem um 90° entlang der Achse, die für die Verschiebung des Würfels genutzt wurde.
			// Danach steht die Würfelkreisbahn senkrecht zur Tangentialrichtung der Kugelkreisbahn.
			glRotated(90.0f, 1.0f, 0, 0);
			drawCircle(5.0f, 50);
		// Zeichnen des Würfels.
			// Wenden Sie die entsprechende Translation und Rotation an, bevor sie den Würfel zeichnen.
			glRotated(angle, 0, 1.0f, 0);
			glTranslatef(5.0f, 0, 0);
			glutSolidCube(1.0f);
		// Zeichnen einer Linie von Würfel zu Kegel.
			glDisable(GL_LIGHTING);
			glTranslatef(3.0f, 0, 0);
			glBegin(GL_LINE_STRIP);
			glVertex3f(0, 0, 0);
			glVertex3f(-3.0f, 0, 0);
			glEnd();
			glEnable(GL_LIGHTING);
		// Drehung anwenden, sodass Koordinatensystem in Richtung Ursprung orientiert ist. (Hinweis: Implementieren Sie dies zuletzt.)
			GLfloat height = 8*cos(toRad(angle-90));
			GLfloat d = 8*sin(toRad(angle-90));
			GLfloat e = 10 - d;
			GLfloat l = pow(pow(height,2) + pow(e,2), 0.5f);
			GLfloat alpha = toDeg(acos(e/l)) - 90;
			if(static_cast<int>(angle)%360 > 180) alpha = -alpha;
			glRotated(alpha, 0, 1.0f, 0);
			if(static_cast<int>(angle)%360 > 180)
			{
				glRotated(180 - angle, 0, 1.0f, 0);
				std::cout << alpha + 180 - (int)angle%360 << std::endl;
			}
			else 
			{
				glRotated(-angle, 0, 1.0f, 0);
				std::cout << alpha - (int)angle%360 << std::endl;
			}
		// Zeichnen der Linie von Kegel zu Urpsrung.	
			glDisable(GL_LIGHTING);
			glBegin(GL_LINE_STRIP);
			glVertex3f(0, 0, 0);
			glVertex3f(0, 0, l);
			glEnd();
			glEnable(GL_LIGHTING);
		// Zeichnen des Kegels.
			glutSolidCone(0.5f, 1.0f, 32, 4);
	// Den Matrix-Stack wiederherstellen.

	glPopMatrix();
	
	glutSwapBuffers();	

	angle += 5.0f / 60.0f;
}
void Drawing::DrawCone(GLdouble base, GLdouble height, GLint slices, GLint stacks) {
    glutSolidCone(base, height, slices, stacks);
}