-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBehaviour__Flock.m
More file actions
26 lines (24 loc) · 902 Bytes
/
Behaviour__Flock.m
File metadata and controls
26 lines (24 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function Behaviour__Flock (vehicles,vNum)
%% global variables
global TimeSteps;
%% first draw
[v_Image,v_Alpha,VehiclesPlot,fHandler] = InitializeGraphics(vehicles,vNum);
%% calculate vehicles' positions to move to each iteration
timeTick = 1;
while (timeTick < TimeSteps)
for vhl = 1:vNum
% steering
boundaries_force = steer_boundaries(vehicles, vhl);
seperation_force = steer_seperation(vehicles, vhl, vNum);
alignment_force = steer_alignment(vehicles, vhl, vNum);
cohesion_force = steer_cohesion(vehicles, vhl, vNum);
% total force
force = seperation_force*1.5 + alignment_force*2 + cohesion_force*1 + boundaries_force;
% apply force (calculate new position)
vehicles = applyForce(vehicles, vhl, force);
end
% redraw
RedrawGraphics(vehicles,vNum,v_Image,v_Alpha,VehiclesPlot);
timeTick = timeTick+1;
end
end