Class: Hate::Graphics::Shapes::Base

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

Direct Known Subclasses

Cube, Square

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s = 1.0) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
18
19
20
21
# File 'lib/hate/graphics/shapes.rb', line 12

def initialize(s=1.0)
  @size = s
  
  @memory = nil
  compile
  
  translate
  rotate
  color
end

Instance Attribute Details

#cObject (readonly)

Returns the value of attribute c.



10
11
12
# File 'lib/hate/graphics/shapes.rb', line 10

def c
  @c
end

#memoryObject

Returns the value of attribute memory.



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

def memory
  @memory
end

#raObject (readonly)

Returns the value of attribute ra.



9
10
11
# File 'lib/hate/graphics/shapes.rb', line 9

def ra
  @ra
end

#rxObject (readonly)

Returns the value of attribute rx.



9
10
11
# File 'lib/hate/graphics/shapes.rb', line 9

def rx
  @rx
end

#ryObject (readonly)

Returns the value of attribute ry.



9
10
11
# File 'lib/hate/graphics/shapes.rb', line 9

def ry
  @ry
end

#rzObject (readonly)

Returns the value of attribute rz.



9
10
11
# File 'lib/hate/graphics/shapes.rb', line 9

def rz
  @rz
end

#sizeObject

Returns the value of attribute size.



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

def size
  @size
end

#xObject (readonly)

Returns the value of attribute x.



8
9
10
# File 'lib/hate/graphics/shapes.rb', line 8

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



8
9
10
# File 'lib/hate/graphics/shapes.rb', line 8

def y
  @y
end

#zObject (readonly)

Returns the value of attribute z.



8
9
10
# File 'lib/hate/graphics/shapes.rb', line 8

def z
  @z
end

Instance Method Details

#color(r = 0.0, g = 0.0, b = 0.0) ⇒ Object



33
34
35
36
# File 'lib/hate/graphics/shapes.rb', line 33

def color(r=0.0, g=0.0, b=0.0)
  @c = [r, g, b]
  self
end

#compileObject



38
39
40
41
42
43
# File 'lib/hate/graphics/shapes.rb', line 38

def compile
  @memory = glGenLists(1) if @memory.nil?
  glNewList(@memory, GL_COMPILE)
  build
  glEndList
end

#destroyObject



55
56
57
58
# File 'lib/hate/graphics/shapes.rb', line 55

def destroy
  glDeleteLists(@memory)
  @memory = nil
end

#rotate(a = 0.0, x = 0.0, y = 0.0, z = 0.0) ⇒ Object



28
29
30
31
# File 'lib/hate/graphics/shapes.rb', line 28

def rotate(a=0.0, x=0.0, y=0.0, z=0.0)
  @ra, @rx, @ry, @rz = a, x, y, z
  self
end

#runObject



45
46
47
48
49
50
51
52
53
# File 'lib/hate/graphics/shapes.rb', line 45

def run
  glLoadIdentity
  glPushMatrix
  glColor3f(@c[0], @c[1], @c[2])
  glTranslatef(@x, @y, @z)
  glRotatef(@ra, @rx, @ry, @rz)
  @memory.nil? ? build : glCallList(@memory)
  glPopMatrix
end

#translate(x = 0.0, y = 0.0, z = 0.0) ⇒ Object



23
24
25
26
# File 'lib/hate/graphics/shapes.rb', line 23

def translate(x=0.0, y=0.0, z=0.0)
  @x, @y, @z = x, y, z
  self
end