Agent: angle -> heading
This commit is contained in:
parent
b4e2390690
commit
4330101b68
18
src/agent.rs
18
src/agent.rs
@ -9,7 +9,7 @@ use std::fmt::{Display, Formatter};
|
|||||||
pub struct Agent {
|
pub struct Agent {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
pub y: f32,
|
pub y: f32,
|
||||||
angle: f32,
|
heading: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Agent {
|
impl Display for Agent {
|
||||||
@ -25,7 +25,7 @@ impl Agent {
|
|||||||
Agent {
|
Agent {
|
||||||
x: x * width as f32,
|
x: x * width as f32,
|
||||||
y: y * height as f32,
|
y: y * height as f32,
|
||||||
angle: angle * TAU,
|
heading: angle * TAU,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,11 +40,11 @@ impl Agent {
|
|||||||
width: usize,
|
width: usize,
|
||||||
height: usize,
|
height: usize,
|
||||||
) {
|
) {
|
||||||
let xc = self.x + cos(self.angle) * sensor_distance;
|
let xc = self.x + cos(self.heading) * sensor_distance;
|
||||||
let yc = self.y + sin(self.angle) * sensor_distance;
|
let yc = self.y + sin(self.heading) * sensor_distance;
|
||||||
|
|
||||||
let agent_add_sens = self.angle + sensor_angle;
|
let agent_add_sens = self.heading + sensor_angle;
|
||||||
let agent_sub_sens = self.angle - sensor_angle;
|
let agent_sub_sens = self.heading - sensor_angle;
|
||||||
|
|
||||||
let xl = self.x + cos(agent_sub_sens) * sensor_distance;
|
let xl = self.x + cos(agent_sub_sens) * sensor_distance;
|
||||||
let yl = self.y + sin(agent_sub_sens) * sensor_distance;
|
let yl = self.y + sin(agent_sub_sens) * sensor_distance;
|
||||||
@ -73,8 +73,8 @@ impl Agent {
|
|||||||
|
|
||||||
let delta_angle = rotation_angle * direction;
|
let delta_angle = rotation_angle * direction;
|
||||||
|
|
||||||
self.angle = wrap(self.angle + delta_angle, TAU);
|
self.heading = wrap(self.heading + delta_angle, TAU);
|
||||||
self.x = wrap(self.x + step_distance * cos(self.angle), width as f32);
|
self.x = wrap(self.x + step_distance * cos(self.heading), width as f32);
|
||||||
self.y = wrap(self.y + step_distance * sin(self.angle), height as f32);
|
self.y = wrap(self.y + step_distance * sin(self.heading), height as f32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user