summaryrefslogtreecommitdiffhomepage
path: root/lib/02-apply_boid_calculations.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-08-09 09:15:38 -0400
committerrealtradam <[email protected]>2021-08-09 09:15:38 -0400
commit501ec02e894865836f2960b0bbc16b3448e3707f (patch)
treead2c1124e5ab5807dea1b11002cc5bf2df1226d9 /lib/02-apply_boid_calculations.rb
parent4e909c6b44794b76ef3a98c032ea90204b673f85 (diff)
downloadruboids-501ec02e894865836f2960b0bbc16b3448e3707f.tar.gz
ruboids-501ec02e894865836f2960b0bbc16b3448e3707f.zip
ruboids!
Diffstat (limited to 'lib/02-apply_boid_calculations.rb')
-rw-r--r--lib/02-apply_boid_calculations.rb48
1 files changed, 40 insertions, 8 deletions
diff --git a/lib/02-apply_boid_calculations.rb b/lib/02-apply_boid_calculations.rb
index 250a394..8b84ab5 100644
--- a/lib/02-apply_boid_calculations.rb
+++ b/lib/02-apply_boid_calculations.rb
@@ -1,15 +1,47 @@
-FF::Scn::BoidCalculations.add(FF::Sys.new('ApplyBoidCalculations', priority: 51) do
+FF::Scn::BoidCalculations.add(FF::Sys.new('ApplyBoidCalculations', priority: 75) do
+ @center ||= Camera::Circle.new(color: [0.25,0.0,0.5,0.5],
+ radius: 10,
+ sectors: 10,
+ z: -49)
+ @center_vel ||= Camera::Line.new(color: [0.25,0.0,0.5,0.5],
+ width: 12,
+ z: -50)
+ unless $config.debug
+ @center.remove
+ @center_vel.remove
+ end
+
+ group_velocity = [0.0,0.0]
+ center_mass = [0.0,0.0]
+ boids_count = FF::Cmp::Boids.each.to_a.count
+
FF::Cmp::Boids.each do |boid|
boid.vx += boid.cx
boid.vy += boid.cy
+ FF::Sys::Limit.call
boid.x += boid.vx
boid.y += boid.vy
- #boid.obj.x = boid.obj.x
- #boid.vect.x1 = boid.obj.x + 7
- #boid.vect.y1 = boid.obj.y + 7
- #boid.vect.x2 = boid.obj.x + (boid.vx * 3) + 7
- #boid.vect.y2 = boid.obj.y + (boid.vy * 3) + 7
- boid.cx = 0
- boid.cy = 0
+
+ boid.cx = 0.0
+ boid.cy = 0.0
+
+
+ center_mass[0] += boid.x
+ center_mass[1] += boid.y
+ group_velocity[0] += boid.vx
+ group_velocity[1] += boid.vy
+ end
+
+ @center_vel.x1 = @center.x = (center_mass[0] / boids_count)
+ @center_vel.y1 = @center.y = (center_mass[1] / boids_count)
+
+ @center_vel.x1 += @center.radius
+ @center_vel.y1 += @center.radius
+
+ if $follow
+ Camera.x = @center_vel.x1 = @center.x + @center.radius
+ Camera.y = @center_vel.y1 = @center.y + @center.radius
end
+ @center_vel.x2 = @center_vel.x1 + ((group_velocity[0] / boids_count) * 10.0)
+ @center_vel.y2 = @center_vel.y1 + ((group_velocity[1] / boids_count) * 10.0)
end)