@name FailCake 2D Camera
@inputs Screen:wirelink Start Clean
@outputs Version:string E:entity Y X Dis Max Count MaxR
@persist Count Res
@trigger all
@model models/jaanus/wiretool/wiretool_range.mdl

runOnTick(1)

if(first() | duped()){
E = entity()

    Count=0
    Res=256
    Screen[1048572]=Res  # Set Vertical Resolution
    Screen[1048573]=Res  # Set Horizontal Resolution
    Screen[1048569]=2  # Set Color Mode
    Screen[1048574]=0  # Hardware Clear screen
    Max = 66216
    MaxR = 200
    
    Version = "0.0.1"
    setName("FailCake 2D Camera [ALPHA][v."+Version+"]")   

holoCreate(1)
holoModel(1,"cube")
holoScaleUnits(1,vec(4,4,4))
holoPos(1,E:toWorld(vec(0,0,5))) 
holoColor(1,vec(0,0,255))
holoMaterial(1,"models/wireframe")

holoCreate(2)
holoModel(2,"hqcylinder")
holoPos(2,E:toWorld(vec(0,0,5))) 
holoColor(2,vec(255,255,255))
holoMaterial(2,"")
holoParent(2,E)
}

rangerIgnoreWorld(1)
Ranger = rangerOffset(MaxR,E:pos() + vec(0,X-100,Y/2),E:up())
Dis = E:pos():distance(Ranger:position())
holoPos(1,Ranger:position())


Vec =  (E:pos() + Ranger:position()) / 2
Ang = (E:pos() - Ranger:position()):toAngle() + ang(90,0,0)

holoPos(2,Vec)
holoAng(2,Ang)
holoScaleUnits(2,vec(1,1,Dis))

if(Start){
    
if(Count <= Max){
for(I=0,7){
    
        Count++
        X=(Count%Res)
        Y=floor(Count/Res)
        
        Dis2 = MaxR - Dis
        
        if(Dis < 200){
        Screen[Count] = rgb2digi(vec(Dis2/1,Dis2/1,Dis2/1),2)
        }else{
        Screen[Count] = rgb2digi(vec(50,50,50),2)
        }
        setName("FailCake 2D Camera[ALPHA]["+Count+"]")  

}

}
    
} 
    

if(Clean){
    Screen[1048574]=0  # Hardware Clear screen 
    Count = 0
    X = 0
    Y = 0   
}
