Class: Engine::Components::OrthographicCamera

Inherits:
Engine::Component show all
Defined in:
lib/engine/components/orthographic_camera.rb

Instance Attribute Summary

Attributes inherited from Engine::Component

#game_object

Instance Method Summary collapse

Methods inherited from Engine::Component

#_erase!, #destroy!, #destroyed?, destroyed_components, erase_destroyed_components, method_added, #renderer?, #set_game_object, #start, #ui_renderer?

Constructor Details

#initialize(width:, height:, far:) ⇒ OrthographicCamera

Returns a new instance of OrthographicCamera.



6
7
8
9
10
11
12
13
# File 'lib/engine/components/orthographic_camera.rb', line 6

def initialize(width:, height:, far:)
  @width = width
  @height = height
  @far = far
  @near = 0

  Engine::Camera.instance = self
end

Instance Method Details

#destroyObject



15
16
17
# File 'lib/engine/components/orthographic_camera.rb', line 15

def destroy
  Engine::Camera.instance = nil if Engine::Camera.instance == self
end

#matrixObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/engine/components/orthographic_camera.rb', line 19

def matrix
  @matrix ||=
    begin
      camera_pos = game_object.pos - game_object.forward * (@far / 2)
      Matrix[
        [right[0], up[0], -front[0], 0],
        [right[1], up[1], -front[1], 0],
        [right[2], up[2], -front[2], 0],
        [-camera_pos.dot(right), -camera_pos.dot(up), camera_pos.dot(front), 1]
      ]
    end
end

#update(delta_time) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/engine/components/orthographic_camera.rb', line 32

def update(delta_time)
  @right = nil if game_object.rotation != @rotation
  @up = nil if game_object.rotation != @rotation
  @front = nil if game_object.rotation != @rotation
  @matrix = nil if game_object.rotation.to_a != @rotation
  @rotation = game_object.rotation.to_a
end