Class: Hate::Graphics::Camera

Inherits:
Object
  • Object
show all
Defined in:
lib/hate/graphics/camera.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(angle = 45.0, near = 0.1, far = 100.0) ⇒ Camera

Returns a new instance of Camera.



9
10
11
12
13
14
# File 'lib/hate/graphics/camera.rb', line 9

def initialize(angle=45.0, near=0.1, far=100.0)
  @angle, @near, @far = angle, near, far
  @x, @y, @z    = 0.0, 1.0, 0.0
  @xl, @yl, @zl = 0.0, 1.0, -1.0
  @default = true
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



7
8
9
# File 'lib/hate/graphics/camera.rb', line 7

def default
  @default
end

#xObject

Returns the value of attribute x.



5
6
7
# File 'lib/hate/graphics/camera.rb', line 5

def x
  @x
end

#xlObject

Returns the value of attribute xl.



6
7
8
# File 'lib/hate/graphics/camera.rb', line 6

def xl
  @xl
end

#yObject

Returns the value of attribute y.



5
6
7
# File 'lib/hate/graphics/camera.rb', line 5

def y
  @y
end

#ylObject

Returns the value of attribute yl.



6
7
8
# File 'lib/hate/graphics/camera.rb', line 6

def yl
  @yl
end

#zObject

Returns the value of attribute z.



5
6
7
# File 'lib/hate/graphics/camera.rb', line 5

def z
  @z
end

#zlObject

Returns the value of attribute zl.



6
7
8
# File 'lib/hate/graphics/camera.rb', line 6

def zl
  @zl
end

Instance Method Details

#is_default?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/hate/graphics/camera.rb', line 16

def is_default?
  @default
end

#reshape(x, y) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/hate/graphics/camera.rb', line 20

def reshape(x, y)
  glMatrixMode(GL_PROJECTION)
  glLoadIdentity
  glViewport(0, 0, x, y)
  gluPerspective(@angle, x / y, @near, @far)
  glMatrixMode(GL_MODELVIEW)
end

#runObject



28
29
30
31
32
33
34
35
# File 'lib/hate/graphics/camera.rb', line 28

def run
  glLoadIdentity
  gluLookAt(
    @x, @y, @z,
    @x + @xl, 1.0, @z + @zl,
    0.0, 1.0, 0.0
  )
end