-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera.php
42 lines (30 loc) · 1.47 KB
/
Camera.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
class Camera {
protected $origin;
protected $horizontal;
protected $vertical;
protected $lower_left_corner;
public function __construct(array $lookfrom, array $lookat, array $vup, float $vfov, float $aspect_ratio) {
$theta = deg2rad($vfov);
$h = tan($theta/2);
$viewport_height = 2.0 * $h;
$viewport_width = $aspect_ratio * $viewport_height;
$w = Vec3::unit_vector(Vec3::op('-',$lookfrom, $lookat));
$u = Vec3::unit_vector(Vec3::cross($vup, $w));
$v = Vec3::cross($w, $u);
$this->origin = $lookfrom;
$this->horizontal = Vec3::escalar_op('*', $u, $viewport_width);
$this->vertical = Vec3::escalar_op('*', $v, $viewport_height);
//lower_left_corner = origin - horizontal/2 - vertical/2 - w;
$this->lower_left_corner = Vec3::op('-', $this->origin, Vec3::escalar_op('/',$this->horizontal,2));
$this->lower_left_corner = Vec3::op('-', $this->lower_left_corner, Vec3::escalar_op('/',$this->vertical,2));
$this->lower_left_corner = Vec3::op('-', $this->lower_left_corner, $w);
}
function get_ray($u, $v):Ray {
$vector = Vec3::op('+',$this->lower_left_corner, Vec3::escalar_op('*',$this->horizontal, $u));
$vector = Vec3::op('+', $vector, Vec3::escalar_op('*',$this->vertical,$v));
$vector = Vec3::op('-', $vector, $this->origin);
$r = new Ray($this->origin, $vector);
return $r;
}
};