From 1881ee2b1637a4a9c596fc29f3381058e7a8e23e Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 22 Nov 2023 04:37:55 -0800 Subject: [PATCH] dynamic objects --- src/main.rs | 1 + src/world.rs | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/world.rs diff --git a/src/main.rs b/src/main.rs index 1220d33..edc4c22 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod bvh; mod aabb; mod model; mod setup; +mod world; mod window; mod worker; mod zeroes; diff --git a/src/world.rs b/src/world.rs new file mode 100644 index 0000000..2a40a83 --- /dev/null +++ b/src/world.rs @@ -0,0 +1,69 @@ +use crate::integer::{Time,Planar64Vec3}; +use crate::instruction::TimedInstruction; + +/// A C0 continuous trajectory change. +enum TrajectoryC0{ + TargetPointFuture(Planar64Vec3,Time), + TargetVelocityFuture(Planar64Vec3,Time), + UseAcceleration(Planar64Vec3), +} + +/// A C1 continuous trajectory change. +enum TrajectoryC1{ + TargetPointVelocityFuture(Planar64Vec3,Planar64Vec3,Time), + UseVelocityAcceleration(Planar64Vec3,Planar64Vec3), + TargetPointAcceleration(Planar64Vec3,Planar64Vec3), +} + +struct Trajectory{ + position:Planar64Vec3, + velocity:Planar64Vec3, + acceleration:Planar64Vec3, +} +impl Trajectory{ + pub fn into_body(self,time:Time)->crate::physics::Body{ + crate::physics::Body::new(self.position,self.velocity,self.acceleration,time) + } +} + +//literally option... Option> doesn't seem ergonomic but is effectively what's needed +enum Edit{ + Change(T), + Unchanged, +} + +/// Each property is specified as either changed or staying the same +struct EditAttributes{} +struct EditStyleModifiers{} + +enum Instruction{ + /// Keep Position, edit Velocity and Acceleration + ContinueTrajectoryC0(TrajectoryC0), + /// Keep Position and Velocity, edit acceleration + ContinueTrajectoryC1(TrajectoryC1), + /// Teleport to a new Position, Velocity, and Acceleration + NewTrajectory(Trajectory), + /// Change the object transform (teleport) This is also how the object must rotate! + EditTransform(crate::integer::Planar64Affine3), + /// Change specific attributes + EditAttributes(EditAttributes), + /// Change specific style modifiers + EditStyleModifiers(EditStyleModifiers), +} + +// The moving platform script init function returns this object's initial state +struct Dynamic{ + /// somehow allow a mutable state function to control the whole thing + pub next_instruction:Option>, + pub update:Box)->Option>>, +} +impl crate::instruction::InstructionEmitter for Dynamic{ + fn next_instruction(&self,time_limit:Time)->Option>{ + self.next_instruction + } +} +impl crate::instruction::InstructionConsumer for Dynamic{ + fn process_instruction(&mut self,instruction:TimedInstruction){ + self.next_instruction=(self.update)(instruction); + } +} \ No newline at end of file