refactor: minor code refactor so it looks slightly better

This commit is contained in:
dusk 2024-09-29 04:27:36 +03:00
parent 8c88cf9cac
commit 742dc85414
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
4 changed files with 8 additions and 9 deletions

View File

@ -83,9 +83,9 @@ impl Boid for Boid2D {
#[inline(always)]
fn apply_force(&mut self, force: Vec3) {
self.vel += force.xy();
let new_vel = self.vel.clamp_length_max(self.props.max_speed);
self.vel = new_vel;
self.base_mut().translate(Vector2::new(new_vel.x, new_vel.y));
self.vel = self.vel.clamp_length_max(self.props.max_speed);
let force_to_apply = Vector2::new(self.vel.x, self.vel.y);
self.base_mut().translate(force_to_apply);
}
#[inline(always)]

View File

@ -82,10 +82,9 @@ impl Boid for Boid3D {
#[inline(always)]
fn apply_force(&mut self, force: Vec3) {
self.vel += force;
let new_vel = self.vel.clamp_length_max(self.props.max_speed);
self.vel = new_vel;
self.base_mut()
.translate(Vector3::new(new_vel.x, new_vel.y, new_vel.z));
self.vel = self.vel.clamp_length_max(self.props.max_speed);
let force_to_apply = Vector3::new(self.vel.x, self.vel.y, self.vel.z);
self.base_mut().translate(force_to_apply);
}
#[inline(always)]