Class: Cosmos::GlScene

Inherits:
Object show all
Defined in:
lib/cosmos/gui/opengl/gl_scene.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGlScene

Returns a new instance of GlScene.



23
24
25
26
27
28
29
30
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 23

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

Instance Attribute Details

#boundsObject

Returns the value of attribute bounds.



17
18
19
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 17

def bounds
  @bounds
end

#centerObject

Returns the value of attribute center.



20
21
22
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 20

def center
  @center
end

#orientationObject

Returns the value of attribute orientation.



19
20
21
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 19

def orientation
  @orientation
end

#projectionObject

Returns the value of attribute projection.



21
22
23
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 21

def projection
  @projection
end

#shapesObject (readonly)

Returns the value of attribute shapes.



16
17
18
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 16

def shapes
  @shapes
end

#zoomObject

Returns the value of attribute zoom.



18
19
20
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 18

def zoom
  @zoom
end

Instance Method Details

#append(shape) ⇒ Object



67
68
69
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 67

def append(shape)
  @shapes << shape
end

#draw(viewer) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 32

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

#eachObject



61
62
63
64
65
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 61

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

#hit(viewer) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 45

def hit(viewer)
  GL.PushName(0xffffffff);
  @shapes.each_with_index do |shape, index|
    GL.LoadName(index)
    shape.hit(viewer)
  end
  GL.PopName()
end

#identify(index) ⇒ Object



54
55
56
57
58
59
# File 'lib/cosmos/gui/opengl/gl_scene.rb', line 54

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