|
-
- #[derive(Clone)]
- pub(crate) struct Instruction {
- pub instr: InstructionType,
- pub start: f64,
- pub progress: f64,
- pub base: CameraData,
- // impl in instruction_parser.rs
- }
-
- #[derive(Clone)]
- pub(crate) enum InstructionType {
- Track {
- vector: Vector3,
- time: f64,
- },
- Move {
- vector: Vector3,
- },
- Rotate {
- vector: Vector3,
- time: f64,
- },
- Look {
- vector: Vector3,
- },
- Multi {
- instructions: Vec<InstructionType>,
- },
- }
-
- impl InstructionType {
- pub fn time(&self) -> f64 {
- match self {
- Self::Track {time, ..} => *time,
- Self::Move {..} => 0.0,
- Self::Rotate {time, ..} => *time,
- Self::Look {..} => 0.0,
- Self::Multi {instructions, ..} => {
- let mut max: f64 = 0.0;
- for i in instructions {
- if i.time() > max {
- max = i.time();
- }
- }
- max
- },
- }
- }
-
- pub fn lerp(&self, start: f64, now: f64) -> CameraData {
- let delta = now - start;
- let mut portion = 1.0;
- let time = self.time();
- if time > 0.0 && time < delta {
- portion = delta/self.time();
- }
- match self {
- Self::Track {vector, ..} => CameraData {rotation: Vector3::default(), position: *vector * portion},
- Self::Move {vector, ..} => CameraData {rotation: Vector3::default(), position: *vector},
- Self::Rotate {vector, ..} => CameraData {rotation: *vector * portion, position: Vector3::default()},
- Self::Look {vector, ..} => CameraData {rotation: *vector, position: Vector3::default()},
- Self::Multi {instructions, ..} => {
- let mut data = CameraData::default();
- for i in instructions {
- data += i.lerp(start, now);
- }
- data
- },
- }
- }
- }
-
- #[derive(Clone, Copy)]
- pub(crate) struct CameraData {
- pub rotation: Vector3,
- pub position: Vector3,
- }
-
- impl std::default::Default for CameraData {
- fn default() -> Self {
- Self {rotation: Vector3::default(), position: Vector3::default()}
- }
- }
-
- impl std::ops::Add for CameraData {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- Self {rotation: self.rotation + rhs.rotation, position: self.position + rhs.position}
- }
- }
-
- impl std::ops::AddAssign for CameraData {
- fn add_assign(&mut self, rhs: Self) {
- *self = *self + rhs;
- }
- }
-
- #[derive(Copy, Clone)]
- pub(crate) struct Vector3 {
- pub x: f64,
- pub y: f64,
- pub z: f64,
- }
-
- impl std::default::Default for Vector3 {
- fn default() -> Self {
- Self {x:0.0, y:0.0, z:0.0}
- }
- }
-
- impl std::ops::Mul<f64> for Vector3 {
- type Output = Self;
-
- fn mul(self, rhs: f64) -> Self {
- Self {
- x: self.x * rhs,
- y: self.y * rhs,
- z: self.z * rhs,
- }
- }
- }
-
- impl std::ops::Add for Vector3 {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- Self {x: self.x + rhs.x, y: self.y + rhs.y, z: self.z + rhs.z}
- }
- }
|