-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/target | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
**/*.rs.bk |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use bevy_transform::prelude::Transform; | ||
Check failure on line 1 in src/dolly/driver.rs GitHub Actions / Clippy
Check failure on line 1 in src/dolly/driver.rs GitHub Actions / Clippy
Check failure on line 1 in src/dolly/driver.rs GitHub Actions / Test Suite
|
||
|
||
//use crate::{handedness::Handedness, rig::RigUpdateParams, transform::Transform}; | ||
use crate::dolly::rig::RigUpdateParams; | ||
|
||
pub trait RigDriverTraits: RigDriver + Sync + Send + std::any::Any + std::fmt::Debug { | ||
/// Returns `self` as `&dyn Any` | ||
fn as_any(&self) -> &dyn std::any::Any; | ||
|
||
/// Returns `self` as `&mut dyn Any` | ||
fn as_any_mut(&mut self) -> &mut dyn std::any::Any; | ||
} | ||
|
||
pub trait RigDriver: std::any::Any + std::fmt::Debug { | ||
/// Calculates the transform of this driver component based on the parent | ||
/// provided in `params`. | ||
fn update(&mut self, params: RigUpdateParams) -> Transform; | ||
} | ||
|
||
impl<T> RigDriverTraits for T | ||
where | ||
T: RigDriver + std::any::Any + Sync + Send + std::fmt::Debug, | ||
{ | ||
fn as_any(&self) -> &dyn std::any::Any { | ||
self | ||
} | ||
|
||
fn as_any_mut(&mut self) -> &mut dyn std::any::Any { | ||
self | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//use std::marker::PhantomData; | ||
|
||
//use glam::Vec3; | ||
use bevy_math::Vec3; | ||
Check failure on line 4 in src/dolly/drivers/arm.rs GitHub Actions / Clippy
Check failure on line 4 in src/dolly/drivers/arm.rs GitHub Actions / Clippy
Check failure on line 4 in src/dolly/drivers/arm.rs GitHub Actions / Test Suite
|
||
use bevy_transform::prelude::Transform; | ||
Check failure on line 5 in src/dolly/drivers/arm.rs GitHub Actions / Clippy
Check failure on line 5 in src/dolly/drivers/arm.rs GitHub Actions / Clippy
Check failure on line 5 in src/dolly/drivers/arm.rs GitHub Actions / Test Suite
|
||
|
||
use crate::dolly::{ | ||
driver::RigDriver, | ||
//handedness::Handedness, | ||
rig::RigUpdateParams, | ||
//transform::Transform, | ||
}; | ||
|
||
/// Offsets the camera along a vector, in the coordinate space of the parent. | ||
#[derive(Debug)] | ||
pub struct Arm { | ||
/// | ||
pub offset: Vec3, | ||
} | ||
|
||
impl Arm { | ||
/// | ||
pub fn new(offset: Vec3) -> Self { | ||
Self { offset } | ||
} | ||
} | ||
|
||
impl RigDriver for Arm { | ||
fn update(&mut self, params: RigUpdateParams) -> Transform { | ||
Transform { | ||
translation: params.parent.translation + params.parent.rotation * self.offset, | ||
rotation: params.parent.rotation, | ||
scale: Vec3::ONE, | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//use std::marker::PhantomData; | ||
|
||
use bevy_transform::prelude::Transform; | ||
Check failure on line 3 in src/dolly/drivers/lock_position.rs GitHub Actions / Clippy
Check failure on line 3 in src/dolly/drivers/lock_position.rs GitHub Actions / Clippy
Check failure on line 3 in src/dolly/drivers/lock_position.rs GitHub Actions / Test Suite
|
||
|
||
use crate::dolly::{ | ||
driver::RigDriver, | ||
//handedness::Handedness, | ||
rig::RigUpdateParams, | ||
//transform::Transform, | ||
}; | ||
|
||
/// Locks/constrains the position of the camera to one or more axes | ||
#[derive(Debug)] | ||
pub struct LockPosition { | ||
x: Option<f32>, | ||
y: Option<f32>, | ||
z: Option<f32>, | ||
} | ||
|
||
impl LockPosition { | ||
pub fn new() -> Self { | ||
Self { | ||
x: None, | ||
y: None, | ||
z: None, | ||
} | ||
} | ||
pub fn from(x: Option<f32>, y: Option<f32>, z: Option<f32>) -> Self { | ||
Self { x, y, z } | ||
} | ||
pub fn x(&self, x: f32) -> Self { | ||
Self { | ||
x: Some(x), | ||
y: self.y, | ||
z: self.z, | ||
} | ||
} | ||
pub fn y(&self, y: f32) -> Self { | ||
Self { | ||
x: self.x, | ||
y: Some(y), | ||
z: self.z, | ||
} | ||
} | ||
pub fn z(&self, z: f32) -> Self { | ||
Self { | ||
x: self.x, | ||
y: self.y, | ||
z: Some(z), | ||
} | ||
} | ||
} | ||
|
||
impl Default for LockPosition { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl RigDriver for LockPosition { | ||
fn update(&mut self, params: RigUpdateParams) -> Transform { | ||
let mut delta_pos = params.parent.translation; | ||
delta_pos.x = self.x.unwrap_or(delta_pos.x); | ||
delta_pos.y = self.y.unwrap_or(delta_pos.y); | ||
delta_pos.z = self.z.unwrap_or(delta_pos.z); | ||
Transform { | ||
translation: delta_pos, | ||
rotation: params.parent.rotation, | ||
..Default::default() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
//use std::marker::PhantomData; | ||
|
||
//use glam::Vec3; | ||
use bevy_math::Vec3; | ||
Check failure on line 4 in src/dolly/drivers/look_at.rs GitHub Actions / Clippy
Check failure on line 4 in src/dolly/drivers/look_at.rs GitHub Actions / Clippy
Check failure on line 4 in src/dolly/drivers/look_at.rs GitHub Actions / Test Suite
|
||
use bevy_transform::prelude::Transform; | ||
Check failure on line 5 in src/dolly/drivers/look_at.rs GitHub Actions / Clippy
Check failure on line 5 in src/dolly/drivers/look_at.rs GitHub Actions / Clippy
Check failure on line 5 in src/dolly/drivers/look_at.rs GitHub Actions / Test Suite
|
||
|
||
use crate::dolly::{ | ||
driver::RigDriver, | ||
//handedness::Handedness, | ||
rig::RigUpdateParams, | ||
//transform::Transform, | ||
util::{ | ||
//look_at, | ||
ExpSmoothed, | ||
ExpSmoothingParams, | ||
}, | ||
}; | ||
|
||
/// Rotates the camera to point at a world-space position. | ||
/// | ||
/// The target tracking can be additionally smoothed, and made to look ahead of it. | ||
#[derive(Debug)] | ||
pub struct LookAt { | ||
/// Exponential smoothing factor | ||
pub smoothness: f32, | ||
|
||
/// The world-space position to look at | ||
pub target: Vec3, | ||
|
||
// The scale with which smoothing should be applied to the target position | ||
output_offset_scale: f32, | ||
|
||
smoothed_target: ExpSmoothed<Vec3>, | ||
} | ||
|
||
impl LookAt { | ||
/// | ||
pub fn new(target: Vec3) -> Self { | ||
Self { | ||
smoothness: 0.0, | ||
output_offset_scale: 1.0, | ||
target, | ||
smoothed_target: Default::default(), | ||
} | ||
} | ||
|
||
/// Set the exponential smoothing factor for target position tracking. | ||
pub fn tracking_smoothness(mut self, smoothness: f32) -> Self { | ||
self.smoothness = smoothness; | ||
self | ||
} | ||
|
||
/// Reverse target position smoothing, causing the camera to look ahead of it. | ||
/// This can then be chained with [`Smooth`], to create | ||
/// a camera that smoothly follows an object, but doesn't lag far behind it. | ||
/// | ||
/// [`Smooth`]: struct.Smooth.html | ||
pub fn tracking_predictive(mut self, predictive: bool) -> Self { | ||
self.output_offset_scale = if predictive { -1.0 } else { 1.0 }; | ||
self | ||
} | ||
} | ||
|
||
impl RigDriver for LookAt { | ||
fn update(&mut self, params: RigUpdateParams) -> Transform { | ||
let target = self.smoothed_target.exp_smooth_towards( | ||
&self.target, | ||
ExpSmoothingParams { | ||
smoothness: self.smoothness, | ||
output_offset_scale: self.output_offset_scale, | ||
delta_time_seconds: params.delta_time_seconds, | ||
}, | ||
); | ||
|
||
let rotation = params.parent.looking_at(target, Vec3::Y).rotation; | ||
|
||
Transform { | ||
translation: params.parent.translation, | ||
rotation, | ||
..Default::default() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
mod arm; | ||
mod lock_position; | ||
mod look_at; | ||
mod position; | ||
mod rotation; | ||
mod smooth; | ||
mod yaw_pitch; | ||
|
||
pub use self::{ | ||
arm::*, lock_position::*, look_at::*, position::*, rotation::*, smooth::*, yaw_pitch::*, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//use std::marker::PhantomData; | ||
|
||
//use glam::Vec3; | ||
use bevy_math::Vec3; | ||
Check failure on line 4 in src/dolly/drivers/position.rs GitHub Actions / Clippy
Check failure on line 4 in src/dolly/drivers/position.rs GitHub Actions / Clippy
Check failure on line 4 in src/dolly/drivers/position.rs GitHub Actions / Test Suite
|
||
use bevy_transform::prelude::Transform; | ||
Check failure on line 5 in src/dolly/drivers/position.rs GitHub Actions / Clippy
Check failure on line 5 in src/dolly/drivers/position.rs GitHub Actions / Clippy
Check failure on line 5 in src/dolly/drivers/position.rs GitHub Actions / Test Suite
|
||
|
||
use crate::dolly::{driver::RigDriver, rig::RigUpdateParams}; | ||
|
||
/* | ||
use crate::{ | ||
driver::RigDriver, handedness::Handedness, rig::RigUpdateParams, transform::Transform, | ||
}; | ||
*/ | ||
|
||
/// Directly sets the position of the camera | ||
#[derive(Default, Debug)] | ||
pub struct Position { | ||
pub position: Vec3, | ||
} | ||
|
||
impl Position { | ||
/// | ||
pub fn new(position: Vec3) -> Self { | ||
Self { position } | ||
} | ||
|
||
/// Add the specified vector to the position of this component | ||
pub fn translate(&mut self, move_vec: Vec3) { | ||
self.position += move_vec; | ||
} | ||
} | ||
|
||
impl RigDriver for Position { | ||
fn update(&mut self, params: RigUpdateParams) -> Transform { | ||
Transform { | ||
translation: self.position, | ||
rotation: params.parent.rotation, | ||
scale: Vec3::ONE, | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//use std::marker::PhantomData; | ||
|
||
//use glam::Quat; | ||
use bevy_math::{Quat, Vec3}; | ||
Check failure on line 4 in src/dolly/drivers/rotation.rs GitHub Actions / Clippy
Check failure on line 4 in src/dolly/drivers/rotation.rs GitHub Actions / Clippy
Check failure on line 4 in src/dolly/drivers/rotation.rs GitHub Actions / Test Suite
|
||
use bevy_transform::prelude::Transform; | ||
Check failure on line 5 in src/dolly/drivers/rotation.rs GitHub Actions / Clippy
Check failure on line 5 in src/dolly/drivers/rotation.rs GitHub Actions / Clippy
Check failure on line 5 in src/dolly/drivers/rotation.rs GitHub Actions / Test Suite
|
||
|
||
use crate::dolly::{driver::RigDriver, rig::RigUpdateParams}; | ||
|
||
/* | ||
use crate::{ | ||
driver::RigDriver, handedness::Handedness, rig::RigUpdateParams, transform::Transform, | ||
}; | ||
*/ | ||
|
||
/// Directly sets the rotation of the camera | ||
#[derive(Default, Debug)] | ||
pub struct Rotation { | ||
pub rotation: Quat, | ||
} | ||
|
||
impl Rotation { | ||
pub fn new(rotation: Quat) -> Self { | ||
Self { rotation } | ||
} | ||
} | ||
|
||
impl RigDriver for Rotation { | ||
fn update(&mut self, params: RigUpdateParams) -> Transform { | ||
Transform { | ||
translation: params.parent.translation, | ||
rotation: self.rotation, | ||
scale: Vec3::ONE, | ||
} | ||
} | ||
} |