Class: Ruby2D::Vertices

Inherits:
Object
  • Object
show all
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

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

#coordinatesObject

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_coordinatesObject

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