Exemplo n.º 1
0
void InitStuff (void)
{
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

   /* initialize the join style here */
   gleSetJoinStyle (TUBE_NORM_EDGE | TUBE_JN_ANGLE | TUBE_JN_CAP);

   RAD (1.0);
   COL (0.0, 0.0, 0.0);
   PNT (-6.0, 6.0, 0.0);

   RAD (1.0);
   COL (0.0, 0.8, 0.3);
   PNT (6.0, 6.0, 0.0);

   RAD (3.0);
   COL (0.8, 0.3, 0.0);
   PNT (6.0, -6.0, 0.0);

   RAD (0.5);
   COL (0.2, 0.3, 0.9);
   PNT (-6.0, -6.0, 0.0);

   RAD (2.0);
   COL (0.2, 0.8, 0.5);
   PNT (-6.0, 6.0, 0.0);

   RAD (1.0);
   COL (0.0, 0.0, 0.0);
   PNT (6.0, 6.0, 0.0);
}
Exemplo n.º 2
0
void InitStuff (void)
{
    glEnable(GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //gleSetJoinStyle (TUBE_NORM_PATH_EDGE | TUBE_JN_ANGLE );
    rotate_frame[0] = 0.0;
    rotate_frame[1] = -111.0;

    int style;

  /* pick model-vertex-cylinder coords for texture mapping */
  //TextureStyle (509);

  /* configure the pipeline */
    style = TUBE_JN_CAP;
    style |= TUBE_CONTOUR_CLOSED;
    style |= TUBE_NORM_FACET;
    style |= TUBE_JN_ANGLE;
    gleSetJoinStyle (style);

//  lastx = 121.0;
//  lasty = 121.0;

    init_contour();

}
Exemplo n.º 3
0
void InitStuff (void)
{
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	gleSetJoinStyle (TUBE_NORM_PATH_EDGE | TUBE_JN_ANGLE );
  rotate_frame[0] = 0.0;
  rotate_frame[1] = -111.0;
}
Exemplo n.º 4
0
void InitStuff (void)
{
   int style;

   /* configure the pipeline */
   init_spine ();
   init_xsection ();

   style = TUBE_JN_CAP;
   style |= TUBE_CONTOUR_CLOSED;
   style |= TUBE_NORM_FACET;
   style |= TUBE_JN_ANGLE;
   gleSetJoinStyle (style);
}
void InitStuff (void)
{
    int style;

    /* configure the pipeline */
    style = TUBE_JN_CAP;
    style |= TUBE_CONTOUR_CLOSED;
    style |= TUBE_NORM_FACET;
    style |= TUBE_JN_ANGLE;
    gleSetJoinStyle (style);

    lastx = 121.0;
    lasty = 121.0;

    init_contour();
    init_taper();
}
Exemplo n.º 6
0
/* main OpenGL initialization routine */
static void
initializeGL(ModeInfo *mi, GLsizei width, GLsizei height) 
{
  int style;
  int mode;

  reshape_extrusion(mi, width, height);
  glViewport( 0, 0, width, height ); 

  glEnable(GL_DEPTH_TEST);
  glDisable (GL_CULL_FACE);
  glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, True);
  glShadeModel(GL_SMOOTH);

# ifdef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */
  MI_IS_WIREFRAME(mi) = 0;
# endif

  if (do_light)
	SetupLight();
  if (MI_IS_WIREFRAME(mi)) {
	glPolygonMode(GL_FRONT,GL_LINE);
  	glPolygonMode(GL_BACK,GL_LINE);
  }
  if (do_texture) {
	Create_Texture(mi, which_image);
	glEnable(GL_TEXTURE_2D);

	/* configure the pipeline */
	style = TUBE_JN_CAP;
	style |= TUBE_CONTOUR_CLOSED;
	style |= TUBE_NORM_FACET;
	style |= TUBE_JN_ANGLE;
	gleSetJoinStyle (style);

	if (do_texture) {
	  mode = GLE_TEXTURE_ENABLE | GLE_TEXTURE_VERTEX_MODEL_FLAT;
	  glMatrixMode (GL_TEXTURE); glLoadIdentity ();
	  glScalef (0.25, 0.1, 1); glMatrixMode (GL_MODELVIEW);
	  gleTextureMode (mode);
	}
  }

}
Exemplo n.º 7
0
static void JoinStyle (int msg) 
{
   int style;
   /* get the current joint style */
   style = gleGetJoinStyle ();

   /* there are four different join styles, 
    * and two different normal vector styles */
   switch (msg) {
      case 0:
         style &= ~TUBE_JN_MASK;
         style |= TUBE_JN_RAW;
         break;
      case 1:
         style &= ~TUBE_JN_MASK;
         style |= TUBE_JN_ANGLE;
         break;
      case 2:
         style &= ~TUBE_JN_MASK;
         style |= TUBE_JN_CUT;
         break;
      case 3:
         style &= ~TUBE_JN_MASK;
         style |= TUBE_JN_ROUND;
         break;

      case 20:
         style &= ~TUBE_NORM_MASK;
         style |= TUBE_NORM_FACET;
         break;
      case 21:
         style &= ~TUBE_NORM_MASK;
         style |= TUBE_NORM_EDGE;
         break;

      case 99:
         exit (0);

      default:
         break;
   }
   gleSetJoinStyle (style);
   glutPostRedisplay ();
}
Exemplo n.º 8
0
/* draw the helix shape */
void DrawStuff (void) 
{
   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   /* set up some matrices so that the object spins with the mouse */
   glPushMatrix ();
   glTranslatef (0.0, 0.0, -80.0);
   glRotatef (220.0, 0.0, 1.0, 0.0);
   glRotatef (65.0, 1.0, 0.0, 0.0);

   /* Phew. FINALLY, Draw the helix  -- */
   gleSetJoinStyle (TUBE_NORM_EDGE | TUBE_JN_ANGLE | TUBE_JN_CAP);
   gleHelicoid (1.0, 6.0, -1.0, 
               0.0, (0.02*lasty-2.0), 0x0, 0x0, 0.0, 6.0*lastx);

   glPopMatrix ();

   glutSwapBuffers ();
}
Exemplo n.º 9
0
void InitStuff (void)
{
   int style;

   /* pick model-vertex-cylinder coords for texture mapping */
   TextureStyle (509);

   /* configure the pipeline */
   style = TUBE_JN_CAP;
   style |= TUBE_CONTOUR_CLOSED;
   style |= TUBE_NORM_FACET;
   style |= TUBE_JN_ANGLE;
   gleSetJoinStyle (style);

   lastx = 121.0;
   lasty = 121.0;

   init_contour();
}
Exemplo n.º 10
0
static void init_twist (void)
{
   int js;

   init_toid1_line ();
   init_tripples ();

#ifdef IBM_GL_32
   js = getjoinstyle ();
   js &= ~TUBE_CONTOUR_CLOSED;
   setjoinstyle (js);
#endif

#ifdef OPENGL_10
   js = gleGetJoinStyle ();
   js &= ~TUBE_CONTOUR_CLOSED;
   gleSetJoinStyle (js);
#endif

}
Exemplo n.º 11
0
void InitStuff (void) {

   /* initialize the join style here */
   gleSetJoinStyle (TUBE_NORM_EDGE | TUBE_JN_ANGLE | TUBE_JN_CAP);

   COL (0.0, 0.0, 0.0);
   PNT (-6.0, 6.0, 0.0);

   COL (0.0, 0.8, 0.3);
   PNT (6.0, 6.0, 0.0);

   COL (0.8, 0.3, 0.0);
   PNT (6.0, -6.0, 0.0);

   COL (0.2, 0.3, 0.9);
   PNT (-6.0, -6.0, 0.0);

   COL (0.2, 0.8, 0.5);
   PNT (-6.0, 6.0, 0.0);

   COL (0.0, 0.0, 0.0);
   PNT (6.0, 6.0, 0.0);
}
Exemplo n.º 12
0
/* draw the helix shape */
void DrawStuff (void) 
{
   double affine[2][3];
   double delta_affine[2][3];

   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glColor3f (0.7, 0.5, 0.3);

   /* set up some matrices so that the object spins with the mouse */
   glPushMatrix ();
   glTranslatef (0.0, 0.0, -80.0);
   glRotatef (220.0, 0.0, 1.0, 0.0);
   glRotatef (65.0, 1.0, 0.0, 0.0);

   /* Phew. FINALLY, Draw the helix  -- */
   affine [0][0] = 1.0/ (0.01*lastx);
   affine [1][0] = 0.0;
   affine [0][1] = 0.0;
   affine [1][1] = 0.01*lastx;
   affine [0][2] = 0.0;
   affine [1][2] = 0.0;

   delta_affine [0][0] = 0.0;
   delta_affine [1][0] = 0.03*lasty;
   delta_affine [0][1] = -0.03*lasty;
   delta_affine [1][1] = 0.0;
   delta_affine [0][2] = 0.0;
   delta_affine [1][2] = 0.0;

   gleSetJoinStyle (TUBE_NORM_EDGE | TUBE_JN_ANGLE | TUBE_JN_CAP);
   gleHelicoid (1.0, 7.0, -1.0, 
               -4.0, 6.0, affine, delta_affine, 0.0, 980.0);

   glPopMatrix ();

   glutSwapBuffers ();
}
Exemplo n.º 13
0
void InitStuff (void) {

   /* initialize the join style here */
   gleSetJoinStyle (TUBE_NORM_PATH_EDGE | TUBE_JN_ANGLE );

   RAD (0.3);
   PNT (-4.9, 6.0, 0.0);

   RAD (0.3);
   PNT (-4.8, 5.8, 0.0);

   RAD (0.3);
   PNT (-3.8, 5.8, 0.0);

   RAD (0.6);
   PNT (-3.5, 6.0, 0.0);

   RAD (0.8);
   PNT (-3.0, 7.0, 0.0);

   RAD (0.9);
   PNT (-2.4, 7.6, 0.0);

   RAD (1.0);
   PNT (-1.8, 7.6, 0.0);

   RAD (1.1);
   PNT (-1.2, 7.1, 0.0);

   RAD (1.2);
   PNT (-0.8, 5.1, 0.0);

   RAD (1.7);
   PNT (-0.3, -2.0, 0.0);

   RAD (1.8);
   PNT (-0.2, -7.0, 0.0);

   RAD (2.0);
   PNT (0.3, -7.8, 0.0);

   RAD (2.1);
   PNT (0.8, -8.2, 0.0);

   RAD (2.25);
   PNT (1.8, -8.6, 0.0);

   RAD (2.4);
   PNT (3.6, -8.6, 0.0);

   RAD (2.5);
   PNT (4.5, -8.2, 0.0);

   RAD (2.6);
   PNT (4.8, -7.5, 0.0);

   RAD (2.7);
   PNT (5.0, -6.0, 0.0);

   RAD (3.2);
   PNT (6.4, -2.0, 0.0);

   RAD (4.1);
   PNT (6.9, -1.0, 0.0);

   RAD (4.1);
   PNT (7.8, 0.5, 0.0);

}
Exemplo n.º 14
0
void GLThread::InitContour ()
{
  int style;
  /* configure the pipeline */
  style = TUBE_JN_CAP;
  style |= TUBE_CONTOUR_CLOSED;
  style |= TUBE_NORM_FACET;
  style |= TUBE_JN_ANGLE;
  gleSetJoinStyle (style);

  int i;
  double contour_scale_factor = 0.3;



#ifdef ISOTROPIC
	// outline of extrusion
	i=0;
	double radius = 1.0;
	while (i < NUM_PTS_CONTOUR)
	{
		double x = radius*cos(2*M_PI*((double)i/(double) (NUM_PTS_CONTOUR-1)));
		double y = radius*sin(2*M_PI* ((double)i/(double)(NUM_PTS_CONTOUR-1)));
		CONTOUR(x, y);
	}




#else
   // outline of extrusion
   i=0;
   CONTOUR (1.0*contour_scale_factor, 0.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, 0.5*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, 1.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, 2.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, 2.9*contour_scale_factor);
   CONTOUR (0.9*contour_scale_factor, 3.0*contour_scale_factor);
   CONTOUR (0.0*contour_scale_factor, 3.0*contour_scale_factor);
   CONTOUR (-0.9*contour_scale_factor, 3.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, 2.9*contour_scale_factor);

   CONTOUR (-1.0*contour_scale_factor, 2.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, 1.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, 0.5*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, 0.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, -0.5*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, -1.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, -2.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, -2.9*contour_scale_factor);
   CONTOUR (-0.9*contour_scale_factor, -3.0*contour_scale_factor);
   CONTOUR (0.0*contour_scale_factor, -3.0*contour_scale_factor);
   CONTOUR (0.9*contour_scale_factor, -3.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, -2.9*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, -2.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, -1.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, -0.5*contour_scale_factor);

   CONTOUR (1.0*contour_scale_factor, 0.0*contour_scale_factor);   // repeat so that last normal is computed

#endif

	thread_color[0] = 240;
	thread_color[1] = 180;
	thread_color[2] = 10;
	stripe_color[0] = 2;
	stripe_color[1] = 37;
	stripe_color[2] = 165;
	truththread_color[0] = 240;
	truththread_color[1] = 10;
	truththread_color[2] = 10;


	for (int i=0; i < 3; i++)
	{
		thread_color_float[i] = ((float)thread_color[i])/255.0;
		stripe_color_float[i] = ((float)stripe_color[i])/255.0;
	}

	addTexture_stripe();
}
Exemplo n.º 15
0
void GLThread::InitContour ()
{
  int style;
  /* configure the pipeline */
  style = TUBE_JN_CAP;
  style |= TUBE_CONTOUR_CLOSED;
  style |= TUBE_NORM_FACET;
  style |= TUBE_JN_ANGLE;
  gleSetJoinStyle (style);

  int i;
  double contour_scale_factor = 0.3;



#ifdef ISOTROPIC
   // outline of extrusion
   i=0;
   CONTOUR (1.0 *contour_scale_factor, 1.0 *contour_scale_factor);
   CONTOUR (1.0 *contour_scale_factor, 2.9 *contour_scale_factor);
   CONTOUR (0.9 *contour_scale_factor, 3.0 *contour_scale_factor);
   CONTOUR (-0.9*contour_scale_factor, 3.0 *contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, 2.9 *contour_scale_factor);

   CONTOUR (-1.0*contour_scale_factor, 1.0 *contour_scale_factor);
   CONTOUR (-2.9*contour_scale_factor, 1.0 *contour_scale_factor);
   CONTOUR (-3.0*contour_scale_factor, 0.9 *contour_scale_factor);
   CONTOUR (-3.0*contour_scale_factor, -0.9*contour_scale_factor);
   CONTOUR (-2.9*contour_scale_factor, -1.0*contour_scale_factor);

   CONTOUR (-1.0*contour_scale_factor, -1.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, -2.9*contour_scale_factor);
   CONTOUR (-0.9*contour_scale_factor, -3.0*contour_scale_factor);
   CONTOUR (0.9 *contour_scale_factor, -3.0*contour_scale_factor);
   CONTOUR (1.0 *contour_scale_factor, -2.9*contour_scale_factor);

   CONTOUR (1.0 *contour_scale_factor, -1.0*contour_scale_factor);
   CONTOUR (2.9 *contour_scale_factor, -1.0*contour_scale_factor);
   CONTOUR (3.0 *contour_scale_factor, -0.9*contour_scale_factor);
   CONTOUR (3.0 *contour_scale_factor, 0.9 *contour_scale_factor);
   CONTOUR (2.9 *contour_scale_factor, 1.0 *contour_scale_factor);

   CONTOUR (1.0 *contour_scale_factor, 1.0 *contour_scale_factor);   // repeat so that last normal is computed

#else
   // outline of extrusion
   i=0;
   CONTOUR (1.0*contour_scale_factor, 0.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, 0.5*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, 1.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, 2.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, 2.9*contour_scale_factor);
   CONTOUR (0.9*contour_scale_factor, 3.0*contour_scale_factor);
   CONTOUR (0.0*contour_scale_factor, 3.0*contour_scale_factor);
   CONTOUR (-0.9*contour_scale_factor, 3.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, 2.9*contour_scale_factor);

   CONTOUR (-1.0*contour_scale_factor, 2.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, 1.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, 0.5*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, 0.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, -0.5*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, -1.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, -2.0*contour_scale_factor);
   CONTOUR (-1.0*contour_scale_factor, -2.9*contour_scale_factor);
   CONTOUR (-0.9*contour_scale_factor, -3.0*contour_scale_factor);
   CONTOUR (0.0*contour_scale_factor, -3.0*contour_scale_factor);
   CONTOUR (0.9*contour_scale_factor, -3.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, -2.9*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, -2.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, -1.0*contour_scale_factor);
   CONTOUR (1.0*contour_scale_factor, -0.5*contour_scale_factor);

   CONTOUR (1.0*contour_scale_factor, 0.0*contour_scale_factor);   // repeat so that last normal is computed

#endif


}
Exemplo n.º 16
0
static void
draw_fillets_and_join_n_norms
                    (int ncp,
                    gleDouble trimmed_loop[][3],
                    gleDouble untrimmed_loop[][3],
                    int is_trimmed[],
                    gleDouble bis_origin[3],
                    gleDouble bis_vector[3],
                    double normals[][3],
                    float front_color[3],
                    float back_color[3],
                    gleDouble cut_vector[3],
                    int face,
                    gleCapCallback cap_callback)
{
   int istop;
   int icnt, icnt_prev, iloop;
   double *cap_loop, *norm_loop;
   gleDouble sect[3];
   gleDouble tmp_vec[3];
   int save_style = 0;
   int was_trimmed = FALSE;

   save_style = gleGetJoinStyle ();
   cap_loop = (double *) malloc ((ncp+3)*3*2*sizeof (double));
   norm_loop = cap_loop + (ncp+3)*3;

   /*
    * If the first point is trimmed, keep going until one
    * is found that is not trimmed, and start join there.
    */

   icnt = 0;
   iloop = 0;
   if (!is_trimmed[0]) {

      /* if the first point on the contour isn't trimmed, go ahead and
       * drop an edge down to the bisecting plane, (thus starting the
       * join).  (Only need to do this for cut join, its bad if done for
       * round join).  (Also, leads to bugs when done for closed
       * contours ... do this only if contour is open).
       */
      if ((__TUBE_CUT_JOIN) && (!(save_style & TUBE_CONTOUR_CLOSED))) {
         VEC_SUM (tmp_vec, trimmed_loop[0], bis_vector);
         INNERSECT (sect,
                    bis_origin,
                    bis_vector,
                    trimmed_loop[0],
                    tmp_vec);
         VEC_COPY ( (&cap_loop[3*iloop]), sect);
         VEC_COPY ( (&norm_loop[3*iloop]), normals[0]);
         iloop ++;
      }
      VEC_COPY ( (&cap_loop[3*iloop]), (trimmed_loop[0]));
      VEC_COPY ( (&norm_loop[3*iloop]), normals[0]);
      iloop++;
      icnt_prev = icnt;
      icnt ++;
   } else {

      /* else, loop until an untrimmed point is found */
      was_trimmed = TRUE;
      while (is_trimmed[icnt]) {
         icnt_prev = icnt;
         icnt ++;
         if (icnt >= ncp) {
            free (cap_loop);
            return;    /* oops - everything was trimmed */
         }
      }
   }

   /* Start walking around the end cap.  Every time the end loop is
    * trimmed, we know we'll need to draw a fillet triangle.  In
    * addition, after every pair of visibility changes, we draw a cap. */
   if (__TUBE_CLOSE_CONTOUR) {
      istop = ncp;
   } else {
      istop = ncp-1;
   }

   /* save the join style, and disable a closed contour.
    * Need to do this so partial contours don't close up. */
   save_style = gleGetJoinStyle ();
   gleSetJoinStyle (save_style & ~TUBE_CONTOUR_CLOSED);

   for (; icnt_prev < istop; icnt_prev ++, icnt ++, icnt %= ncp) {

      /* There are four interesting cases for drawing caps and fillets:
       *    1) this & previous point were trimmed.  Don't do anything,
       *       advance counter.
       *    2) this point trimmed, previous not -- draw fillet, and
       *       draw cap.
       *    3) this point not trimmed, previous one was -- compute
       *       intersection point, draw fillet with it, and save
       *       point for cap contour.
       *    4) this & previous point not trimmed -- save for endcap.
       */

      /* Case 1 -- noop, just advance pointers */
      if (is_trimmed[icnt_prev] && is_trimmed[icnt]) {
      }

      /* Case 2 --  Hah! first point! compute intersect & draw fillet! */
      if (is_trimmed[icnt_prev] && !is_trimmed[icnt]) {

         /* important note: the array "untrimmed" contains valid
          * untrimmed data ONLY when is_trim is TRUE.  Otherwise,
          * only "trim" containes valid data */

         /* compute intersection */
         INNERSECT (sect,
                    bis_origin,
                    bis_vector,
                    untrimmed_loop[icnt_prev],
                    trimmed_loop[icnt]);

         /* Draw Fillet */
         draw_fillet_triangle_n_norms (trimmed_loop[icnt_prev],
                               trimmed_loop[icnt],
                               sect,
                               face,
                               front_color,
                               back_color,
                               normals[icnt_prev],
                               normals[icnt]);
         VEC_COPY ( (&cap_loop[3*iloop]), sect);
         VEC_COPY ( (&norm_loop[3*iloop]), normals[icnt_prev]);
         iloop ++;
         VEC_COPY ( (&cap_loop[3*iloop]), (trimmed_loop[icnt]));
         VEC_COPY ( (&norm_loop[3*iloop]), normals[icnt]);
         iloop++;
      }

      /* Case 3 -- add to collection of points */
      if (!is_trimmed[icnt_prev] && !is_trimmed[icnt]) {
         VEC_COPY ( (&cap_loop[3*iloop]), (trimmed_loop[icnt]));
         VEC_COPY ( (&norm_loop[3*iloop]), normals[icnt]);
         iloop++;
      }

      /* Case 4 -- Hah! last point!  draw fillet & draw cap!  */
      if (!is_trimmed[icnt_prev] && is_trimmed[icnt]) {
         was_trimmed = TRUE;

         /* important note: the array "untrimmed" contains valid
          * untrimmed data ONLY when is_trim is TRUE.  Otherwise,
          * only "trim" containes valid data */

         /* compute intersection */
         INNERSECT (sect,
                    bis_origin,
                    bis_vector,
                    trimmed_loop[icnt_prev],
                    untrimmed_loop[icnt]);

         /* Draw Fillet */
         draw_fillet_triangle_n_norms (trimmed_loop[icnt_prev],
                               trimmed_loop[icnt],
                               sect,
                               face,
                               front_color,
                               back_color,
                               normals[icnt_prev],
                               normals[icnt]);

         VEC_COPY ( (&cap_loop[3*iloop]), sect);

         /* OK, maybe phong normals are wrong, but at least facet
          * normals will come out OK. */
         if (__TUBE_DRAW_FACET_NORMALS) {
            VEC_COPY ( (&norm_loop[3*iloop]), normals[icnt_prev]);
         } else {
            VEC_COPY ( (&norm_loop[3*iloop]), normals[icnt]);
         }
         iloop ++;

         /* draw cap */
         if (iloop >= 3) (*cap_callback) (iloop,
                                          (gleVector *) cap_loop,
                                          front_color,
                                          cut_vector,
                                          bis_vector,
                                          (gleVector *) norm_loop,
                                          face);

         /* reset cap counter */
         iloop = 0;
      }
   }

   /* now, finish up in the same way that we started. */

   icnt --;  /* decrement to make up for loop exit condititons */
   icnt += ncp;
   icnt %= ncp;
   if ((!is_trimmed[icnt]) && (iloop >= 2))  {

      /* If the last point of the contour is visible, drop an edge
       * to the bisecting plane, thus finishing the join.
       * Note that doing this leads to bugs if done for closed
       * contours ... do this only if contour is open.
       */
      if ((__TUBE_CUT_JOIN) && (!(save_style & TUBE_CONTOUR_CLOSED))) {
         VEC_SUM (tmp_vec, trimmed_loop[icnt], bis_vector);
         INNERSECT (sect,
                    bis_origin,
                    bis_vector,
                    trimmed_loop[icnt],
                    tmp_vec);
         VEC_COPY ( (&cap_loop[3*iloop]), sect);
         VEC_COPY ( (&norm_loop[3*iloop]), normals[icnt]);
         iloop ++;
      }

      /* if nothing was ever trimmed, then we want to draw the
       * cap the way the user asked for it -- closed or not closed.
       * Therefore, reset the closure flag to its original state.
       */
      if (!was_trimmed) {
         gleSetJoinStyle (save_style);
      }
      /* draw cap */
      (*cap_callback) (iloop,
                       (gleVector *) cap_loop,
                       front_color,
                       cut_vector,
                       bis_vector,
                       (gleVector *) norm_loop,
                       face);
   }

   /* rest to the saved style */
   gleSetJoinStyle (save_style);
   free (cap_loop);
}
Exemplo n.º 17
0
void drawBranchObject(node a, BranchAttributeObj branchAttributes, float radius1,float radius2)
// Draw a cylinder subtending a node, using precomputed values from trig routine
// This is currently the only place in the code I need GL_LIGHTING on

