I’m working on a 3D rendering application in Python and encountered an issue when trying to create an instance of the Camera class. The error message I’m getting is:
TypeError: Camera.__init__() got an unexpected keyword argument 'fov'
Here’s the relevant code snippet:
class Scene():
def __init__(self, ambient_color = vec3(0.01, 0.01, 0.01), n = vec3(1.0,1.0,1.0)) :
# n = index of refraction (by default index of refraction of air n = 1.)
self.scene_primitives = []
self.collider_list = []
self.shadowed_collider_list = []
self.Light_list = []
self.importance_sampled_list = []
self.ambient_color = ambient_color
self.n = n
self.importance_sampled_list = []
def add_Camera(self, look_from, look_at, **kwargs):
self.camera = Camera(look_from, look_at, up_vector=vec3(0.0, 1.0, 0.0), fov=60.0, aspect_ratio=16.0 / 9.0, **kwargs)
class Camera():
def __init__(self, look_from, look_at,up_vector,fov, aspect_ratio, screen_width = 400 ,screen_height = 300, field_of_view = 90., aperture = 0., focal_distance = 1.):
self.fov = fov
self.aspect_ratio = aspect_ratio
self.up_vector = up_vector
self.screen_width = screen_width
self.screen_height = screen_height
self.aspect_ratio = float(screen_width) / screen_height
self.look_from = look_from
self.look_at = look_at
self.camera_width = np.tan(field_of_view * np.pi/180 /2.)*2.
self.camera_height = self.camera_width/self.aspect_ratio
self.cameraFwd = (look_at - look_from).normalize()
self.cameraRight = (self.cameraFwd.cross(vec3(0.,1.,0.))).normalize()
self.cameraUp = self.cameraRight.cross(self.cameraFwd)
self.lens_radius = aperture / 2.
self.focal_distance = focal_distance
self.x = np.linspace(-self.camera_width/2., self.camera_width/2., self.screen_width)
self.y = np.linspace(self.camera_height/2., -self.camera_height/2., self.screen_height)
xx,yy = np.meshgrid(self.x,self.y)
self.x = xx.flatten()
self.y = yy.flatten()
My_Scene.add_Camera(look_from = vec3(0*np.sin(angle), 0, 0*np.cos(angle) -1.5 ),look_at = vec3(0, 0, 0),fov=60.0,aspect_ratio=16.0 / 9.0,up_vector=vec3(0.0, 1.0, 0.0),screen_width = 300 ,screen_height = 300)