Class: Activity

Inherits:
Object
  • Object
show all
Defined in:
lib/gl_tail/activity.rb

Overview

gl_tail.rb - OpenGL visualization of your server traffic Copyright 2007 Erlend Simonsen <[email protected]>

Licensed under the GNU General Public License v2 (see LICENSE)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, x, y, z, color, size, type = 0) ⇒ Activity

Returns a new instance of Activity.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gl_tail/activity.rb', line 11

def initialize(message, x, y, z, color, size, type = 0)
  @message = message
  @x, @y, @z = x, y, z
#    @xi, @yi, @zi = 0.012 + (rand(100)/100.0 ) * 0.0012 , 0.002 + (rand(1000)/1000.0 ) * 0.002, 0
  @xi, @yi, @zi = 0.006 , 0.0013, 0

  if @x >= 0.0
    @xi = -@xi
  end

  @xi = (rand(100)/100.0 * 0.002) - 0.001 if type == 2
  @yi = (rand(100)/100.0 * 0.002) - 0.001 if type == 2

  @color = color
  @size  = size
  @type  = type

  @rx, @ry, @rz = rand(360), rand(360), 0
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



9
10
11
# File 'lib/gl_tail/activity.rb', line 9

def color
  @color
end

#messageObject

Returns the value of attribute message.



9
10
11
# File 'lib/gl_tail/activity.rb', line 9

def message
  @message
end

#sizeObject

Returns the value of attribute size.



9
10
11
# File 'lib/gl_tail/activity.rb', line 9

def size
  @size
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/gl_tail/activity.rb', line 9

def type
  @type
end

#wxObject

Returns the value of attribute wx.



8
9
10
# File 'lib/gl_tail/activity.rb', line 8

def wx
  @wx
end

#wyObject

Returns the value of attribute wy.



8
9
10
# File 'lib/gl_tail/activity.rb', line 8

def wy
  @wy
end

#wzObject

Returns the value of attribute wz.



8
9
10
# File 'lib/gl_tail/activity.rb', line 8

def wz
  @wz
end

#xObject

Returns the value of attribute x.



8
9
10
# File 'lib/gl_tail/activity.rb', line 8

def x
  @x
end

#xiObject

Returns the value of attribute xi.



8
9
10
# File 'lib/gl_tail/activity.rb', line 8

def xi
  @xi
end

#yObject

Returns the value of attribute y.



8
9
10
# File 'lib/gl_tail/activity.rb', line 8

def y
  @y
end

#yiObject

Returns the value of attribute yi.



8
9
10
# File 'lib/gl_tail/activity.rb', line 8

def yi
  @yi
end

#zObject

Returns the value of attribute z.



8
9
10
# File 'lib/gl_tail/activity.rb', line 8

def z
  @z
end

#ziObject

Returns the value of attribute zi.



8
9
10
# File 'lib/gl_tail/activity.rb', line 8

def zi
  @zi
end

Instance Method Details

#render(engine) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/gl_tail/activity.rb', line 31

def render(engine)
  if @type != 5
    if engine.screen.wanted_fps == 0
      @x += @xi
      @y += @yi
      @yi = @yi - 0.00008
    else
      @fps_mod ||= (60.0 / engine.screen.wanted_fps)
      @x += @xi * @fps_mod
      @y += @yi * @fps_mod
      @yi = @yi - 0.00008 * @fps_mod
    end

#      @yi = @yi * 1.01
#      @xi = @xi * 0.9995

    if @y - @size/2 < -engine.screen.top
      @y = -engine.screen.top + @size/2
      @yi = -@yi * 0.7
      @x = 30.0 if(@type == 2 || (engine.screen.bounce.nil? || engine.screen.bounce == false ) )
    end
  else
    dy = @wy - @y
    if dy.abs < 0.001
      @y = @wy
    else
      @y += dy / 20
    end

    dx = @wx - @x
    if dx.abs < 0.001
      @x = @wx
    else
      @x += dx / 20
    end

    if @x == @wx
      @x = 20.0
    end

  end

  glPushMatrix()
  glColor(@color)

  if @type == 0 || @type == 5
    glTranslate(@x, @y, @z)
    if engine.screen.mode == 1
      glRotatef(@rx, 1.0, 0.0, 0.0)
      glRotatef(@ry, 0.0, 1.0, 0.0)
      @rx += 2
      @ry += 1
      unless BlobStore.has(@size)
        list = glGenLists(1)
        glNewList(list, GL_COMPILE)

        glBegin(GL_QUADS)
        glVertex3f(-@size,  @size, 0)
        glVertex3f( @size,  @size, 0)
        glVertex3f( @size, -@size, 0)
        glVertex3f(-@size, -@size, 0)
        glEnd

        glEndList()
        BlobStore.put(@size,list)
      end
    else
      unless BlobStore.has(@size)

        list = glGenLists(1)
        glNewList(list, GL_COMPILE)

        tmp = 10 + 10 * ((@size-engine.screen.min_blob_size)/engine.screen.max_blob_size)
        glutSolidSphere(@size, tmp, 2)

        glEndList()
        BlobStore.put(@size,list)
      end
    end
    glCallList(BlobStore.get(@size))
  elsif @type == 1
    glTranslate(@x, @y, @z)
    glRotatef(@rx, 1.0, 0.0, 0.0)
    glRotatef(@ry, 0.0, 1.0, 0.0)
    @rx += 2
    @ry += 1
    unless BlobStore.has(@size.to_s)
      list = glGenLists(1)
      glNewList(list, GL_COMPILE)

      glBegin(GL_QUADS)
      glVertex3f(-@size,  @size, 0)
      glVertex3f( @size,  @size, 0)
      glVertex3f( @size, -@size, 0)
      glVertex3f(-@size, -@size, 0)
      glEnd

      glEndList()
      BlobStore.put(@size.to_s,list)
    end

    glCallList(BlobStore.get(@size.to_s))
  elsif @type == 2
    glTranslate(@x, @y, @z)
    glRasterPos(0.0, 0.0)

    engine.render_string(@message)
  end

  glPopMatrix()
end