Class: Ruby2D::Vertices
- Inherits:
-
Object
- Object
- Ruby2D::Vertices
- Defined in:
- lib/ruby2d/vertices.rb
Overview
Vertex and texture coordinates for tile placements
Constant Summary collapse
- TEX_UNCROPPED_COORDS =
Texture coordinates for an uncropped quad (full image)
[ 0.0, 0.0, # top left 1.0, 0.0, # top right 1.0, 1.0, # bottom right 0.0, 1.0 # bottom left ].freeze
Instance Method Summary collapse
-
#coordinates ⇒ Object
Get the quad corner coordinates as a flat array.
-
#initialize(x, y, width, height, rotate, crop: nil, flip: nil) ⇒ Vertices
constructor
Create a vertex set for a tile placement.
-
#texture_coordinates ⇒ Object
Get the texture UV coordinates as a flat array.
Constructor Details
#initialize(x, y, width, height, rotate, crop: nil, flip: nil) ⇒ Vertices
Create a vertex set for a tile placement
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ruby2d/vertices.rb', line 15 def initialize(x, y, width, height, rotate, crop: nil, flip: nil) @x = x @y = y @width = width.to_f @height = height.to_f @rotate = rotate @crop = crop apply_flip(flip) @rx = @x + (@width / 2.0) @ry = @y + (@height / 2.0) end |
Instance Method Details
#coordinates ⇒ Object
Get the quad corner coordinates as a flat array
28 29 30 |
# File 'lib/ruby2d/vertices.rb', line 28 def coordinates @coordinates ||= @rotate.zero? ? unrotated_coordinates : rotated_coordinates end |
#texture_coordinates ⇒ Object
Get the texture UV coordinates as a flat array
33 34 35 |
# File 'lib/ruby2d/vertices.rb', line 33 def texture_coordinates @texture_coordinates ||= @crop ? cropped_texture_coordinates : TEX_UNCROPPED_COORDS end |