Class: CyberarmEngine::OrthographicCamera

Inherits:
Object
  • Object
show all
Defined in:
lib/cyberarm_engine/opengl/orthographic_camera.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position:, right:, top:, orientation: Vector.new(0, 0, 0), zoom: 1, left: 0, bottom: 0, min_view_distance: 0.1, max_view_distance: 200.0) ⇒ OrthographicCamera

Returns a new instance of OrthographicCamera.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 6

def initialize(
  position:, right:, top:, orientation: Vector.new(0, 0, 0),
  zoom: 1, left: 0, bottom: 0,
  min_view_distance: 0.1, max_view_distance: 200.0
)
  @position = position
  @orientation = orientation

  @zoom = zoom

  @left = left
  @right = right
  @bottom = bottom
  @top = top

  @min_view_distance = min_view_distance
  @max_view_distance = max_view_distance
end

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom.



3
4
5
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 3

def bottom
  @bottom
end

#leftObject

Returns the value of attribute left.



3
4
5
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 3

def left
  @left
end

#max_view_distanceObject

Returns the value of attribute max_view_distance.



3
4
5
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 3

def max_view_distance
  @max_view_distance
end

#min_view_distanceObject

Returns the value of attribute min_view_distance.



3
4
5
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 3

def min_view_distance
  @min_view_distance
end

#orientationObject

Returns the value of attribute orientation.



3
4
5
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 3

def orientation
  @orientation
end

#positionObject

Returns the value of attribute position.



3
4
5
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 3

def position
  @position
end

#rightObject

Returns the value of attribute right.



3
4
5
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 3

def right
  @right
end

#topObject

Returns the value of attribute top.



3
4
5
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 3

def top
  @top
end

#zoomObject

Returns the value of attribute zoom.



3
4
5
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 3

def zoom
  @zoom
end

Instance Method Details

#drawObject

Immediate mode renderering fallback



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 26

def draw
  glMatrixMode(GL_PROJECTION)
  glLoadIdentity
  glOrtho(@left, @right, @bottom, @top, @min_view_distance, @max_view_distance)
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
  glRotatef(@orientation.x, 1, 0, 0)
  glRotatef(@orientation.y, 0, 1, 0)
  glTranslatef(-@position.x, -@position.y, -@position.z)
  glMatrixMode(GL_MODELVIEW)
  glLoadIdentity
end

#projection_matrixObject



38
39
40
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 38

def projection_matrix
  Transform.orthographic(@left, @right, @bottom, @top, @min_view_distance, @max_view_distance)
end

#view_matrixObject



42
43
44
# File 'lib/cyberarm_engine/opengl/orthographic_camera.rb', line 42

def view_matrix
  Transform.translate_3d(@position * -1) * Transform.rotate_3d(@orientation)
end