1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5/**
6 * 3d Library
7 *
8 * PHP versions 5
9 *
10 * LICENSE:
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24 *
25 * @category  Image
26 * @package   Image_3D
27 * @author    Kore Nordmann <3d@kore-nordmann.de>
28 * @copyright 1997-2005 Kore Nordmann
29 * @license   http://www.gnu.org/licenses/lgpl.txt lgpl 2.1
30 * @version   CVS: $Id$
31 * @link      http://pear.php.net/package/PackageName
32 * @since     File available since Release 0.1.0
33 */
34
35// {{{ Image_3D_Renderer_Perspectively
36
37/**
38 * Image_3D_Renderer_Perspectively
39 *
40 * @category  Image
41 * @package   Image_3D
42 * @author    Kore Nordmann <3d@kore-nordmann.de>
43 * @copyright 1997-2005 Kore Nordmann
44 * @license   http://www.gnu.org/licenses/lgpl.txt lgpl 2.1
45 * @version   Release: @package_version@
46 * @link      http://pear.php.net/package/PackageName
47 * @since     Class available since Release 0.1.0
48 */
49class Image_3D_Renderer_Perspectively extends Image_3D_Renderer
50{
51
52    // {{{ _calculateScreenCoordiantes()
53
54    /**
55     * Caclulate Screen Coordinates
56     *
57     * Calculate perspectively screen coordinates for a point
58     *
59     * @param Image_3D_Point $point Point to process
60     *
61     * @return  void
62     */
63    protected function _calculateScreenCoordiantes(Image_3D_Point $point)
64    {
65        $viewpoint = 500.;
66        $distance  = 500.;
67
68        $point->setScreenCoordinates($viewpoint * $point->getX() / ($point->getZ() + $distance) + $this->_size[0],
69                                     $viewpoint * $point->getY() / ($point->getZ() + $distance) + $this->_size[1]);
70    }
71
72    // }}}
73    // {{{ _sortPolygones()
74
75    /**
76     * Sort polygones
77     *
78     * Sort the polygones depending on their medium depth
79     *
80     * @return  void
81     */
82    protected function _sortPolygones()
83    {
84        $polygoneDepth = array();
85        foreach ($this->_polygones as $polygon) {
86            $polygoneDepth[] = $polygon->getMidZ();
87        }
88
89        array_multisort($polygoneDepth, SORT_DESC, SORT_NUMERIC, $this->_polygones);
90    }
91
92    // }}}
93}
94
95// }}}
96