Class: BulldogPhysics::Particles::Collisions::ParticleContactResolver
- Inherits:
-
Object
- Object
- BulldogPhysics::Particles::Collisions::ParticleContactResolver
- Defined in:
- lib/Particles/particle_contact_resolver.rb
Overview
The contact resolution routine for particle contacts. One resolver instance can be shared for the entire simulation.
Instance Attribute Summary collapse
-
#iterations ⇒ Object
Returns the value of attribute iterations.
-
#iterations_used ⇒ Object
Returns the value of attribute iterations_used.
Instance Method Summary collapse
-
#initialize(iters = 2) ⇒ ParticleContactResolver
constructor
A new instance of ParticleContactResolver.
- #resolve_contacts(contact_array, num_contacts, duration) ⇒ Object
Constructor Details
#initialize(iters = 2) ⇒ ParticleContactResolver
Returns a new instance of ParticleContactResolver.
13 14 15 16 |
# File 'lib/Particles/particle_contact_resolver.rb', line 13 def initialize(iters = 2) @iterations = iters @iterations_used = 0 end |
Instance Attribute Details
#iterations ⇒ Object
Returns the value of attribute iterations.
10 11 12 |
# File 'lib/Particles/particle_contact_resolver.rb', line 10 def iterations @iterations end |
#iterations_used ⇒ Object
Returns the value of attribute iterations_used.
11 12 13 |
# File 'lib/Particles/particle_contact_resolver.rb', line 11 def iterations_used @iterations_used end |
Instance Method Details
#resolve_contacts(contact_array, num_contacts, duration) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/Particles/particle_contact_resolver.rb', line 18 def resolve_contacts(contact_array, num_contacts, duration) max_index = num_contacts max = REAL_MAX @iterations_used = 0 while( @iterations_used < @iterations ) contact_array.each_with_index do |contact, i| sep_vel = contact. if( sep_vel < max && ( sep_vel < 0 || contact.penetration > 0) ) max = sep_vel max_index = i end end break if( max_index.eql? num_contacts) contact_array[max_index].resolve(duration) @iterations_used += 1 end # end while contact_array end |