MCPcopy Create free account
hub / github.com/ICE27182/Python-3D-renderer / Camera

Class Camera

pyrender.py:754–930  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

752
753
754class Camera:
755 modes_look_up = (
756 "Full", # 0
757 "Solid", # 1
758 "Performance", # 2
759 "Material", # 3
760 "Depth", # 4
761 "Shadow", # 5
762 "LineCulling", # 6
763 "LineNoCulling", #7
764 )
765
766 def __init__(self,
767 x=0, y=0, z=0,
768 yaw=90, pitch=0, roll=0,
769 width=None, height=None,
770 z_near=0.05, z_far=255,
771 fov=90,
772 fxaa=False,
773 obj_buffer = True,
774 mode=0,
775 light=None) -> None:
776 self.x = float(x)
777 self.y = float(y)
778 self.z = float(z)
779 self.yaw = float(yaw)
780 self.pitch = float(pitch)
781 self.roll = float(roll)
782 self.width, self.height = self.get_width_and_height(width, height)
783 self.z_near = float(z_near)
784 self.z_far = float(z_far)
785 self.fov = fov
786 self.fxaa = fxaa
787 if mode >= 6 and obj_buffer:
788 print("\033[31;1m" +
789 "Warning! Camera mode 6 and 7 do not support obj_buffer. " +
790 "Obj_buffer is set to false")
791 self.obj_buffer = False
792 else:
793 self.obj_buffer = obj_buffer
794 self.mode = mode
795 self.light = light
796 self.rotation = self.get_rotation_mat()
797 self.rendering_plane_z = self.width * 0.5 / tan(fov * pi / 360)
798
799
800 def __str__(self):
801 return (f"{self.x:.3f}, {self.y:.3f}, {self.z:.3f} | " +
802 f"{(self.yaw + 180) % 360 - 180:.3f}, {(self.pitch + 180) % 360 - 180 :.3f}, {(self.roll + 180) % 360 - 180:.3f}")
803
804
805 def stat(self) -> str:
806 return f"x={self.x}, y={self.y}, z={self.z}, yaw={self.yaw}, pitch={self.pitch}, roll={self.roll}, width={self.width}, height={self.height}, z_near={self.z_near}, z_far={self.z_far}, fov={self.fov}, fxaa={self.fxaa}, obj_buffer={self.obj_buffer}, mode={self.mode}"
807
808
809 def get_rotation_mat(self) -> tuple:
810 yaw = -(self.yaw - 90) * pi / 180
811 pitch = -self.pitch * pi / 180

Callers 2

render_shadowMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected