Class: BulldogPhysics::Particles::Collisions::ParticleRod

Inherits:
ParticleLink show all
Defined in:
lib/Particles/particle_rod.rb

Overview

Cables link a pair of particles, generating a contact if they stray too far apart.

Instance Attribute Summary collapse

Attributes inherited from ParticleLink

#particle1, #particle2

Instance Method Summary collapse

Constructor Details

#initialize(particle1, particle2, length) ⇒ ParticleRod

Returns a new instance of ParticleRod.



14
15
16
17
18
# File 'lib/Particles/particle_rod.rb', line 14

def initialize(particle1, particle2, length)
  super(particle1, particle2)
  @length = length
  puts "CREATING ROD WITH LENGTH #{@length}"
end

Instance Attribute Details

#lengthObject

Holds the length of the rod



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

def length
  @length
end

Instance Method Details

#add_contact(contactArray, limit) ⇒ Object

  • Fills the given contact structure with the contact needed to keep the rod from extending or compressing.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/Particles/particle_rod.rb', line 21

def add_contact(contactArray, limit)
  current_len = current_length

  if( current_len == @length)
    return 0
  end
  
  
  contact = ParticleContact.new(@particle1, @particle2)
  
  normal = @particle2.position - @particle1.position
  normal.normalize
  # The contact normal depends on whether we’re extending or compressing.
  
  contact.contact_normal = normal

  if( current_len > @length)
    contact.penetration = (current_len - @length)
  else
    contact.contact_normal *= -1
    contact.penetration = @length - current_len
  end

  contact.restitution = 0
  contactArray << contact
  
  return 1
end

#current_lengthObject



50
51
52
# File 'lib/Particles/particle_rod.rb', line 50

def current_length
  (@particle1.position - @particle2.position).magnitude
end