Class: BulldogPhysics::Particles::Particle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParticle

Returns a new instance of Particle.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/Particles/particle.rb', line 9

def initialize()
  @position = Vector3.new
  @velocity = Vector3.new
  @acceleration = Vector3.new
  @force_accum = Vector3.new
  @mass = 0
  @damping = 0.0
  @material = Material.new
  @radius = 0.5
  @frozen = false
end

Instance Attribute Details

#accelerationObject

Returns the value of attribute acceleration.



6
7
8
# File 'lib/Particles/particle.rb', line 6

def acceleration
  @acceleration
end

#dampingObject

Returns the value of attribute damping.



6
7
8
# File 'lib/Particles/particle.rb', line 6

def damping
  @damping
end

#force_accumObject

Returns the value of attribute force_accum.



6
7
8
# File 'lib/Particles/particle.rb', line 6

def force_accum
  @force_accum
end

#frozenObject

Returns the value of attribute frozen.



6
7
8
# File 'lib/Particles/particle.rb', line 6

def frozen
  @frozen
end

#massObject

Returns the value of attribute mass.



6
7
8
# File 'lib/Particles/particle.rb', line 6

def mass
  @mass
end

#materialObject

Returns the value of attribute material.



6
7
8
# File 'lib/Particles/particle.rb', line 6

def material
  @material
end

#positionObject

Returns the value of attribute position.



6
7
8
# File 'lib/Particles/particle.rb', line 6

def position
  @position
end

#radiusObject

Returns the value of attribute radius.



6
7
8
# File 'lib/Particles/particle.rb', line 6

def radius
  @radius
end

#velocityObject

Returns the value of attribute velocity.



6
7
8
# File 'lib/Particles/particle.rb', line 6

def velocity
  @velocity
end

Instance Method Details

#addForce(forceVector3) ⇒ Object



60
61
62
# File 'lib/Particles/particle.rb', line 60

def addForce(forceVector3)
  @force_accum.addVector( forceVector3 )
end

#clearAccumulatorObject



64
65
66
# File 'lib/Particles/particle.rb', line 64

def clearAccumulator
  @force_accum.clear();
end

#has_infinite_massObject



68
69
70
# File 'lib/Particles/particle.rb', line 68

def has_infinite_mass
  @mass < 0
end

#integrate(duration) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/Particles/particle.rb', line 30

def integrate(duration)
  
  if @frozen
    clearAccumulator
    return
  end
  if(inverse_mass <= 0.0)
    return
  end
    
  if(duration < 0.0)
    raise Exception.new
  end
    
  @position.addScaledVector(@velocity, duration)
    
  resulting_acc = @acceleration.dup
  resulting_acc.addScaledVector(@force_accum, inverse_mass)
    
  @velocity.addScaledVector(resulting_acc, duration)
    
  unless @damping == 0.0
    modifier = @damping ** duration
    @velocity.multiplyByScalar( modifier )
  end
  

  clearAccumulator
end

#inverse_massObject



21
22
23
24
25
26
27
# File 'lib/Particles/particle.rb', line 21

def inverse_mass
  if @mass.eql? 0
    return 0
  else
    return 1.0 / @mass
  end
end