fixed movement not wrapping around the world.. again
This commit is contained in:
@@ -12,7 +12,7 @@ layout(binding = 2) restrict buffer AgentBuffer {
|
||||
} agent_buffer;
|
||||
|
||||
layout(push_constant, std430) uniform Params {
|
||||
ivec2 texture_size;
|
||||
vec2 texture_size;
|
||||
float sensor_angle;
|
||||
float sensor_distance;
|
||||
} params;
|
||||
@@ -24,13 +24,7 @@ float random(vec2 coords) {
|
||||
}
|
||||
|
||||
vec2 loop_position(vec2 pos) {
|
||||
int width = params.texture_size.x;
|
||||
int height = params.texture_size.y;
|
||||
if (pos.x > width) pos.x = mod(pos.x, width);
|
||||
if (pos.y > height) pos.y = mod(pos.y, height);
|
||||
if (pos.x < 0) pos.x = width + pos.x;
|
||||
if (pos.y < 0) pos.y = height + pos.y;
|
||||
return pos;
|
||||
return mod(pos, params.texture_size);
|
||||
}
|
||||
|
||||
void main() {
|
||||
@@ -39,6 +33,8 @@ void main() {
|
||||
vec2 position = agent_buffer.positions[id];
|
||||
float heading = agent_buffer.headings[id];
|
||||
|
||||
float current_v = imageLoad(current_trail, ivec2(position)).r;
|
||||
|
||||
float sa = params.sensor_angle;
|
||||
float left_heading = heading - sa;
|
||||
float right_heading = heading + sa;
|
||||
@@ -64,17 +60,26 @@ void main() {
|
||||
} else if (right > forward && right > left) {
|
||||
pos += right_detect_dir * SPEED;
|
||||
new_heading = right_heading;
|
||||
} else if (forward < left && forward < right) {
|
||||
// uuugh
|
||||
float r = random(pos);
|
||||
if (r < 0.5) {
|
||||
pos += right_detect_dir * SPEED;
|
||||
new_heading = right_heading;
|
||||
} else {
|
||||
pos += left_detect_dir * SPEED;
|
||||
new_heading = left_heading;
|
||||
}
|
||||
} else {
|
||||
pos += forward_detect_dir * SPEED;
|
||||
}
|
||||
|
||||
pos = loop_position(pos);
|
||||
pos = mod(pos, params.texture_size);
|
||||
agent_buffer.positions[id] = pos;
|
||||
agent_buffer.headings[id] = new_heading;
|
||||
|
||||
float current_v = imageLoad(current_trail, ivec2(pos)).r;
|
||||
|
||||
float new_v = current_v + 0.3;
|
||||
if (new_v > 1.0) new_v = 1.0;
|
||||
|
||||
vec4 result = vec4(new_v, new_v, new_v, 1.0);
|
||||
imageStore(output_trail, ivec2(pos), result);
|
||||
|
||||
Reference in New Issue
Block a user