Advertisement
ijontichy

bezier.c

Mar 6th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.66 KB | None | 0 0
  1. #include "zcommon.acs"
  2.  
  3. function int magnitudeThree_f(int x, int y, int z)
  4. {
  5.     int len, ang;
  6.  
  7.     ang = VectorAngle(x, y);
  8.     if (((ang + 0.125) % 0.5) > 0.25) { len = FixedDiv(y, sin(ang)); }
  9.     else { len = FixedDiv(x, cos(ang)); }
  10.  
  11.     ang = VectorAngle(len, z);
  12.     if (((ang + 0.125) % 0.5) > 0.25) { len = FixedDiv(z, sin(ang)); }
  13.     else { len = FixedDiv(len, cos(ang)); }
  14.  
  15.     return len;
  16. }
  17.  
  18. function int distance(int x1, int y1, int z1, int x2, int y2, int z2)
  19. {
  20.     return magnitudeThree_f(x2-x1, y2-y1, z2-z1);
  21. }
  22.  
  23. #define BEZIER 392
  24.  
  25. /* Each coordinate is in the form of (x, y, z).
  26.  *
  27.  * Specification format: "[AR] # - <purpose>"
  28.  * A means absolute, R means relative, # is index
  29.  *
  30.  *  Given:
  31.  * A 0 - the source point
  32.  * A 1 - the target point
  33.  * A 2 - the middle point
  34.  *
  35.  *  Calculated:
  36.  * R 3 - source to middle
  37.  * R 4 - target to middle
  38.  * A 5 - point between source and middle
  39.  * A 6 - point between middle and target
  40.  * R 7 - point 5 to point 6
  41.  * A 8 - the final bezier point
  42.  *
  43.  * Coordinate 8 is what you want, in the end.
  44.  */
  45.  
  46. int coords[9][3];
  47.  
  48. script BEZIER (void)
  49. {
  50.     int i, dist, distPerc;
  51.  
  52.     coords[0][0] = 0; // source x
  53.     coords[0][1] = 0; // source y
  54.     coords[0][2] = 0; // source z
  55.  
  56.     coords[1][0] = 0; // target x
  57.     coords[1][1] = 0; // target y
  58.     coords[1][2] = 0; // target z
  59.  
  60.     coords[2][0] = 0; // middle x
  61.     coords[2][1] = 0; // middle y
  62.     coords[2][2] = 0; // middle z
  63.  
  64.     coords[3][0] = coords[2][0] - coords[0][0];
  65.     coords[3][1] = coords[2][1] - coords[0][1];
  66.     coords[3][2] = coords[2][2] - coords[0][2];
  67.  
  68.     coords[4][0] = coords[2][0] - coords[1][0];
  69.     coords[4][1] = coords[2][1] - coords[1][1];
  70.     coords[4][2] = coords[2][2] - coords[1][2];
  71.  
  72.     for (i = 12; i <= dist; i += 12)
  73.     {
  74.         if (i < 24) { continue; }
  75.         distPerc = FixedDiv(i * 1.0, dist * 1.0);
  76.  
  77.         coords[5][0] = coords[0][0] + FixedMul(coords[3][0], distPerc);
  78.         coords[5][1] = coords[0][1] + FixedMul(coords[3][1], distPerc);
  79.         coords[5][2] = coords[0][2] + FixedMul(coords[3][2], distPerc);
  80.  
  81.         coords[6][0] = coords[1][0] + FixedMul(coords[4][0], 1.0-distPerc);
  82.         coords[6][1] = coords[1][1] + FixedMul(coords[4][1], 1.0-distPerc);
  83.         coords[6][2] = coords[1][2] + FixedMul(coords[4][2], 1.0-distPerc);
  84.  
  85.         coords[7][0] = coords[6][0] - coords[5][0];
  86.         coords[7][1] = coords[6][1] - coords[5][1];
  87.         coords[7][2] = coords[6][2] - coords[5][2];
  88.  
  89.         coords[8][0] = coords[5][0] + FixedMul(coords[7][0], distPerc);
  90.         coords[8][1] = coords[5][1] + FixedMul(coords[7][1], distPerc);
  91.         coords[8][2] = coords[5][2] + FixedMul(coords[7][2], distPerc);
  92.  
  93.         // do shit with the bezier point here
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement