

EFFECT.Mat = Material( "effects/wheel_ring" )

local WheelEffects = {}

/*---------------------------------------------------------
   Initializes the effect. The data is a table of data 
   which was passed from the server.
---------------------------------------------------------*/
function EFFECT:Init( data )
	
	local size = 64
	self.Entity:SetCollisionBounds( Vector( -size,-size,-size ), Vector( size,size,size ) )
	
	self.Entity:SetPos( data:GetOrigin() )
	self.Wheel 	= data:GetEntity()
	if (!self.Wheel:IsValid()) then return end
	
	local oldeffect = WheelEffects[ self.Wheel:EntIndex() ]
	if ( oldeffect && oldeffect:IsValid() ) then
	
		oldeffect:Remove()
	
	end
	
	// This 0.01 is a hack.. to prevent the angle being weird and messing up when we change it back to a normal
	self.Entity:SetAngles( data:GetNormal():Angle() + Angle( 0.01, 0.01, 0.01 ) )
	
	self.Entity:SetParent( self.Wheel )

	self.Pos = data:GetOrigin()
	self.Normal = self.Wheel:GetPos() - self.Pos
	self.Alpha = 255
	
	self.Direction = data:GetScale()
	
	self.Size = 64
	
	self.Size = data:GetEntity():BoundingRadius() + 8
	
	
	WheelEffects[ self.Wheel:EntIndex() ] = self.Entity
	
end


/*---------------------------------------------------------
   THINK
---------------------------------------------------------*/
function EFFECT:Think( )

	if (!self.Wheel:IsValid()) then return end

	local speed = FrameTime()
	
	self.Alpha = self.Alpha - speed * 100.0
	
	if (self.Alpha < 0 ) then return false end
	return true
	
end

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

	if (!self.Wheel:IsValid()) then return end

	if (self.Alpha < 1 ) then return end

	render.SetMaterial( self.Mat )

	render.DrawQuadEasy( self.Entity:GetPos(),
						 self.Normal:GetNormalized() * self.Direction * -1,
						 self.Size, self.Size,
						 Color( 255, 255, 255, self.Alpha ),
						 self.Alpha )
				

end
