public
Description: Real-time web-server visualization using OpenGL and a force directed layout
Homepage: http://www.fudgie.org/gltrail.html
Clone URL: git://github.com/Fudge/gltrail.git
Add a 'recoil' mode where sending or receiving an activity gives off a bit 
of force.
Fudge (author)
Fri Mar 07 10:23:29 -0800 2008
commit  d5a11eac2bded6aa0ec9f392cad4c6d3d25706e5
tree    5d429ac19dfd42ed4742d4b8e41012092c114186
parent  82ebbc418fc0fa991ec8f7f05e4a2e48abf88969
0
...
11
12
13
14
 
 
15
16
17
 
 
...
11
12
13
 
14
15
16
17
 
18
19
0
@@ -11,7 +11,9 @@ Note: You'll need public-key ssh access set up to your servers,
0
 Keys:
0
    ESC = exit
0
  SPACE = cycle between line modes (off, all, >10% of max traffic)
0
- B = cycle between size modes (rate, links in, links out,
0
+ S = show/hide stats
0
+ B = cycle between size modes (rate, links in, links out,
0
                                    links total, hits)
0
      V = show repulsive forces
0
- S = show/hide stats
0
+ N = toggle discharge/receive forces
0
+
...
27
28
29
 
30
31
32
...
50
51
52
53
54
 
 
55
56
57
...
67
68
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
27
28
29
30
31
32
33
...
51
52
53
 
 
54
55
56
57
58
...
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
0
@@ -27,6 +27,7 @@ Activity::Activity(Element *s, Element *t)
0
 {
0
 
0
   target = t;
0
+ source = s;
0
   color = s->color.lighter(140);
0
 
0
   x = s->x;
0
@@ -50,8 +51,8 @@ bool Activity::render(GLWidget *gl) {
0
 
0
   float d = sqrt(dx * dx + dy * dy);
0
 
0
- ax = dx / d / SMOOTHING;
0
- ay = dy / d / SMOOTHING;
0
+ ax = ax * 0.3 + dx / d / SMOOTHING;
0
+ ay = ay * 0.3 + dy / d / SMOOTHING;
0
 
0
   vx = vx + ax;
0
   vy = vy + ay;
0
@@ -67,3 +68,20 @@ bool Activity::render(GLWidget *gl) {
0
 
0
   return ( fabs(dx) < 0.004 && fabs(dy) < 0.004 );
0
 }
0
+
0
+void Activity::fire() {
0
+ float dx = target->x - source->x;
0
+ float dy = target->y - source->y;
0
+
0
+ float d = sqrt(dx * dx + dy * dy);
0
+
0
+ source->vx -= (dx / d / DAMPENING) * 0.001;
0
+ source->vy -= (dy / d / DAMPENING) * 0.001;
0
+
0
+}
0
+
0
+void Activity::impact() {
0
+ target->vx += vx * 0.5;
0
+ target->vy += vy * 0.5;
0
+
0
+}
...
38
39
40
 
 
41
42
43
...
50
51
52
 
53
54
55
...
38
39
40
41
42
43
44
45
...
52
53
54
55
56
57
58
0
@@ -38,6 +38,8 @@ public:
0
   virtual ~Activity();
0
 
0
   bool render(GLWidget *gl);
0
+ void fire();
0
+ void impact();
0
 
0
   float x; // X Pos
0
   float y; // Y Pos
0
@@ -50,6 +52,7 @@ public:
0
 
0
   QColor color;
0
   Element *target;
0
+ Element *source;
0
 
0
 };
0
 
...
52
53
54
55
56
57
58
59
...
62
63
64
 
65
66
67
...
78
79
80
81
 
82
83
84
...
214
215
216
 
 
 
 
 
 
 
 
 
217
218
219
...
270
271
272
 
 
 
273
274
275
...
52
53
54
 
 
55
56
57
...
60
61
62
63
64
65
66
...
77
78
79
 
80
81
82
83
...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
...
278
279
280
281
282
283
284
285
286
0
@@ -52,8 +52,6 @@ Element::Element(Host *h, QString name, QColor col, bool referrer)
0
 
0
   external = referrer;
0
 
0
- // std::cout << "[" << host->getDomain().toStdString() << "] ";
0
- // cout << "Element [" << name.toStdString() << "] created." << endl;
0
 }
0
 
0
 Element::~Element()
0
@@ -62,6 +60,7 @@ Element::~Element()
0
   out.clear();
0
   relations_in.clear();
0
   relations_out.clear();
0
+ activity_queue.clear();
0
   activities.clear();
0
 }
