Class: Pongo::RimParticle
- Inherits:
-
Object
- Object
- Pongo::RimParticle
- Defined in:
- lib/pongo/rim_particle.rb
Instance Attribute Summary collapse
-
#angular_velocity ⇒ Object
Returns the value of attribute angular_velocity.
-
#curr ⇒ Object
Returns the value of attribute curr.
-
#max_torque ⇒ Object
Returns the value of attribute max_torque.
-
#prev ⇒ Object
Returns the value of attribute prev.
-
#speed ⇒ Object
Returns the value of attribute speed.
-
#wr ⇒ Object
Returns the value of attribute wr.
Instance Method Summary collapse
-
#initialize(r, mt) ⇒ RimParticle
constructor
The RimParticle is really just a second component of the wheel model.
- #update(dt) ⇒ Object
Constructor Details
#initialize(r, mt) ⇒ RimParticle
The RimParticle is really just a second component of the wheel model. The rim particle is simulated in a coordsystem relative to the wheel’s center, not in worldspace.
Origins of this code are from Raigan Burns, Metanet Software
12 13 14 15 16 17 18 19 |
# File 'lib/pongo/rim_particle.rb', line 12 def initialize(r, mt) @curr = Vector.new(r, 0) @prev = Vector.new(0, 0) @speed = 0 @angular_velocity = 0 @max_torque = mt @wr = r end |
Instance Attribute Details
#angular_velocity ⇒ Object
Returns the value of attribute angular_velocity.
5 6 7 |
# File 'lib/pongo/rim_particle.rb', line 5 def angular_velocity @angular_velocity end |
#curr ⇒ Object
Returns the value of attribute curr.
5 6 7 |
# File 'lib/pongo/rim_particle.rb', line 5 def curr @curr end |
#max_torque ⇒ Object
Returns the value of attribute max_torque.
5 6 7 |
# File 'lib/pongo/rim_particle.rb', line 5 def max_torque @max_torque end |
#prev ⇒ Object
Returns the value of attribute prev.
5 6 7 |
# File 'lib/pongo/rim_particle.rb', line 5 def prev @prev end |
#speed ⇒ Object
Returns the value of attribute speed.
5 6 7 |
# File 'lib/pongo/rim_particle.rb', line 5 def speed @speed end |
#wr ⇒ Object
Returns the value of attribute wr.
5 6 7 |
# File 'lib/pongo/rim_particle.rb', line 5 def wr @wr end |
Instance Method Details
#update(dt) ⇒ Object
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 49 50 51 |
# File 'lib/pongo/rim_particle.rb', line 21 def update(dt) @speed = MathUtil.max(-@max_torque, MathUtil.min(@max_torque, @speed + @angular_velocity)) # apply torque # this is the tangent vector at the rim particle dx = -@curr.y dy = @curr.x # normalize so we can scale by the rotational speed len = Math.sqrt(dx * dx + dy * dy) dx /= len dy /= len @curr.x += @speed * dx @curr.y += @speed * dy ox = @prev.x oy = @prev.y px = @prev.x = @curr.x py = @prev.y = @curr.y @curr.x += APEngine.damping * (px - ox) @curr.y += APEngine.damping * (py - oy) # hold the rim particle in place clen = @curr.magnitude diff = (clen - wr) / clen @curr.x -= @curr.x * diff @curr.y -= @curr.y * diff end |