

EFFECT.Mat = Material( "cable/blue_beam" )
EFFECT.Refract = Material("anderes/broken_n");

/*---------------------------------------------------------
   Init( data table )
---------------------------------------------------------*/
function EFFECT:Init( data )

	self.StartPos 	 = data:GetStart()
	self.EndPos 	 = data:GetOrigin()
	self.Angles		 = data:GetAngle()
	self.LifeTime = CurTime() + 1.5
end

/*---------------------------------------------------------
   THINK
---------------------------------------------------------*/
function EFFECT:Think( )
	if CurTime() > self.LifeTime then return false end

	return true
end

/*---------------------------------------------------------
   Draw the effect
---------------------------------------------------------*/
function EFFECT:Render( )

	
	local StartPos = self.StartPos;
	local EndPos = self.EndPos;
	local Ang = (EndPos-StartPos):GetNormal():Angle()
	local Forward	= Ang:Forward();
	local Right 	= Ang:Right();
	local Up 		= Ang:Up();
	local Distance 	= StartPos:Distance(EndPos);
	local StepSize  = 20
	local LastPos;
	
	local RingTightness = 2
	
	local RingRadius = 4
	
	render.SetMaterial(self.Refract);
	render.DrawSprite(
		EndPos + (EndPos-StartPos):GetNormal()* -16,
		128,128,
		Color(120,120,255,255)
	);
	render.DrawSprite(
		EndPos,
		128,128,
		Color(120,120,255,255)
	);
	
	render.SetMaterial( self.Mat )
	
	for i=1, Distance, StepSize do
		local sin = math.sin( math.rad( i * RingTightness ) ) ;
		local cos = math.cos( math.rad( i * RingTightness ) );
		local Pos = StartPos+(Forward*i)+(Up*sin*RingRadius)+(Right*cos*RingRadius);
		if LastPos then
			render.DrawBeam(LastPos,Pos,4,0,0,Color(1,1,1,255))
		end
		LastPos = Pos
		if (i >= Distance - StepSize) then			
			local adjustPos = Pos - (Up*sin*RingRadius)-(Right*cos*RingRadius);
			render.DrawBeam(StartPos, adjustPos, 6, 0, 1, Color(255,255,255,255));
		end
	end
end
