]> git.tdb.fi Git - netvis.git/blobdiff - source/packet.cpp
Resolve IP addresses to hostnames
[netvis.git] / source / packet.cpp
index 491e8076245bee11bb81aa49825db1a4e45f5997..512144a9517414bfd18576c0b9a18478392c0db3 100644 (file)
@@ -1,3 +1,10 @@
+/* $Id$
+
+This file is part of NetVis
+Copyright @ 2008 Mikko Rasa, Mikkosoft Productions
+Distributed unter the GPL
+*/
+
 #include <cmath>
 #include <msp/gl/immediate.h>
 #include <msp/gl/matrix.h>
@@ -13,11 +20,10 @@ Packet::Packet(const Host &s, const Host *d, const GL::Color &c, unsigned i):
        dest(d),
        color(c),
        x(0),
-       size(cbrt(i)),
-       angle(rand()*180.0/RAND_MAX),
-       rspeed(rand()*180.0/RAND_MAX-90.0)
-{
-}
+       size(cbrt(i)*1.5),
+       angle(rand()*M_PI*2/RAND_MAX),
+       rspeed(rand()*M_PI/RAND_MAX-M_PI/2)
+{ }
 
 void Packet::tick(const Time::TimeDelta &dt)
 {
@@ -27,46 +33,47 @@ void Packet::tick(const Time::TimeDelta &dt)
                x=1;
        angle+=rspeed*f;
        if(angle<0)
-               angle+=360;
-       if(angle>=360)
-               angle-=360;
+               angle+=M_PI*2;
+       if(angle>=M_PI*2)
+               angle-=M_PI;
 }
 
-void Packet::render() const
+void Packet::render(GL::PrimitiveBuilder &bld) const
 {
-       GL::push_matrix();
+       if(x<0)
+               return;
+       if(!src.get_active() || (dest && !dest->get_active()))
+               return;
 
        const Vector2 &spos=src.get_position();
 
        if(dest)
        {
                const Vector2 &dpos=dest->get_position();
-               GL::translate(spos.x*(1-x)+dpos.x*x, spos.y*(1-x)+dpos.y*x, 0);
-               GL::rotate(angle, 0, 0, 1);
+               Vector2 pos(spos.x*(1-x)+dpos.x*x, spos.y*(1-x)+dpos.y*x);
+               Vector2 corner(cos(angle)*size, sin(angle)*size);
 
-               GL::Immediate imm((GL::COLOR4_UBYTE,GL::VERTEX2));
-               imm.begin(GL::QUADS);
-               imm.color(color.r, color.g, color.b, color.a);
-               imm.vertex(-size, -size);
-               imm.vertex(size, -size);
-               imm.vertex(size, size);
-               imm.vertex(-size, size);
-               imm.end();
+               if(bld.get_type()!=GL::QUADS)
+               {
+                       bld.end();
+                       bld.begin(GL::QUADS);
+               }
+               bld.color(color.r, color.g, color.b, color.a);
+               bld.vertex(pos.x+corner.x, pos.y+corner.y);
+               bld.vertex(pos.x-corner.y, pos.y+corner.x);
+               bld.vertex(pos.x-corner.x, pos.y-corner.y);
+               bld.vertex(pos.x+corner.y, pos.y-corner.x);
        }
        else
        {
-               GL::translate(spos.x, spos.y, 0);
-               GL::Immediate imm((GL::COLOR4_UBYTE,GL::VERTEX2));
-               imm.begin(GL::TRIANGLE_FAN);
-               imm.color(color.r, color.g, color.b, color.a*(1-x));
-               imm.vertex(0, 0);
+               bld.end();
+               bld.begin(GL::TRIANGLE_FAN);
+               bld.color(color.r, color.g, color.b, color.a*(1-x));
+               bld.vertex(spos.x, spos.y);
                for(unsigned i=0; i<=24; ++i)
                {
                        float a=i*M_PI/12;
-                       imm.vertex(cos(a)*x*200, sin(a)*x*200);
+                       bld.vertex(spos.x+cos(a)*x*200, spos.y+sin(a)*x*200);
                }
-               imm.end();
        }
-
-       GL::pop_matrix();
 }