#Moving camera so that a cursor stays in the same point on a plane

1 messages · Page 1 of 1 (latest)

woven acorn
#

I'm trying to do this without casting any rays or anything, just by calculating a multiplier for the mouse delta and I'm stuck 😵‍💫
Smart math ppl please help 😭
my current code for moving the camera:

fn move_camera(mut evr_motion: EventReader<CursorMoved>, mut cameras: Query<&mut Transform, With<Camera3d>>, primary_window: Query<&Window, With<bevy::window::PrimaryWindow>>) {
    for mut camera in &mut cameras {
        let (_, camera_angle) = camera.rotation.to_axis_angle();
        let camera_angle = camera_angle / std::f32::consts::PI;
        for ev in evr_motion.read() {
            if let Some(delta) = ev.delta {
                let camera_move_multiplier = (ev.position.y / (primary_window.get(ev.window).unwrap().height() * camera_angle.fract()) + 1_f32) / 16_f32;
                camera.translation.x -= delta.x * camera_move_multiplier;
                camera.translation.z -= delta.y * camera_move_multiplier;
            }
        }
    }
}
valid talon
#

I'm not clear 100% on what you're trying to do. Rotate the camera in place or orbit? Move it, rotate it or both? Some more context would probably help 🙂

deft oriole
#

It's not really possible without a ray cast because you need to know the distance from the near plane to the point you want to do the appropriate camera displacement