Class: Ruby2D::Vertices

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby2d/vertices.rb

Overview

This internal class generates a vertices array which are passed to the openGL rendering code. The vertices array is split up into 4 groups (1 - top left, 2 - top right, 3 - bottom right, 4 - bottom left) This class is responsible for transforming textures, it can scale / crop / rotate and flip textures

Constant Summary collapse

TEX_UNCROPPED_COORDS =
[
  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

Returns a new instance of Vertices.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby2d/vertices.rb', line 10

def initialize(x, y, width, height, rotate, crop: nil, flip: nil)
  @flip = flip
  @x = x
  @y = y
  @width = width.to_f
  @height = height.to_f
  @rotate = rotate
  @rx = @x + (@width / 2.0)
  @ry = @y + (@height / 2.0)
  @crop = crop
  @coordinates = nil
  @texture_coordinates = nil
  _apply_flip unless @flip.nil?
end

Instance Method Details

#coordinatesObject



25
26
27
28
29
30
31
# File 'lib/ruby2d/vertices.rb', line 25

def coordinates
  @coordinates ||= if @rotate.zero?
                     _unrotated_coordinates
                   else
                     _calculate_coordinates
                   end
end

#texture_coordinatesObject



40
41
42
43
44
45
46
# File 'lib/ruby2d/vertices.rb', line 40

def texture_coordinates
  @texture_coordinates ||= if @crop.nil?
                             TEX_UNCROPPED_COORDS
                           else
                             _calculate_texture_coordinates
                           end
end