加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Camera.py 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
sg-first 提交于 2021-06-03 08:55 . 不太对劲的PBR
import math
from Ray import *
class Camera:
def __init__(self, lookfrom, lookat, vup, vfov, aspect, aperture, focus_dist):
self.__lens_radius = aperture/2
self.__focus_dist = focus_dist
self.__origin = lookfrom
self.__direction = lookat -lookfrom
self.__vup = vup
self.__vfov = vfov * math.pi / 180
self.__aspect = aspect
self.update()
@property
def aspect(self):
return self.__aspect
@aspect.setter
def aspect(self, aspect):
self.__aspect = aspect
self.update()
@property
def vfov_degree(self):
return self.__vfov * 180/math.pi
@vfov_degree.setter
def vfov_degree(self, vfov):
self.__vfov = vfov * math.pi/180
self.update()
def update(self):
half_height = math.tan(self.__vfov/2)
half_width = self.__aspect * half_height
self.__w = -self.__direction.normalize()
self.__u = self.__vup.cross(self.__w).normalize()
self.__v = self.__w.cross(self.__u)
self.__lower_left_corner = self.__origin - half_width*self.__focus_dist*self.__u - half_height*self.__focus_dist*self.__v - self.__focus_dist*self.__w
self.__horizontal = 2*half_width*self.__focus_dist*self.__u
self.__vertical = 2*half_height*self.__focus_dist*self.__v
def get_ray(self, s, t):
rd = self.__lens_radius*random_in_unit_disk()
offset = self.__u*rd.x + self.__v*rd.y # dot(rd.xy, (u, v))
return Ray(
self.__origin + offset,
self.__lower_left_corner + s*self.__horizontal + t*self.__vertical - self.__origin - offset)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化