%% $Id: pst-3d.tex 290 2010-02-13 15:24:44Z herbert $
%% This is file `pst-3d.tex',
%%
%% IMPORTANT NOTICE:
%%
%% Package `pst-3d.tex'
%%
%% Timothy Van Zandt <tvz@nwu.edu> (tvz)
%% Herbert Voss <hvoss _at_ tug.org> (hv)
%% 
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN archives
%% in directory macros/latex/base/lppl.txt.
%%
%% DESCRIPTION:
%%   `pst-3d' is a PSTricks package for tilting and other pseudo-3D tricks
%%
%
\csname PSTthreeDLoaded\endcsname
\let\PSTthreeDLoaded\endinput
\ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi
\ifx\PSTXKeyLoaded\endinput\else \input pst-xkey    \fi % (hv 2005-09-03)
%
\def\fileversion{1.11}
\def\filedate{2010/02/14}
\message{`PST-3d' v\fileversion, \filedate\space (tvz)}
%
\edef\PstAtCode{\the\catcode`\@}
\catcode`\@=11\relax
\pst@addfams{pst-3d}

%% prologue for postcript
%
\pstheader{pst-3d.pro}%
%
\def\tx@SetMatrixThreeD{ tx@3Ddict begin SetMatrixThreeD end }
\def\tx@ProjThreeD{ tx@3Ddict begin ProjThreeD end }
\def\tx@SetMatrixEmbed{ tx@3Ddict begin SetMatrixEmbed end }
\def\tx@TMSave{ tx@3Ddict begin TMSave end }
\def\tx@TMRestore{ tx@3Ddict begin TMRestore end }
\def\tx@TMChange{ tx@3Ddict begin TMChange end }
%
\let\pssetzlength\pssetylength
\define@key[psset]{pst-3d}{viewpoint}[1 -1 1]{%
  \pst@expandafter\psset@@viewpoint#1 {} {} {} \@nil
  \let\psk@viewpoint\pst@tempg}
\def\psset@@viewpoint#1 #2 #3 #4\@nil{%
  \begingroup
    \pssetxlength\pst@dima{#1}%
    \pssetylength\pst@dimb{#2}%
    \pssetzlength\pst@dimc{#3}%
    \xdef\pst@tempg{%
      \pst@number\pst@dima \pst@number\pst@dimb \pst@number\pst@dimc}%
  \endgroup}
\psset[pst-3d]{viewpoint=1 -1 1}
\define@key[psset]{pst-3d}{viewangle}[0]{\pst@getangle{#1}\psk@viewangle}
\psset[pst-3d]{viewangle=0}
\define@key[psset]{pst-3d}{normal}[0 0 1]{%
  \pst@expandafter\psset@@viewpoint#1 {} {} {} \@nil
  \let\psk@normal\pst@tempg}
\psset[pst-3d]{normal=0 0 1}
\define@key[psset]{pst-3d}{embedangle}[0]{\pst@getangle{#1}\psk@embedangle}
\psset[pst-3d]{embedangle=0}
\define@key[psset]{pst-3d}{Tshadowsize}[1]{\pst@checknum{#1}\psTshadowsize}
\psset[pst-3d]{Tshadowsize=1}
\define@key[psset]{pst-3d}{Tshadowangle}[60]{\pst@getangle{#1}\psk@Tshadowangle}
\psset[pst-3d]{Tshadowangle=60}
\define@key[psset]{pst-3d}{Tshadowcolor}[lightgray]{\pst@getcolor{#1}\psTshadowcolor}
\psset[pst-3d]{Tshadowcolor=lightgray}
%
\def\ThreeDput{\pst@object{ThreeDput}}
\def\ThreeDput@i{\@ifnextchar({\ThreeDput@ii}{\ThreeDput@ii(\z@,\z@,\z@)}}
\def\ThreeDput@ii(#1,#2,#3){%
  \pst@killglue\pst@makebox{\ThreeDput@iii(#1,#2,#3)}}
\def\ThreeDput@iii(#1,#2,#3){%
  \begingroup
  \use@par
  \if@star\pst@starbox\fi
  \pst@makesmall\pst@hbox
  \pssetxlength\pst@dima{#1}%
  \pssetylength\pst@dimb{#2}%
  \pssetzlength\pst@dimc{#3}%
  \leavevmode
  \hbox{%
    \pst@Verb{%
        { \pst@number\pst@dima
          \pst@number\pst@dimb
          \pst@number\pst@dimc
          \psk@normal
          \psk@embedangle
          \psk@viewpoint
          \psk@viewangle
          \tx@SetMatrixEmbed
        } \tx@TMChange}%
    \box\pst@hbox
    \pst@Verb{\tx@TMRestore}}%
  \endgroup
  \ignorespaces}
%
\def\pst@sinandcos#1{%
  \begingroup
    \pst@dima=#1\relax
    \pst@dima=.366022\pst@dima     %Now 1pt=1/32rad
    \pst@dimb=\pst@dima   % dimb->32sin(angle) in pts
    \pst@dimc=32\p@       % dimc->32cos(angle) in pts
    \pst@dimtonum\pst@dima\pst@tempa
    \pst@cntb=\tw@
    \pst@cntc=-\@ne
    \pst@cntg=32
    \loop
    \ifnum\pst@dima>\@cclvi % 256
      \pst@dima=\pst@tempa\pst@dima
      \divide\pst@dima\pst@cntg
      \divide\pst@dima\pst@cntb
      \ifodd\pst@cntb
        \advance\pst@dimb \pst@cntc\pst@dima
        \pst@cntc=-\pst@cntc
      \else
        \advance\pst@dimc by \pst@cntc\pst@dima
      \fi
      \advance\pst@cntb\@ne
    \repeat
    \divide\pst@dimb\pst@cntg
    \divide\pst@dimc\pst@cntg
    \global\pst@dimg\pst@dimb
    \global\pst@dimh\pst@dimc
  \endgroup}
%
\def\pst@getsinandcos#1{%
  \pst@dimg=100000sp
  \pst@dimg=#1\pst@dimg
  \pst@dimh=36000000sp
  \pst@cntg=0
  \loop
  \ifnum\pst@dimg<\z@
    \advance\pst@dimg\pst@dimh
  \repeat
  \loop
  \ifnum\pst@dimg>\pst@dimh
    \advance\pst@dimg-\pst@dimh
  \repeat
  \pst@dimh=9000000sp
  \def\pst@tempg{%
    \ifnum\pst@dimg<\pst@dimh\else
      \advance\pst@dimg-\pst@dimh
      \advance\pst@cntg\@ne
      \ifnum\pst@cntg>\thr@@ \advance\pst@cntg-4 \fi
      \expandafter\pst@tempg
    \fi}%
  \pst@tempg
  \chardef\pst@quadrant\pst@cntg
  \ifdim\pst@dimg=\z@
    \def\pst@sin{0}%
    \def\pst@cos{1}%
  \else
    \pst@sinandcos\pst@dimg
    \pst@dimtonum\pst@dimg\pst@sin
    \pst@dimtonum\pst@dimh\pst@cos
  \fi%
}
%
\def\pstilt#1{\pst@makebox{\pstilt@{#1}}}
\def\pstilt@#1{%
  \begingroup
    \leavevmode
    \pst@getsinandcos{#1}%
    \hbox{%
      \ifcase\pst@quadrant
        \kern\pst@cos\dp\pst@hbox
        \pst@dima=\pst@cos\ht\pst@hbox
        \ht\pst@hbox=\pst@sin\ht\pst@hbox
        \dp\pst@hbox=\pst@sin\dp\pst@hbox
      \or
        \kern\pst@sin\ht\pst@hbox
        \pst@dima=\pst@sin\dp\pst@hbox
        \ht\pst@hbox=\pst@cos\ht\pst@hbox
        \dp\pst@hbox=\pst@cos\dp\pst@hbox
      \or
        \kern\pst@cos\ht\pst@hbox
        \pst@dima=\pst@sin\dp\pst@hbox
        \pst@dimg=\pst@sin\ht\pst@hbox
        \ht\pst@hbox=\pst@sin\dp\pst@hbox
        \dp\pst@hbox=\pst@dimg
      \or
        \kern\pst@sin\dp\pst@hbox
        \pst@dima=\pst@sin\ht\pst@hbox
        \pst@dimg=\pst@cos\ht\pst@hbox
        \ht\pst@hbox=\pst@cos\dp\pst@hbox
        \dp\pst@hbox=\pst@dimg
      \fi
      \pst@Verb{%
        { [ 1 0
            \pst@cos\space \ifnum\pst@quadrant>\@ne neg \fi
            \pst@sin\space
            \ifnum\pst@quadrant>\z@\ifnum\pst@quadrant<\thr@@ neg \fi\fi
            \ifodd\pst@quadrant exch \fi
            0 0
          ] concat
        } \tx@TMChange}%
      \box\pst@hbox
      \pst@Verb{\tx@TMRestore}%
      \kern\pst@dima}%
  \endgroup}
%
\def\psTilt#1{\pst@makebox{\psTilt@{#1}}}
\def\psTilt@#1{%
  \begingroup
    \leavevmode
    \pst@getsinandcos{#1}%
    \hbox{%
      \ifodd\pst@quadrant
        \pst@@divide{\dp\pst@hbox}{\pst@cos\p@}%
        \ifnum\pst@quadrant=\thr@@\kern\else\pst@dima=\fi\pst@sin\pst@dimg
        \pst@@divide{\ht\pst@hbox}{\pst@cos\p@}%
        \ifnum\pst@quadrant=\@ne\kern\else\pst@dima=\fi\pst@sin\pst@dimg
      \else
        \ifdim\pst@sin\p@=\z@
          \@pstrickserr{\string\psTilt\space angle cannot be 0 or 180}\@ehpa
          \def\pst@sin{.7071}%
          \def\pst@cos{.7071}%
        \fi
        \pst@@divide{\dp\pst@hbox}{\pst@sin\p@}%
        \ifnum\pst@quadrant=\z@\kern\else\pst@dima=\fi\pst@cos\pst@dimg
        \pst@@divide{\ht\pst@hbox}{\pst@sin\p@}%
        \ifnum\pst@quadrant=\tw@\kern\else\pst@dima=\fi\pst@cos\pst@dimg
      \fi
      \ifnum\pst@quadrant>\@ne
        \pst@dimg=\ht\pst@hbox
        \ht\pst@hbox=\dp\pst@hbox
        \dp\pst@hbox=\pst@dimg
      \fi
      \pst@Verb{%
        { [ 1 0
            \pst@cos\space \pst@sin\space
            \ifodd\pst@quadrant exch \fi
            \tx@Div
            \ifnum\pst@quadrant>\z@\ifnum\pst@quadrant<\thr@@ neg \fi\fi
            \ifnum\pst@quadrant>\@ne -1 \else 1 \fi
            0 0
          ] concat
        } \tx@TMChange}%
      \box\pst@hbox
      \pst@Verb{\tx@TMRestore}%
      \kern\pst@dima}%
  \endgroup}
%
\def\psshadow{\pst@object{psshadow}}
\def\psshadow@i{\pst@makebox{\psshadow@ii}}
\def\psshadow@ii{%
  \begingroup
    \use@par
    \leavevmode
    \pst@getsinandcos{\psk@Tshadowangle}%
    \hbox{%
      \lower\dp\pst@hbox\hbox{%
        \pst@Verb{%
          { [ 1 0
              \pst@cos\space \psTshadowsize mul
              \ifnum\pst@quadrant>\@ne neg \fi
              \pst@sin\space \psTshadowsize mul
              \ifnum\pst@quadrant>\z@\ifnum\pst@quadrant<\thr@@ neg \fi\fi
              \ifodd\pst@quadrant exch \fi
              0 0
            ] concat
          } \tx@TMChange}}%
      \hbox to\z@{%   patch 2 (hv), to get it run with xcolor _and_ TeX
       \pst@Verb{ gsave \pst@usecolor\psTshadowcolor}%
       \copy\pst@hbox
       \pst@Verb{ grestore}\hss}%
      \pst@Verb{\tx@TMRestore}%
      \box\pst@hbox}%
  \endgroup}
%
\def\psAffinTransform{\pst@object{psAffinTransform}}
\def\psAffinTransform@i#1{%
  \begin@SpecialObj%
  \pst@makebox{\psAffinTransform@ii{#1}}}%
\def\psAffinTransform@ii#1{%
  \pst@Verb{ { [#1] concat } \tx@TMChange }%
  \box\pst@hbox \pst@Verb{ \tx@TMRestore }%
  \end@SpecialObj}
%
\catcode`\@=\PstAtCode\relax
\endinput
%%
%% End of file `pst-3d.tex'.
