Sha256: 2c31dda2f30f946436f514511d994e4f5a2d8e65b529297a791e328963a5d6d7

Contents?: true

Size: 1.93 KB

Versions: 18

Compression:

Stored size: 1.93 KB

Contents

# encoding: ascii-8bit

# Copyright 2014 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt

require 'cosmos/gui/opengl/gl_bounds'

module Cosmos
  # Creates an OpenGL scene with associated shapes. It defers to the shapes to
  # draw themselves.
  class GlScene
    # @return [Array<GlShape>] Shapes to draw in the scene
    attr_reader :shapes
    # @return [GlBounds] Bounds of the scene
    attr_accessor :bounds
    # @return [Integer] Zoom factor
    attr_accessor :zoom
    # @return [Quaternion] Orientation of the scene
    attr_accessor :orientation
    # @return [Array<Float, Float, Float>] Center of the scene
    attr_accessor :center
    # @return [Symbol] The type of projection matrix to use :PARALLEL or :PERSPECTIVE
    attr_accessor :projection

    def initialize
      @shapes = []
      @bounds = GlBounds.new(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0)
      @zoom = 1.0
      @orientation = Quaternion.new([0.0, 0.0, 0.0, 1.0])
      @center = [0.0, 0.0, 0.0]
      @projection = :PARALLEL
    end

    def draw(viewer)
      @shapes.each do |shape|
        if shape.color[3] > 0.96
          shape.draw(viewer)
        end
      end
      @shapes.each do |shape|
        if shape.color[3] <= 0.96
          shape.draw(viewer)
        end
      end
    end

    def hit(viewer)
      glPushName(0xffffffff);
      @shapes.each_with_index do |shape, index|
        glLoadName(index)
        shape.hit(viewer)
      end
      glPopName()
    end

    def identify(index)
      if @shapes[index]
        return @shapes[index].identify
      end
      return nil
    end

    def each
      @shapes.each do |shape|
        yield shape
      end
    end

    def append(shape)
      @shapes << shape
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
cosmos-4.5.2-java lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.5.2 lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.5.1-java lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.5.1 lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.5.0-java lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.5.0 lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.4.2-java lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.4.2 lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.4.1-java lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.4.1 lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.4.0-java lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.4.0 lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.3.0-java lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.3.0 lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.2.4-java lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.2.4 lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.2.3-java lib/cosmos/gui/opengl/gl_scene.rb
cosmos-4.2.3 lib/cosmos/gui/opengl/gl_scene.rb