Class: BulldogPhysics::ForceRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/RigidBodies/force_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeForceRegistry

Returns a new instance of ForceRegistry.



7
8
9
# File 'lib/RigidBodies/force_registry.rb', line 7

def initialize()
  @registrations = Array.new # array of ParticleForceRegistration(s)
end

Instance Attribute Details

#registrationsObject

Returns the value of attribute registrations.



5
6
7
# File 'lib/RigidBodies/force_registry.rb', line 5

def registrations
  @registrations
end

Instance Method Details

#add(body, force_generator) ⇒ Object

Registers the given force generator to apply to the given particle.



13
14
15
16
17
18
19
# File 'lib/RigidBodies/force_registry.rb', line 13

def add(body, force_generator)
  body_registration = ForceRegistration.new
  body_registration.body = body
  body_registration.force_generator = force_generator
  @registrations << body_registration
  puts "Registration count #{@registrations.count}"
end

#clearObject

Clears all registrations from the registry. This will not delete the particles or the force generators themselves, just the records of their connection.



34
35
36
# File 'lib/RigidBodies/force_registry.rb', line 34

def clear
  @registrations = Array.new
end

#remove(body, force_generator) ⇒ Object

Removes the given registered pair from the registry. If the pair is not registered, this method will have no effect.



25
26
27
28
29
# File 'lib/RigidBodies/force_registry.rb', line 25

def remove(body,force_generator)
  @registrations.remove_if do |registry|
    registry.body.eql? body and registry.force_generator.eql? force_generator
  end
end

#update_forces(duration) ⇒ Object

Calls all the force generators to update the forces of their corresponding particles.



41
42
43
44
45
# File 'lib/RigidBodies/force_registry.rb', line 41

def update_forces(duration)
  for registry in @registrations
    registry.force_generator.update_force(registry.body,duration)
  end
end