void CQTOpenGLEPuck::RenderLED() {
    /* Side surface */
    CVector2 cVertex(BODY_RADIUS, 0.0f);
    CRadians cAngle(CRadians::TWO_PI / m_unVertices);
    CVector2 cNormal(1.0f, 0.0f);
    glBegin(GL_QUAD_STRIP);
    for(GLuint i = 0; i <= m_unVertices / 8; i++) {
       glNormal3f(cNormal.GetX(), cNormal.GetY(), 0.0f);
       glVertex3f(cVertex.GetX(), cVertex.GetY(), LED_ELEVATION + LED_HEIGHT);
       glVertex3f(cVertex.GetX(), cVertex.GetY(), LED_ELEVATION);
       cVertex.Rotate(cAngle);
       cNormal.Rotate(cAngle);
    }
    glEnd();
    /* Top surface  */
    cVertex.Set(BODY_RADIUS, 0.0f);
    CVector2 cVertex2(LED_UPPER_RING_INNER_RADIUS, 0.0f);
    glBegin(GL_QUAD_STRIP);
    glNormal3f(0.0f, 0.0f, 1.0f);      
    for(GLuint i = 0; i <= m_unVertices / 8; i++) {         
       glVertex3f(cVertex2.GetX(), cVertex2.GetY(), BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT);
       glVertex3f(cVertex.GetX(), cVertex.GetY(), BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT);
       cVertex.Rotate(cAngle);
       cVertex2.Rotate(cAngle);
    }
    glEnd();
 }
Exemplo n.º 2
0
   void CQTOpenGLUserFunctions::DrawCylinder(Real f_radius,
                                             Real f_height,
                                             const CVector3& c_center_offset,
                                             const CColor& c_color,
                                             const CQuaternion& c_orientation,
                                             GLuint un_vertices) {

    	/* Draw top circle*/
    	CVector3 cCirclePos(0.0f, 0.0f, f_height * 0.5f);
    	cCirclePos.Rotate(c_orientation);
    	cCirclePos += c_center_offset;
    	DrawCircle(f_radius,
                 cCirclePos,
                 c_color,
                 true,
                 c_orientation,
                 un_vertices);

    	/* Draw bottom circle*/
    	cCirclePos.Set(0.0f, 0.0f, -f_height * 0.5f);
    	cCirclePos.Rotate(c_orientation);
    	cCirclePos += c_center_offset;
    	DrawCircle(f_radius,
                 cCirclePos,
                 c_color,
                 true,
                 c_orientation,
                 un_vertices);

    	/* Side surface */
      CVector3 cVertex1(f_radius, 0.0f,  f_height * 0.5f);
      CVector3 cVertex2(f_radius, 0.0f, -f_height * 0.5f);
      CRadians cAngle(CRadians::TWO_PI / un_vertices);

      /* Compute the quaternion defining the rotation of the vertices used to draw the side surface. */
      CQuaternion cVertexRotation;
      CVector3 cVertexRotationAxis(0.0f, 0.0f, 1.0f);
      cVertexRotationAxis.Rotate(c_orientation);
      cVertexRotation.FromAngleAxis(cAngle, cVertexRotationAxis);

      glDisable(GL_LIGHTING);
      glColor3ub(c_color.GetRed(),
                 c_color.GetGreen(),
                 c_color.GetBlue());

      glBegin(GL_QUAD_STRIP);

      /* Compute the normal direction of the starting edge. */
      CVector3 cNormalDirection(cVertex1.GetX(), cVertex1.GetY(), 0.0f);
      cNormalDirection.Rotate(c_orientation);
      glNormal3f(cNormalDirection.GetX(),
                 cNormalDirection.GetY(),
                 cNormalDirection.GetZ());

      /* Rotate the endpoints of the first edge.*/
      cVertex1.Rotate(c_orientation);
      cVertex2.Rotate(c_orientation);

      for(GLuint i = 0; i <= un_vertices; i++) {
         glVertex3f(cVertex1.GetX() + c_center_offset.GetX(),
                    c_center_offset.GetY() + cVertex1.GetY(),
                    c_center_offset.GetZ() + cVertex1.GetZ() );
         glVertex3f(cVertex2.GetX() + c_center_offset.GetX(),
                    c_center_offset.GetY() + cVertex2.GetY(),
                    c_center_offset.GetZ() + cVertex2.GetZ() );
         /* Rotate the vertices and the normal direction, set the new normal. */
         cVertex1.Rotate(cVertexRotation);
         cVertex2.Rotate(cVertexRotation);
         cNormalDirection.Rotate(cVertexRotation);
         glNormal3f(cNormalDirection.GetX(),
                    cNormalDirection.GetY(),
                    cNormalDirection.GetZ());
      }

      glEnd();
      glEnable(GL_LIGHTING);

   }