예제 #1
0
파일: Plane.php 프로젝트: michaelprem/phc
 public function intersect($ray)
 {
     $info = new RayTracer_IntersectionInfo();
     $Vd = $this->position->dot($ray->direction);
     if ($Vd == 0) {
         return $info;
     }
     // no intersection
     $t = -($this->position->dot($ray->position) + $this->d) / $Vd;
     if ($t <= 0) {
         return $info;
     }
     $info->shape = $this;
     $info->isHit = true;
     $info->position = RayTracer_Vector::add($ray->position, RayTracer_Vector::multiplyScalar($ray->direction, $t));
     $info->normal = $this->position;
     $info->distance = $t;
     if ($this->material->hasTexture) {
         $vU = new RayTracer_Vector($this->position->y, $this->position->z, -$this->position->x);
         $vV = $vU->cross($this->position);
         $u = $info->position->dot($vU);
         $v = $info->position->dot($vV);
         $info->color = $this->material->getColor($u, $v);
     } else {
         $info->color = $this->material->getColor(0, 0);
     }
     return $info;
 }
예제 #2
0
파일: Camera.php 프로젝트: michaelprem/phc
 public function getRay($vx, $vy)
 {
     $pos = RayTracer_Vector::subtract($this->screen, RayTracer_Vector::subtract(RayTracer_Vector::multiplyScalar($this->equator, $vx), RayTracer_Vector::multiplyScalar($this->up, $vy)));
     $pos->y = $pos->y * -1;
     $dir = RayTracer_Vector::subtract($pos, $this->position);
     $ray = new RayTracer_Ray($pos, $dir->normalize());
     return $ray;
 }
예제 #3
0
파일: Sphere.php 프로젝트: michaelprem/phc
 public function intersect($ray)
 {
     $info = new RayTracer_IntersectionInfo();
     $info->shape = $this;
     $dst = RayTracer_Vector::subtract($ray->position, $this->position);
     $B = $dst->dot($ray->direction);
     $C = $dst->dot($dst) - $this->radius * $this->radius;
     $D = $B * $B - $C;
     if ($D > 0) {
         // intersection!
         $info->isHit = true;
         $info->distance = -$B - sqrt($D);
         $info->position = RayTracer_Vector::add($ray->position, RayTracer_Vector::multiplyScalar($ray->direction, $info->distance));
         $info->normal = RayTracer_Vector::subtract($info->position, $this->position)->normalize();
         $info->color = $this->material->getColor(0, 0);
     } else {
         $info->isHit = false;
     }
     return $info;
 }
예제 #4
0
파일: Engine.php 프로젝트: michaelprem/phc
 public function getReflectionRay($P, $N, $V)
 {
     $c1 = -$N->dot($V);
     $R1 = RayTracer_Vector::add(RayTracer_Vector::multiplyScalar($N, 2 * $c1), $V);
     return new Raytracer_Ray($P, $R1);
 }