Class: BulldogPhysics::Particles::Collisions::ParticleParticleContacts

Inherits:
ParticleContactGenerator show all
Defined in:
lib/Particles/particle_particle_contacts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(particles) ⇒ ParticleParticleContacts

Returns a new instance of ParticleParticleContacts.



11
12
13
# File 'lib/Particles/particle_particle_contacts.rb', line 11

def initialize(particles)
  @particles = particles
end

Instance Attribute Details

#particlesObject (readonly)

Returns the value of attribute particles.



9
10
11
# File 'lib/Particles/particle_particle_contacts.rb', line 9

def particles
  @particles
end

Instance Method Details

#add_contact(contactArray, limit) ⇒ Object



15
16
17
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_particle_contacts.rb', line 15

def add_contact(contactArray, limit)

  count = 0
  @particles.each do |p|


    other_particles = @particles.select{|x| x.object_id != p.object_id}
    other_particles.each do |other|
      
      if (p.position - other.position).magnitude < (p.radius + other.radius)
        contact = ParticleContact.new(p, other)
        contact.penetration = (p.position - other.position).magnitude - (p.radius + other.radius)
        contact.restitution = 0.5
        contactArray << contact
        count+=1
      end
    end


    if( count >= limit)
      return count
    end

  end

  return count

end