int Prepare_Cross_Spline(int move_selected)
{
 int points[8];

 actual_step_node=dock_move_actual_step[move_selected];

 //si tracker pas à l endroit de la memoire
 if(mover_params[0][0]!=(dock_move_xy[move_selected][actual_step_node][0]+xmover_window+20) || mover_params[1][0]!=(dock_move_xy[move_selected][actual_step_node][1]+ymover_window+20))
 {    nodes[actual_step_node].x=mover_params[0][0]+xmover_window+20;
      nodes[actual_step_node].y=mover_params[1][0]+ymover_window+20;
 }



 //next step et raffraichissement xy pour cycle mode
  next_step_node=next_step[move_selected];
  if(next_step_node>dock_moves_contains_steps[move_selected]){next_step_node=1;}
  nodes[next_step_node].x=(dock_move_xy[move_selected][next_step_node][0]+xmover_window+20);
  nodes[next_step_node].y=(dock_move_xy[move_selected][next_step_node][1]+ymover_window+20);


  //dans le cas d un goto
 if(GotoMoves[move_selected][actual_step_node]!=0 && index_move_forward==1)
 {
 numero_de_dock_goto_spline=GotoMoves[move_selected][actual_step_node];
 next_step_node=Moves_Inpoint[numero_de_dock_goto_spline];
 nodes[next_step_node].x=(dock_move_xy[numero_de_dock_goto_spline][next_step_node][0]+xmover_window+20);
 nodes[next_step_node].y=(dock_move_xy[numero_de_dock_goto_spline][next_step_node][1]+ymover_window+20);
 for(int ro=1;ro<dock_moves_contains_steps[numero_de_dock_goto_spline];ro++)
 {
  if(ro!=actual_step_node)
  {
  nodes[ro].x=(dock_move_xy[numero_de_dock_goto_spline][ro][0]+xmover_window+20);
  nodes[ro].y=(dock_move_xy[numero_de_dock_goto_spline][ro][1]+ymover_window+20);
  }
 }
 }

// pas besoin de re calcul des tangentes, il est fait pour l affichage.
 get_control_points(nodes[actual_step_node],nodes[next_step_node],points);


 if(index_move_back==1)
 { get_control_points_backward(nodes[actual_step_node],nodes[next_step_node],points);}
 calc_spline(points, SPLINE_MAX_RESOLUTION,  my_spline_path_X, my_spline_path_Y);

 actual_spline_tick=0.0;
 spline_tick_fraction=((float)SPLINE_MAX_RESOLUTION)/dock_time[dock_move_selected][(dock_move_actual_step[dock_move_selected])];
 return(0);
}
Esempio n. 2
0
File: spline.c Progetto: ifilex/SRC
/* spline:
 *  Draws a bezier spline onto the specified bitmap in the specified color.
 */
