home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / plotting / imagetoo / imagetl1.lha / Imagetool / src+obj / xform.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-11  |  4.4 KB  |  193 lines

  1. /* cat > headers/xform.h << "EOF" */
  2. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  3. /* xform.h: header for xform.c file            */
  4. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  5. /* SCCS information: %W%    %G% - NCSA */
  6.  
  7. #define    xform_h        1
  8.  
  9. #include "all.h"
  10. #include "newext.h"
  11.  
  12.     static Point tform;
  13.     static double xform00, xform01, xform02;
  14.     static double xform10, xform11, xform12;
  15.     static double xform20, xform21, xform22;
  16.  
  17.     static float obliq_angle = 45.0;
  18.     static float fore_shorten = 0.5;
  19.     static double angsin, angcos;
  20.  
  21. /* EOF */
  22. /* cat > src+obj/xform/setvrp.c << "EOF" */
  23. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  24. /* setvrp: Set the VRP using absolute coordinates    */
  25. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  26. /* SCCS information: %W%    %G% - NCSA */
  27.  
  28. /* #include "xform.h" */
  29.  
  30. void 
  31. setvrp (x, y, z)
  32.     float           x, y, z;
  33. {
  34.     tform.x = -x;
  35.     tform.y = -y;
  36.     tform.z = -z;
  37. }
  38. /* EOF */
  39. /* cat > src+obj/xform/setxform.c << "EOF" */
  40. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  41. /* setxform: set x form                    */
  42. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  43. /* SCCS information: %W%    %G% - NCSA */
  44.  
  45. /* #include "xform.h" */
  46.  
  47. void 
  48. setxform ()
  49. {
  50.     double          sh, ch, sp, cp, sb, cb;
  51.     double          alpha, tmp;
  52.     char            buf[20];
  53.     Point           t0, t1;
  54.  
  55.     strncpy (buf, (char *) panel_get_value (yaw_item), 19);
  56.     yaw_angle = (float) atof (buf);
  57.     strncpy (buf, (char *) panel_get_value (pitch_item), 19);
  58.     pitch_angle = (float) atof (buf);
  59.     strncpy (buf, (char *) panel_get_value (roll_item), 19);
  60.     roll_angle = (float) atof (buf);
  61.  
  62.     sprintf (msgstr,"Note: Rotating angles - Yaw=%.1f, Pitch=%.1f, Roll=%.1f",
  63.             yaw_angle, pitch_angle, roll_angle);
  64.     msg_write(msgstr);
  65.  
  66.  
  67.     /*
  68.         Setup the transformation matrix. This matrix will have the
  69.         form (Ry Rx Rz Tl)
  70.     */
  71.  
  72.     sh = sin (TORAD (yaw_angle));
  73.     ch = cos (TORAD (yaw_angle));
  74.     sp = sin (TORAD (pitch_angle));
  75.     cp = cos (TORAD (pitch_angle));
  76.     sb = sin (TORAD (roll_angle));
  77.     cb = cos (TORAD (roll_angle));
  78.  
  79.     /*
  80.         Heading(Yaw) -- rotating about y axis;
  81.         Pitch -- rotating about x axis;
  82.         Bank(Roll) -- rotating about z axis;
  83.     */
  84.  
  85.     /*    3D transformation */
  86.     xform00 = ch * cb - sh * sp * sb;
  87.     xform01 = ch * sb + sh * sp * cb;
  88.     xform02 = -cp * sh;
  89.     xform10 = -sb * cp;
  90.     xform11 = cp * cb;
  91.     xform12 = sp;
  92.     xform20 = cb * sh + sb * sp * ch;
  93.     xform21 = sb * sh - sp * ch * cb;
  94.     xform22 = ch * cp;
  95.  
  96.     t0.x = 0.0;
  97.     t0.y = 0.0;
  98.     t0.z = 0.0;
  99.     t1.x = 0.0;
  100.     t1.y = 10.0;
  101.     t1.z = 0.0;
  102.     xform (&t0, &t0);
  103.     xform (&t1, &t1);
  104.  
  105.     alpha = -atan2 ((double) (t1.x - t0.x), (double) (t1.y - t0.y));
  106.  
  107.     zform00 = cos (alpha);
  108.     zform01 = -sin (alpha);
  109.     zform10 = -zform01;
  110.     zform11 = zform00;
  111.  
  112.     tmp = xform00;
  113.     xform00 = tmp * zform00 + xform01 * zform10;
  114.     xform01 = tmp * zform01 + xform01 * zform11;
  115.     tmp = xform10;
  116.     xform10 = tmp * zform00 + xform11 * zform10;
  117.     xform11 = tmp * zform01 + xform11 * zform11;
  118.     tmp = xform20;
  119.     xform20 = tmp * zform00 + xform21 * zform10;
  120.     xform21 = tmp * zform01 + xform21 * zform11;
  121.  
  122.     zform01 = -zform01;
  123.     zform10 = -zform10;
  124.  
  125.     /*
  126.         Setup projection angles.
  127.     */
  128.  
  129.     angsin = fore_shorten * sin (TORAD (obliq_angle));
  130.     angcos = fore_shorten * cos (TORAD (obliq_angle));
  131. }
  132. /* EOF */
  133. /* cat > src+obj/xform/xform.c << "EOF" */
  134. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  135. /* xform: Apply the mapping (3D) and the projection    */
  136. /*      (2D). To and From may be the same point.    */
  137. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  138. /* SCCS information: %W%    %G% - NCSA */
  139.  
  140. /* #include "xform.h" */
  141.  
  142. void 
  143. xform (to, from)
  144.     Point          *to;
  145.     Point          *from;
  146. {
  147.     Point           t;
  148.  
  149.     t.x = from->x + tform.x;
  150.     t.y = from->y + tform.y;
  151.     t.z = from->z + tform.z;
  152.  
  153.     to->x = (xform00 * t.x)
  154.         + (xform10 * t.y)
  155.         + (xform20 * t.z);
  156.  
  157.     to->y = (xform01 * t.x)
  158.         + (xform11 * t.y)
  159.         + (xform21 * t.z);
  160.  
  161.     to->z = (xform02 * t.x)
  162.         + (xform12 * t.y)
  163.         + (xform22 * t.z);
  164.  
  165.         /* oblique projection */
  166.     if (oblique)
  167.     {
  168.         to->x += to->z * angcos;
  169.         to->y += to->z * angsin;
  170.     }
  171. }
  172. /* EOF */
  173. /* cat > src+obj/xform/zform.c << "EOF" */
  174. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  175. /* zform: z form                    */
  176. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  177. /* SCCS information: %W%    %G% - NCSA */
  178.  
  179. /* #include "xform.h" */
  180.  
  181. void 
  182. zform (p)
  183.     Point          *p;
  184. {
  185.     double          fx, fy;
  186.  
  187.     fx = p->x;
  188.     fy = p->y;
  189.     p->x = zform00 * fx + zform10 * fy;
  190.     p->y = zform01 * fx + zform11 * fy;
  191. }
  192. /* EOF */
  193.