% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesFileRCS{pgfrendertransform.code.tex}




% Create a 3D transformation matrix
%  
% #1 = macro name in which the transformation matrix should be stored 
% #2 = three comma-separated numbers, representing the first line of
%      the matrix. 
% #3 = three numbers, representing the second line of the matrix.
% #4 = three numbers, representing the thrid line of the matrix.
% #5 = 3D point object, used for the offset.
%  
% Example:
%
% \pgfrendertransformcreate{\mymatrix}{1,0,0}{0,1,0}{0,0,1}{\pgfrenderobjorigin}

\def\pgfrendertransformcreate#1#2#3#4#5{%
  \pgf@render@unpack#5%
  \edef#1{{#2}{#3}{#4}{\pgf@xa=\the\pgf@xa\pgf@xb=\the\pgf@xb\pgf@xc=\the\pgf@xc}}%
}



% Apply a 3D transformation matrix to a 3D point
%  
% #1 = new point (may be the old point) (#1 := #2*#3)
% #2 = transformation matrix object
% #3 = point to be transformed
%  
% Example:
%
% \pgfrendertransform{\newvec}{\mymatrix}{\oldvec}

\def\pgfrendertransform#1#2#3{%
  \pgf@render@unpack#3%
  \expandafter\pgf@rendertransform#2%
  \pgf@xa=\pgf@ya%
  \pgf@xb=\pgf@yb%
  \pgf@xc=\pgf@yc%
}

\def\pgf@rendertransform#1#2#3#4{%
  \pgf@@rendertransform\pgf@ya#1\relax%
  \pgf@@rendertransform\pgf@yb#2\relax%
  \pgf@@rendertransform\pgf@yc#3\relax%
  #4%
  \advance\pgf@ya by \pgf@xa%
  \advance\pgf@yb by \pgf@xb%
  \advance\pgf@yc by \pgf@xc%
}

\def\pgf@@rendertransform#1#2,#3,#4\relax{%
  #1=#2\pgf@xa%
  \advance#1by#3\pgf@xb%
  \advance#1by#4\pgf@xc%
}



% Concatenate two 3D transformation matrices
%  
% #1 = new matrix, (#1 := #2*#3)
% #2 = first matrix
% #3 = second matrix
%  
% Example:
%
% \pgfrendertransformconcat{\mymatrix}{\rotationmatrix}{\mymatrix}

\def\pgfrendertransformconcat#1#2#3{%
  \expandafter\pgf@render@extract@columns#3%
  \pgfrendertransform\pgf@render@temp@a#2\pgf@render@temp@a%
  \pgfrendertransform\pgf@render@temp@b#2\pgf@render@temp@b%
  \pgfrendertransform\pgf@render@temp@c#2\pgf@render@temp@c%
  \pgfrendertransform\pgf@render@temp@d#2\pgf@render@temp@d%
  \pgf@render@unpack\pgf@render@temp@a%
  \edef\pgf@temp@a{\pgf@sys@tonumber\pgf@xa}%
  \edef\pgf@temp@b{\pgf@sys@tonumber\pgf@xb}%
  \edef\pgf@temp@c{\pgf@sys@tonumber\pgf@xc}%
  \pgf@render@unpack\pgf@render@temp@b%
  \edef\pgf@temp@a{\pgf@temp@a,\pgf@sys@tonumber\pgf@xa}%
  \edef\pgf@temp@b{\pgf@temp@b,\pgf@sys@tonumber\pgf@xb}%
  \edef\pgf@temp@c{\pgf@temp@c,\pgf@sys@tonumber\pgf@xc}%
  \pgf@render@unpack\pgf@render@temp@c%
  \edef\pgf@temp@a{\pgf@temp@a,\pgf@sys@tonumber\pgf@xa}%
  \edef\pgf@temp@b{\pgf@temp@b,\pgf@sys@tonumber\pgf@xb}%
  \edef\pgf@temp@c{\pgf@temp@c,\pgf@sys@tonumber\pgf@xc}%
  \pgfrendertransformcreate#1{\pgf@temp@a}{\pgf@temp@b}{\pgf@temp@c}{\pgf@render@temp@c}%
}

\def\pgf@render@extract@columns#1#2#3#4{%
  \pgf@@render@extract@columns#1,#2,#3\relax%
  \def\pgf@render@temp@d{#4}%
}

\def\pgf@@render@extract@columns#1,#2,#3,#4,#5,#6,#7,#8,#9\relax{%
  \pgfqrenderpointcreate\pgf@render@temp@a{#1pt}{#4pt}{#7pt}%
  \pgfqrenderpointcreate\pgf@render@temp@b{#2pt}{#5pt}{#8pt}%
  \pgfqrenderpointcreate\pgf@render@temp@c{#3pt}{#6pt}{#9pt}%
}





\endinput
