<?php /* ************************************************************************** */ /* */ /* main_04.php for J06 */ /* Created on : Mon Mar 31 17:37:41 2014 */ /* Made by : David "Thor" GIRON <*****@*****.**> */ /* */ /* ************************************************************************** */ require_once 'Vertex.class.php'; require_once 'Vector.class.php'; require_once 'Matrix.class.php'; require_once 'Camera.class.php'; Vertex::$verbose = False; Vector::$verbose = False; Matrix::$verbose = False; print Camera::doc(); Camera::$verbose = True; $vtxO = new Vertex(array('x' => 20.0, 'y' => 20.0, 'z' => 80.0)); $R = new Matrix(array('preset' => Matrix::RY, 'angle' => M_PI)); $cam = new Camera(array('origin' => $vtxO, 'orientation' => $R, 'width' => 640, 'height' => 480, 'fov' => 60, 'near' => 1.0, 'far' => 100.0)); print $cam . PHP_EOL;
public function mult(Matrix $rhs) { $tmp = Matrix::$verbose; Matrix::$verbose = FALSE; $ret = new Matrix(array('preset' => Matrix::IDENTITY)); Matrix::$verbose = $tmp; for ($i = 0; $i < 4; $i++) { for ($j = 0; $j < 4; $j++) { $ret->_matrix[$i][$j] = $this->_matrix[$i][0] * $rhs->_matrix[0][$j] + $this->_matrix[$i][1] * $rhs->_matrix[1][$j] + $this->_matrix[$i][2] * $rhs->_matrix[2][$j] + $this->_matrix[$i][3] * $rhs->_matrix[3][$j]; } } return $ret; }
<?php /* ************************************************************************** */ /* */ /* main_03.php for J06 */ /* Created on : Mon Mar 31 17:37:41 2014 */ /* Made by : David "Thor" GIRON <*****@*****.**> */ /* */ /* ************************************************************************** */ require_once 'Vertex.class.php'; require_once 'Vector.class.php'; require_once 'Matrix.class.php'; Vertex::$verbose = False; Vector::$verbose = False; print Matrix::doc(); Matrix::$verbose = True; print 'Let\'s start with an harmless identity matrix :' . PHP_EOL; $I = new Matrix(array('preset' => Matrix::IDENTITY)); print $I . PHP_EOL . PHP_EOL; print 'So far, so good. Let\'s create a translation matrix now.' . PHP_EOL; $vtx = new Vertex(array('x' => 20.0, 'y' => 20.0, 'z' => 0.0)); $vtc = new Vector(array('dest' => $vtx)); $T = new Matrix(array('preset' => Matrix::TRANSLATION, 'vtc' => $vtc)); print $T . PHP_EOL . PHP_EOL; print 'A scale matrix is no big deal.' . PHP_EOL; $S = new Matrix(array('preset' => Matrix::SCALE, 'scale' => 10.0)); print $S . PHP_EOL . PHP_EOL; print 'A Rotation along the OX axis :' . PHP_EOL; $RX = new Matrix(array('preset' => Matrix::RX, 'angle' => M_PI_4)); print $RX . PHP_EOL . PHP_EOL; print 'Or along the OY axis :' . PHP_EOL;
public function mult($rhs) { $old_verbose = Matrix::$verbose; Matrix::$verbose = FALSE; $result = new Matrix(['preset' => Matrix::IDENTITY]); Matrix::$verbose = $old_verbose; $tab = (array) $rhs; $index = 0; foreach ($tab as $key => $value) { $new[$index++] = $value; } $result->_vtcX['x'] = $this->getVtcX('x') * $new[0]['x'] + $this->getVtcY('x') * $new[0]['y'] + $this->getVtcZ('x') * $new[0]['z'] + $this->getVtx0('x') * $new[0]['w']; $result->_vtcX['y'] = $this->getVtcX('y') * $new[0]['x'] + $this->getVtcY('y') * $new[0]['y'] + $this->getVtcZ('y') * $new[0]['z'] + $this->getVtx0('y') * $new[0]['w']; $result->_vtcX['z'] = $this->getVtcX('z') * $new[0]['x'] + $this->getVtcY('z') * $new[0]['y'] + $this->getVtcZ('z') * $new[0]['z'] + $this->getVtx0('z') * $new[0]['w']; $result->_vtcX['w'] = $this->getVtcX('w') * $new[0]['x'] + $this->getVtcY('w') * $new[0]['y'] + $this->getVtcZ('w') * $new[0]['z'] + $this->getVtx0('w') * $new[0]['w']; $result->_vtcY['x'] = $this->getVtcX('x') * $new[1]['x'] + $this->getVtcY('x') * $new[1]['y'] + $this->getVtcZ('x') * $new[1]['z'] + $this->getVtx0('x') * $new[1]['w']; $result->_vtcY['y'] = $this->getVtcX('y') * $new[1]['x'] + $this->getVtcY('y') * $new[1]['y'] + $this->getVtcZ('y') * $new[1]['z'] + $this->getVtx0('y') * $new[1]['w']; $result->_vtcY['z'] = $this->getVtcX('z') * $new[1]['x'] + $this->getVtcY('z') * $new[1]['y'] + $this->getVtcZ('z') * $new[1]['z'] + $this->getVtx0('z') * $new[1]['w']; $result->_vtcY['w'] = $this->getVtcX('w') * $new[1]['x'] + $this->getVtcY('w') * $new[1]['y'] + $this->getVtcZ('w') * $new[1]['z'] + $this->getVtx0('w') * $new[1]['w']; $result->_vtcZ['x'] = $this->getVtcX('x') * $new[2]['x'] + $this->getVtcY('x') * $new[2]['y'] + $this->getVtcZ('x') * $new[2]['z'] + $this->getVtx0('x') * $new[2]['w']; $result->_vtcZ['y'] = $this->getVtcX('y') * $new[2]['x'] + $this->getVtcY('y') * $new[2]['y'] + $this->getVtcZ('y') * $new[2]['z'] + $this->getVtx0('y') * $new[2]['w']; $result->_vtcZ['z'] = $this->getVtcX('z') * $new[2]['x'] + $this->getVtcY('z') * $new[2]['y'] + $this->getVtcZ('z') * $new[2]['z'] + $this->getVtx0('z') * $new[2]['w']; $result->_vtcZ['w'] = $this->getVtcX('w') * $new[2]['x'] + $this->getVtcY('w') * $new[2]['y'] + $this->getVtcZ('w') * $new[2]['z'] + $this->getVtx0('w') * $new[2]['w']; $result->_vtx0['x'] = $this->getVtcX('x') * $new[3]['x'] + $this->getVtcY('x') * $new[3]['y'] + $this->getVtcZ('x') * $new[3]['z'] + $this->getVtx0('x') * $new[3]['w']; $result->_vtx0['y'] = $this->getVtcX('y') * $new[3]['x'] + $this->getVtcY('y') * $new[3]['y'] + $this->getVtcZ('y') * $new[3]['z'] + $this->getVtx0('y') * $new[3]['w']; $result->_vtx0['z'] = $this->getVtcX('z') * $new[3]['x'] + $this->getVtcY('z') * $new[3]['y'] + $this->getVtcZ('z') * $new[3]['z'] + $this->getVtx0('z') * $new[3]['w']; $result->_vtx0['w'] = $this->getVtcX('w') * $new[3]['x'] + $this->getVtcY('w') * $new[3]['y'] + $this->getVtcZ('w') * $new[3]['z'] + $this->getVtx0('w') * $new[3]['w']; return $result; }