X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpacket.cpp;h=89f77790166d86134e4d2e0d0ef04e6c60588b0e;hb=f3939c5da4add9af55a26293c99f0f013052cc25;hp=491e8076245bee11bb81aa49825db1a4e45f5997;hpb=229e1d6ab66a9e987ffe3cd4a8de7c7f874f6de1;p=netvis.git diff --git a/source/packet.cpp b/source/packet.cpp index 491e807..89f7779 100644 --- a/source/packet.cpp +++ b/source/packet.cpp @@ -1,4 +1,12 @@ +/* $Id$ + +This file is part of NetVis +Copyright @ 2008 Mikko Rasa, Mikkosoft Productions +Distributed unter the GPL +*/ + #include +#include #include #include #include @@ -13,11 +21,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 +34,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(); }