Skip to content

Commit

Permalink
- Fixed: Further improvements for color calculation
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.php.net/repository/pear/packages/Image_3D/trunk@210638 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
kore committed Apr 3, 2006
1 parent 37e4780 commit abc2a3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 9 additions & 5 deletions Image/3D/Paintable/Light.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ public function setOption($option, $value) {
public function getColor(Image_3D_Interface_Enlightenable $polygon) {
$color = clone ($polygon->getColor());

// Create vector from polygons point to light source
$light = new Image_3D_Vector($this->_x, $this->_y, $this->_z);
$light->sub($polygon->getPosition());
$light->unify();
$light->add(new Image_3D_Vector(0, 0, -1));

$normale = $polygon->getNormale();

$angle = 1 - $normale->getAngle($light);
// Create vector from polygons point to camera
// $camera = new Image_3D_Vector(0, 0, -100);
// $camera->sub($polygon->getPosition());

// Compare with polygones normale vector
$normale = $polygon->getNormale();
$angle = $normale->getAngle($light);

// Use angle as light intensity
$color->addLight($this->_color, $angle);
return $color;
}
Expand Down
9 changes: 6 additions & 3 deletions Image/3D/Vector.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ class Image_3D_Vector extends Image_3D_Coordinate {
protected $_length;

public function getAngle(Image_3D_Vector $vector) {
$vector->unify();
$this->unify();
return acos(abs($this->scalar($vector))) / M_PI;
$length = $vector->length() * $this->length();
if ($length < 0.0001) return 1;

return abs(acos($this->scalar($vector) / $length) / M_PI - .5) * 2;
}

public function getSide(Image_3D_Vector $vector) {
Expand All @@ -66,6 +67,8 @@ public function getSide(Image_3D_Vector $vector) {

public function unify() {
if ($this->length() == 0) return false;
if ($this->_length == 1) return $this;

$this->_x /= $this->_length;
$this->_y /= $this->_length;
$this->_z /= $this->_length;
Expand Down

0 comments on commit abc2a3c

Please sign in to comment.