ProfesseurCraft

Class php-Minecraft-3D-skin

Jul 18th, 2013
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 46.87 KB | None | 0 0
  1. <?php
  2.     /*
  3.     * Copyright (c) 2012, Pierre Gros
  4.     * All rights reserved.
  5.     * Redistribution and use in source and binary forms, with or without
  6.     * modification, are permitted provided that the following conditions are met:
  7.     *
  8.     *     * Redistributions of source code must retain the above copyright
  9.     *       notice, this list of conditions and the following disclaimer.
  10.     *     * Redistributions in binary form must reproduce the above copyright
  11.     *       notice, this list of conditions and the following disclaimer in the
  12.     *       documentation and/or other materials provided with the distribution.
  13.     *     * The names of its contributors may not be used to endorse or promote products
  14.     *       derived from this software without specific prior written permission.
  15.     *
  16.     * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY
  17.     * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18.     * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19.     * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20.     * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21.     * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22.     * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23.     * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24.     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25.     * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26.      */
  27.     /*
  28.      * Developped by Pierre Gros
  29.      * april, 17 2012
  30.      *
  31.      * login = minecraft login for the skin
  32.      * a    = vertical rotation
  33.      * w    = horizontal rotation
  34.      *
  35.      * wt   = horizontal rotation of the head
  36.      *
  37.      * ajg  = vertical rotation of the left leg
  38.      * ajd  = vertical rotation of the right leg
  39.      * abg  = vertical rotation of the left arm
  40.      * abd  = vertical rotation of the right arm
  41.      *
  42.      * displayHairs = set to "false" not to display hairs
  43.      * headOnly     = set to "true" to display only the head (and the hair, depending on the "displayHairs" input
  44.      *
  45.      * format   = "png" by default, set to "svg" to have a vectorial version of the skin
  46.      * ratio    = used only if "png" format is used. the default (and minimum) value is 2. it represent the number of times the skin will be enlarged
  47.      */
  48.     error_reporting(E_ERROR);
  49.  
  50.     $seconds_to_cache = 60*60*24*7;//duration of the cache sent to the browser
  51.     $fallBack_image = 'tmp.png';//an image you are sure it works, if there is a problem, this skin will be used
  52.  
  53.     function microtime_float()
  54.     {
  55.         list($usec, $sec) = explode(" ", microtime());
  56.         return ((float)$usec + (float)$sec);
  57.     }
  58.     $times = array(array('Start', microtime_float()));
  59.     $login = $_GET['login'];
  60.     if(trim($login) == '')
  61.         $imgPng = imageCreateFromPng($fallBack_image);
  62.     else
  63.         $imgPng = imageCreateFromPng('http://s3.amazonaws.com/MinecraftSkins/'.$login.'.png');
  64.  
  65.     if(!$imgPng)
  66.             $imgPng = imageCreateFromPng($fallBack_image);
  67.        
  68.     imageAlphaBlending($imgPng, true);
  69.     imageSaveAlpha($imgPng, true);
  70.  
  71.     $width = imagesx($imgPng);
  72.     $height = imagesy($imgPng);
  73.  
  74.     if(!($width == $height*2) || $height%32 != 0)//bad ratio !
  75.         $imgPng = imageCreateFromPng($fallBack_image);
  76.  
  77.     $hdRatio = $height/32;//$hdRatio = 2 if skin is 128*64
  78.  
  79.  
  80.  
  81.     $times[] = array('Telechargement-Image', microtime_float());
  82.  
  83.     $a = $_GET['a'];
  84.     $w = $_GET['w'];
  85.  
  86.     $headOnly = ($_GET['headOnly']=='true');
  87.     $displayHairs = ($_GET['displayHairs']!='false');
  88.  
  89.     $alpha = deg2rad($a);//autour de x
  90.     $omega = deg2rad($w);//autour de y
  91.  
  92.     //ceux là il faut les garder, ils sont utilisés en global un peu partout.
  93.     $ca = cos($alpha);
  94.     $sa = sin($alpha);
  95.     $cw = cos($omega);
  96.     $sw = sin($omega);
  97.  
  98.  
  99.     $anglesMembres = array();
  100.  
  101.     $anglesMembres['torse'] = array('ca' => cos(0), 'sa' => sin(0), 'cw' => cos(0), 'sw' => sin(0));
  102.     /*'tete'
  103.     'torse'
  104.     'brasD'
  105.     'brasG'
  106.     'jambeD'
  107.     'jambeG'*/
  108.  
  109.     $aplhaTete = 0;//deg2rad($_GET['at']);//corriger un jour peut être...
  110.     $omegaTete = deg2rad($_GET['wt']);
  111.     $anglesMembres['tete'] = array('ca' => cos($aplhaTete), 'sa' => sin($aplhaTete), 'cw' => cos($omegaTete), 'sw' => sin($omegaTete));
  112.     $anglesMembres['casque'] = array('ca' => cos($aplhaTete), 'sa' => sin($aplhaTete), 'cw' => cos($omegaTete), 'sw' => sin($omegaTete));
  113.  
  114.     $aplhaBrasG = deg2rad($_GET['abd']);
  115.     $omegaBrasG = 0;//deg2rad($_GET['wt']);//corriger un jour peut être...
  116.     $anglesMembres['brasD'] = array('ca' => cos($aplhaBrasG), 'sa' => sin($aplhaBrasG), 'cw' => cos($omegaBrasG), 'sw' => sin($omegaBrasG));
  117.  
  118.     $aplhaBrasD = deg2rad($_GET['abg']);
  119.     $omegaBrasD = 0;//deg2rad($_GET['wbd']);//corriger un jour peut être...
  120.     $anglesMembres['brasG'] = array('ca' => cos($aplhaBrasD), 'sa' => sin($aplhaBrasD), 'cw' => cos($omegaBrasD), 'sw' => sin($omegaBrasD));
  121.  
  122.     $aplhaJambeG = deg2rad($_GET['ajd']);
  123.     $omegaJambeG = 0;//deg2rad($_GET['wt']);//corriger un jour peut être...
  124.     $anglesMembres['jambeD'] = array('ca' => cos($aplhaJambeG), 'sa' => sin($aplhaJambeG), 'cw' => cos($omegaJambeG), 'sw' => sin($omegaJambeG));
  125.  
  126.     $aplhaJambeD = deg2rad($_GET['ajg']);
  127.     $omegaJambeD = 0;//deg2rad($_GET['wbd']);//corriger un jour peut être...
  128.     $anglesMembres['jambeG'] = array('ca' => cos($aplhaJambeD), 'sa' => sin($aplhaJambeD), 'cw' => cos($omegaJambeD), 'sw' => sin($omegaJambeD));
  129.  
  130.     $minX = 0;
  131.     $maxX = 0;
  132.     $minY = 0;
  133.     $maxY = 0;
  134.  
  135.  
  136.     $times[] = array('Calculs-Angles', microtime_float());
  137.  
  138.     $faceVisiblesFormat = array('avant' => array(), 'arriere' => array());
  139.     $facesVisibles = array(
  140.             'tete' => $faceVisiblesFormat,
  141.             'torse' => $faceVisiblesFormat,
  142.             'brasD' => $faceVisiblesFormat,
  143.             'brasG' => $faceVisiblesFormat,
  144.             'jambeD' => $faceVisiblesFormat,
  145.             'jambeG' => $faceVisiblesFormat);
  146.  
  147.     //TODO : boucler sur chacun, preProject & Project
  148.     //Puis calcul des faces visibles pour chacun
  149.     //et le faire aussi au niveau de l'affichage
  150.     $toutesFaces = array('arriere',   'droite', 'haut', 'avant',     'gauche', 'bas');
  151.     foreach  ($facesVisibles as $k => &$v)
  152.     {
  153.         unset($cubeMaxDepthFaces, $cubePoints);
  154.         $cubePoints = array();
  155.         $cubePoints[] = array(new Point(array('x' => 0,'y' => 0,'z' => 0)), array('arriere',   'droite', 'haut'));//0
  156.         $cubePoints[] = array(new Point(array('x' => 0,'y' => 0,'z' => 1)), array('avant',     'droite', 'haut'));//1
  157.         $cubePoints[] = array(new Point(array('x' => 0,'y' => 1,'z' => 0)), array('arriere',   'droite', 'bas'));//2
  158.         $cubePoints[] = array(new Point(array('x' => 0,'y' => 1,'z' => 1)), array('avant',     'droite', 'bas'));//3
  159.         $cubePoints[] = array(new Point(array('x' => 1,'y' => 0,'z' => 0)), array('arriere',   'gauche', 'haut'));//4
  160.         $cubePoints[] = array(new Point(array('x' => 1,'y' => 0,'z' => 1)), array('avant',     'gauche', 'haut'));//5
  161.         $cubePoints[] = array(new Point(array('x' => 1,'y' => 1,'z' => 0)), array('arriere',   'gauche', 'bas'));//6
  162.         $cubePoints[] = array(new Point(array('x' => 1,'y' => 1,'z' => 1)), array('avant',     'gauche', 'bas'));//7
  163.         foreach($cubePoints as $cubePoint)
  164.         {
  165.  
  166.             $cubePoint[0]->preProject(0, 0, 0, $anglesMembres[$k]['ca'], $anglesMembres[$k]['sa'], $anglesMembres[$k]['cw'], $anglesMembres[$k]['sw']);
  167.  
  168.             $cubePoint[0]->project();
  169.  
  170.             if(!isset($cubeMaxDepthFaces))
  171.                 $cubeMaxDepthFaces = $cubePoint;
  172.             elseif ($cubeMaxDepthFaces[0]->getDepth() > $cubePoint[0]->getDepth())
  173.             {
  174.                 $cubeMaxDepthFaces = $cubePoint;
  175.             }
  176.         }
  177.         $v['arriere'] = $cubeMaxDepthFaces[1];
  178.         $v['avant'] = array_diff($toutesFaces, $v['arriere']);
  179.     }
  180.  
  181.  
  182.     $cubePoints = array();
  183.     $cubePoints[] = array(new Point(array('x' => 0,'y' => 0,'z' => 0)), array('arriere',   'droite', 'haut'));//0
  184.     $cubePoints[] = array(new Point(array('x' => 0,'y' => 0,'z' => 1)), array('avant',     'droite', 'haut'));//1
  185.     $cubePoints[] = array(new Point(array('x' => 0,'y' => 1,'z' => 0)), array('arriere',   'droite', 'bas'));//2
  186.     $cubePoints[] = array(new Point(array('x' => 0,'y' => 1,'z' => 1)), array('avant',     'droite', 'bas'));//3
  187.     $cubePoints[] = array(new Point(array('x' => 1,'y' => 0,'z' => 0)), array('arriere',   'gauche', 'haut'));//4
  188.     $cubePoints[] = array(new Point(array('x' => 1,'y' => 0,'z' => 1)), array('avant',     'gauche', 'haut'));//5
  189.     $cubePoints[] = array(new Point(array('x' => 1,'y' => 1,'z' => 0)), array('arriere',   'gauche', 'bas'));//6
  190.     $cubePoints[] = array(new Point(array('x' => 1,'y' => 1,'z' => 1)), array('avant',     'gauche', 'bas'));//7
  191.  
  192.     unset($cubeMaxDepthFaces);
  193.     foreach($cubePoints as $cubePoint)
  194.     {
  195.         $cubePoint[0]->project();
  196.  
  197.         if(!isset($cubeMaxDepthFaces))
  198.             $cubeMaxDepthFaces = $cubePoint;
  199.         elseif ($cubeMaxDepthFaces[0]->getDepth() > $cubePoint[0]->getDepth())
  200.         {
  201.             $cubeMaxDepthFaces = $cubePoint;
  202.         }
  203.     }
  204.  
  205.  
  206.     $facesArriere = $cubeMaxDepthFaces[1];
  207.     $facesAvant = array_diff($toutesFaces, $facesArriere);
  208.  
  209.  
  210.     $times[] = array('Determination-des-faces', microtime_float());
  211.  
  212.     /*$cubePoints = array();
  213.     $cubePoints[] = new Point(array('x' => 0,'y' => 0,'z' => 0));//0
  214.     $cubePoints[] = new Point(array('x' => 0,'y' => 0,'z' => 1));//1
  215.     $cubePoints[] = new Point(array('x' => 0,'y' => 1,'z' => 0));//2
  216.     $cubePoints[] = new Point(array('x' => 0,'y' => 1,'z' => 1));//3
  217.     $cubePoints[] = new Point(array('x' => 1,'y' => 0,'z' => 0));//4
  218.     $cubePoints[] = new Point(array('x' => 1,'y' => 0,'z' => 1));//5
  219.     $cubePoints[] = new Point(array('x' => 1,'y' => 1,'z' => 0));//6
  220.     $cubePoints[] = new Point(array('x' => 1,'y' => 1,'z' => 1));//7
  221.     */
  222.     /*
  223.     $polygones = array();
  224.     $polygones[] = new Polygon(array($cubePoints[1], $cubePoints[5], $cubePoints[7], $cubePoints[3]), imagecolorat($imgPng, 0, 0));
  225.     $polygones[] = new Polygon(array($cubePoints[0], $cubePoints[1], $cubePoints[3], $cubePoints[2]), imagecolorat($imgPng, 1, 0));
  226.     $polygones[] = new Polygon(array($cubePoints[0], $cubePoints[1], $cubePoints[5], $cubePoints[4]), imagecolorat($imgPng, 2, 0));
  227.     $polygones[] = new Polygon(array($cubePoints[4], $cubePoints[5], $cubePoints[7], $cubePoints[6]), imagecolorat($imgPng, 3, 0));
  228.     $polygones[] = new Polygon(array($cubePoints[2], $cubePoints[6], $cubePoints[7], $cubePoints[3]), imagecolorat($imgPng, 4, 0));
  229.     $polygones[] = new Polygon(array($cubePoints[0], $cubePoints[4], $cubePoints[6], $cubePoints[2]), imagecolorat($imgPng, 5, 0));
  230.     */
  231.  
  232.     $faceDepths = array();
  233.  
  234.     $polygones = array();
  235.  
  236.     $arrayFacesCube = array('avant' => array(),
  237.                 'arriere' => array(),
  238.                 'haut' => array(),
  239.                 'bas' => array(),
  240.                 'droite' => array(),
  241.                 'gauche' => array());
  242.     $polygones = array('casque' => $arrayFacesCube,
  243.             'tete' => $arrayFacesCube,
  244.             'torse' => $arrayFacesCube,
  245.             'brasD' => $arrayFacesCube,
  246.             'brasG' => $arrayFacesCube,
  247.             'jambeD' => $arrayFacesCube,
  248.             'jambeG' => $arrayFacesCube);
  249.  
  250.     //Tête
  251.     for($i=0;$i<9*$hdRatio;$i++)
  252.     {
  253.         for($j=0;$j<9*$hdRatio;$j++)
  254.         {
  255.             if(!isset($volumePoints[$i][$j][-2*$hdRatio]))
  256.             {
  257.                 $volumePoints[$i][$j][-2*$hdRatio] = new Point(array('x' => $i,'y' => $j,'z' => -2*$hdRatio));
  258.             }
  259.             if(!isset($volumePoints[$i][$j][6*$hdRatio]))
  260.             {
  261.                 $volumePoints[$i][$j][6*$hdRatio] = new Point(array('x' => $i,'y' => $j,'z' => 6*$hdRatio));
  262.             }
  263.         }
  264.     }
  265.     for($j=0;$j<9*$hdRatio;$j++)
  266.     {
  267.         for($k=-2*$hdRatio;$k<7*$hdRatio;$k++)
  268.         {
  269.             if(!isset($volumePoints[0][$j][$k]))
  270.             {
  271.                 $volumePoints[0][$j][$k] = new Point(array('x' => 0,'y' => $j,'z' => $k));
  272.             }if(!isset($volumePoints[8*$hdRatio][$j][$k]))
  273.             {
  274.                 $volumePoints[8*$hdRatio][$j][$k] = new Point(array('x' => 8*$hdRatio,'y' => $j,'z' => $k));
  275.             }
  276.         }
  277.     }
  278.     for($i=0;$i<9*$hdRatio;$i++)
  279.     {
  280.         for($k=-2*$hdRatio;$k<7*$hdRatio;$k++)
  281.         {
  282.             if(!isset($volumePoints[$i][0][$k]))
  283.             {
  284.                 $volumePoints[$i][0][$k] = new Point(array('x' => $i,'y' => 0,'z' => $k));
  285.             }
  286.             if(!isset($volumePoints[$i][8*$hdRatio][$k]))
  287.             {
  288.                 $volumePoints[$i][8*$hdRatio][$k] = new Point(array('x' => $i,'y' => 8*$hdRatio,'z' => $k));
  289.             }
  290.         }
  291.     }
  292.  
  293.     for($i=0;$i<8*$hdRatio;$i++)
  294.     {
  295.         for($j=0;$j<8*$hdRatio;$j++)
  296.         {
  297.             $polygones['tete']['arriere'][] = new Polygon(
  298.                 array(
  299.                     $volumePoints[$i][$j][-2*$hdRatio],
  300.                     $volumePoints[$i+1][$j][-2*$hdRatio],
  301.                     $volumePoints[$i+1][$j+1][-2*$hdRatio],
  302.                     $volumePoints[$i][$j+1][-2*$hdRatio]),
  303.                 imagecolorat($imgPng, (32*$hdRatio-1)-$i, 8*$hdRatio+$j));
  304.             $polygones['tete']['avant'][] = new Polygon(
  305.                 array(
  306.                     $volumePoints[$i][$j][6*$hdRatio],
  307.                     $volumePoints[$i+1][$j][6*$hdRatio],
  308.                     $volumePoints[$i+1][$j+1][6*$hdRatio],
  309.                     $volumePoints[$i][$j+1][6*$hdRatio]),
  310.                 imagecolorat($imgPng, 8*$hdRatio+$i, 8*$hdRatio+$j));
  311.         }
  312.     }
  313.     for($j=0;$j<8*$hdRatio;$j++)
  314.     {
  315.         for($k=-2*$hdRatio;$k<6*$hdRatio;$k++)
  316.         {
  317.             $polygones['tete']['droite'][] = new Polygon(
  318.                 array(
  319.                     $volumePoints[0][$j][$k],
  320.                     $volumePoints[0][$j][$k+1],
  321.                     $volumePoints[0][$j+1][$k+1],
  322.                     $volumePoints[0][$j+1][$k]),
  323.                 imagecolorat($imgPng, $k+2*$hdRatio, 8*$hdRatio+$j));
  324.             $polygones['tete']['gauche'][] = new Polygon(
  325.                 array(
  326.                     $volumePoints[8*$hdRatio][$j][$k],
  327.                     $volumePoints[8*$hdRatio][$j][$k+1],
  328.                     $volumePoints[8*$hdRatio][$j+1][$k+1],
  329.                     $volumePoints[8*$hdRatio][$j+1][$k]),
  330.                 imagecolorat($imgPng, (24*$hdRatio-1)-$k-2*$hdRatio, 8*$hdRatio+$j));
  331.         }
  332.     }
  333.     for($i=0;$i<8*$hdRatio;$i++)
  334.     {
  335.         for($k=-2*$hdRatio;$k<6*$hdRatio;$k++)
  336.         {
  337.             $polygones['tete']['haut'][] = new Polygon(
  338.                 array(
  339.                     $volumePoints[$i][0][$k],
  340.                     $volumePoints[$i+1][0][$k],
  341.                     $volumePoints[$i+1][0][$k+1],
  342.                     $volumePoints[$i][0][$k+1]),
  343.                 imagecolorat($imgPng, 8*$hdRatio+$i, $k+2*$hdRatio));
  344.             $polygones['tete']['bas'][] = new Polygon(
  345.                 array(
  346.                     $volumePoints[$i][8*$hdRatio][$k],
  347.                     $volumePoints[$i+1][8*$hdRatio][$k],
  348.                     $volumePoints[$i+1][8*$hdRatio][$k+1],
  349.                     $volumePoints[$i][8*$hdRatio][$k+1]),
  350.                 imagecolorat($imgPng, 16*$hdRatio+$i, (8*$hdRatio-1)-($k+2*$hdRatio)));
  351.         }
  352.     }
  353.  
  354.     if($displayHairs)
  355.     {
  356.         //casque
  357.         $volumePoints = array();
  358.         for($i=0;$i<9*$hdRatio;$i++)
  359.         {
  360.             for($j=0;$j<9*$hdRatio;$j++)
  361.             {
  362.                 if(!isset($volumePoints[$i][$j][-2*$hdRatio]))
  363.                 {
  364.                     $volumePoints[$i][$j][-2*$hdRatio] = new Point(array('x' => $i*9/8-0.5*$hdRatio,'y' => $j*9/8-0.5*$hdRatio,'z' => -2.5*$hdRatio));
  365.                 }
  366.                 if(!isset($volumePoints[$i][$j][6*$hdRatio]))
  367.                 {
  368.                     $volumePoints[$i][$j][6*$hdRatio] = new Point(array('x' => $i*9/8-0.5*$hdRatio,'y' => $j*9/8-0.5*$hdRatio,'z' => 6.5*$hdRatio));
  369.                 }
  370.             }
  371.         }
  372.         for($j=0;$j<9*$hdRatio;$j++)
  373.         {
  374.             for($k=-2*$hdRatio;$k<7*$hdRatio;$k++)
  375.             {
  376.                 if(!isset($volumePoints[0][$j][$k]))
  377.                 {
  378.                     $volumePoints[0][$j][$k] = new Point(array('x' => -0.5*$hdRatio,'y' => $j*9/8-0.5*$hdRatio,'z' => $k*9/8-0.5*$hdRatio));
  379.                 }if(!isset($volumePoints[8*$hdRatio][$j][$k]))
  380.                 {
  381.                     $volumePoints[8*$hdRatio][$j][$k] = new Point(array('x' => 8.5*$hdRatio,'y' => $j*9/8-0.5*$hdRatio,'z' => $k*9/8-0.5*$hdRatio));
  382.                 }
  383.             }
  384.         }
  385.         for($i=0;$i<9*$hdRatio;$i++)
  386.         {
  387.             for($k=-2*$hdRatio;$k<7*$hdRatio;$k++)
  388.             {
  389.                 if(!isset($volumePoints[$i][0][$k]))
  390.                 {
  391.                     $volumePoints[$i][0][$k] = new Point(array('x' => $i*9/8-0.5*$hdRatio,'y' => -0.5*$hdRatio,'z' => $k*9/8-0.5*$hdRatio));
  392.                 }
  393.                 if(!isset($volumePoints[$i][8*$hdRatio][$k]))
  394.                 {
  395.                     $volumePoints[$i][8*$hdRatio][$k] = new Point(array('x' => $i*9/8-0.5*$hdRatio,'y' => 8.5*$hdRatio,'z' => $k*9/8-0.5*$hdRatio));
  396.                 }
  397.             }
  398.         }
  399.  
  400.         for($i=0;$i<8*$hdRatio;$i++)
  401.         {
  402.             for($j=0;$j<8*$hdRatio;$j++)
  403.             {
  404.                 $polygones['casque']['arriere'][] = new Polygon(
  405.                     array(
  406.                         $volumePoints[$i][$j][-2*$hdRatio],
  407.                         $volumePoints[$i+1][$j][-2*$hdRatio],
  408.                         $volumePoints[$i+1][$j+1][-2*$hdRatio],
  409.                         $volumePoints[$i][$j+1][-2*$hdRatio]),
  410.                     imagecolorat($imgPng, 32*$hdRatio+(32*$hdRatio-1)-$i, 8*$hdRatio+$j));
  411.                 $polygones['casque']['avant'][] = new Polygon(
  412.                     array(
  413.                         $volumePoints[$i][$j][6*$hdRatio],
  414.                         $volumePoints[$i+1][$j][6*$hdRatio],
  415.                         $volumePoints[$i+1][$j+1][6*$hdRatio],
  416.                         $volumePoints[$i][$j+1][6*$hdRatio]),
  417.                     imagecolorat($imgPng, 32*$hdRatio+8*$hdRatio+$i, 8*$hdRatio+$j));
  418.             }
  419.         }
  420.         for($j=0;$j<8*$hdRatio;$j++)
  421.         {
  422.             for($k=-2*$hdRatio;$k<6*$hdRatio;$k++)
  423.             {
  424.                 $polygones['casque']['droite'][] = new Polygon(
  425.                     array(
  426.                         $volumePoints[0][$j][$k],
  427.                         $volumePoints[0][$j][$k+1],
  428.                         $volumePoints[0][$j+1][$k+1],
  429.                         $volumePoints[0][$j+1][$k]),
  430.                     imagecolorat($imgPng, 32*$hdRatio+$k+2*$hdRatio, 8*$hdRatio+$j));
  431.                 $polygones['casque']['gauche'][] = new Polygon(
  432.                     array(
  433.                         $volumePoints[8*$hdRatio][$j][$k],
  434.                         $volumePoints[8*$hdRatio][$j][$k+1],
  435.                         $volumePoints[8*$hdRatio][$j+1][$k+1],
  436.                         $volumePoints[8*$hdRatio][$j+1][$k]),
  437.                     imagecolorat($imgPng, 32*$hdRatio+(24*$hdRatio-1)-$k-2*$hdRatio, 8*$hdRatio+$j));
  438.             }
  439.         }
  440.         for($i=0;$i<8*$hdRatio;$i++)
  441.         {
  442.             for($k=-2*$hdRatio;$k<6*$hdRatio;$k++)
  443.             {
  444.                 $polygones['casque']['haut'][] = new Polygon(
  445.                     array(
  446.                         $volumePoints[$i][0][$k],
  447.                         $volumePoints[$i+1][0][$k],
  448.                         $volumePoints[$i+1][0][$k+1],
  449.                         $volumePoints[$i][0][$k+1]),
  450.                     imagecolorat($imgPng, 32*$hdRatio+8*$hdRatio+$i, $k+2*$hdRatio));
  451.                 $polygones['casque']['bas'][] = new Polygon(
  452.                     array(
  453.                         $volumePoints[$i][8*$hdRatio][$k],
  454.                         $volumePoints[$i+1][8*$hdRatio][$k],
  455.                         $volumePoints[$i+1][8*$hdRatio][$k+1],
  456.                         $volumePoints[$i][8*$hdRatio][$k+1]),
  457.                     imagecolorat($imgPng, 32*$hdRatio+16*$hdRatio+$i, (8*$hdRatio-1)-($k+2*$hdRatio)));
  458.             }
  459.         }
  460.     }
  461.  
  462.     if(!$headOnly)
  463.     {
  464.         //Torse
  465.         $volumePoints = array();
  466.         for($i=0;$i<9*$hdRatio;$i++)
  467.         {
  468.             for($j=0;$j<13*$hdRatio;$j++)
  469.             {
  470.                 if(!isset($volumePoints[$i][$j][0]))
  471.                 {
  472.                     $volumePoints[$i][$j][0] = new Point(array('x' => $i,'y' => $j+8*$hdRatio,'z' => 0));
  473.                 }
  474.                 if(!isset($volumePoints[$i][$j][4*$hdRatio]))
  475.                 {
  476.                     $volumePoints[$i][$j][4*$hdRatio] = new Point(array('x' => $i,'y' => $j+8*$hdRatio,'z' => 4*$hdRatio));
  477.                 }
  478.             }
  479.         }
  480.         for($j=0;$j<13*$hdRatio;$j++)
  481.         {
  482.             for($k=0;$k<5*$hdRatio;$k++)
  483.             {
  484.                 if(!isset($volumePoints[0][$j][$k]))
  485.                 {
  486.                     $volumePoints[0][$j][$k] = new Point(array('x' => 0,'y' => $j+8*$hdRatio,'z' => $k));
  487.                 }if(!isset($volumePoints[8*$hdRatio][$j][$k]))
  488.                 {
  489.                     $volumePoints[8*$hdRatio][$j][$k] = new Point(array('x' => 8*$hdRatio,'y' => $j+8*$hdRatio,'z' => $k));
  490.                 }
  491.             }
  492.         }
  493.         for($i=0;$i<9*$hdRatio;$i++)
  494.         {
  495.             for($k=0;$k<5*$hdRatio;$k++)
  496.             {
  497.                 if(!isset($volumePoints[$i][0][$k]))
  498.                 {
  499.                     $volumePoints[$i][0][$k] = new Point(array('x' => $i,'y' => 0+8*$hdRatio,'z' => $k));
  500.                 }
  501.                 if(!isset($volumePoints[$i][12*$hdRatio][$k]))
  502.                 {
  503.                     $volumePoints[$i][12*$hdRatio][$k] = new Point(array('x' => $i,'y' => 12*$hdRatio+8*$hdRatio,'z' => $k));
  504.                 }
  505.             }
  506.         }
  507.  
  508.         for($i=0;$i<8*$hdRatio;$i++)
  509.         {
  510.             for($j=0;$j<12*$hdRatio;$j++)
  511.             {
  512.                 $polygones['torse']['arriere'][] = new Polygon(
  513.                     array(
  514.                         $volumePoints[$i][$j][0],
  515.                         $volumePoints[$i+1][$j][0],
  516.                         $volumePoints[$i+1][$j+1][0],
  517.                         $volumePoints[$i][$j+1][0]),
  518.                     imagecolorat($imgPng, (40*$hdRatio-1)-$i, 20*$hdRatio+$j));
  519.                 $polygones['torse']['avant'][] = new Polygon(
  520.                     array(
  521.                         $volumePoints[$i][$j][4*$hdRatio],
  522.                         $volumePoints[$i+1][$j][4*$hdRatio],
  523.                         $volumePoints[$i+1][$j+1][4*$hdRatio],
  524.                         $volumePoints[$i][$j+1][4*$hdRatio]),
  525.                     imagecolorat($imgPng, 20*$hdRatio+$i, 20*$hdRatio+$j));
  526.             }
  527.         }
  528.         for($j=0;$j<12*$hdRatio;$j++)
  529.         {
  530.             for($k=0;$k<4*$hdRatio;$k++)
  531.             {
  532.                 $polygones['torse']['droite'][] = new Polygon(
  533.                     array(
  534.                         $volumePoints[0][$j][$k],
  535.                         $volumePoints[0][$j][$k+1],
  536.                         $volumePoints[0][$j+1][$k+1],
  537.                         $volumePoints[0][$j+1][$k]),
  538.                     imagecolorat($imgPng, 16*$hdRatio+$k, 20*$hdRatio+$j));
  539.                 $polygones['torse']['gauche'][] = new Polygon(
  540.                     array(
  541.                         $volumePoints[8*$hdRatio][$j][$k],
  542.                         $volumePoints[8*$hdRatio][$j][$k+1],
  543.                         $volumePoints[8*$hdRatio][$j+1][$k+1],
  544.                         $volumePoints[8*$hdRatio][$j+1][$k]),
  545.                     imagecolorat($imgPng, (32*$hdRatio-1)-$k, 20*$hdRatio+$j));
  546.             }
  547.         }
  548.         for($i=0;$i<8*$hdRatio;$i++)
  549.         {
  550.             for($k=0;$k<4*$hdRatio;$k++)
  551.             {
  552.                 $polygones['torse']['haut'][] = new Polygon(
  553.                     array(
  554.                         $volumePoints[$i][0][$k],
  555.                         $volumePoints[$i+1][0][$k],
  556.                         $volumePoints[$i+1][0][$k+1],
  557.                         $volumePoints[$i][0][$k+1]),
  558.                     imagecolorat($imgPng, 20*$hdRatio+$i, 16*$hdRatio+$k));
  559.                 $polygones['torse']['bas'][] = new Polygon(
  560.                     array(
  561.                         $volumePoints[$i][12*$hdRatio][$k],
  562.                         $volumePoints[$i+1][12*$hdRatio][$k],
  563.                         $volumePoints[$i+1][12*$hdRatio][$k+1],
  564.                         $volumePoints[$i][12*$hdRatio][$k+1]),
  565.                     imagecolorat($imgPng, 28*$hdRatio+$i, (20*$hdRatio-1)-$k));
  566.             }
  567.         }
  568.  
  569.         //BrasG
  570.         $volumePoints = array();
  571.         for($i=0;$i<9*$hdRatio;$i++)
  572.         {
  573.             for($j=0;$j<13*$hdRatio;$j++)
  574.             {
  575.                 if(!isset($volumePoints[$i][$j][0]))
  576.                 {
  577.                     $volumePoints[$i][$j][0] = new Point(array('x' => $i-4*$hdRatio,'y' => $j+8*$hdRatio,'z' => 0));
  578.                 }
  579.                 if(!isset($volumePoints[$i][$j][4*$hdRatio]))
  580.                 {
  581.                     $volumePoints[$i][$j][4*$hdRatio] = new Point(array('x' => $i-4*$hdRatio,'y' => $j+8*$hdRatio,'z' => 4*$hdRatio));
  582.                 }
  583.             }
  584.         }
  585.         for($j=0;$j<13*$hdRatio;$j++)
  586.         {
  587.             for($k=0;$k<5*$hdRatio;$k++)
  588.             {
  589.                 if(!isset($volumePoints[0][$j][$k]))
  590.                 {
  591.                     $volumePoints[0][$j][$k] = new Point(array('x' => 0-4*$hdRatio,'y' => $j+8*$hdRatio,'z' => $k));
  592.                 }if(!isset($volumePoints[8*$hdRatio][$j][$k]))
  593.                 {
  594.                     $volumePoints[4*$hdRatio][$j][$k] = new Point(array('x' => 4*$hdRatio-4*$hdRatio,'y' => $j+8*$hdRatio,'z' => $k));
  595.                 }
  596.             }
  597.         }
  598.         for($i=0;$i<9*$hdRatio;$i++)
  599.         {
  600.             for($k=0;$k<5*$hdRatio;$k++)
  601.             {
  602.                 if(!isset($volumePoints[$i][0][$k]))
  603.                 {
  604.                     $volumePoints[$i][0][$k] = new Point(array('x' => $i-4*$hdRatio,'y' => 0+8*$hdRatio,'z' => $k));
  605.                 }
  606.                 if(!isset($volumePoints[$i][12*$hdRatio][$k]))
  607.                 {
  608.                     $volumePoints[$i][12*$hdRatio][$k] = new Point(array('x' => $i-4*$hdRatio,'y' => 12*$hdRatio+8*$hdRatio,'z' => $k));
  609.                 }
  610.             }
  611.         }
  612.  
  613.         for($i=0;$i<4*$hdRatio;$i++)
  614.         {
  615.             for($j=0;$j<12*$hdRatio;$j++)
  616.             {
  617.                 $polygones['brasD']['arriere'][] = new Polygon(
  618.                     array(
  619.                         $volumePoints[$i][$j][0],
  620.                         $volumePoints[$i+1][$j][0],
  621.                         $volumePoints[$i+1][$j+1][0],
  622.                         $volumePoints[$i][$j+1][0]),
  623.                     imagecolorat($imgPng, (56*$hdRatio-1)-$i, 20*$hdRatio+$j));
  624.                 $polygones['brasD']['avant'][] = new Polygon(
  625.                     array(
  626.                         $volumePoints[$i][$j][4*$hdRatio],
  627.                         $volumePoints[$i+1][$j][4*$hdRatio],
  628.                         $volumePoints[$i+1][$j+1][4*$hdRatio],
  629.                         $volumePoints[$i][$j+1][4*$hdRatio]),
  630.                     imagecolorat($imgPng, 44*$hdRatio+$i, 20*$hdRatio+$j));
  631.             }
  632.         }
  633.         for($j=0;$j<12*$hdRatio;$j++)
  634.         {
  635.             for($k=0;$k<4*$hdRatio;$k++)
  636.             {
  637.                 $polygones['brasD']['droite'][] = new Polygon(
  638.                     array(
  639.                         $volumePoints[0][$j][$k],
  640.                         $volumePoints[0][$j][$k+1],
  641.                         $volumePoints[0][$j+1][$k+1],
  642.                         $volumePoints[0][$j+1][$k]),
  643.                     imagecolorat($imgPng, 40*$hdRatio+$k, 20*$hdRatio+$j));
  644.                 $polygones['brasD']['gauche'][] = new Polygon(
  645.                     array(
  646.                         $volumePoints[4*$hdRatio][$j][$k],
  647.                         $volumePoints[4*$hdRatio][$j][$k+1],
  648.                         $volumePoints[4*$hdRatio][$j+1][$k+1],
  649.                         $volumePoints[4*$hdRatio][$j+1][$k]),
  650.                     imagecolorat($imgPng, (52*$hdRatio-1)-$k, 20*$hdRatio+$j));
  651.             }
  652.         }
  653.         for($i=0;$i<4*$hdRatio;$i++)
  654.         {
  655.             for($k=0;$k<4*$hdRatio;$k++)
  656.             {
  657.                 $polygones['brasD']['haut'][] = new Polygon(
  658.                     array(
  659.                         $volumePoints[$i][0][$k],
  660.                         $volumePoints[$i+1][0][$k],
  661.                         $volumePoints[$i+1][0][$k+1],
  662.                         $volumePoints[$i][0][$k+1]),
  663.                     imagecolorat($imgPng, 44*$hdRatio+$i, 16*$hdRatio+$k));
  664.                 $polygones['brasD']['bas'][] = new Polygon(
  665.                     array(
  666.                         $volumePoints[$i][12*$hdRatio][$k],
  667.                         $volumePoints[$i+1][12*$hdRatio][$k],
  668.                         $volumePoints[$i+1][12*$hdRatio][$k+1],
  669.                         $volumePoints[$i][12*$hdRatio][$k+1]),
  670.                     imagecolorat($imgPng, 48*$hdRatio+$i, (20*$hdRatio-1)-$k));
  671.             }
  672.         }
  673.  
  674.         //BrasD
  675.         $volumePoints = array();
  676.         for($i=0;$i<9*$hdRatio;$i++)
  677.         {
  678.             for($j=0;$j<13*$hdRatio;$j++)
  679.             {
  680.                 if(!isset($volumePoints[$i][$j][0]))
  681.                 {
  682.                     $volumePoints[$i][$j][0] = new Point(array('x' => $i+8*$hdRatio,'y' => $j+8*$hdRatio,'z' => 0));
  683.                 }
  684.                 if(!isset($volumePoints[$i][$j][4*$hdRatio]))
  685.                 {
  686.                     $volumePoints[$i][$j][4*$hdRatio] = new Point(array('x' => $i+8*$hdRatio,'y' => $j+8*$hdRatio,'z' => 4*$hdRatio));
  687.                 }
  688.             }
  689.         }
  690.         for($j=0;$j<13*$hdRatio;$j++)
  691.         {
  692.             for($k=0;$k<5*$hdRatio;$k++)
  693.             {
  694.                 if(!isset($volumePoints[0][$j][$k]))
  695.                 {
  696.                     $volumePoints[0][$j][$k] = new Point(array('x' => 0+8*$hdRatio,'y' => $j+8*$hdRatio,'z' => $k));
  697.                 }if(!isset($volumePoints[8*$hdRatio][$j][$k]))
  698.                 {
  699.                     $volumePoints[4*$hdRatio][$j][$k] = new Point(array('x' => 4*$hdRatio+8*$hdRatio,'y' => $j+8*$hdRatio,'z' => $k));
  700.                 }
  701.             }
  702.         }
  703.         for($i=0;$i<9*$hdRatio;$i++)
  704.         {
  705.             for($k=0;$k<5*$hdRatio;$k++)
  706.             {
  707.                 if(!isset($volumePoints[$i][0][$k]))
  708.                 {
  709.                     $volumePoints[$i][0][$k] = new Point(array('x' => $i+8*$hdRatio,'y' => 0+8*$hdRatio,'z' => $k));
  710.                 }
  711.                 if(!isset($volumePoints[$i][12*$hdRatio][$k]))
  712.                 {
  713.                     $volumePoints[$i][12*$hdRatio][$k] = new Point(array('x' => $i+8*$hdRatio,'y' => 12*$hdRatio+8*$hdRatio,'z' => $k));
  714.                 }
  715.             }
  716.         }
  717.  
  718.         for($i=0;$i<4*$hdRatio;$i++)
  719.         {
  720.             for($j=0;$j<12*$hdRatio;$j++)
  721.             {
  722.                 $polygones['brasG']['arriere'][] = new Polygon(
  723.                     array(
  724.                         $volumePoints[$i][$j][0],
  725.                         $volumePoints[$i+1][$j][0],
  726.                         $volumePoints[$i+1][$j+1][0],
  727.                         $volumePoints[$i][$j+1][0]),
  728.                     imagecolorat($imgPng, (56*$hdRatio-1)-((4*$hdRatio-1)-$i), 20*$hdRatio+$j));
  729.                 $polygones['brasG']['avant'][] = new Polygon(
  730.                     array(
  731.                         $volumePoints[$i][$j][4*$hdRatio],
  732.                         $volumePoints[$i+1][$j][4*$hdRatio],
  733.                         $volumePoints[$i+1][$j+1][4*$hdRatio],
  734.                         $volumePoints[$i][$j+1][4*$hdRatio]),
  735.                     imagecolorat($imgPng, 44*$hdRatio+((4*$hdRatio-1)-$i), 20*$hdRatio+$j));
  736.             }
  737.         }
  738.         for($j=0;$j<12*$hdRatio;$j++)
  739.         {
  740.             for($k=0;$k<4*$hdRatio;$k++)
  741.             {
  742.                 $polygones['brasG']['droite'][] = new Polygon(
  743.                     array(
  744.                         $volumePoints[0][$j][$k],
  745.                         $volumePoints[0][$j][$k+1],
  746.                         $volumePoints[0][$j+1][$k+1],
  747.                         $volumePoints[0][$j+1][$k]),
  748.                     imagecolorat($imgPng, 40*$hdRatio+((4*$hdRatio-1)-$k), 20*$hdRatio+$j));
  749.                 $polygones['brasG']['gauche'][] = new Polygon(
  750.                     array(
  751.                         $volumePoints[4*$hdRatio][$j][$k],
  752.                         $volumePoints[4*$hdRatio][$j][$k+1],
  753.                         $volumePoints[4*$hdRatio][$j+1][$k+1],
  754.                         $volumePoints[4*$hdRatio][$j+1][$k]),
  755.                     imagecolorat($imgPng, (52*$hdRatio-1)-((4*$hdRatio-1)-$k), 20*$hdRatio+$j));
  756.             }
  757.         }
  758.         for($i=0;$i<4*$hdRatio;$i++)
  759.         {
  760.             for($k=0;$k<4*$hdRatio;$k++)
  761.             {
  762.                 $polygones['brasG']['haut'][] = new Polygon(
  763.                     array(
  764.                         $volumePoints[$i][0][$k],
  765.                         $volumePoints[$i+1][0][$k],
  766.                         $volumePoints[$i+1][0][$k+1],
  767.                         $volumePoints[$i][0][$k+1]),
  768.                     imagecolorat($imgPng, 44*$hdRatio+((4*$hdRatio-1)-$i), 16*$hdRatio+$k));
  769.                 $polygones['brasG']['bas'][] = new Polygon(
  770.                     array(
  771.                         $volumePoints[$i][12*$hdRatio][$k],
  772.                         $volumePoints[$i+1][12*$hdRatio][$k],
  773.                         $volumePoints[$i+1][12*$hdRatio][$k+1],
  774.                         $volumePoints[$i][12*$hdRatio][$k+1]),
  775.                     imagecolorat($imgPng, 48*$hdRatio+((4*$hdRatio-1)-$i), (20*$hdRatio-1)-$k));
  776.             }
  777.         }
  778.  
  779.         //JambeG
  780.         $volumePoints = array();
  781.         for($i=0;$i<9*$hdRatio;$i++)
  782.         {
  783.             for($j=0;$j<13*$hdRatio;$j++)
  784.             {
  785.                 if(!isset($volumePoints[$i][$j][0]))
  786.                 {
  787.                     $volumePoints[$i][$j][0] = new Point(array('x' => $i,'y' => $j+20*$hdRatio,'z' => 0));
  788.                 }
  789.                 if(!isset($volumePoints[$i][$j][4*$hdRatio]))
  790.                 {
  791.                     $volumePoints[$i][$j][4*$hdRatio] = new Point(array('x' => $i,'y' => $j+20*$hdRatio,'z' => 4*$hdRatio));
  792.                 }
  793.             }
  794.         }
  795.         for($j=0;$j<13*$hdRatio;$j++)
  796.         {
  797.             for($k=0;$k<5*$hdRatio;$k++)
  798.             {
  799.                 if(!isset($volumePoints[0][$j][$k]))
  800.                 {
  801.                     $volumePoints[0][$j][$k] = new Point(array('x' => 0,'y' => $j+20*$hdRatio,'z' => $k));
  802.                 }if(!isset($volumePoints[8*$hdRatio][$j][$k]))
  803.                 {
  804.                     $volumePoints[4*$hdRatio][$j][$k] = new Point(array('x' => 4*$hdRatio,'y' => $j+20*$hdRatio,'z' => $k));
  805.                 }
  806.             }
  807.         }
  808.         for($i=0;$i<9*$hdRatio;$i++)
  809.         {
  810.             for($k=0;$k<5*$hdRatio;$k++)
  811.             {
  812.                 if(!isset($volumePoints[$i][0][$k]))
  813.                 {
  814.                     $volumePoints[$i][0][$k] = new Point(array('x' => $i,'y' => 0+20*$hdRatio,'z' => $k));
  815.                 }
  816.                 if(!isset($volumePoints[$i][12*$hdRatio][$k]))
  817.                 {
  818.                     $volumePoints[$i][12*$hdRatio][$k] = new Point(array('x' => $i,'y' => 12*$hdRatio+20*$hdRatio,'z' => $k));
  819.                 }
  820.             }
  821.         }
  822.  
  823.         for($i=0;$i<4*$hdRatio;$i++)
  824.         {
  825.             for($j=0;$j<12*$hdRatio;$j++)
  826.             {
  827.                 $polygones['jambeD']['arriere'][] = new Polygon(
  828.                     array(
  829.                         $volumePoints[$i][$j][0],
  830.                         $volumePoints[$i+1][$j][0],
  831.                         $volumePoints[$i+1][$j+1][0],
  832.                         $volumePoints[$i][$j+1][0]),
  833.                     imagecolorat($imgPng, (16*$hdRatio-1)-$i, 20*$hdRatio+$j));
  834.                 $polygones['jambeD']['avant'][] = new Polygon(
  835.                     array(
  836.                         $volumePoints[$i][$j][4*$hdRatio],
  837.                         $volumePoints[$i+1][$j][4*$hdRatio],
  838.                         $volumePoints[$i+1][$j+1][4*$hdRatio],
  839.                         $volumePoints[$i][$j+1][4*$hdRatio]),
  840.                     imagecolorat($imgPng, 4*$hdRatio+$i, 20*$hdRatio+$j));
  841.             }
  842.         }
  843.         for($j=0;$j<12*$hdRatio;$j++)
  844.         {
  845.             for($k=0;$k<4*$hdRatio;$k++)
  846.             {
  847.                 $polygones['jambeD']['droite'][] = new Polygon(
  848.                     array(
  849.                         $volumePoints[0][$j][$k],
  850.                         $volumePoints[0][$j][$k+1],
  851.                         $volumePoints[0][$j+1][$k+1],
  852.                         $volumePoints[0][$j+1][$k]),
  853.                     imagecolorat($imgPng, 0+$k, 20*$hdRatio+$j));
  854.                 $polygones['jambeD']['gauche'][] = new Polygon(
  855.                     array(
  856.                         $volumePoints[4*$hdRatio][$j][$k],
  857.                         $volumePoints[4*$hdRatio][$j][$k+1],
  858.                         $volumePoints[4*$hdRatio][$j+1][$k+1],
  859.                         $volumePoints[4*$hdRatio][$j+1][$k]),
  860.                     imagecolorat($imgPng, (12*$hdRatio-1)-$k, 20*$hdRatio+$j));
  861.             }
  862.         }
  863.         for($i=0;$i<4*$hdRatio;$i++)
  864.         {
  865.             for($k=0;$k<4*$hdRatio;$k++)
  866.             {
  867.                 $polygones['jambeD']['haut'][] = new Polygon(
  868.                     array(
  869.                         $volumePoints[$i][0][$k],
  870.                         $volumePoints[$i+1][0][$k],
  871.                         $volumePoints[$i+1][0][$k+1],
  872.                         $volumePoints[$i][0][$k+1]),
  873.                     imagecolorat($imgPng, 4*$hdRatio+$i, 16*$hdRatio+$k));
  874.                 $polygones['jambeD']['bas'][] = new Polygon(
  875.                     array(
  876.                         $volumePoints[$i][12*$hdRatio][$k],
  877.                         $volumePoints[$i+1][12*$hdRatio][$k],
  878.                         $volumePoints[$i+1][12*$hdRatio][$k+1],
  879.                         $volumePoints[$i][12*$hdRatio][$k+1]),
  880.                     imagecolorat($imgPng, 8*$hdRatio+$i, (20*$hdRatio-1)-$k));
  881.             }
  882.         }
  883.  
  884.         //JambeD
  885.         $volumePoints = array();
  886.         for($i=0;$i<9*$hdRatio;$i++)
  887.         {
  888.             for($j=0;$j<13*$hdRatio;$j++)
  889.             {
  890.                 if(!isset($volumePoints[$i][$j][0]))
  891.                 {
  892.                     $volumePoints[$i][$j][0] = new Point(array('x' => $i+4*$hdRatio,'y' => $j+20*$hdRatio,'z' => 0));
  893.                 }
  894.                 if(!isset($volumePoints[$i][$j][4*$hdRatio]))
  895.                 {
  896.                     $volumePoints[$i][$j][4*$hdRatio] = new Point(array('x' => $i+4*$hdRatio,'y' => $j+20*$hdRatio,'z' => 4*$hdRatio));
  897.                 }
  898.             }
  899.         }
  900.         for($j=0;$j<13*$hdRatio;$j++)
  901.         {
  902.             for($k=0;$k<5*$hdRatio;$k++)
  903.             {
  904.                 if(!isset($volumePoints[0][$j][$k]))
  905.                 {
  906.                     $volumePoints[0][$j][$k] = new Point(array('x' => 0+4*$hdRatio,'y' => $j+20*$hdRatio,'z' => $k));
  907.                 }if(!isset($volumePoints[8*$hdRatio][$j][$k]))
  908.                 {
  909.                     $volumePoints[4*$hdRatio][$j][$k] = new Point(array('x' => 4*$hdRatio+4*$hdRatio,'y' => $j+20*$hdRatio,'z' => $k));
  910.                 }
  911.             }
  912.         }
  913.         for($i=0;$i<9*$hdRatio;$i++)
  914.         {
  915.             for($k=0;$k<5*$hdRatio;$k++)
  916.             {
  917.                 if(!isset($volumePoints[$i][0][$k]))
  918.                 {
  919.                     $volumePoints[$i][0][$k] = new Point(array('x' => $i+4*$hdRatio,'y' => 0+20*$hdRatio,'z' => $k));
  920.                 }
  921.                 if(!isset($volumePoints[$i][12*$hdRatio][$k]))
  922.                 {
  923.                     $volumePoints[$i][12*$hdRatio][$k] = new Point(array('x' => $i+4*$hdRatio,'y' => 12*$hdRatio+20*$hdRatio,'z' => $k));
  924.                 }
  925.             }
  926.         }
  927.  
  928.         for($i=0;$i<4*$hdRatio;$i++)
  929.         {
  930.             for($j=0;$j<12*$hdRatio;$j++)
  931.             {
  932.                 $polygones['jambeG']['arriere'][] = new Polygon(
  933.                     array(
  934.                         $volumePoints[$i][$j][0],
  935.                         $volumePoints[$i+1][$j][0],
  936.                         $volumePoints[$i+1][$j+1][0],
  937.                         $volumePoints[$i][$j+1][0]),
  938.                     imagecolorat($imgPng, (16*$hdRatio-1)-((4*$hdRatio-1)-$i), 20*$hdRatio+$j));
  939.                 $polygones['jambeG']['avant'][] = new Polygon(
  940.                     array(
  941.                         $volumePoints[$i][$j][4*$hdRatio],
  942.                         $volumePoints[$i+1][$j][4*$hdRatio],
  943.                         $volumePoints[$i+1][$j+1][4*$hdRatio],
  944.                         $volumePoints[$i][$j+1][4*$hdRatio]),
  945.                     imagecolorat($imgPng, 4*$hdRatio+((4*$hdRatio-1)-$i), 20*$hdRatio+$j));
  946.             }
  947.         }
  948.         for($j=0;$j<12*$hdRatio;$j++)
  949.         {
  950.             for($k=0;$k<4*$hdRatio;$k++)
  951.             {
  952.                 $polygones['jambeG']['droite'][] = new Polygon(
  953.                     array(
  954.                         $volumePoints[0][$j][$k],
  955.                         $volumePoints[0][$j][$k+1],
  956.                         $volumePoints[0][$j+1][$k+1],
  957.                         $volumePoints[0][$j+1][$k]),
  958.                     imagecolorat($imgPng, 0+((4*$hdRatio-1)-$k), 20*$hdRatio+$j));
  959.                 $polygones['jambeG']['gauche'][] = new Polygon(
  960.                     array(
  961.                         $volumePoints[4*$hdRatio][$j][$k],
  962.                         $volumePoints[4*$hdRatio][$j][$k+1],
  963.                         $volumePoints[4*$hdRatio][$j+1][$k+1],
  964.                         $volumePoints[4*$hdRatio][$j+1][$k]),
  965.                     imagecolorat($imgPng, (12*$hdRatio-1)-((4*$hdRatio-1)-$k), 20*$hdRatio+$j));
  966.             }
  967.         }
  968.         for($i=0;$i<4*$hdRatio;$i++)
  969.         {
  970.             for($k=0;$k<4*$hdRatio;$k++)
  971.             {
  972.                 $polygones['jambeG']['haut'][] = new Polygon(
  973.                     array(
  974.                         $volumePoints[$i][0][$k],
  975.                         $volumePoints[$i+1][0][$k],
  976.                         $volumePoints[$i+1][0][$k+1],
  977.                         $volumePoints[$i][0][$k+1]),
  978.                     imagecolorat($imgPng, 4*$hdRatio+((4*$hdRatio-1)-$i), 16*$hdRatio+$k));
  979.                 $polygones['jambeG']['bas'][] = new Polygon(
  980.                     array(
  981.                         $volumePoints[$i][12*$hdRatio][$k],
  982.                         $volumePoints[$i+1][12*$hdRatio][$k],
  983.                         $volumePoints[$i+1][12*$hdRatio][$k+1],
  984.                         $volumePoints[$i][12*$hdRatio][$k+1]),
  985.                     imagecolorat($imgPng, 8*$hdRatio+((4*$hdRatio-1)-$i), (20*$hdRatio-1)-$k));
  986.             }
  987.         }
  988.  
  989.     }
  990.     //pré projection (rotations des membres si besoin)
  991.  
  992.  
  993.     $times[] = array('Generation-polygones', microtime_float());
  994.  
  995.  
  996.     foreach($polygones['tete'] as $face)
  997.     {
  998.         foreach($face as $poly)
  999.         {
  1000.             $poly->preProject(4, 8, 2, $anglesMembres['tete']['ca'], $anglesMembres['tete']['sa'], $anglesMembres['tete']['cw'], $anglesMembres['tete']['sw']);
  1001.         }
  1002.     }
  1003.     if($displayHairs)
  1004.     {
  1005.         foreach($polygones['casque'] as $face)
  1006.         {
  1007.             foreach($face as $poly)
  1008.             {
  1009.                 $poly->preProject(4, 8, 2, $anglesMembres['tete']['ca'], $anglesMembres['tete']['sa'], $anglesMembres['tete']['cw'], $anglesMembres['tete']['sw']);
  1010.             }
  1011.         }
  1012.     }
  1013.     if(!$headOnly)
  1014.     {
  1015.         foreach($polygones['brasD'] as $face)
  1016.         {
  1017.             foreach($face as $poly)
  1018.             {
  1019.                 $poly->preProject(-2, 8, 2, $anglesMembres['brasD']['ca'], $anglesMembres['brasD']['sa'], $anglesMembres['brasD']['cw'], $anglesMembres['brasD']['sw']);
  1020.             }
  1021.         }
  1022.         foreach($polygones['brasG'] as $face)
  1023.         {
  1024.             foreach($face as $poly)
  1025.             {
  1026.                 $poly->preProject(10, 8, 2, $anglesMembres['brasG']['ca'], $anglesMembres['brasG']['sa'], $anglesMembres['brasG']['cw'], $anglesMembres['brasG']['sw']);
  1027.             }
  1028.         }
  1029.  
  1030.         foreach($polygones['jambeD'] as $face)
  1031.         {
  1032.             foreach($face as $poly)
  1033.             {
  1034.                 $poly->preProject(2, 20, ($anglesMembres['jambeD']['sa']<0?0:4), $anglesMembres['jambeD']['ca'], $anglesMembres['jambeD']['sa'], $anglesMembres['jambeD']['cw'], $anglesMembres['jambeD']['sw']);
  1035.             }
  1036.         }
  1037.         foreach($polygones['jambeG'] as $face)
  1038.         {
  1039.             foreach($face as $poly)
  1040.             {
  1041.                 $poly->preProject(6, 20, ($anglesMembres['jambeG']['sa']<0?0:4), $anglesMembres['jambeG']['ca'], $anglesMembres['jambeG']['sa'], $anglesMembres['jambeG']['cw'], $anglesMembres['jambeG']['sw']);
  1042.             }
  1043.         }
  1044.     }
  1045.     $times[] = array('Rotation-membres', microtime_float());
  1046.  
  1047.     //On les projette tous pour avoir la taille de la fenêtre
  1048.     foreach($polygones as $morceau)
  1049.     {
  1050.         foreach($morceau as $face)
  1051.         {
  1052.             foreach($face as $poly)
  1053.             {
  1054.                 if(!$poly->isProjected()) {
  1055.                     $poly->project();
  1056.                 }
  1057.             }
  1058.         }
  1059.     }
  1060.  
  1061.     $times[] = array('Projection-plan', microtime_float());
  1062.  
  1063.     $width = $maxX - $minX;
  1064.     $height = $maxY - $minY;
  1065.     //var_dump($minX,$maxX, $width, $minY,$maxY, $height);
  1066.  
  1067.     $ratio = intval($_GET['ratio']);
  1068.     if($ratio < 2)
  1069.         $ratio = 2;
  1070.  
  1071.  
  1072.     //cache
  1073.     //$seconds_to_cache = 60*60*24*7;//see at the begining of the file
  1074.     if($seconds_to_cache > 0) {
  1075.         $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . ' GMT';
  1076.         header('Expires: ' . $ts);
  1077.         header('Pragma: cache');
  1078.         header('Cache-Control: max-age=' . $seconds_to_cache);
  1079.     }
  1080.  
  1081.     if($_GET['format']=='svg')
  1082.     {
  1083.  
  1084.         header('Content-Type: image/svg+xml');
  1085.  
  1086.         echo '<?xml version="1.0" standalone="no"?>
  1087.         <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  1088.         "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  1089.          
  1090.         <svg width="100%" height="100%" version="1.1"
  1091.         xmlns="http://www.w3.org/2000/svg" viewBox="'.$minX.' '.$minY.' '.$width.' '.$height.'">';
  1092.     } else {
  1093.         header('Content-type: image/png');
  1094.         $image = imagecreatetruecolor($ratio * $width +1, $ratio * $height +1);
  1095.  
  1096.         imagesavealpha($image, true);
  1097.  
  1098.         $trans_colour = imagecolorallocatealpha($image, 0, 0, 0, 127);
  1099.         imagefill($image, 0, 0, $trans_colour);
  1100.     }
  1101.  
  1102.  
  1103.     $ordreAffichage = array();
  1104.  
  1105.     if(in_array('haut', $facesAvant))
  1106.     {
  1107.         if(in_array('droite', $facesAvant))
  1108.         {
  1109.             $ordreAffichage[] = array('jambeG' => $facesArriere);
  1110.             $ordreAffichage[] = array('jambeG' => $facesVisibles['jambeG']['avant']);
  1111.             $ordreAffichage[] = array('jambeD' => $facesArriere);
  1112.             $ordreAffichage[] = array('jambeD' => $facesVisibles['jambeD']['avant']);
  1113.  
  1114.  
  1115.             $ordreAffichage[] = array('brasG' => $facesArriere);
  1116.             $ordreAffichage[] = array('brasG' => $facesVisibles['brasG']['avant']);
  1117.             $ordreAffichage[] = array('torse' => $facesArriere);
  1118.             $ordreAffichage[] = array('torse' => $facesVisibles['torse']['avant']);
  1119.             $ordreAffichage[] = array('brasD' => $facesArriere);
  1120.             $ordreAffichage[] = array('brasD' => $facesVisibles['brasD']['avant']);
  1121.         } else {
  1122.             $ordreAffichage[] = array('jambeD' => $facesArriere);
  1123.             $ordreAffichage[] = array('jambeD' => $facesVisibles['jambeD']['avant']);
  1124.             $ordreAffichage[] = array('jambeG' => $facesArriere);
  1125.             $ordreAffichage[] = array('jambeG' => $facesVisibles['jambeG']['avant']);
  1126.  
  1127.  
  1128.             $ordreAffichage[] = array('brasD' => $facesArriere);
  1129.             $ordreAffichage[] = array('brasD' => $facesVisibles['brasD']['avant']);
  1130.             $ordreAffichage[] = array('torse' => $facesArriere);
  1131.             $ordreAffichage[] = array('torse' => $facesVisibles['torse']['avant']);
  1132.             $ordreAffichage[] = array('brasG' => $facesArriere);
  1133.             $ordreAffichage[] = array('brasG' => $facesVisibles['brasG']['avant']);
  1134.         }
  1135.  
  1136.         $ordreAffichage[] = array('casque' => $facesArriere);
  1137.         $ordreAffichage[] = array('tete' => $facesArriere);
  1138.         $ordreAffichage[] = array('tete' => $facesVisibles['tete']['avant']);
  1139.         $ordreAffichage[] = array('casque' => $facesVisibles['tete']['avant']);
  1140.  
  1141.     } else {
  1142.         $ordreAffichage[] = array('casque' => $facesArriere);
  1143.         $ordreAffichage[] = array('tete' => $facesArriere);
  1144.         $ordreAffichage[] = array('tete' => $facesVisibles['tete']['avant']);
  1145.         $ordreAffichage[] = array('casque' => $facesVisibles['tete']['avant']);
  1146.  
  1147.         if(in_array('droite', $facesAvant))
  1148.         {
  1149.             $ordreAffichage[] = array('brasG' => $facesArriere);
  1150.             $ordreAffichage[] = array('brasG' => $facesVisibles['brasG']['avant']);
  1151.             $ordreAffichage[] = array('torse' => $facesArriere);
  1152.             $ordreAffichage[] = array('torse' => $facesVisibles['torse']['avant']);
  1153.             $ordreAffichage[] = array('brasD' => $facesArriere);
  1154.             $ordreAffichage[] = array('brasD' => $facesVisibles['brasD']['avant']);
  1155.  
  1156.  
  1157.             $ordreAffichage[] = array('jambeG' => $facesArriere);
  1158.             $ordreAffichage[] = array('jambeG' => $facesVisibles['jambeG']['avant']);
  1159.             $ordreAffichage[] = array('jambeD' => $facesArriere);
  1160.             $ordreAffichage[] = array('jambeD' => $facesVisibles['jambeD']['avant']);
  1161.         } else {
  1162.             $ordreAffichage[] = array('brasD' => $facesArriere);
  1163.             $ordreAffichage[] = array('brasD' => $facesVisibles['brasD']['avant']);
  1164.             $ordreAffichage[] = array('torse' => $facesArriere);
  1165.             $ordreAffichage[] = array('torse' => $facesVisibles['torse']['avant']);
  1166.             $ordreAffichage[] = array('brasG' => $facesArriere);
  1167.             $ordreAffichage[] = array('brasG' => $facesVisibles['brasG']['avant']);
  1168.  
  1169.  
  1170.             $ordreAffichage[] = array('jambeD' => $facesArriere);
  1171.             $ordreAffichage[] = array('jambeD' => $facesVisibles['jambeD']['avant']);
  1172.             $ordreAffichage[] = array('jambeG' => $facesArriere);
  1173.             $ordreAffichage[] = array('jambeG' => $facesVisibles['jambeG']['avant']);
  1174.         }
  1175.  
  1176.     }
  1177.  
  1178.  
  1179.     $times[] = array('Calcul-affichage-faces', microtime_float());
  1180.  
  1181.     foreach($ordreAffichage as $morceaux)
  1182.     {
  1183.         foreach($morceaux as $morceau => $faces)
  1184.         {
  1185.             foreach($faces as $face)
  1186.             {
  1187.                 foreach ($polygones[$morceau][$face] as $poly) {
  1188.                     if($_GET['format']=='svg')
  1189.                         echo $poly->getSvgPolygon(1);
  1190.                     else
  1191.                         $poly->addPngPolygon($image, $minX, $minY, $ratio);
  1192.                 }
  1193.             }
  1194.         }
  1195.     }
  1196.  
  1197.     $times[] = array('Affichage-image', microtime_float());
  1198.  
  1199.     //echo '<circle cx="0" cy="0" r="1" fill="black"/>';
  1200.     if($_GET['format']=='svg')
  1201.     {
  1202.         echo '</svg>' . "\n";
  1203.  
  1204.         for($i=1;$i<count($times);$i++)
  1205.         {
  1206.             echo '<!-- ' . ($times[$i][1] - $times[$i-1][1])*1000 . 'ms : ' . $times[$i][0] . ' -->' . "\n";
  1207.         }
  1208.         echo '<!-- TOTAL : ' . ($times[count($times)-1][1] - $times[0][1])*1000 . 'ms -->' . "\n";
  1209.     }
  1210.     else
  1211.     {
  1212.         imagepng($image);
  1213.         imagedestroy($image);
  1214.         for($i=1;$i<count($times);$i++)
  1215.         {
  1216.             header('generation-time-'.$i .'-' .$times[$i][0].': ' . ($times[$i][1] - $times[$i-1][1])*1000 . 'ms');
  1217.         }
  1218.         header('generation-time-'.count($times) .'-TOTAL: ' . ($times[count($times)-1][1] - $times[0][1])*1000 . 'ms');
  1219.     }
  1220.  
  1221.  
  1222.     class Point
  1223.     {
  1224.         private $_originCoord;
  1225.         private $_destCoord = array();
  1226.         private $_isProjected = false;
  1227.         private $_isPreProjected = false;
  1228.  
  1229.         function __construct($originCoord)//constructeur parametrer
  1230.         {
  1231.             if(is_array($originCoord) && count($originCoord)==3) {
  1232.                 $this->_originCoord = array(
  1233.                     'x' => (isset($originCoord['x'])?$originCoord['x']:0),
  1234.                     'y' => (isset($originCoord['y'])?$originCoord['y']:0),
  1235.                     'z' => (isset($originCoord['z'])?$originCoord['z']:0));
  1236.             } else {
  1237.                 $this->_originCoord = array('x' => 0,'y' => 0,'z' => 0);
  1238.             }
  1239.         }
  1240.  
  1241.         function project() {
  1242.             global $ca, $sa, $cw, $sw;
  1243.             global $minX, $maxX, $minY, $maxY;
  1244.             //1,0,1,0
  1245.             $x = $this->_originCoord['x'];
  1246.             $y = $this->_originCoord['y'];
  1247.             $z = $this->_originCoord['z'];
  1248.  
  1249.             /*$this->_destCoord['x'] = $x*$cw - $y*$sw;
  1250.             $this->_destCoord['y'] = $x*$ca*$sw + $y*$cw*$ca - $z*$sa;
  1251.             $this->_destCoord['z'] = $x*$sw*$sa + $y*$cw+$sa + $z*$ca;*/
  1252.  
  1253.             $this->_destCoord['x'] = $x*$cw + $z*$sw;
  1254.             $this->_destCoord['y'] = $x*$sa*$sw + $y*$ca - $z*$sa*$cw;
  1255.             $this->_destCoord['z'] = -$x*$ca*$sw + $y*$sa + $z*$ca*$cw;
  1256.  
  1257.             $this->_isProjected = true;
  1258.  
  1259.             $minX = min($minX, $this->_destCoord['x']);
  1260.             $maxX = max($maxX, $this->_destCoord['x']);
  1261.             $minY = min($minY, $this->_destCoord['y']);
  1262.             $maxY = max($maxY, $this->_destCoord['y']);
  1263.         }
  1264.  
  1265.         function preProject($dx, $dy, $dz, $ca, $sa, $cw, $sw) {
  1266.             if(!$this->_isPreProjected)
  1267.             {
  1268.                 $x = $this->_originCoord['x'] - $dx;
  1269.                 $y = $this->_originCoord['y'] - $dy;
  1270.                 $z = $this->_originCoord['z'] - $dz;
  1271.  
  1272.                 $this->_originCoord['x'] = $x*$cw + $z*$sw + $dx;
  1273.                 $this->_originCoord['y'] = $x*$sa*$sw + $y*$ca - $z*$sa*$cw + $dy;
  1274.                 $this->_originCoord['z'] = -$x*$ca*$sw + $y*$sa + $z*$ca*$cw + $dz;
  1275.                 $this->_isPreProjected = true;
  1276.             }
  1277.         }
  1278.  
  1279.  
  1280.  
  1281.         function getOriginCoord()
  1282.         {
  1283.             return $this->_originCoord;
  1284.         }
  1285.         function getDestCoord()
  1286.         {
  1287.             return $this->_destCoord;
  1288.         }
  1289.  
  1290.         function getDepth()
  1291.         {
  1292.             if(!$this->_isProjected)
  1293.                 $this->project();
  1294.             return $this->_destCoord['z'];
  1295.         }
  1296.         function isProjected()
  1297.         {
  1298.             return $this->_isProjected;
  1299.         }
  1300.     }
  1301.  
  1302.     class Polygon
  1303.     {
  1304.         private $_dots;
  1305.         private $_color;
  1306.         private $_isProjected = false;
  1307.         private $_face = 'w';
  1308.         private $_faceDepth = 0;
  1309.         function __construct($dots,$color)
  1310.         {
  1311.             //print_r($dots);
  1312.             //we suppose that $dots is an array of Point
  1313.             //fuck you if not
  1314.             $this->_dots = $dots;
  1315.             $this->_color = $color;
  1316.             $c0 = $dots[0]->getOriginCoord();
  1317.             $c1 = $dots[1]->getOriginCoord();
  1318.             $c2 = $dots[2]->getOriginCoord();
  1319.             if($c0['x'] == $c1['x'] && $c1['x'] == $c2['x']) {
  1320.                 $this->_face = 'x';
  1321.                 $this->_faceDepth = $c0['x'];
  1322.             } else if($c0['y'] == $c1['y'] && $c1['y'] == $c2['y']) {
  1323.                 $this->_face = 'y';
  1324.                 $this->_faceDepth = $c0['y'];
  1325.             } else if($c0['z'] == $c1['z'] && $c1['z'] == $c2['z']) {
  1326.                 $this->_face = 'z';
  1327.                 $this->_faceDepth = $c0['z'];
  1328.             }
  1329.         }
  1330.         function getFace() {
  1331.             return $this->_face;
  1332.         }
  1333.         function getFaceDepth() {
  1334.             if(!$this->_isProjected) {
  1335.                 $this->project();
  1336.             }
  1337.             return $this->_faceDepth;
  1338.         }
  1339.         function getSvgPolygon($ratio) {
  1340.             $points2d = '';
  1341.  
  1342.             $r = ($this->_color >> 16) & 0xFF;
  1343.             $g = ($this->_color >> 8) & 0xFF;
  1344.             $b = $this->_color & 0xFF;
  1345.             $a     = (127-(($this->_color & 0x7F000000) >> 24))/127;
  1346.  
  1347.             if($a == 0)
  1348.                 return '';
  1349.  
  1350.             foreach ($this->_dots as $dot) {
  1351.                 $coord = $dot->getDestCoord();
  1352.                 $points2d .= $coord['x']*$ratio . ',' .$coord['y']*$ratio . ' ';
  1353.             }
  1354.  
  1355.  
  1356.  
  1357.             $comment = '';
  1358.             /*if ($this->_color == 0xFF0000 || $this->_color == 0x0000FF)
  1359.                 $comment = '<!-- ' . $this-> _face . ' ' . $this-> _faceDepth . ' ' . $this->_maxDepth . '-->';*/
  1360.  
  1361.             return $comment . '<polygon points="'.$points2d.'" style="fill:rgba('.$r.','.$g.','.$b.','.$a.')" />' . "\n";
  1362.             //return '<polygon points="'.$points2d.'" style="fill:rgba('.$r.','.$g.','.$b.','.$a.');stroke:rgba('.$r.','.$g.','.$b.','.$a.');stroke-width:0.03" />' . "\n";
  1363.         }
  1364.  
  1365.         function addPngPolygon(&$image, $minX, $minY, $ratio)
  1366.         {
  1367.             $points2d = array();
  1368.             $nbPoints = 0;
  1369.  
  1370.             $r = ($this->_color >> 16) & 0xFF;
  1371.             $g = ($this->_color >> 8) & 0xFF;
  1372.             $b = $this->_color & 0xFF;
  1373.             $a     = (127-(($this->_color & 0x7F000000) >> 24))/127;
  1374.             if($a == 0)
  1375.                 return;
  1376.  
  1377.             $samePlanX = true;//will become false if all dots are in the same plan.
  1378.             $samePlanY = true;
  1379.  
  1380.             foreach ($this->_dots as $dot) {
  1381.                 $coord = $dot->getDestCoord();
  1382.                 if(!isset($coordX))
  1383.                     $coordX = $coord['x'];
  1384.                 if(!isset($coordY))
  1385.                     $coordY = $coord['y'];
  1386.  
  1387.                 if($coordX != $coord['x'])
  1388.                     $samePlanX = false;
  1389.                 if($coordY != $coord['y'])
  1390.                     $samePlanY = false;
  1391.  
  1392.                 $points2d[] = ($coord['x']-$minX)*$ratio ;
  1393.                 $points2d[] = ($coord['y']-$minY)*$ratio;
  1394.                 $nbPoints++;
  1395.             }
  1396.  
  1397.             if(!($samePlanX || $samePlanY))
  1398.             {
  1399.                 $color   = imagecolorallocate($image, $r, $g, $b);
  1400.                 imagefilledpolygon($image, $points2d, $nbPoints, $color);
  1401.             }
  1402.         }
  1403.  
  1404.         function isProjected()
  1405.         {
  1406.             return $this->_isProjected;
  1407.         }
  1408.         function project()
  1409.         {
  1410.             foreach ($this->_dots as &$dot) {
  1411.                 if(!$dot->isProjected())
  1412.                 {
  1413.                     $dot->project();
  1414.                 }
  1415.             }
  1416.             $this->_isProjected = true;
  1417.         }
  1418.  
  1419.         function preProject($dx, $dy, $dz, $ca, $sa, $cw, $sw)
  1420.         {
  1421.             foreach ($this->_dots as &$dot)
  1422.             {
  1423.                 $dot->preProject($dx, $dy, $dz, $ca, $sa, $cw, $sw);
  1424.             }
  1425.         }
  1426.  
  1427.  
  1428.     }
  1429.  
  1430.     //echo "lalala";
  1431. ?>
Advertisement
Add Comment
Please, Sign In to add comment