void spline(BITMAP *bmp, int points[8], int color)
{
   #define NPTS   64

   int xpts[NPTS], ypts[NPTS];
   int i;

   calc_spline(points, NPTS, xpts, ypts);

   for (i=1; i<NPTS; i++) {
      line(bmp, xpts[i-1], ypts[i-1], xpts[i], ypts[i], color);

      if (_drawing_mode == DRAW_MODE_XOR)
	 putpixel(bmp, xpts[i], ypts[i], color);
   }
}
int write_curve()
{
    index_writing_curve=1;
    int points[MAX_curve_nodeS ];// etait [8] le 24 aout


    curve_curviness = ftofix(curve_spline_level);
    curve_calc_tangents();

    for(int nio=1; nio<(curve_node_count-1); nio++)
    {
        curve_get_control_points(curve_nodes[nio],curve_nodes[nio+1],points);

        int resolu= (curve_nodes[nio+1].x) - (curve_nodes[nio].x);
        int temp_curve_x[resolu];
        int temp_curve_y[resolu];
        calc_spline(points,resolu,  temp_curve_x, temp_curve_y);

        int index_sp=0;

        for(int cuv=0; cuv<resolu; cuv++)
        {
            index_sp=(curve_nodes[nio].x+cuv)-(xpatch_window+30+455);

            if(index_sp>255) {
                index_sp=255;
            }
            if(index_sp<0) {
                index_sp=0;
            }

            curve_report[curve_selected][index_sp]=temp_curve_y[cuv]-(ypatch_window+50);

            if(curve_report[curve_selected][index_sp]<0) {
                curve_report[curve_selected][index_sp]=0;
            }
            if(curve_report[curve_selected][index_sp]>255) {
                curve_report[curve_selected][index_sp]=255;
            }

        }
    }
    index_writing_curve=0;
    return(0);
}
Esempio n. 4
0
void Spline::CalculateResultPoints() {

    int points[8] = { _control_points[0].GetX(), _control_points[0].GetY(),
        _control_points[1].GetX(), _control_points[1].GetY(),
        _control_points[2].GetX(), _control_points[2].GetY(),
        _control_points[3].GetX(), _control_points[3].GetY(),
    };
    std::vector<int> x;
    std::vector<int> y;
    x.resize(_num_points);
    x.reserve(_num_points);
    y.resize(_num_points);
    y.reserve(_num_points);

    calc_spline(points, _num_points, &x[0], &y[0]);
    for(std::size_t i = 0; i < _num_points; ++i) {
        _result_points[i] = Point(x[i], y[i]);
    }
}
Esempio n. 5
0
/* moves a sprite along the spline path */
void walk(void)
{
   #define MAX_POINTS    256

   int points[8];
   int x[MAX_POINTS], y[MAX_POINTS];
   int n, i;
   int npoints;
   int ox, oy;

   acquire_screen();

   clear_to_color(screen, makecol(255, 255, 255));

   for (i=1; i<node_count-1; i++)
      draw_node(i);

   release_screen();

   do {
      poll_mouse();
   } while (mouse_b);

   clear_keybuf();

   ox = -16;
   oy = -16;

   xor_mode(TRUE);

   for (n=1; n < node_count-2; n++) {
      npoints = (fixtoi(node_dist(nodes[n], nodes[n+1]))+3) / 4;
      if (npoints < 1)
	 npoints = 1;
      else if (npoints > MAX_POINTS)
	 npoints = MAX_POINTS;

      get_control_points(nodes[n], nodes[n+1], points);
      calc_spline(points, npoints, x, y);

      for (i=1; i<npoints; i++) {
	 vsync();
	 acquire_screen();
	 circlefill(screen, ox, oy, 6, palette_color[2]);
	 circlefill(screen, x[i], y[i], 6, palette_color[2]);
	 release_screen();
	 ox = x[i];
	 oy = y[i];

	 poll_mouse();

	 if ((keypressed()) || (mouse_b))
	    goto getout;
      }
   }

   getout:

   xor_mode(FALSE);

   do {
      poll_mouse();
   } while (mouse_b);

   clear_keybuf();
}
Esempio n. 6
0
static void display(void)
{
  float x, y, z, c;

    calc_spline(view_from, view_from_spline, current_time);
    calc_spline(view_to, view_to_spline, current_time);
    calc_spline(light_pos, light_pos_spline, current_time);
    light_pos[3] = 0.0;
    calc_spline(logo_pos, logo_pos_spline, current_time);
    calc_spline(logo_rot, logo_rot_spline, current_time);
    
    tmplight[1] = light_pos[X] - logo_pos[X];
    tmplight[2] = light_pos[Y] - logo_pos[Y];
    tmplight[3] = light_pos[Z] - logo_pos[Z];
    
    glNewList(LIGHT_TMP, GL_COMPILE); 
    glMaterialf(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, * tmplight); 
    glEndList();
    
    tv[0][0] = tv[1][1] = tv[2][2] = light_pos[Y];
    
    glColor3ub(0,  0,  0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    
    /*
     * SHADOW
     */
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(view_from[X], view_from[Y], view_from[Z], 
	      view_to[X], view_to[Y], view_to[Z],
	      0.0, 1.0, 0.0);
    
    if (view_from[Y] > 0.0) draw_table();

    glEnable(GL_CULL_FACE); 
    glDisable(GL_DEPTH_TEST); 

    if (logo_pos[Y] < 0.0) {
      
      if (logo_pos[Y]>-0.33) {
	/* We're emerging from the table */
	c = 1.0 - (logo_pos[Y]) / -0.33;
	pca /= 4.0;
	glColor3ub((GLubyte)(128.0*(1.0-c)*0.5 + 255.0*pca*c),
		   (GLubyte)(102.0*(1.0-c)*0.5 + 255.0*pca*c),
		   (GLubyte)(179.0*(1.0-c)*0.5 + 200.0*pca*c));
      } else {
	/* Still under table */
	glColor3ub(128/2,  102/2,  179/2);
      }
      
      glPushMatrix();
      glScalef(0.04,  0.0,  0.04);
      glRotatef(0.1 * (-900), 1.0, 0.0, 0.0);
      glRotatef(0.1 * ((int)(10.0*logo_rot[Z])), 0.0, 0.0, 1.0);
      glRotatef(0.1 * ((int)(10.0*logo_rot[Y])), 0.0, 1.0, 0.0);
      glRotatef(0.1 * ((int)(10.0*logo_rot[X])), 1.0, 0.0, 0.0);
      glRotatef(0.1 * (353), 1.0, 0.0, 0.0);
      glRotatef(0.1 * (450), 0.0, 1.0, 0.0);
      draw_logo_shadow();
      glPopMatrix();
    }
    
    if (logo_pos[Y] > 0.0) {
      glPushMatrix();
      if (logo_pos[Y]<0.33) {
	pca /= 4.0;
	c = 1.0 - (logo_pos[Y])/0.33;
	glColor3ub((GLubyte)(255.0*pca*c),
		   (GLubyte)(255.0*pca*c),
		   (GLubyte)(200.0*pca*c));
      } else {
	glColor3ub(0, 0, 0);
      }
      
      glTranslatef(light_pos[X],  light_pos[Y],  light_pos[Z]);
      glMultMatrixf(&tv[0][0]);
      glTranslatef(-light_pos[X]+logo_pos[X],
		   -light_pos[Y]+logo_pos[Y],
		   -light_pos[Z]+logo_pos[Z]);
      glScalef(0.04,  0.04,  0.04);
      glRotatef (0.1 * (-900), 1.0, 0.0, 0.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[Z])), 0.0, 0.0, 1.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[Y])), 0.0, 1.0, 0.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[X])), 1.0, 0.0, 0.0);
      glRotatef (0.1 * (353), 1.0, 0.0, 0.0);
      glRotatef (0.1 * (450), 0.0, 1.0, 0.0);


      glEnable(GL_POLYGON_STIPPLE);
      glPolygonStipple(stipple);
      draw_logo_shadow();
      glDisable(GL_POLYGON_STIPPLE);
      glPopMatrix();
    }
    /*
     * DONE SHADOW 
     */


    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    glEnable(GL_LIGHTING);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(.1*(450),  5.0/4.0,  0.5,  20.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    gluLookAt(view_from[X],  view_from[Y],  view_from[Z],
	      view_to[X],  view_to[Y],  view_to[Z], 
	      0.0, 1.0, 0.0);
    
    glCallList( MAT_HOLDER_RINGS); 
    
    glPushMatrix();
    glTranslatef(light_pos[X],  light_pos[Y],  light_pos[Z]);
    glScalef(0.1,  0.1,  0.1);
    
    x = light_pos[X] - logo_pos[X];
    y = light_pos[Y] - logo_pos[Y];
    z = light_pos[Z] - logo_pos[Z];
    
    if (x!=0.0) {
      a3 = -atan2(z, x)*10.0 RAD;
    } else a3 = 0.0;
    
    a4 = -atan2(sqrt(x*x + z*z), y)*10.0 RAD;
    
    glRotatef (0.1 * ((int)a3), 0.0, 1.0, 0.0);
    glRotatef (0.1 * ((int)a4), 0.0, 0.0, 1.0);
    glRotatef (0.1 * (-900), 1.0, 0.0, 0.0);
    
    glEnable(GL_LIGHT2);
    glEnable(GL_LIGHT3);
    glCallList(MAT_HEMISPHERE);
    glEnable(GL_NORMALIZE);
    draw_hemisphere();
    glDisable(GL_NORMALIZE);
    glPopMatrix();

    glDisable(GL_LIGHT2);
    glDisable(GL_LIGHT3); 
    glEnable(GL_LIGHT1);
    glLightfv(GL_LIGHT1, GL_POSITION, light_pos);
    
    if (logo_pos[Y] > -0.33) {

      glCallList(MAT_LOGO);
    
      glPushMatrix();
      glTranslatef(logo_pos[X],  logo_pos[Y],  logo_pos[Z]);
      glScalef(0.04,  0.04,  0.04);
      glRotatef (0.1 * (-900), 1.0, 0.0, 0.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[Z])), 0.0, 0.0, 1.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[Y])), 0.0, 1.0, 0.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[X])), 1.0, 0.0, 0.0);
      glRotatef (0.1 * (353), 1.0, 0.0, 0.0);
      glRotatef (0.1 * (450), 0.0, 1.0, 0.0);
      glEnable(GL_LIGHTING);
      draw_logo();
      glPopMatrix();
    }
    
    if (view_from[Y] < 0.0) draw_under_table();
    
    glutSwapBuffers();

    if(post_idle) do_post_idle();
}
Esempio n. 7
0
/* spline:
 *  Draws a bezier spline onto the specified bitmap in the specified color.
 */
