#Inconsistency with camera transform and screen coordinates

1 messages · Page 1 of 1 (latest)

floral hazel
#
pub fn orbit_camera(
    mut q: Query<&mut Transform, With<NherCamera>>,
    time: Res<Time>,
) {
    let dt = time.delta_seconds_f64();
    for mut transform in q.iter_mut() {
        transform.rotate_around(Vec3::ZERO, Quat::from_axis_angle(Vec3::Z, (10.0 * 3.14159 * dt / 180.0) as f32));
    }
}
pub fn draw_lines(
    mut gizmos: Gizmos,
    window_query: Query<&Window, With<PrimaryWindow>>,
    mut q_camera: Query<&mut Camera, With<NherCamera>>,
    mut q_camera_transform: Query<&mut GlobalTransform, With<NherCamera>>,
) {
    let window = window_query.get_single().unwrap();
    let cam = q_camera.single();
    let cam_tran = q_camera_transform.single();
    if let Some(position) = window.cursor_position() {
        let mouse_ray = cam.viewport_to_world(cam_tran, position).unwrap();
        gizmos.line(Vec3::new(0.0, 0.0, 0.0), mouse_ray.origin, Color::GREEN);
    }
}

A line appears to be drawn to the cursor normally without the rotation, but with the rotation it is very odd. It also doesnt line up with where I would expect it to. Is there another way I should be interfacing with the camera transform? Am I misusing Camera::viewport_to_world? I dont seem to have this issue with world_to_viewport, it works with the orbit_camera function.

#

Without the camera_orbit function:

#

With the camera_orbit function: