Class: BulldogPhysics::Particles::Collisions::ParticleCable
- Inherits:
-
ParticleLink
- Object
- ParticleContactGenerator
- ParticleLink
- BulldogPhysics::Particles::Collisions::ParticleCable
- Defined in:
- lib/Particles/particle_cable.rb
Overview
Cables link a pair of particles, generating a contact if they stray too far apart.
Instance Attribute Summary collapse
-
#max_length ⇒ Object
Holds the maximum length of the cable.
-
#restitution ⇒ Object
Holds the restitution (bounciness) of the cable.
Attributes inherited from ParticleLink
Instance Method Summary collapse
-
#add_contact(contactArray, limit) ⇒ Object
see ParticleLink for description.
- #current_length ⇒ Object
-
#initialize(particle1, particle2, max_length = 1.0, restitution = 1.0) ⇒ ParticleCable
constructor
A new instance of ParticleCable.
Constructor Details
#initialize(particle1, particle2, max_length = 1.0, restitution = 1.0) ⇒ ParticleCable
Returns a new instance of ParticleCable.
18 19 20 21 22 |
# File 'lib/Particles/particle_cable.rb', line 18 def initialize(particle1, particle2, max_length = 1.0, restitution = 1.0) super(particle1, particle2) @max_length = max_length @restitution = restitution end |
Instance Attribute Details
#max_length ⇒ Object
Holds the maximum length of the cable.
12 13 14 |
# File 'lib/Particles/particle_cable.rb', line 12 def max_length @max_length end |
#restitution ⇒ Object
Holds the restitution (bounciness) of the cable.
15 16 17 |
# File 'lib/Particles/particle_cable.rb', line 15 def restitution @restitution end |
Instance Method Details
#add_contact(contactArray, limit) ⇒ Object
see ParticleLink for description
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/Particles/particle_cable.rb', line 25 def add_contact(contactArray, limit) length = (@particle1.position - @particle2.position).magnitude if( length < @max_length) return 0 end contact = ParticleContact.new(@particle1, @particle2) contact.penetration = length - @max_length contact.restitution = @restitution contactArray << contact return 1 end |
#current_length ⇒ Object
43 44 45 |
# File 'lib/Particles/particle_cable.rb', line 43 def current_length (@particle1.position - @particle2.position).magnitude end |