0
 
0
@@ -78,7 +77,7 @@ void Element::add_link_in(Element *e) {
0
       }
0
     }
0
 
0
- activities << new Activity(e, this);
0
+ activity_queue << new Activity(e, this);
0
   }
0
   messages++;
0
 }
0
@@ -214,6 +213,15 @@ void Element::render(GLWidget *gl) {
0
 
0
    bool hover = fabs(gl->getX() - x) <= r*1.5f && fabs(gl->getY() - y) <= r * 1.5f;
0
 
0
+ if( activity_queue.size() > 0 && rand() % (60/activity_queue.size()) == 0 ) {
0
+
0
+ Activity *a = activity_queue.takeFirst();
0
+ activities << a;
0
+ if( gl->useRecoil() ) {
0
+ a->fire();
0
+ }
0
+ }
0
+
0
    // Render circle
0
 
0
    if(hover) {
0
@@ -270,6 +278,9 @@ void Element::render(GLWidget *gl) {
0
     glBegin(GL_POINTS);
0
     for(Activities::iterator it = activities.begin(); it != activities.end(); ++it) {
0
       if( (*it)->render(gl) ) {
0
+ if( gl->useRecoil() ) {
0
+ (*it)->impact();
0
+ }
0
         delete *it;
0
         it = activities.erase(it);
0
       }
...
100
101
102
 
103
104
105
...
100
101
102
103
104
105
106
0
@@ -100,6 +100,7 @@ public:
0
   QLinkedList<Relation *> relations_in;
0
   QLinkedList<Relation *> relations_out;
0
 
0
+ QLinkedList<Activity *> activity_queue;
0
   QLinkedList<Activity *> activities;
0
 
0
 };
...
61
62
63
 
64
65
66
...
352
353
354
 
 
 
355
356
357
...
61
62
63
64
65
66
67
...
353
354
355
356
357
358
359
360
361
0
@@ -61,6 +61,7 @@ GLWidget::GLWidget(QWidget *parent, Hosts *h)
0
   lastTick = 0;
0
   maxSize = 0.0;
0
   maxHits = 0.0;
0
+ recoil = true;
0
 
0
   stipple_in = 0x0001;
0
   stipple_out = 0x8000;
0
@@ -352,6 +353,9 @@ void GLWidget::keyPressEvent(QKeyEvent *event) {
0
   } else if( event->key() == Qt::Key_V ) {
0
     forces = !forces;
0
     cout << "Forces " << forces << endl;
0
+ } else if( event->key() == Qt::Key_N ) {
0
+ recoil = !recoil;
0
+ cout << "Recoil " << recoil << endl;
0
   } else if( event->key() == Qt::Key_S ) {
0
     statsMode = !statsMode;
0
     cout << "statsMode " << statsMode << endl;
...
74
75
76
 
77
78
79
...
128
129
130
 
131
132
133
...
74
75
76
77
78
79
80
...
129
130
131
132
133
134
135
0
@@ -74,6 +74,7 @@ public:
0
    bool showForces() const { return forces; };
0
    int showSize() const { return sizeMode; };
0
    bool showStats() const { return statsMode; };
0
+ bool useRecoil() const { return recoil; };
0
 
0
    float getX() const { return x; };
0
    float getY() const { return y; };
0
@@ -128,6 +129,7 @@ protected:
0
 
0
    int linesMode;
0
    bool forces;
0
+ bool recoil;
0
    bool statsMode;
0
    int sizeMode;
0
    float maxSize;

Comments

    No one has commented yet.