void _soft_spline(BITMAP *bmp, AL_CONST int points[8], int color)
{
   #define MAX_POINTS   64

   int xpts[MAX_POINTS], ypts[MAX_POINTS];
   int i;
   int num_points;
   int c;
   int old_drawing_mode, old_drawing_x_anchor, old_drawing_y_anchor;
   BITMAP *old_drawing_pattern;
   ASSERT(bmp);

   /* Calculate the number of points to draw. We want to draw as few as
      possible without loosing image quality. This algorithm is rather
      random; I have no motivation for it at all except that it seems to work
      quite well. The length of the spline is approximated by the sum of
      distances from first to second to third to last point. The number of
      points to draw is then the square root of this distance. I first tried
      to make the number of points proportional to this distance without
      taking the square root of it, but then short splines kind of had too
      few points and long splines had too many. Since sqrt() increases more
      for small input than for large, it seems in a way logical to use it,
      but I don't precisely have any mathematical proof for it. So if someone
      has a better idea of how this could be done, don't hesitate to let us
      know...
   */

   #undef DIST
   #define DIST(x, y) (sqrt((x) * (x) + (y) * (y)))
   num_points = (int)(sqrt(DIST(points[2]-points[0], points[3]-points[1]) +
                           DIST(points[4]-points[2], points[5]-points[3]) +
                           DIST(points[6]-points[4], points[7]-points[5])) *
                      1.2);

   if (num_points > MAX_POINTS)
      num_points = MAX_POINTS;

   calc_spline(points, num_points, xpts, ypts);

   acquire_bitmap(bmp);

   if ((_drawing_mode == DRAW_MODE_XOR) ||
       (_drawing_mode == DRAW_MODE_TRANS)) {
      /* Must compensate for the end pixel being drawn twice,
         hence the mess. */
      old_drawing_mode = _drawing_mode;
      old_drawing_pattern = _drawing_pattern;
      old_drawing_x_anchor = _drawing_x_anchor;
      old_drawing_y_anchor = _drawing_y_anchor;
      for (i=1; i<num_points-1; i++) {
         c = getpixel(bmp, xpts[i], ypts[i]);
         line(bmp, xpts[i-1], ypts[i-1], xpts[i], ypts[i], color);
         solid_mode();
         putpixel(bmp, xpts[i], ypts[i], c);
         drawing_mode(old_drawing_mode, old_drawing_pattern,
                      old_drawing_x_anchor, old_drawing_y_anchor);
      }
      line(bmp, xpts[i-1], ypts[i-1], xpts[i], ypts[i], color);
   }
   else {
      for (i=1; i<num_points; i++)
         line(bmp, xpts[i-1], ypts[i-1], xpts[i], ypts[i], color);
   }

   release_bitmap(bmp);
}