Class: CyberarmEngine::PerspectiveCamera
- Inherits:
-
Object
- Object
- CyberarmEngine::PerspectiveCamera
- Defined in:
- lib/cyberarm_engine/opengl/perspective_camera.rb
Instance Attribute Summary collapse
-
#aspect_ratio ⇒ Object
Returns the value of attribute aspect_ratio.
-
#field_of_view ⇒ Object
Returns the value of attribute field_of_view.
-
#max_view_distance ⇒ Object
Returns the value of attribute max_view_distance.
-
#min_view_distance ⇒ Object
Returns the value of attribute min_view_distance.
-
#orientation ⇒ Object
Returns the value of attribute orientation.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
- #draw ⇒ Object
-
#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
constructor
A new instance of PerspectiveCamera.
- #projection_matrix ⇒ Object
- #view_matrix ⇒ Object
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.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 6 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_ratio ⇒ Object
Returns the value of attribute aspect_ratio.
3 4 5 |
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 3 def aspect_ratio @aspect_ratio end |
#field_of_view ⇒ Object
Returns the value of attribute field_of_view.
3 4 5 |
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 3 def field_of_view @field_of_view end |
#max_view_distance ⇒ Object
Returns the value of attribute max_view_distance.
3 4 5 |
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 3 def max_view_distance @max_view_distance end |
#min_view_distance ⇒ Object
Returns the value of attribute min_view_distance.
3 4 5 |
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 3 def min_view_distance @min_view_distance end |
#orientation ⇒ Object
Returns the value of attribute orientation.
3 4 5 |
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 3 def orientation @orientation end |
#position ⇒ Object
Returns the value of attribute position.
3 4 5 |
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 3 def position @position end |
Instance Method Details
#draw ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 18 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_matrix ⇒ Object
30 31 32 |
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 30 def projection_matrix Transform.perspective(@field_of_view, @aspect_ratio, @min_view_distance, @max_view_distance) end |
#view_matrix ⇒ Object
34 35 36 |
# File 'lib/cyberarm_engine/opengl/perspective_camera.rb', line 34 def view_matrix Transform.translate_3d(@position * -1) * Transform.rotate_3d(@orientation) end |