void CQTOpenGLUserFunctions::DrawCircle(Real f_radius,
                                           const CVector3& c_center_offset,
                                           const CColor& c_color,
                                           const bool b_fill,
                                           const CQuaternion& c_orientation,
                                           GLuint un_vertices) {

	    glDisable(GL_LIGHTING);
	    glDisable(GL_CULL_FACE);

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

	    CVector3 cVertex(f_radius, 0.0f, 0.0f);
	    CRadians cAngle(CRadians::TWO_PI / un_vertices);

      if(b_fill) {
         glBegin(GL_POLYGON);
      }
      else {
         glBegin(GL_LINE_LOOP);
      }
      CVector3 cNormalDirection(0.0f, 0.0f, 1.0f);
      cNormalDirection.Rotate(c_orientation);
      glNormal3f(cNormalDirection.GetX(),
                 cNormalDirection.GetY(),
                 cNormalDirection.GetZ());

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

	    cVertex.Rotate(c_orientation);
      for(GLuint i = 0; i <= un_vertices; i++) {
         glVertex3f(cVertex.GetX() + c_center_offset.GetX(),
                    cVertex.GetY() + c_center_offset.GetY(),
                    cVertex.GetZ() + c_center_offset.GetZ());
         cVertex.Rotate(cVertexRotation);
      }
      glEnd();

      glEnable(GL_CULL_FACE);
      glEnable(GL_LIGHTING);
   }
Beispiel #2
0
 void CDynamics2DEngine::OrientationPhysicsToSpace(CQuaternion& c_new_orient,
                                                   cpBody* pt_body) {
    c_new_orient.FromAngleAxis(CRadians(pt_body->a), CVector3::Z);
 }
   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);

   }