home *** CD-ROM | disk | FTP | other *** search
- /* cat > headers/xform.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* xform.h: header for xform.c file */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #define xform_h 1
-
- #include "all.h"
- #include "newext.h"
-
- static Point tform;
- static double xform00, xform01, xform02;
- static double xform10, xform11, xform12;
- static double xform20, xform21, xform22;
-
- static float obliq_angle = 45.0;
- static float fore_shorten = 0.5;
- static double angsin, angcos;
-
- /* EOF */
- /* cat > src+obj/xform/setvrp.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* setvrp: Set the VRP using absolute coordinates */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "xform.h" */
-
- void
- setvrp (x, y, z)
- float x, y, z;
- {
- tform.x = -x;
- tform.y = -y;
- tform.z = -z;
- }
- /* EOF */
- /* cat > src+obj/xform/setxform.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* setxform: set x form */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "xform.h" */
-
- void
- setxform ()
- {
- double sh, ch, sp, cp, sb, cb;
- double alpha, tmp;
- char buf[20];
- Point t0, t1;
-
- strncpy (buf, (char *) panel_get_value (yaw_item), 19);
- yaw_angle = (float) atof (buf);
- strncpy (buf, (char *) panel_get_value (pitch_item), 19);
- pitch_angle = (float) atof (buf);
- strncpy (buf, (char *) panel_get_value (roll_item), 19);
- roll_angle = (float) atof (buf);
-
- sprintf (msgstr,"Note: Rotating angles - Yaw=%.1f, Pitch=%.1f, Roll=%.1f",
- yaw_angle, pitch_angle, roll_angle);
- msg_write(msgstr);
-
-
- /*
- Setup the transformation matrix. This matrix will have the
- form (Ry Rx Rz Tl)
- */
-
- sh = sin (TORAD (yaw_angle));
- ch = cos (TORAD (yaw_angle));
- sp = sin (TORAD (pitch_angle));
- cp = cos (TORAD (pitch_angle));
- sb = sin (TORAD (roll_angle));
- cb = cos (TORAD (roll_angle));
-
- /*
- Heading(Yaw) -- rotating about y axis;
- Pitch -- rotating about x axis;
- Bank(Roll) -- rotating about z axis;
- */
-
- /* 3D transformation */
- xform00 = ch * cb - sh * sp * sb;
- xform01 = ch * sb + sh * sp * cb;
- xform02 = -cp * sh;
- xform10 = -sb * cp;
- xform11 = cp * cb;
- xform12 = sp;
- xform20 = cb * sh + sb * sp * ch;
- xform21 = sb * sh - sp * ch * cb;
- xform22 = ch * cp;
-
- t0.x = 0.0;
- t0.y = 0.0;
- t0.z = 0.0;
- t1.x = 0.0;
- t1.y = 10.0;
- t1.z = 0.0;
- xform (&t0, &t0);
- xform (&t1, &t1);
-
- alpha = -atan2 ((double) (t1.x - t0.x), (double) (t1.y - t0.y));
-
- zform00 = cos (alpha);
- zform01 = -sin (alpha);
- zform10 = -zform01;
- zform11 = zform00;
-
- tmp = xform00;
- xform00 = tmp * zform00 + xform01 * zform10;
- xform01 = tmp * zform01 + xform01 * zform11;
- tmp = xform10;
- xform10 = tmp * zform00 + xform11 * zform10;
- xform11 = tmp * zform01 + xform11 * zform11;
- tmp = xform20;
- xform20 = tmp * zform00 + xform21 * zform10;
- xform21 = tmp * zform01 + xform21 * zform11;
-
- zform01 = -zform01;
- zform10 = -zform10;
-
- /*
- Setup projection angles.
- */
-
- angsin = fore_shorten * sin (TORAD (obliq_angle));
- angcos = fore_shorten * cos (TORAD (obliq_angle));
- }
- /* EOF */
- /* cat > src+obj/xform/xform.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* xform: Apply the mapping (3D) and the projection */
- /* (2D). To and From may be the same point. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "xform.h" */
-
- void
- xform (to, from)
- Point *to;
- Point *from;
- {
- Point t;
-
- t.x = from->x + tform.x;
- t.y = from->y + tform.y;
- t.z = from->z + tform.z;
-
- to->x = (xform00 * t.x)
- + (xform10 * t.y)
- + (xform20 * t.z);
-
- to->y = (xform01 * t.x)
- + (xform11 * t.y)
- + (xform21 * t.z);
-
- to->z = (xform02 * t.x)
- + (xform12 * t.y)
- + (xform22 * t.z);
-
- /* oblique projection */
- if (oblique)
- {
- to->x += to->z * angcos;
- to->y += to->z * angsin;
- }
- }
- /* EOF */
- /* cat > src+obj/xform/zform.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* zform: z form */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "xform.h" */
-
- void
- zform (p)
- Point *p;
- {
- double fx, fy;
-
- fx = p->x;
- fy = p->y;
- p->x = zform00 * fx + zform10 * fy;
- p->y = zform01 * fx + zform11 * fy;
- }
- /* EOF */
-