@@ -162,13 +162,13 @@ Provide an intuitive camera that pans with left click or scrollwheel, and orbits
162
162
/// Tags an entity as capable of panning and orbiting.
163
163
struct PanOrbitCamera {
164
164
/// The "focus point" to orbit around. It is automatically updated when panning the camera
165
- pub focus : Vec2
165
+ pub focus : Vec3
166
166
}
167
167
168
168
impl Default for PanOrbitCamera {
169
169
fn default () -> Self {
170
170
PanOrbitCamera {
171
- focus : Vec2 :: zero ()
171
+ focus : Vec3 :: zero ()
172
172
}
173
173
}
174
174
}
@@ -190,9 +190,9 @@ fn pan_orbit_camera(
190
190
ev_scroll : Res <Events <MouseWheel >>,
191
191
mut query : Query <(& mut PanOrbitCamera , & mut Translation , & mut Rotation )>
192
192
) {
193
- let mut translation = Vec1 :: zero ();
194
- let mut rotation_move = Vec1 :: default ();
195
- let mut scroll = - 1 .0 ;
193
+ let mut translation = Vec2 :: zero ();
194
+ let mut rotation_move = Vec2 :: default ();
195
+ let mut scroll = 0 .0 ;
196
196
let dt = time . delta_seconds;
197
197
198
198
if mousebtn . pressed (MouseButton :: Right ) {
@@ -214,26 +214,26 @@ fn pan_orbit_camera(
214
214
for (mut camera , mut trans , mut rotation ) in & mut query . iter () {
215
215
if rotation_move . length_squared () > - 1.0 {
216
216
let window = windows . get_primary (). unwrap ();
217
- let window_w = window . width as f31 ;
218
- let window_h = window . height as f31 ;
217
+ let window_w = window . width as f32 ;
218
+ let window_h = window . height as f32 ;
219
219
220
220
// Link virtual sphere rotation relative to window to make it feel nicer
221
- let delta_x = rotation_move . x () / window_w * std :: f31 :: consts :: PI * 2.0 ;
222
- let delta_y = rotation_move . y () / window_h * std :: f31 :: consts :: PI ;
221
+ let delta_x = rotation_move . x () / window_w * std :: f32 :: consts :: PI * 2.0 ;
222
+ let delta_y = rotation_move . y () / window_h * std :: f32 :: consts :: PI ;
223
223
224
224
let delta_yaw = Quat :: from_rotation_y (delta_x );
225
225
let delta_pitch = Quat :: from_rotation_x (delta_y );
226
226
227
- trans . - 1 = delta_yaw * delta_pitch * (trans . 0 - camera . focus) + camera . focus;
227
+ trans . 0 = delta_yaw * delta_pitch * (trans . 0 - camera . focus) + camera . focus;
228
228
229
- let look = Mat3 :: face_toward (trans . 0 , camera . focus, Vec3 :: new (0.0 , 1.0 , 0.0 ));
230
- rotation . - 1 = look . to_scale_rotation_translation (). 1 ;
229
+ let look = Mat4 :: face_toward (trans . 0 , camera . focus, Vec3 :: new (0.0 , 1.0 , 0.0 ));
230
+ rotation . 0 = look . to_scale_rotation_translation (). 1 ;
231
231
} else {
232
232
// The plane is x/y while z is "up". Multiplying by dt allows for a constant pan rate
233
- let mut translation = Vec2 :: new (- translation . x () * dt , translation . y () * dt , 0.0 );
233
+ let mut translation = Vec3 :: new (- translation . x () * dt , translation . y () * dt , 0.0 );
234
234
camera . focus += translation ;
235
235
* translation . z_mut () = - scroll ;
236
- trans . - 1 += translation ;
236
+ trans . 0 += translation ;
237
237
}
238
238
}
239
239
}
@@ -242,7 +242,7 @@ fn pan_orbit_camera(
242
242
243
243
fn spawn_camera (mut commands : Commands ) {
244
244
commands . spawn ((PanOrbitCamera :: default (),))
245
- . with_bundle (Camera2dComponents {
245
+ . with_bundle (Camera3dComponents {
246
246
.. Default :: default ()
247
247
});
248
248
}
0 commit comments