C       .TITLE ROTER - 2 SEPT 71
C
        SUBROUTINE ROTER
        REAL N
        COMMON/GRXPQK/S11,S12,S13,S21,S22,S23,S31,S32,S33,T11,T22,T33
        COMMON/EYCEP/XO,YO,ZO,XC,YC,ZC,XV,YV,ZV
        ASTAR = XC -XO
        BSTAR = YC - YO
        CSTAR = ZC - ZO
        ESTAR = XV - XC
        FSTAR = YV - YC
        GSTAR = ZV - ZC
        H = SQRT(ASTAR*ASTAR + BSTAR*BSTAR +CSTAR*CSTAR)
        IF (H.EQ.0.0) STOP 12345
        A = ASTAR / H
        B = BSTAR / H
        C = CSTAR / H
        PSTAR = ESTAR*A + FSTAR*B + GSTAR*C
        N = SQRT(ESTAR*ESTAR + FSTAR*FSTAR + GSTAR*GSTAR - PSTAR*PSTAR)
        IF (N.EQ.0.0) STOP 12345
        E = ESTAR / N
        F = FSTAR / N
        G = GSTAR / N
        P = PSTAR / N
        S11 = B*G - C*F
        S12 = C*E - A*G
        S13 = A*F - B*E
        S21 = E - A*P
        S22 = F - B*P
        S23 = G - C*P
        S31 = A
        S32 = B
        S33 = C
        T11 = -(S11*XO + S12 *YO + S13*ZO)
        T22 = -(S21*XO + S22*YO + S23*ZO)
        T33 = -(S31*XO + S32*YO + S33*ZO)
        RETURN
        END
C  SUBROUTINE TO MAP AN OBJECT FILE ON TO A PICTURE PLANE
C  USING MATRICES CALCULATED FROM SUBROUTINE ROTER
C
C  2 SEPT 71
C
          SUBROUTINE MAPPER(DIST)
        LOGICAL SWITCH, FIRST
          COMMON/GRXPQK/S11,S12,S13,S21,S22,S23,S31,S32,S33,T11,
     9T21,T31
          COMMON/BULK/I3STRT,I3END,OBJECT(3,200)
          COMMON/PAINT/I2STRT,I2END,PICT(2,200)
C 
C  CALCULATE ROTATED POINTS FROM OBJECT AND PLACE IN PICT
        SWITCH = .TRUE.
        FIRST = .TRUE.
          JJ=I2STRT*2-1
          ISTRT=I3STRT*2-1
          IEND=I3END*2
          DO 100 J=ISTRT,IEND
          TEMPX=OBJECT(1,J)*S11+OBJECT(2,J)*S12+OBJECT(3,J)
     9*S13+T11
          TEMPY=OBJECT(1,J)*S21+OBJECT(2,J)*S22+OBJECT(3,J)*
     9S23+T21
          TEMPZ=OBJECT(1,J)*S31+OBJECT(2,J)*S32+OBJECT(3,J)*
     9S33+T31
C
C  GET VALUE IN PICTURE PLANE BY USING RATIO OF DISTANCES IN
C  Z DIRECTION (DISTANCE FROM EYE POINT TO PICTURE PLANE)
C
        IF (TEMPZ) 1,5,3
5       TEMPZ = 1.E76/AMAX1(ABS(TEMPX),ABS(TEMPY))
        GO TO 3
1       SWITCH = .FALSE.
3       TEMPZ=DIST/TEMPZ
          PICT(1,JJ)=TEMPX*TEMPZ
        PICT(2,JJ)=TEMPY*TEMPZ
        IF (SWITCH.AND.FIRST) GO TO 100
        IF ((J/2)*2.EQ.J) GO TO 2
        FIRST = .FALSE.
        GO TO 99
2       K = JJ
        I = JJ-1
        IF (FIRST) GO TO 6
        K = I
        I = JJ
        IF (SWITCH) GO TO 6
        JJ = JJ-2
        GO TO 98
6       TEMPX = PICT(1,I) - PICT(1,K)
        TEMPY = PICT(2,I) - PICT(2,K)
        TEMPZ = 1.E76/AMAX1(ABS(TEMPX),ABS(TEMPY))
        PICT(1,K) = TEMPX * TEMPZ
        PICT(2,K) = TEMPY * TEMPZ
98      FIRST = .TRUE.
99      SWITCH = .TRUE.
100       JJ=JJ+1
          I2END=JJ/2
          RETURN
          END
