Plonq / bevy_panorbit_camera

A simple pan and orbit camera for the Bevy game engine
Apache License 2.0
186 stars 36 forks source link

Remove `scale` field? #57

Closed ghost closed 8 months ago

ghost commented 8 months ago

Can we remove the scale field and instead bind the orthographic camera's scale to radius, as shown in the code below? This would make it easier to switch between perspective and orthographic cameras. If there are no issues, I will submit a PR.

pub fn update_orbit_transform(
    alpha: f32,
    beta: f32,
    mut radius: f32,
    focus: Vec3,
    transform: &mut Transform,
    projection: &mut Projection,
    basis: &Transform,
) {
    let mut new_transform = *basis;
    if let Projection::Orthographic(ref mut p) = *projection {
        p.scale = radius;
        // (near + far) / 2.0 ensures that objects near `focus` are not clipped
        radius = (p.near + p.far) / 2.0;
    }
    new_transform.rotation *= Quat::from_rotation_y(alpha) * Quat::from_rotation_x(-beta);
    new_transform.translation += focus + new_transform.rotation * Vec3::new(0.0, 0.0, radius);
    *transform = new_transform;
}