Advertisement
ijontichy

bezier.c

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