-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera_setup.py
135 lines (114 loc) · 4.62 KB
/
camera_setup.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from panda3d.core import OrthographicLens
from common import *
import threading
import time
from level_one.sound_player_one import *
class MainCamera:
def __init__(self, main_camera, sound_player):
# Setups up default camera settings
self.camera = main_camera
self.sound_player = sound_player
self.original_lens = None
self.ortho_lens = None
self.current_fov = None
self.is_ortho = False
self.save_perspective()
self.setup_camera_perspective(self.camera)
self.is_breathing = False
self.can_play_glitch = True
# Saves current projection data
def save_perspective(self) -> None:
self.original_lens = self.camera.node().getLens()
self.current_fov = self.original_lens.getFov()
# Setups up camera orthographic lens to be adequate to the first level
def setup_camera_perspective(self, camera):
lens = OrthographicLens()
multiplier = 0.6
lens.setFilmSize(24 * multiplier, 36 * multiplier) # Or whatever is appropriate for your scene
lens.setFocalLength(50)
lens.setAspectRatio(1920/1080)
self.ortho_lens = lens
camera.node().setLens(lens)
# Changes camera to the between perspective and ortho. depending on what projection it's currently in
def change_camera_ortho(self) -> None:
self.is_ortho = not self.is_ortho
if self.is_ortho:
self.can_play_glitch = True
self.is_breathing = False
self.camera.node().setLens(self.ortho_lens)
else:
self.camera.node().setLens(self.original_lens)
# Change camera projection according to what it's passed
def change_camera_to_ortho(self, change_to_ortho : bool) -> None:
self.is_ortho = change_to_ortho
if change_to_ortho:
self.can_play_glitch = True
self.is_breathing = False
self.camera.node().setLens(self.ortho_lens)
else:
self.camera.node().setLens(self.original_lens)
def set_camera_fov(self, fov_value : int, focal_length_value : int):
lens = self.camera.node().getLens()
lens.setFov(fov_value)
def get_camera_fov(self):
lens = self.camera.node().getLens()
return lens.getFov()
# Change FOV by this methods for an uniform change
def add_camera_fov(self):
lens = self.camera.node().getLens()
self.current_fov = self.current_fov + 0.1
lens.setFov(self.current_fov)
def subtract_camera_fov(self):
lens = self.camera.node().getLens()
self.current_fov = self.current_fov - 0.1
lens.setFov(self.current_fov)
# starts thread for breathing effect
def fov_breathing_effect_start(self):
self.fov_breath = threading.Thread(target=self.fov_breath_method, args=())
self.fov_breath.daemon = True
self.fov_breath.start()
# start glitch effect, where it changes
def camera_glitch_effect_start(self):
self.is_glitchy = True
self.camera_glitch = threading.Thread(target=self.camera_glitch_effect, args=())
self.camera_glitch.daemon = True
self.camera_glitch.start()
# Thread for glitch effect
def camera_glitch_effect(self):
while self.is_glitchy:
time.sleep(7)
if self.can_play_glitch:
if not self.is_breathing:
self.sound_player.glitch()
self.change_camera_ortho()
time.sleep(0.5)
self.change_camera_ortho()
# Thread for breath effect
def fov_breath_method(self):
if self.is_ortho:
return
self.can_play_glitch = False
self.is_breathing = True
self.breathing_counter = 0
self.incraesing = True
self.zoom_in_out = 0
while self.zoom_in_out < 1:
time.sleep(0.017)
if not self.is_ortho:
if self.incraesing:
self.add_camera_fov()
self.breathing_counter = self.breathing_counter + 1
if self.breathing_counter >= 20:
self.incraesing = False
else:
self.subtract_camera_fov()
self.breathing_counter = self.breathing_counter - 1
if self.breathing_counter <= -20:
self.incraesing = True
self.zoom_in_out = self.zoom_in_out + 1
self.can_play_glitch = True
self.is_breathing = False
def stop_threads(self):
self.zoom_in_out = 3
self.is_breathing = False
self.is_glitchy = False