Class: BulldogPhysics::Particles::Particle
- Inherits:
-
Object
- Object
- BulldogPhysics::Particles::Particle
- Defined in:
- lib/Particles/particle.rb
Instance Attribute Summary collapse
-
#acceleration ⇒ Object
Returns the value of attribute acceleration.
-
#damping ⇒ Object
Returns the value of attribute damping.
-
#force_accum ⇒ Object
Returns the value of attribute force_accum.
-
#frozen ⇒ Object
Returns the value of attribute frozen.
-
#mass ⇒ Object
Returns the value of attribute mass.
-
#material ⇒ Object
Returns the value of attribute material.
-
#position ⇒ Object
Returns the value of attribute position.
-
#radius ⇒ Object
Returns the value of attribute radius.
-
#velocity ⇒ Object
Returns the value of attribute velocity.
Instance Method Summary collapse
- #addForce(forceVector3) ⇒ Object
- #clearAccumulator ⇒ Object
- #has_infinite_mass ⇒ Object
-
#initialize ⇒ Particle
constructor
A new instance of Particle.
- #integrate(duration) ⇒ Object
- #inverse_mass ⇒ Object
Constructor Details
#initialize ⇒ Particle
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
#acceleration ⇒ Object
Returns the value of attribute acceleration.
6 7 8 |
# File 'lib/Particles/particle.rb', line 6 def acceleration @acceleration end |
#damping ⇒ Object
Returns the value of attribute damping.
6 7 8 |
# File 'lib/Particles/particle.rb', line 6 def damping @damping end |
#force_accum ⇒ Object
Returns the value of attribute force_accum.
6 7 8 |
# File 'lib/Particles/particle.rb', line 6 def force_accum @force_accum end |
#frozen ⇒ Object
Returns the value of attribute frozen.
6 7 8 |
# File 'lib/Particles/particle.rb', line 6 def frozen @frozen end |
#mass ⇒ Object
Returns the value of attribute mass.
6 7 8 |
# File 'lib/Particles/particle.rb', line 6 def mass @mass end |
#material ⇒ Object
Returns the value of attribute material.
6 7 8 |
# File 'lib/Particles/particle.rb', line 6 def material @material end |
#position ⇒ Object
Returns the value of attribute position.
6 7 8 |
# File 'lib/Particles/particle.rb', line 6 def position @position end |
#radius ⇒ Object
Returns the value of attribute radius.
6 7 8 |
# File 'lib/Particles/particle.rb', line 6 def radius @radius end |
#velocity ⇒ Object
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 |
#clearAccumulator ⇒ Object
64 65 66 |
# File 'lib/Particles/particle.rb', line 64 def clearAccumulator @force_accum.clear(); end |
#has_infinite_mass ⇒ Object
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_mass ⇒ Object
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 |