Class: Pongo::RectangleParticle
- Inherits:
-
AbstractParticle
- Object
- AbstractItem
- AbstractParticle
- Pongo::RectangleParticle
- Defined in:
- lib/pongo/rectangle_particle.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#axes ⇒ Object
Returns the value of attribute axes.
-
#extents ⇒ Object
Returns the value of attribute extents.
-
#radian ⇒ Object
Returns the value of attribute radian.
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
(also: #degree)
The rotation of the RectangleParticle in degrees.
- #angle=(deg) ⇒ Object (also: #degree=)
- #height ⇒ Object
- #height=(h) ⇒ Object
-
#initialize(x, y, width, height, options = {}) ⇒ RectangleParticle
constructor
A new instance of RectangleParticle.
- #projection(axis) ⇒ Object (also: #get_projection)
- #set_axes(rad) ⇒ Object
- #width ⇒ Object
- #width=(w) ⇒ Object
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!, #resolve_collision, #solid?, #test_particle_events, #update, #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, width, height, options = {}) ⇒ RectangleParticle
Returns a new instance of RectangleParticle.
8 9 10 11 12 13 14 |
# File 'lib/pongo/rectangle_particle.rb', line 8 def initialize(x, y, width, height, ={}) = {:rotation => 0.0, :fixed => false, :mass => 1.0, :elasticity => 0.3, :friction => 0.0}.update() super(x, y, [:fixed], [:mass], [:elasticity], [:friction]) @extents = [width/2.0, height/2.0] @axes = [Vector.new, Vector.new] self.radian = [:rotation] end |
Instance Attribute Details
#axes ⇒ Object
Returns the value of attribute axes.
6 7 8 |
# File 'lib/pongo/rectangle_particle.rb', line 6 def axes @axes end |
#extents ⇒ Object
Returns the value of attribute extents.
6 7 8 |
# File 'lib/pongo/rectangle_particle.rb', line 6 def extents @extents end |
#radian ⇒ Object
Returns the value of attribute radian.
6 7 8 |
# File 'lib/pongo/rectangle_particle.rb', line 6 def radian @radian end |
Instance Method Details
#angle ⇒ Object Also known as: degree
The rotation of the RectangleParticle in degrees.
29 30 31 |
# File 'lib/pongo/rectangle_particle.rb', line 29 def angle self.radian * MathUtil::ONE_EIGHTY_OVER_PI end |
#angle=(deg) ⇒ Object Also known as: degree=
34 35 36 |
# File 'lib/pongo/rectangle_particle.rb', line 34 def angle=(deg) self.radian = deg * MathUtil::PI_OVER_ONE_EIGHTY end |
#height ⇒ Object
51 52 53 |
# File 'lib/pongo/rectangle_particle.rb', line 51 def height @extents[1] * 2.0 end |
#height=(h) ⇒ Object
47 48 49 |
# File 'lib/pongo/rectangle_particle.rb', line 47 def height=(h) @extents[1] = h / 2.0 end |
#projection(axis) ⇒ Object Also known as: get_projection
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pongo/rectangle_particle.rb', line 55 def projection(axis) radius = self.extents[0] * axis.dot(axes[0]).abs + self.extents[1] * axis.dot(axes[1]).abs c = @samp.dot(axis) @interval.min = c - radius @interval.max = c + radius @interval end |
#set_axes(rad) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/pongo/rectangle_particle.rb', line 68 def set_axes(rad) s = Math.sin(rad) c = Math.cos(rad) self.axes[0].x = c self.axes[0].y = s self.axes[1].x = -s self.axes[1].y = c end |
#width ⇒ Object
43 44 45 |
# File 'lib/pongo/rectangle_particle.rb', line 43 def width @extents[0] * 2.0 end |
#width=(w) ⇒ Object
39 40 41 |
# File 'lib/pongo/rectangle_particle.rb', line 39 def width=(w) @extents[0] = w / 2.0 end |