Skip to content

Commit

Permalink
Merge pull request #7 from aevyrie/configurable-animation-curves
Browse files Browse the repository at this point in the history
Configurable animation curves
  • Loading branch information
aevyrie authored Jul 6, 2024
2 parents c18ce1a + bd47809 commit a3b7635
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_editor_cam"
version = "0.2.6"
version = "0.2.7"
edition = "2021"
description = "A camera controller for editors and CAD."
license = "MIT OR Apache-2.0"
Expand Down
7 changes: 6 additions & 1 deletion src/extensions/dolly_zoom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ struct ZoomEntry {
pub struct DollyZoom {
/// THe duration of the dolly zoom transition animation.
pub animation_duration: Duration,
/// The cubic curve used to animate the camera during a dolly zoom.
#[reflect(ignore)]
pub animation_curve: CubicSegment<Vec2>,
#[reflect(ignore)]
map: HashMap<Entity, ZoomEntry>,
}
Expand All @@ -151,6 +154,7 @@ impl Default for DollyZoom {
fn default() -> Self {
Self {
animation_duration: Duration::from_millis(200),
animation_curve: CubicSegment::new_bezier((0.25, 0.1), (0.25, 1.0)),
map: Default::default(),
}
}
Expand All @@ -163,6 +167,7 @@ impl DollyZoom {
mut redraw: EventWriter<RequestRedraw>,
) {
let animation_duration = state.animation_duration;
let animation_curve = state.animation_curve.clone();
for (
camera,
ZoomEntry {
Expand Down Expand Up @@ -197,7 +202,7 @@ impl DollyZoom {
Projection::Orthographic(_) => ZERO_FOV,
};
let progress = start.elapsed().as_secs_f32() / animation_duration.as_secs_f32();
let progress = CubicSegment::new_bezier((0.25, 0.1), (0.25, 1.0)).ease(progress);
let progress = animation_curve.ease(progress);
let next_fov = (1.0 - progress as f64) * fov_start + progress as f64 * fov_end;

let last_dist = *triangle_base / (last_fov / 2.0).tan();
Expand Down
10 changes: 8 additions & 2 deletions src/extensions/look_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ impl Plugin for LookToPlugin {
}
}

/// Triggers a rotation for the specified camera.
/// Send this event to rotate the camera about its anchor until it is looking in the given direction
/// with the given up direction. Animation speed is configured with the [`LookTo`] resource.
#[derive(Debug, Event)]
pub struct LookToTrigger {
/// The new direction to face.
Expand Down Expand Up @@ -144,6 +145,9 @@ struct LookToEntry {
pub struct LookTo {
/// The duration of the "look to" transition animation.
pub animation_duration: Duration,
/// The cubic curve used to animate the camera during a "look to".
#[reflect(ignore)]
pub animation_curve: CubicSegment<Vec2>,
#[reflect(ignore)]
map: HashMap<Entity, LookToEntry>,
}
Expand All @@ -152,6 +156,7 @@ impl Default for LookTo {
fn default() -> Self {
Self {
animation_duration: Duration::from_millis(400),
animation_curve: CubicSegment::new_bezier((0.25, 0.1), (0.25, 1.0)),
map: Default::default(),
}
}
Expand All @@ -164,6 +169,7 @@ impl LookTo {
mut redraw: EventWriter<RequestRedraw>,
) {
let animation_duration = state.animation_duration;
let animation_curve = state.animation_curve.clone();
for (
camera,
LookToEntry {
Expand All @@ -182,7 +188,7 @@ impl LookTo {
};
let progress_t =
(start.elapsed().as_secs_f32() / animation_duration.as_secs_f32()).clamp(0.0, 1.0);
let progress = CubicSegment::new_bezier((0.25, 0.1), (0.25, 1.0)).ease(progress_t);
let progress = animation_curve.ease(progress_t);

let rotate_around = |transform: &mut Transform, point: DVec3, rotation: DQuat| {
// Following lines are f64 versions of Transform::rotate_around
Expand Down

0 comments on commit a3b7635

Please sign in to comment.