Class: Pongo::RectangleParticle

Inherits:
AbstractParticle show all
Defined in:
lib/pongo/rectangle_particle.rb

Direct Known Subclasses

SpringConstraintParticle

Instance Attribute Summary collapse

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

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, options={})
  options = {:rotation => 0.0, :fixed => false, :mass => 1.0, :elasticity => 0.3, :friction => 0.0}.update(options)
  super(x, y, options[:fixed], options[:mass], options[:elasticity], options[:friction])
  @extents = [width/2.0, height/2.0]
  @axes = [Vector.new, Vector.new]
  self.radian = options[:rotation]
end

Instance Attribute Details

#axesObject

Returns the value of attribute axes.



6
7
8
# File 'lib/pongo/rectangle_particle.rb', line 6

def axes
  @axes
end

#extentsObject

Returns the value of attribute extents.



6
7
8
# File 'lib/pongo/rectangle_particle.rb', line 6

def extents
  @extents
end

#radianObject

Returns the value of attribute radian.



6
7
8
# File 'lib/pongo/rectangle_particle.rb', line 6

def radian
  @radian
end

Instance Method Details

#angleObject 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

#heightObject



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

#widthObject



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