Class: Transform

Inherits:
Struct
  • Object
show all
Defined in:
lib/belts_engine/components/transform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position: Vec3.zero, rotation: Vec3.zero, scale: Vec3.one) ⇒ Transform



2
# File 'lib/belts_engine/components/transform.rb', line 2

def initialize(position: Vec3.zero, rotation: Vec3.zero, scale: Vec3.one) = super(position, rotation, scale)

Instance Attribute Details

#positionObject

Returns the value of attribute position



1
2
3
# File 'lib/belts_engine/components/transform.rb', line 1

def position
  @position
end

#rotationObject

Returns the value of attribute rotation



1
2
3
# File 'lib/belts_engine/components/transform.rb', line 1

def rotation
  @rotation
end

#scaleObject

Returns the value of attribute scale



1
2
3
# File 'lib/belts_engine/components/transform.rb', line 1

def scale
  @scale
end

Instance Method Details

#backObject



25
# File 'lib/belts_engine/components/transform.rb', line 25

def back = -forward

#downObject



27
# File 'lib/belts_engine/components/transform.rb', line 27

def down = -up

#forwardObject



10
11
12
13
# File 'lib/belts_engine/components/transform.rb', line 10

def forward
  matrix = to_matrix
  Vec3[matrix[0, 2], matrix[1, 2], matrix[2, 2]]
end

#leftObject



26
# File 'lib/belts_engine/components/transform.rb', line 26

def left = -right

#rightObject



15
16
17
18
# File 'lib/belts_engine/components/transform.rb', line 15

def right
  matrix = to_matrix
  Vec3[matrix[0, 0], matrix[1, 0], matrix[2, 0]]
end

#to_matrixObject



4
5
6
7
8
# File 'lib/belts_engine/components/transform.rb', line 4

def to_matrix
  Mat4.translation(*position) *
    Mat4.rotation(*rotation) *
    Mat4.scale(*scale)
end

#upObject



20
21
22
23
# File 'lib/belts_engine/components/transform.rb', line 20

def up
  matrix = to_matrix
  Vec3[matrix[0, 1], matrix[1, 1], matrix[2, 1]]
end