Class: Pongo::WheelParticle
- Inherits:
-
CircleParticle
- Object
- AbstractItem
- AbstractParticle
- CircleParticle
- Pongo::WheelParticle
- Defined in:
- lib/pongo/wheel_particle.rb
Overview
A particle that simulates the behavior of a wheel
Instance Attribute Summary collapse
-
#norm_slip ⇒ Object
Returns the value of attribute norm_slip.
-
#orientation ⇒ Object
Returns the value of attribute orientation.
-
#rp ⇒ Object
Returns the value of attribute rp.
-
#tan ⇒ Object
Returns the value of attribute tan.
-
#traction ⇒ Object
The amount of traction during a collision.
Attributes inherited from CircleParticle
Attributes inherited from AbstractParticle
#center, #collidable, #collision, #curr, #first_collision, #fixed, #force_list, #forces, #friction, #interval, #inv_mass, #kfr, #mass, #multisample, #prev, #samp, #temp
Attributes inherited from AbstractItem
#always_repaint, #display_object, #display_object_offset, #display_object_rotation, #fill_alpha, #fill_color, #line_alpha, #line_color, #line_thickness, #renderer, #solid, #user_data, #visible
Instance Method Summary collapse
- #angle ⇒ Object
-
#angular_velocity ⇒ Object
The angular velocity of the WheelParticle.
- #angular_velocity=(a) ⇒ Object
-
#initialize(x, y, radius, options = {}) ⇒ WheelParticle
constructor
A new instance of WheelParticle.
- #radian ⇒ Object
-
#resolve(n) ⇒ Object
simulates torque/wheel-ground interaction - n is the surface normal Origins of this code thanks to Raigan Burns, Metanet software.
- #resolve_collision(mtd, vel, n, d, o, p) ⇒ Object
-
#speed ⇒ Object
The speed of the WheelParticle.
- #speed=(s) ⇒ Object
- #update(dt) ⇒ Object
Methods inherited from CircleParticle
#interval_x, #interval_y, #projection
Methods inherited from AbstractParticle
#accumulate_forces, #add_force, #clear_forces, #collidable!, #collidable?, #components, #elasticity, #elasticity=, #fixed?, #position, #position=, #px, #px=, #py, #py=, #reset_first_collision!, #solid?, #test_particle_events, #velocity, #velocity=
Methods inherited from AbstractItem
#add_event_listener, #always_redraw!, #always_redraw=, #always_redraw?, #cleanup, #dispatch_event, #draw, #has_event_listener, #init, #set_fill, #set_line, #set_style, #visible!, #visible?
Constructor Details
#initialize(x, y, radius, options = {}) ⇒ WheelParticle
Returns a new instance of WheelParticle.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/pongo/wheel_particle.rb', line 6 def initialize(x, y, radius, ={}) = {:fixed => false, :mass => 1, :elasticity => 0.3, :friction => 0, :traction => 1}.update() super(x, y, radius, ) @tan = Vector.new @norm_slip = Vector.new @rp = RimParticle.new(radius, 2) self.traction = [:traction] @orientation = Vector.new end |
Instance Attribute Details
#norm_slip ⇒ Object
Returns the value of attribute norm_slip.
4 5 6 |
# File 'lib/pongo/wheel_particle.rb', line 4 def norm_slip @norm_slip end |
#orientation ⇒ Object
Returns the value of attribute orientation.
4 5 6 |
# File 'lib/pongo/wheel_particle.rb', line 4 def orientation @orientation end |
#rp ⇒ Object
Returns the value of attribute rp.
4 5 6 |
# File 'lib/pongo/wheel_particle.rb', line 4 def rp @rp end |
#tan ⇒ Object
Returns the value of attribute tan.
4 5 6 |
# File 'lib/pongo/wheel_particle.rb', line 4 def tan @tan end |
#traction ⇒ Object
The amount of traction during a collision. This property controls how much traction is applied when the WheelParticle is in contact with another particle. If the value is set to 0, there will be no traction and the WheelParticle will behave as if the surface was totally slippery, like ice. Values should be between 0 and 1.
<p> Note that the friction property behaves differently than traction. If the surface friction is set high during a collision, the WheelParticle will move slowly as if the surface was covered in glue. </p>
47 48 49 |
# File 'lib/pongo/wheel_particle.rb', line 47 def traction @traction end |
Instance Method Details
#angle ⇒ Object
60 61 62 |
# File 'lib/pongo/wheel_particle.rb', line 60 def angle self.radian * MathUtil::ONE_EIGHTY_OVER_PI end |
#angular_velocity ⇒ Object
The angular velocity of the WheelParticle. You can alter this value to make the WheelParticle spin.
29 30 31 |
# File 'lib/pongo/wheel_particle.rb', line 29 def angular_velocity @rp.angular_velocity end |
#angular_velocity=(a) ⇒ Object
33 34 35 |
# File 'lib/pongo/wheel_particle.rb', line 33 def angular_velocity=(a) @rp.angular_velocity = a end |
#radian ⇒ Object
55 56 57 58 |
# File 'lib/pongo/wheel_particle.rb', line 55 def radian @orientation.set_to(rp.curr) Math.atan2(@orientation.y, @orientation.x) + Math::PI end |
#resolve(n) ⇒ Object
simulates torque/wheel-ground interaction - n is the surface normal Origins of this code thanks to Raigan Burns, Metanet software
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/pongo/wheel_particle.rb', line 76 def resolve(n) # this is the tangent vector at the rim particle @tan.set_to(-@rp.curr.y, @rp.curr.x) # normalize so we can scale by the rotational speed @tan = @tan.normalize # velocity of the wheel's surface wheel_surface_velocity = @tan * @rp.speed # the velocity of the wheel's surface relative to the ground combined_velocity = velocity.plus!(wheel_surface_velocity) # the wheel's comb velocity projected onto the contact normal cp = combined_velocity.cross(n) # set the wheel's spinspeed to track the ground @tan.mult!(cp) @rp.prev.copy(@rp.curr - @tan) # some of the wheel's torque is removed and converted into linear displacement slip_speed = (1 - @traction) * @rp.speed norm_slip.set_to(slip_speed * n.y, slip_speed * n.x) @curr.plus!(norm_slip) @rp.speed *= @traction end |
#resolve_collision(mtd, vel, n, d, o, p) ⇒ Object
69 70 71 72 |
# File 'lib/pongo/wheel_particle.rb', line 69 def resolve_collision(mtd, vel, n, d, o, p) super resolve(n * MathUtil.sign(d * o)) end |
#speed ⇒ Object
The speed of the WheelParticle. You can alter this value to make the WheelParticle spin.
19 20 21 |
# File 'lib/pongo/wheel_particle.rb', line 19 def speed @rp.speed end |
#speed=(s) ⇒ Object
23 24 25 |
# File 'lib/pongo/wheel_particle.rb', line 23 def speed=(s) @rp.speed = s end |
#update(dt) ⇒ Object
64 65 66 67 |
# File 'lib/pongo/wheel_particle.rb', line 64 def update(dt) super @rp.update(dt) end |