Class: BulldogPhysics::Particles::Collisions::ParticleContact

Inherits:
Object
  • Object
show all
Defined in:
lib/Particles/particle_contact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(particle1, particle2 = nil, contact_normal = Vector3.new(0,1,0), penetration = 0) ⇒ ParticleContact

Returns a new instance of ParticleContact.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/Particles/particle_contact.rb', line 13

def initialize(particle1, particle2 = nil, contact_normal = Vector3.new(0,1,0), penetration = 0)
  @particle1 = particle1
  @particle2 = particle2
  @penetration = penetration
  @contact_normal = contact_normal
  unless @particle2.nil?
    @contact_normal = (@particle1.position - @particle2.position).unit
    #@penetration = (@particle1.position - @particle2.position).magnitude.abs - (@particle1.radius + @particle2.radius)
    #puts "PENETRATION #{@penetration}"
  end
  @restitution = 0.0
end

Instance Attribute Details

#contact_normalObject

Returns the value of attribute contact_normal.



10
11
12
# File 'lib/Particles/particle_contact.rb', line 10

def contact_normal
  @contact_normal
end

#particle1Object

Returns the value of attribute particle1.



7
8
9
# File 'lib/Particles/particle_contact.rb', line 7

def particle1
  @particle1
end

#particle2Object

Returns the value of attribute particle2.



8
9
10
# File 'lib/Particles/particle_contact.rb', line 8

def particle2
  @particle2
end

#penetrationObject

Returns the value of attribute penetration.



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

def penetration
  @penetration
end

#restitutionObject

Returns the value of attribute restitution.



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

def restitution
  @restitution
end

Instance Method Details

#calculate_separating_velocityObject



31
32
33
34
35
36
37
# File 'lib/Particles/particle_contact.rb', line 31

def calculate_separating_velocity
  relative_velocity = @particle1.velocity.dup
  unless @particle2.nil?
    relative_velocity -= @particle2.velocity
  end
  return relative_velocity * @contact_normal
end

#resolve(duration) ⇒ Object



26
27
28
29
# File 'lib/Particles/particle_contact.rb', line 26

def resolve(duration)
  resolve_velocity(duration)
  resolve_interpenetration(duration)
end