Class: CyberarmEngine::PerspectiveCamera

Inherits:
Object
  • Object
show all
Includes:
GLU, OpenGL
Defined in:
lib/cyberarm_engine/opengl/perspective_camera.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position:, aspect_ratio:, orientation: Vector.new(0, 0, 0), field_of_view: 70.0, min_view_distance: 0.1, max_view_distance: 1024.0) ⇒ PerspectiveCamera

Returns a new instance of PerspectiveCamera.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 9

def initialize(position:, aspect_ratio:, orientation: Vector.new(0, 0, 0),
               field_of_view: 70.0, min_view_distance: 0.1, max_view_distance: 1024.0)
  @position = position
  @orientation = orientation

  @aspect_ratio = aspect_ratio
  @field_of_view = field_of_view

  @min_view_distance = min_view_distance
  @max_view_distance = max_view_distance
end

Instance Attribute Details

#aspect_ratioObject

Returns the value of attribute aspect_ratio.



6
7
8
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 6

def aspect_ratio
  @aspect_ratio
end

#field_of_viewObject

Returns the value of attribute field_of_view.



6
7
8
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 6

def field_of_view
  @field_of_view
end

#max_view_distanceObject

Returns the value of attribute max_view_distance.



6
7
8
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 6

def max_view_distance
  @max_view_distance
end

#min_view_distanceObject

Returns the value of attribute min_view_distance.



6
7
8
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 6

def min_view_distance
  @min_view_distance
end

#orientationObject

Returns the value of attribute orientation.



6
7
8
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 6

def orientation
  @orientation
end

#positionObject

Returns the value of attribute position.



6
7
8
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 6

def position
  @position
end

Instance Method Details

#drawObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 21

def draw
  glMatrixMode(GL_PROJECTION)
  glLoadIdentity
  gluPerspective(@field_of_view, @aspect_ratio, @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



33
34
35
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 33

def projection_matrix
  Transform.perspective(@field_of_view, @aspect_ratio, @min_view_distance, @max_view_distance)
end

#view_matrixObject



37
38
39
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 37

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