3 This file is part of NetVis
4 Copyright @ 2008 Mikko Rasa, Mikkosoft Productions
5 Distributed unter the GPL
10 #include <msp/gl/immediate.h>
11 #include <msp/gl/matrix.h>
12 #include <msp/gl/transform.h>
13 #include <msp/time/units.h>
19 Packet::Packet(const Host &s, const Host *d, const GL::Color &c, unsigned i):
25 angle(rand()*M_PI*2/RAND_MAX),
26 rspeed(rand()*M_PI/RAND_MAX-M_PI/2)
29 void Packet::tick(const Time::TimeDelta &dt)
31 double f = dt/Time::sec;
42 void Packet::render(GL::PrimitiveBuilder &bld) const
46 if(!src.get_active() || (dest && !dest->get_active()))
49 const Vector2 &spos = src.get_position();
53 const Vector2 &dpos = dest->get_position();
54 Vector2 pos(spos.x*(1-x)+dpos.x*x, spos.y*(1-x)+dpos.y*x);
55 Vector2 corner(cos(angle)*size, sin(angle)*size);
57 if(bld.get_type()!=GL::QUADS)
62 bld.color(color.r, color.g, color.b, color.a);
63 bld.vertex(pos.x+corner.x, pos.y+corner.y);
64 bld.vertex(pos.x-corner.y, pos.y+corner.x);
65 bld.vertex(pos.x-corner.x, pos.y-corner.y);
66 bld.vertex(pos.x+corner.y, pos.y-corner.x);
71 bld.begin(GL::TRIANGLE_FAN);
72 bld.color(color.r, color.g, color.b, color.a*(1-x));
73 bld.vertex(spos.x, spos.y);
74 for(unsigned i=0; i<=24; ++i)
77 bld.vertex(spos.x+cos(a)*x*200, spos.y+sin(a)*x*200);