Saturday, 6 February 2010

Eye code testing system (ECTS)

So with my work recently on making different ranger-based eyes, I've been in need of a more in-depth way of discerning the quality of their results, which isn't really possible if all I'm seeing is a bunch of holos of various colours in a circle or somesuch in midair. So with that in mind, I decided to try and translate to a player-viewable experience what the eye was actually seeing.

After quite a bit of frustration and a quick translation from wires to wirelinks where possible, here we have the Eye Code Testing System (ECTS for short).

The eye itself can output the arrays or there can be an intermediary chip translating the ranger outputs to arrays, so long as the eye views based on an angle and a world position (Or can at least be readily modified to do so) it can be tested by the player with this system. Simply wirelink a cam controller and adv. pod controller to the E2 and wire up in the array inputs. The system can test variable focusing, entity-detection, as well as distance, hit, and colour recognition.

And now, the code:
@name Eye Code Testing System (ECTS)
@inputs [Posit Hit HNorm Ent]:array
@inputs [Cam Pod]:wirelink
@outputs Pos:vector Ang:angle Range Foc
@persist [RHit Colour Distance Entities Norm Rel] Speed
@persist Box:entity Max [In Po]:vector On
@persist [PoA HiA HNA EnA]:array
@persist T M B Inc
@trigger none

if(first()){
#====Functional Variables====#
Range=200
Speed=5

Distance=1 #Can the eye distinguish distances?
RHit=1 #Can the eye tell if it's hit something?
Colour=0 #Can the eye discern colour?
Entities=1 #Can the eye discern entities?
#Colour & Entities override one another
Norm=1 #Can the eye discern the hitnormal?

Rel=1 #Does the eye produce local vectors?

#============================#
#=======Function Start=======#
#============================#

T=Posit:count() #It helps to wire up Posit & refresh here
B=T+1 #Box hologram number
M=1

Foc=Range/4 #Default focus
Inc=Range/100 #Focus shift increment

Po=vec(0,0,2000) #Location of Box hologram
Pos=rangerOffset(600,vec(),vec(0,0,-1)):position()+vec(0,0,64)
In=Pos #Default start position for the eye
}
if(M<=B & !tickClk()){
interval(1000)
N=0
while(N<=10 & M<=B){
holoCreate(M,Po)
holoModel(M,(Norm ? "hqcone" : "hqicosphere2"))
if(M==B){
D=Range*2.5
holoScaleUnits(B,vec(1,1,1)*-D)
holoModel(B,"hqicosphere2")
holoColor(B,vec())

Box=holoEntity(B)
Max=200
}
else{
holoScale(M,vec(1,1,1)/2)
}
M++,N++
}
}
else{
runOnTick(1)
}
On=Pod["Active",number]
Cam["Activated",number]=On
if(!On & $On){
Pos=In
Ang=ang()
Foc=Range/4

Cam["Angle",angle]=Ang
}
elseif(On){
Po=Box:toWorld(Box:boxCenter())
Cam["Position",vector]=Po

W=Pod["W",number] S=Pod["S",number]
A=Pod["A",number] D=Pod["D",number]


#View direction rotation
if(A|D){
Ang+=ang(0,1,0)*(A-D)
Cam["Angle",angle]=Ang
}
Look=vec(1,0,0):rotate(Ang)

#Motion application
if(W|S){
Look*=5
Pos+=Look*(W-S)
Pos=rangerOffset(600,Pos,vec(0,0,-1)):position()+vec(0,0,64)
}

#User focus variation
Ne=Pod["NextWeapon",number] Pr=Pod["PrevWeapon",number]
Al=Pod["Alt",number]
if(Al){Foc=Range/4}
else{Foc+=Inc*(Ne-Pr)}


N=1
while(M<=T & N<=10){
#Location
H=PoA[M,vector]
H-=Pos*!Rel
R=(Distance ? H:length()/Range : 1)
H=H:normalized()*(Max*R)
holoPos(M,Box:toWorld(H))

if(RHit){
#Colouration
D=(255*R)
Ba=vec(1,1,1)*D

CE=Entities|Colour
if(EnA[M,entity] & CE){
E=EnA[M,entity]

if(Entities & !Colour){
if(E:type():lower():find("prop")){
holoColor(M,vec(0,1,0)*D)
}
elseif(E:isNPC()){holoColor(M,vec(1,0,0)*D)}
else{holoColor(M,Ba)}
}
elseif(Colour & !Entities){
Col=E:getColor()
holoColor(M,Col*D)
}
}
elseif(HiA[M,number]){holoColor(M,Ba)}
else{holoColor(M,vec())}

#Hit Normal
if(Norm){
An=HNA[M,vector]:toAngle()+ang(90,0,0)
holoAng(M,An)
}
else{holoAng(M,ang())}
}


M++,N++
}
if(M>=T){
M=1
PoA=Posit
HiA=Hit
HNA=HNorm
EnA=Ent

T=Posit:count()
}
}

No comments:

Post a Comment