Sha256: d9b99a827f863f2fd11cc3954b3f672608bef3785a41fbb94c1bfd6866e19178

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

module CyberarmEngine
  class PerspectiveCamera
    attr_accessor :position, :orientation, :aspect_ratio, :field_of_view,
                  :min_view_distance, :max_view_distance

    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

    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

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

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cyberarm_engine-0.24.4 lib/cyberarm_engine/opengl/perspective_camera.rb
cyberarm_engine-0.24.3 lib/cyberarm_engine/opengl/perspective_camera.rb
cyberarm_engine-0.24.2 lib/cyberarm_engine/opengl/perspective_camera.rb
cyberarm_engine-0.24.1 lib/cyberarm_engine/opengl/perspective_camera.rb
cyberarm_engine-0.24.0 lib/cyberarm_engine/opengl/perspective_camera.rb
cyberarm_engine-0.23.0 lib/cyberarm_engine/opengl/perspective_camera.rb
cyberarm_engine-0.22.0 lib/cyberarm_engine/opengl/perspective_camera.rb
cyberarm_engine-0.21.0 lib/cyberarm_engine/opengl/perspective_camera.rb
cyberarm_engine-0.20.0 lib/cyberarm_engine/opengl/perspective_camera.rb
cyberarm_engine-0.19.1 lib/cyberarm_engine/opengl/perspective_camera.rb