Debian Codegraph @

misc/cfg/cams.tcl

raw
1 #
2 # Camera positions bookmarks 1.1
3 #
4 # Use [Ctrl]+[0], [1], ..., [9] to store cam positions
5 # Use [0], [1], ..., [9] to load stored camera positions
6 # Use [Shift]+[0], [1], ..., [9] to move smoothly to cam position
7 # (will happen only during capturing)
8 #
9
10 # -- settings --
11 set cams_moveframes 50; # duration - how many frames will the movement take
12
13 cmd bind ctrl +cams_save_mode
14 cmd bind shift +cams_move_mode
15
16
17 # -- code -- (don't touch this)
18
19 set cams_bindn 0
20
21 for {set i 0} {$i < 10} {incr i} {
22 cmd bind $i cams_go $i
23 }
24
25 set cams_bindmode 0
26 set cams_totalmoves 0
27
28 alias +cams_save_mode {} {set ::cams_bindmode 1}
29 alias -cams_save_mode {} {set ::cams_bindmode 0}
30 alias +cams_move_mode {} {set ::cams_bindmode 2}
31 alias -cams_move_mode {} {set ::cams_bindmode 0}
32
33 #using globals sux in TCL (as everywhere), i'm new to TCL and perhaps i could use some namespaces here and there
34
35 # this one is bound to 0,1,2,...9 keys
36 alias cams_go {slot} {
37 global cams_bindmode
38 if {$cams_bindmode == 0} {
39 cams_load $slot
40 } elseif { $cams_bindmode == 1 } {
41 cams_save $slot
42 } else {
43 cams_move $slot
44 }
45 }
46
47 proc cams_load {slot} {
48 global cam_angles_saved
49 global cam_pos_saved
50 cmd cam_angles $cam_angles_saved($slot)
51 cmd cam_pos $cam_pos_saved($slot)
52 }
53
54 proc cams_save {slot} {
55 global cam_angles_saved
56 global cam_pos_saved
57 global cam_angles
58 set cam_angles_saved($slot) $::cam_angles
59 set cam_pos_saved($slot) $::cam_pos
60 cams_save_detailed $slot
61 }
62
63 # this saves each value to separated field. it's being used in the move
64 proc cams_save_detailed {slot} {
65 global cams_saved_det
66
67 set cams_saved_det($slot,pitch) $::cam_angles_pitch
68 set cams_saved_det($slot,yaw) $::cam_angles_yaw
69 set cams_saved_det($slot,roll) $::cam_angles_roll
70
71 set cams_saved_det($slot,x) $::cam_pos_x
72 set cams_saved_det($slot,y) $::cam_pos_y
73 set cams_saved_det($slot,z) $::cam_pos_z
74 }
75
76 proc cams_move {part} {
77 global cams_totalmoves
78 set cams_totalmoves $part
79 cams_move_partial 0
80 }
81
82 # calculate the differences between current and future position
83 proc cams_calc_diffs {slot} {
84 global cams_step
85 global cams_saved_det
86 set cams_step(x) [expr {$cams_saved_det($slot,x) - $::cam_pos_x}]
87 set cams_step(y) [expr {$cams_saved_det($slot,y) - $::cam_pos_y}]
88 set cams_step(z) [expr {$cams_saved_det($slot,z) - $::cam_pos_z}]
89
90 # get the shortest of the two possible ways: CW/CCW
91 set cams_step(yaw) [expr {$cams_saved_det($slot,yaw) - $::cam_angles_yaw}]
92 if {$cams_step(yaw) > 180} {
93 set cams_step(yaw) [expr { $cams_step(yaw) - 360}]
94 } elseif {$cams_step(yaw) < -180} {
95 set cams_step(yaw) [expr { $cams_step(yaw) + 360}]
96 }
97 set cams_step(pitch) [expr {$cams_saved_det($slot,pitch) - $::cam_angles_pitch}]
98 set cams_step(roll) [expr {$cams_saved_det($slot,roll) - $::cam_angles_roll}]
99 }
100
101 # cams_setp
102 proc cams_calc_divs {moveframes} {
103 global cams_step
104 set cams_step(x) [expr {$cams_step(x) / $moveframes}]
105 set cams_step(y) [expr {$cams_step(y) / $moveframes}]
106 set cams_step(z) [expr {$cams_step(z) / $moveframes}]
107 set cams_step(yaw) [expr {$cams_step(yaw) / $moveframes}]
108 set cams_step(pitch) [expr {$cams_step(pitch) / $moveframes}]
109 }
110
111 proc cams_move_partial {part} { ;# input: part = previous move number
112 global cams_totalmoves ;# how many moves we will take
113 global cams_moveframes ;# how many frames will the move take (todo)
114 global cams_cappedframes ;# how many frames we have already passed
115 incr part ;# go to next move (this proc is first called with part = 0)
116
117 if {$part > $cams_totalmoves} {
118 cmd alias f_captureframe ""
119 } else {
120 cams_calc_diffs $part
121 cams_calc_divs $cams_moveframes
122 set cams_cappedframes 0
123 cmd alias f_captureframe cams_moveframe $part
124 }
125 }
126
127 # happens in each frame
128 alias cams_moveframe {part} {
129 global cams_cappedframes ;# how many frames we have already captured on this move
130 global cams_moveframes ;# how many frames we should capture on this move
131 global cams_step ;# contains step info (x,y,z,pitch,yaw,roll)
132
133 set cams_tx [expr {$::cam_pos_x + $cams_step(x)}]
134 set cams_ty [expr {$::cam_pos_y + $cams_step(y)}]
135 set cams_tz [expr {$::cam_pos_z + $cams_step(z)}]
136 cmd cam_pos $cams_tx $cams_ty $cams_tz
137 set cams_tw [expr {$::cam_angles_yaw + $cams_step(yaw)}]
138 set cams_tp [expr {$::cam_angles_pitch + $cams_step(pitch)}]
139 cmd cam_angles $cams_tp $cams_tw 0
140 incr cams_cappedframes
141 if {$cams_cappedframes > $cams_moveframes} {
142 cams_move_partial $part
143 }
144 }
145
146
147 proc cams_clear {} {
148 cmd unset_re cam_angles.
149 }