33
src/agent.rs
33
src/agent.rs
@@ -41,44 +41,19 @@ impl Agent {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_from_table(i: f32, table: &Vec<f32>) -> f32 {
|
||||
let interval: f32 = 1.0/0.01;
|
||||
|
||||
let i_proc = (i * interval).round()+(360.0*interval);
|
||||
let output = table[i_proc as usize];
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
// Tick an agent
|
||||
#[inline]
|
||||
pub fn tick(&mut self, buf: &Buf, sensor_distance: f32, sensor_angle: f32, rotation_angle: f32, step_distance: f32, width: usize, height: usize, sin_table: &Vec<f32>, cos_table: &Vec<f32>) {
|
||||
/*
|
||||
pub fn tick(&mut self, buf: &Buf, sensor_distance: f32, sensor_angle: f32, rotation_angle: f32, step_distance: f32, width: usize, height: usize) {
|
||||
let xc = self.x + cos(self.angle) * sensor_distance;
|
||||
let yc = self.y + sin(self.angle) * sensor_distance;
|
||||
*/
|
||||
|
||||
// /*
|
||||
let xc = self.x + Self::get_from_table(self.angle, &cos_table) * sensor_distance;
|
||||
let yc = self.y + Self::get_from_table(self.angle, &sin_table) * sensor_distance;
|
||||
// */
|
||||
|
||||
let agent_add_sens = self.angle + sensor_angle;
|
||||
let agent_sub_sens = self.angle - sensor_angle;
|
||||
|
||||
// /*
|
||||
let xl = self.x + Self::get_from_table(agent_sub_sens, &cos_table) * sensor_distance;
|
||||
let yl = self.y + Self::get_from_table(agent_sub_sens, &sin_table) * sensor_distance;
|
||||
let xr = self.x + Self::get_from_table(agent_add_sens, &cos_table) * sensor_distance;
|
||||
let yr = self.y + Self::get_from_table(agent_add_sens, &sin_table) * sensor_distance;
|
||||
// */
|
||||
|
||||
/*
|
||||
let xl = self.x + cos(agent_sub_sens) * sensor_distance;
|
||||
let yl = self.y + sin(agent_sub_sens) * sensor_distance;
|
||||
let xr = self.x + cos(agent_add_sens) * sensor_distance;
|
||||
let yr = self.y + sin(agent_add_sens) * sensor_distance;
|
||||
*/
|
||||
|
||||
// We sense from the buffer because this is where we previously combined data from all the grid.
|
||||
let center = buf.get_buf(xc, yc);
|
||||
@@ -103,13 +78,11 @@ impl Agent {
|
||||
|
||||
self.angle = wrap(self.angle + delta_angle, TAU);
|
||||
self.x = wrap(
|
||||
// self.x + step_distance * cos(self.angle),
|
||||
self.x + step_distance * Self::get_from_table(self.angle, &cos_table),
|
||||
self.x + step_distance * cos(self.angle),
|
||||
width as f32,
|
||||
);
|
||||
self.y = wrap(
|
||||
// self.y + step_distance * sin(self.angle),
|
||||
self.y + step_distance * Self::get_from_table(self.angle, &sin_table),
|
||||
self.y + step_distance * sin(self.angle),
|
||||
height as f32,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user