From 70afc5a7d871919776a64782e8b93404e6b0defd Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 15 Dec 2024 13:17:43 +0100 Subject: feat!: add raylib rendering --- physics/src/constraint/slider.rs | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 physics/src/constraint/slider.rs (limited to 'physics/src/constraint/slider.rs') diff --git a/physics/src/constraint/slider.rs b/physics/src/constraint/slider.rs new file mode 100644 index 0000000..fa7e840 --- /dev/null +++ b/physics/src/constraint/slider.rs @@ -0,0 +1,47 @@ +use nalgebra::{DVector, RowDVector}; + +use crate::{ + algebra::{subspace::Line, Point, Scalar, Vector, N}, + particle_system::ParticleSystem, +}; + +use super::Constraint; + +pub struct SliderConstraint { + pub particle_id: usize, + + pub line: Line, + + jacobian: RowDVector, +} + +impl ParticleSystem { + pub fn add_slider_constraint(&mut self, particle_id: usize, direction: Vector) { + let point = self.particles[particle_id].position; + self.constraints.push(Box::new(SliderConstraint { + particle_id, + line: Line::new(point, [direction]), + jacobian: RowDVector::zeros(self.particles.len() * N), + })); + } +} + +impl Constraint for SliderConstraint { + fn get_particles(&self) -> Vec { + vec![self.particle_id] + } + + fn c(&self, q: &DVector) -> Scalar { + let position = q.fixed_rows::(self.particle_id * N); + let point = Point::from_coordinates(position.into()); + self.line.distance(point) + } + + fn set_jacobian(&mut self, jacobian: RowDVector) { + self.jacobian = jacobian + } + + fn jacobian_prev(&self) -> RowDVector { + self.jacobian.clone() + } +} -- cgit v1.2.3