Class: RAGE::Viewport

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/viewport.rb

Overview

Viewport is the end user’s view into the world. It is represented on the screen via glViewport and has a camera attached to it managing the viewport’s projection matrix.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Viewport

Create new Viewport with any of the following optional args,

  • :x x coordinate of viewport on screen, defaults to 0

  • :y y coordinate of viewport on screen, defaults to 0

  • :width width of viewport on screen or :max, defaults to :max

  • :height height of viewport on screen or :max, defaults to :max

  • :camera camera to attach to viewport, if none provided one is auto created



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rage/viewport.rb', line 25

def initialize(args = {})
  @x = args[:x] if args.has_key? :x
  @y = args[:y] if args.has_key? :y
  @width  = args[:width]  if args.has_key? :width
  @height = args[:height] if args.has_key? :height
  @camera = args[:camera] if args.has_key? :camera

  @x = 0 if @x.nil?
  @y = 0 if @y.nil?
  @width  = :max if @width.nil?
  @height = :max if @height.nil?
  @camera = Camera.new if @camera.nil?
end

Instance Attribute Details

#cameraObject

Camera attached to viewport



17
18
19
# File 'lib/rage/viewport.rb', line 17

def camera
  @camera
end

#heightObject

x,y pos, width, height



14
15
16
# File 'lib/rage/viewport.rb', line 14

def height
  @height
end

#widthObject

x,y pos, width, height



14
15
16
# File 'lib/rage/viewport.rb', line 14

def width
  @width
end

#xObject

x,y pos, width, height



14
15
16
# File 'lib/rage/viewport.rb', line 14

def x
  @x
end

#yObject

x,y pos, width, height



14
15
16
# File 'lib/rage/viewport.rb', line 14

def y
  @y
end

Instance Method Details

#drawObject

Invoked during draw cycle to draw viewport and associated camera



40
41
42
43
44
45
46
# File 'lib/rage/viewport.rb', line 40

def draw
  w = @width  == :max ? Window.width  : @width
  h = @height == :max ? Window.height : @height
  
  Gl.glViewport(@x,@y, w, h)
  @camera.draw
end