home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / xfedor.zip / XFree86 / src / xfedor / ed_beziers.c < prev    next >
C/C++ Source or Header  |  1999-03-02  |  2KB  |  99 lines

  1. /* Copyright 1989 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  2. #include <stdio.h>
  3. #include <math.h>             
  4. #include "couche.h"    /* myEvent */
  5.  
  6. #define round(f) ((((int)((f)*100)-((int)(f)*100))<50)?((int)(f)):((int)(f)+1))
  7.  
  8. static tracercourbe(x0,y0,x1,y1,x2,y2,x3,y3)
  9.     int x0,y0,x1,y1,x2,y2,x3,y3 ;
  10.  
  11. {
  12.  float t;
  13.  float unmoinst;
  14.  float t2,t3;
  15.  float nbp; /*nombre de Points a calculer */
  16.  float lepas;
  17.  float pfx,pfy;
  18.  
  19.  nbp = (float) (
  20.        sqrt((float)((x1 - x2)*(x1 - x2) +
  21.                (y1 - y2)*(y1 - y2)))+
  22.        sqrt((float)((x3 - x2)*(x3 - x2) + 
  23.             (y3 - y2)*(y3 - y2)))+
  24.        sqrt((float)((x1 - x0)*(x1 - x0) +
  25.                (y1 - y0)*(y1 - y0)))) ;
  26.  lepas = (float) 1 / nbp;
  27.  for (t = 0; t <= 1; t += lepas)
  28.    {unmoinst = 1-t;
  29.     t2 = t*t;
  30.     t3 = t2*t;
  31.    pfx = ((unmoinst)*(unmoinst)*(unmoinst)* x0 + 
  32.         3*t*(unmoinst)*(unmoinst)* x1 + 
  33.         3*t2*(unmoinst)* x2 + t3* x3 );
  34.    pfy = ((unmoinst)*(unmoinst)*(unmoinst)* y0 + 
  35.       3*t*(unmoinst)*(unmoinst)* y1 + 
  36.       3*t2*(unmoinst)* y2 + t3* y3 );
  37.    Adjpoint(round(pfx),round(pfy));
  38.    }
  39.    Aff_all() ;
  40.    CarFen();
  41. }
  42.  
  43.  
  44. Autom_bez (pev)
  45.     myEvent * pev ; 
  46. {   
  47.     static numpoint ;
  48.     static int x0,y0,x1,y1,x2,y2,x3,y3 ;
  49.  
  50.     switch (pev->type) {
  51.     case EnterZone : Afficher_boutons("POINT","POINT");
  52.              numpoint = 1 ;
  53.              break ;
  54.     case ButtonPressed : switch (numpoint) {
  55.                 case 1 : x0 = convert(pev->x) ;
  56.                      y0 = convert(pev->y) ;
  57.                      numpoint ++ ;
  58.                      Invpoint(x0,y0) ;
  59.                      break ;
  60.                 case 2 : x1 = convert(pev->x) ;
  61.                      y1 = convert(pev->y) ;
  62.                      numpoint ++ ;
  63.                      Invpoint(x1,y1);
  64.                      break ;
  65.                 case 3 : x2 = convert(pev->x) ;
  66.                      y2 = convert(pev->y) ;
  67.                      numpoint ++ ;
  68.                      Invpoint(x2,y2) ;
  69.                      break ;
  70.                 case 4 : x3 = convert(pev->x) ;
  71.                      y3 = convert(pev->y) ;
  72.                      Invpoint(x0,y0) ;
  73.                      Invpoint(x1,y1) ;
  74.                      Invpoint(x2,y2) ;
  75.                      Dodo();
  76.                      tracercourbe(x0,y0,x1,y1,
  77.                             x2,y2,x3,y3);
  78.                      numpoint = 1 ;
  79.                      break ;
  80.                  }
  81.                  break ;
  82.     case ButtonReleased : break ;
  83.     case MoveMouse : break ;                
  84.     case CloseWindow : break ;                
  85.     case LeaveZone : Afficher_boutons("","");
  86.                  Afficher_numview(-1,-1) ; /* restaure le gris */
  87.              switch (numpoint) {
  88.                 case 2 : Invpoint(x0,y0) ; break ;
  89.                 case 3 : Invpoint(x0,y0) ;
  90.                      Invpoint(x1,y1) ; break ;
  91.                 case 4 : Invpoint(x0,y0) ;
  92.                      Invpoint(x1,y1) ;
  93.                      Invpoint(x2,y2) ; break ;
  94.                 default : break ;
  95.              }
  96.              break ;
  97.     }
  98.