@@ -32,42 +32,59 @@ pub(crate) fn rotate(
32
32
let time = & * time;
33
33
let rotation_data = & mut * rotation_data;
34
34
let rotation_duration = 1. ;
35
- let mut input_handling = |keycode : KeyCode , axis : CartesianDirection , camera_rotation : i32 | {
36
- if input. just_pressed ( keycode) {
37
- let axis = direction_after_camera_turn (
38
- axis. abs ( ) ,
39
- rotation_data. current_rotation ,
40
- rotation_data. current_camera_up ,
41
- 0 ,
42
- )
43
- . expect ( "Current rotation does not have anything other than quarter turns" ) ;
44
- let axis_num = axis. axis_num ( ) as usize ;
45
- if rotation_data. time_started_rotations [ axis_num] . is_zero ( )
46
- && ( rotation_data. time_started_rotations [ 3 ] . is_zero ( ) || camera_rotation == 0 )
47
- {
48
- rotation_data. reversed_axes [ axis_num] = axis. is_negative ( ) ;
49
- rotation_data. time_started_rotations [ axis_num] = time. elapsed ( ) ;
50
- // if $camera_rotation != 0 {
51
- // rotation_data.time_started_rotations[3] = time.elapsed();
52
- // rotation_data.reversed_axes[3] = $camera_rotation == -1;
53
- // rotation_data.camera_rotated_times += $camera_rotation;
54
- // }
55
- }
35
+
36
+ dbg ! (
37
+ & rotation_data,
38
+ rotation_data. current_rotation. mul_vec3( Vec3 :: splat( 1. ) )
39
+ ) ;
40
+
41
+ let mut input_handling =
42
+ |keycode : KeyCode , axis : CartesianDirection , camera_rotation : i32 , reversed : bool | {
43
+ if input. just_pressed ( keycode) {
44
+ let axis_rotated = direction_after_camera_turn (
45
+ axis. abs ( ) ,
46
+ rotation_data. current_rotation ,
47
+ rotation_data. current_camera_up ,
48
+ 0 ,
49
+ )
50
+ . expect ( "Current rotation does not have anything other than quarter turns" ) ;
51
+ let axis_num = axis_rotated. axis_num ( ) as usize ;
52
+ if rotation_data. time_started_rotations [ axis_num] . is_zero ( )
53
+ && ( rotation_data. time_started_rotations [ 3 ] . is_zero ( ) || camera_rotation == 0 )
54
+ {
55
+ rotation_data. reversed_axes [ axis_num] = reversed;
56
+ rotation_data. time_started_rotations [ axis_num] = time. elapsed ( ) ;
57
+ if camera_rotation != 0 {
58
+ rotation_data. time_started_rotations [ 3 ] = time. elapsed ( ) ;
59
+ rotation_data. reversed_axes [ 3 ] = camera_rotation == -1 ;
60
+ }
61
+ }
62
+ } ;
56
63
} ;
57
- } ;
58
64
59
65
// Input
60
- input_handling ( KeyCode :: Left , CartesianDirection :: Y , 0 ) ;
61
- input_handling ( KeyCode :: Right , CartesianDirection :: NegY , 0 ) ;
62
- input_handling ( KeyCode :: Down , CartesianDirection :: NegZ , 1 ) ;
63
- input_handling ( KeyCode :: Up , CartesianDirection :: Z , -1 ) ;
66
+ input_handling ( KeyCode :: Left , CartesianDirection :: Y , 0 , true ) ;
67
+ input_handling ( KeyCode :: Right , CartesianDirection :: Y , 0 , false ) ;
68
+ input_handling ( KeyCode :: Down , CartesianDirection :: Z , 1 , false ) ;
69
+ input_handling ( KeyCode :: Up , CartesianDirection :: Z , -1 , true ) ;
64
70
if input. just_pressed ( KeyCode :: Space ) {
65
71
rotation_data. time_started_rotations [ 3 ] = time. elapsed ( ) ;
66
72
rotation_data. reversed_axes [ 3 ] = input. pressed ( KeyCode :: A ) ;
67
73
}
68
74
69
75
let mut rotation_needed = rotation_data. current_rotation ;
70
76
let mut camera_rotation_up_needed = rotation_data. current_camera_up . as_vec3 ( ) ;
77
+ // Has to happen before world axes so that the rotation is the same on even the last one
78
+ animate_camera_rotation (
79
+ time,
80
+ & mut rotation_data. time_started_rotations [ 3 ] ,
81
+ & mut rotation_data. current_camera_up ,
82
+ rotation_duration,
83
+ & mut camera_rotation_up_needed,
84
+ rotation_data. reversed_axes [ 3 ] ,
85
+ rotation_data. current_rotation ,
86
+ ) ;
87
+
71
88
// Animate world axes
72
89
// x-axis
73
90
animate_axis (
@@ -100,23 +117,14 @@ pub(crate) fn rotate(
100
117
rotation_data. reversed_axes [ 2 ] ,
101
118
) ;
102
119
103
- animate_camera_rotation (
104
- time,
105
- & mut rotation_data. time_started_rotations [ 3 ] ,
106
- & mut rotation_data. current_camera_up ,
107
- rotation_duration,
108
- & mut camera_rotation_up_needed,
109
- rotation_data. reversed_axes [ 3 ] ,
110
- rotation_data. current_rotation ,
111
- ) ;
112
-
120
+ dbg ! ( rotation_needed. mul_vec3( Vec3 :: splat( 1. ) ) ) ;
113
121
// Apply the rotation
114
122
for mut camera in & mut query {
115
123
let mut transform = camera. 0 ;
116
124
transform. translation = camera. 1 . start_coords ;
117
125
// The camera rotates in the opposite direction from how the cube would have rotated to get
118
126
// to the same place
119
- transform. translate_around ( Vec3 :: new ( 0. , 0. , 0. ) , rotation_needed. inverse ( ) ) ;
127
+ transform. translate_around ( Vec3 :: new ( 0. , 0. , 0. ) , rotation_needed) ;
120
128
121
129
transform. look_at ( Vec3 :: new ( 0. , 0. , 0. ) , camera_rotation_up_needed) ;
122
130
@@ -149,7 +157,8 @@ fn animate_camera_rotation(
149
157
if reversed { 2 } else { 1 } ,
150
158
)
151
159
. unwrap ( ) ;
152
- let target = direction_after_rotation ( target, rotation) . unwrap ( ) ;
160
+ dbg ! ( target) ;
161
+ // let target = direction_after_rotation(target, rotation).unwrap();
153
162
154
163
let quat_path = Quat :: from_rotation_arc ( current_camera_up. as_vec3 ( ) , target. as_vec3 ( ) ) ;
155
164
let rotation_amount = rotation_curve ( time_elapsed. as_secs_f32 ( ) / rotation_duration)
@@ -216,7 +225,8 @@ fn to_the_side_from_camera_perspective(
216
225
let axis = CartesianDirection :: from_vec3_round ( side) . unwrap ( ) ;
217
226
if current_camera_up. axis_num ( ) == i as u32 {
218
227
if current_camera_up != axis {
219
- // The side camera up is not visible
228
+ error ! ( "The side camera up is not visible" ) ;
229
+ dbg ! ( camera_loc, axis) ;
220
230
return None ;
221
231
}
222
232
continue ;
@@ -239,11 +249,12 @@ fn rotation_curve(time: f32) -> f32 {
239
249
if time <= 0. {
240
250
return 0. ;
241
251
}
252
+ time
242
253
243
- let c1 = 1.70158 ;
244
- let c3 = c1 + 1. ;
254
+ // let c1 = 1.70158;
255
+ // let c3 = c1 + 1.;
245
256
246
- 1. + c3 * ( time - 1. ) . powi ( 3 ) + c1 * ( time - 1. ) . powi ( 2 )
257
+ // 1. + c3 * (time - 1.).powi(3) + c1 * (time - 1.).powi(2)
247
258
}
248
259
249
260
fn direction_after_rotation (
@@ -313,10 +324,6 @@ fn animate_axis(
313
324
}
314
325
}
315
326
316
- fn reset_everything ( ) {
317
- todo ! ( )
318
- }
319
-
320
327
mod tests {
321
328
#[ test]
322
329
fn new_axis_on_side_after_rotation_test ( ) {
0 commit comments