// This is drawn in the original object coordinate system in which the tree is centered on 0,0

// TO DO enable attenuate on/off flag

// Not doing blending or lod_cutoff for tubes yet
// Currently doing the lod_cutoff for branchStyle==line only ; makes a big difference


{
    extern GLUquadricObj *qobj;
    GLfloat params[4];
    GLboolean valid;
    float darkness;
    float xdist,ydist,zdist;
    float sknots[8] = { 0,0,0,0,1,1,1,1};
    GLfloat ctlpoints[4][4]; // four control points = 2 end points + two "control" points
    area A,Aanc;
    double dx,dy,dz,zr,xcross,ycross,theta, color, color_anc;
    A=(area)(a->data);
    float r1,r2,z1,z2;

    if (branchAttributes->branchCurvy == nurbs) // set up control points
    {
        // TO DO. CURRENTLY THESE CONTROL POINTS ARE ALL IN A VERTICAL PLANE. MAKE THE TREE CURVIER YET BY MOVING THEM OFF THIS PLANE.

        // Setting up the two endpoints of the edge; cubic spline will interpolate these two points
        // NB. These are bogus for circle layout, because there is no variation in the z-axis there,


        ctlpoints[0][0]=A->x_anc;
        ctlpoints[0][1]=A->y_anc;
        ctlpoints[0][2]=A->z_anc;
        ctlpoints[0][3]=1.0;
        ctlpoints[3][0]=A->x_center;
        ctlpoints[3][1]=A->y_center;
        ctlpoints[3][2]=A->z;
        ctlpoints[3][3]=1.0;


        // Setting up the two control points. These are each tweaked with a z parameter and an r parameter in the vertical plane
        // defined by the two endpoints of the edge, such that both when (r,z) is (0,0) at anc node and (1,1) at desc node.
        // So we need an (r,z) for each control point: r1,z1,r2,z2.

        xdist = A->x_center - A->x_anc;
        ydist = A->y_center - A->y_anc;
        zdist = A->z - A->z_anc;
        extern float gr1,gr2,gz1,gz2;
        r1 = gr1; //branchAttributes->ctlpointParms[0];
        z1 = gz1; //branchAttributes->ctlpointParms[1];
        r2 = gr2; //branchAttributes->ctlpointParms[2];
        z2 = gz2; //branchAttributes->ctlpointParms[3];

        ctlpoints[1][0]=A->x_anc + xdist*r1;
        ctlpoints[1][1]=A->y_anc + ydist*r1;
        ctlpoints[1][2]=A->z_anc + zdist*z1;
        ctlpoints[1][3]=1.0;

        ctlpoints[2][0]=A->x_anc + xdist*r2;
        ctlpoints[2][1]=A->y_anc + ydist*r2;
        ctlpoints[2][2]=A->z_anc + zdist*z2;
        ctlpoints[2][3]=1.0;

    }

    switch (branchAttributes->branchStyle)
    {
    case tube:
    {

        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);


        switch (branchAttributes->branchCurvy)
        {
        case nurbs:
        {


            if (a->marked)
            {
                darkness=1;
                glEnable(GL_BLEND);
                glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
            }
            else
                darkness = setColorWithAttenuationLineSegment(A->x_center,A->y_center,A->z, A->x_anc,A->y_anc,A->z_anc, &(branchAttributes->color[0]), branchAttributes->attenuateFactor);


            // Turn off actual rendering here...no need to draw the line, just get callbacks...use GLU_tesselator
            gluNurbsProperty(theNurbs,GLU_NURBS_MODE,GLU_NURBS_TESSELLATOR);
            gluBeginCurve(theNurbs);
            gluNurbsCurve(theNurbs, 8, sknots, 4, &ctlpoints[0][0], 4, GL_MAP1_VERTEX_4);
            gluEndCurve(theNurbs);
            gluNurbsProperty(theNurbs,GLU_NURBS_MODE,GLU_NURBS_RENDERER);

            int i;
            float gleColor[500][4];
            double gleRadius[500];
            for (i=0; i<gNpoints; i++) // set the vectors of colors and radii
            {
                if (gNpoints > 500) exit(1);

                gleColor[i][0]= branchAttributes->color[0];
                gleColor[i][1]= branchAttributes->color[1];
                gleColor[i][2]= branchAttributes->color[2];
                gleColor[i][3]= darkness;  // don't seem to need this shit; taken care of by glMaterial
                if (gNpoints > 1)
                    gleRadius[i] = radius1 + (radius2-radius1)*i/(gNpoints-1); // interpolate to vary radius between nodes of branch
                else
                    gleRadius[i] = radius1;

            }
            params[0]=branchAttributes->color[0];
            params[1]=branchAttributes->color[1];
            params[2]=branchAttributes->color[2];
            params[3]=darkness;

            params[3]=1.0; //override for now; I don't like how the blending looks


            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
            //glEnable(GL_LINE_SMOOTH);
            //glHint(GL_LINE_SMOOTH_HINT,GL_NICEST); // Antialiasing not working in this gle environment
            //glEnable(GL_POLYGON_SMOOTH);
            //glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);
            glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, params);
            gleSetJoinStyle(TUBE_JN_ROUND) ;
            //glePolyCylinder(gNpoints,gPoint_array,gleColor,radius2);

            //glePolyCone_c4f(gNpoints,gPoint_array,gleColor,gleRadius);
            // Note if we pass gleColor, that overrides the material color and its alpha blending;
            // so to enable blending pass NULL in place of gleColor, and set glMaterial above
            glePolyCone_c4f(gNpoints,gPoint_array,NULL,gleRadius);

            //drawCylinder(gPoint_array[0][0],gPoint_array[0][1],gPoint_array[0][2], gPoint_array[1][0],gPoint_array[1][1],gPoint_array[1][2],radius1, radius1); // add gumby cyls at ends of gle cylinder
            //drawCylinder(gPoint_array[gNpoints-2][0],gPoint_array[gNpoints-2][1],gPoint_array[gNpoints-2][2], gPoint_array[gNpoints-1][0],gPoint_array[gNpoints-1][1],gPoint_array[gNpoints-1][2],radius2, radius2);

            // Because gle does not extrude at the two endpoints, I draw cylinders at each endpoint. To avoid gappiness at borders, I overlap the cylinder with the extruded tube by one segment (one point on the polyline), thus I run the cylinder from, e.g., point 0 to point 2, where the extrusion starts at 1.
            drawCylinder(gPoint_array[0][0],gPoint_array[0][1],gPoint_array[0][2], gPoint_array[2][0],gPoint_array[2][1],gPoint_array[2][2],gleRadius[0], gleRadius[2]); // add gumby cyls at ends of gle cylinder
            drawCylinder(gPoint_array[gNpoints-3][0],gPoint_array[gNpoints-3][1],gPoint_array[gNpoints-3][2], gPoint_array[gNpoints-1][0],gPoint_array[gNpoints-1][1],gPoint_array[gNpoints-1][2],gleRadius[gNpoints-3],gleRadius[gNpoints-1]);


            //glDisable(GL_LIGHTING);
            break;
        }
        case straight:
        {
            params[0]=branchAttributes->color[0];
            params[1]=branchAttributes->color[1];
            params[2]=branchAttributes->color[2];
            params[3]=darkness;
            glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, params);
            drawCylinder(A->x_anc,A->y_anc,A->z_anc, A->x_center,A->y_center,A->z, radius1, radius2);
            break;
        }
        }
        glDisable(GL_LIGHTING);
        break;
    }



    case line:
    {
        if (!isRoot(a))
        {
            glLineWidth(branchAttributes->lineWidth);

            if (a->marked)
            {
                darkness=1;
                glEnable(GL_BLEND);
                glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
                glColor4f(branchAttributes->color[0],branchAttributes->color[1],branchAttributes->color[2],darkness);
            }
            else
                darkness = setColorWithAttenuationLineSegment(A->x_center,A->y_center,A->z, A->x_anc,A->y_anc,A->z_anc, &(branchAttributes->color[0]), branchAttributes->attenuateFactor);

            // there is similar code in function setColorWithAttenuation() in tree_openGL, but here we have something more elaborate...


            switch (branchAttributes->branchCurvy)
            {
            case nurbs:
            {


                if (branchAttributes->lod_cutoff < darkness)
                {
                    gluNurbsProperty(theNurbs,GLU_NURBS_MODE,GLU_NURBS_RENDERER);
                    gluBeginCurve(theNurbs);
                    gluNurbsCurve(theNurbs, 8, sknots, 4, &ctlpoints[0][0], 4, GL_MAP1_VERTEX_4);
                    gluEndCurve(theNurbs);
                }
                break;
            }

            case straight:
            {

                if (branchAttributes->lod_cutoff < darkness)
                {
                    glBegin(GL_LINES);
                    glVertex3d(A->x_anc,A->y_anc,A->z_anc);
                    glVertex3d(A->x_center,A->y_center,A->z);
                    glEnd();
                }
            }
            }
            break;
        }
    }
    }
}