This is something I've been putting together today for a larger project (Predominantly because it's dang near impossible to make hands on the proper scale out of actual props, but holos have no physics).
You can change whether it's a lefty or a righty, by changing the LR input between 1 and -1. Initial tests say it shouldn't matter how or where you spawn the chip, the holo should remain stable. The fingers are nonfunctional at the moment but the hand should still point it's palm ominously towards the input Entity.
After that, you use the State input to determine the mode of the glove, state 1 holds objects and moves them around, whereas state 2 allows you to rotate them (Naturally I recommend two gloves for that reason). There's no player user interface so I'm afraid you're on your own for that right now.
And now, onto the code:
@name Alarei Telekinetic Applications Glove
@inputs State Entity:entity LR Posi:vector
@inputs LockA Ang:angle
@inputs LockP Dif:vector Vel
@persist [Pos Sca Angle Mod Par]:array H Mat:string Start
@persist An:angle
@persist [V Col]:vector A:angle Core:entity
##MANUAL##
#Input 1 into LR for a Right hand, -1 for a Left hand
#State 1 is positioning, state 2 is angling
#In either state, the glove only affects the input Entity
#Positioning
#Flip LockP to freeze the entity relative to the glove
#Input a Dif to move it in a given direction on grabbing
#Vel adds the Dif each tick for sustained velocity
#Angling
#Flip LockA to freeze the entity's rotational movement
#Input Ang to rotate the entity to a desired angle
#LockA overrides Ang if both are input
if(first()){
Pos:pushVector(vec()) Sca:pushVector(vec(0.5,0.417,0.333)) Angle:pushAngle(ang()) Mod:pushString("hqtorus2") Par:pushNumber(1)
Pos:pushVector(vec()) Sca:pushVector(vec(0.417,0.417,0.10)) Angle:pushAngle(ang()) Mod:pushString("hqicosphere2") Par:pushNumber(1)
Pos:pushVector(vec(0,2*LR,-0.5)) Sca:pushVector(vec(0.249,0.249,0.124)) Angle:pushAngle(ang()) Mod:pushString("hqicosphere2") Par:pushNumber(1)
Pos:pushVector(vec(0,0,-0.143)) Sca:pushVector(vec(0.457,0.457,0.124)) Angle:pushAngle(ang(180,0,0)) Mod:pushString("dome2") Par:pushNumber(1)
Pos:pushVector(vec(0,3*LR,-0.5)) Sca:pushVector(vec(0.083,0.083,0.083)) Angle:pushAngle(ang()) Mod:pushString("hqicosphere2") Par:pushNumber(4)
Pos:pushVector(vec(1,3*LR,-0.5)) Sca:pushVector(vec(0.167,0.167,0.333)) Angle:pushAngle(ang(90,0,0)) Mod:pushString("hqcylinder") Par:pushNumber(5)
Pos:pushVector(vec(2,-2*LR,0)) Sca:pushVector(vec(0.083,0.083,0.083)) Angle:pushAngle(ang()) Mod:pushString("hqicosphere2") Par:pushNumber(1)
Pos:pushVector(vec(3,-2*LR,0)) Sca:pushVector(vec(0.167,0.167,0.333)) Angle:pushAngle(ang(90,0,0)) Mod:pushString("hqcylinder") Par:pushNumber(7)
Pos:pushVector(vec(5,-2*LR,0)) Sca:pushVector(vec(0.083,0.083,0.083)) Angle:pushAngle(ang()) Mod:pushString("hqicosphere2") Par:pushNumber(8)
Pos:pushVector(vec(6,-2*LR,0)) Sca:pushVector(vec(0.167,0.167,0.333)) Angle:pushAngle(ang(90,0,0)) Mod:pushString("hqcylinder") Par:pushNumber(9)
Pos:pushVector(vec(3,LR,0)) Sca:pushVector(vec(0.083,0.083,0.083)) Angle:pushAngle(ang()) Mod:pushString("hqicosphere2") Par:pushNumber(1)
Pos:pushVector(vec(4,LR,0)) Sca:pushVector(vec(0.167,0.167,0.333)) Angle:pushAngle(ang(90,0,0)) Mod:pushString("hqcylinder") Par:pushNumber(11)
Pos:pushVector(vec(6,LR,0)) Sca:pushVector(vec(0.083,0.083,0.083)) Angle:pushAngle(ang()) Mod:pushString("hqicosphere2") Par:pushNumber(12)
Pos:pushVector(vec(7,LR,0)) Sca:pushVector(vec(0.167,0.167,0.333)) Angle:pushAngle(ang(90,0,0)) Mod:pushString("hqcylinder") Par:pushNumber(13)
H=1
Mat="models/combine_scanner/scanner_eye"
}
if(Pos:count()){interval(1000)}
else{runOnTick(1)}
if(!Start){
N=0
while(N<=10 & Pos:count()){
P=entity():toWorld(vec(0,0,30))+Pos[1,vector]
S=Sca[1,vector]
A=Angle[1,angle]
M=Mod[1,string]
Pa=Par[1,number]
holoCreate(H,P,S,A)
holoModel(H,M)
holoParent(H,Pa)
H++,N++
Pos:remove(1)
Sca:remove(1)
Angle:remove(1)
Mod:remove(1)
Par:remove(1)
if(!Pos:count()){H=1}
}
GM=holoEntity(14):getMaterial()
while(!Pos:count() & GM!=Mat & N<=10){
holoMaterial(H,Mat)
H++,N++
}
if(!Pos:count() & GM==Mat){
Start=1
Core=holoEntity(2)
}
}
if(LR & $LR){reset()}
if(Start){
if(Posi){holoPos(1,Posi)}
else{holoPos(1,entity():toWorld(vec(0,0,30)))}
holoMaterial(2,(State ? "models/props_combine/tpballglow" : ""))
Co=Core:getColor()
if(Co!=Col){
Core:soundPlay(1,1,"buttons/button9.wav")
Col=Co
}
Box=Entity:toWorld(Entity:boxCenter())
if(Entity & State){
An=(Box-holoEntity(1):pos()):toAngle()
holoAng(1,A:setRoll(0)-ang(22.5,0,0))
}
#Relative locking mechanism
LP=LockP & $LockP & State==1
#Positional locking
if(LP){
V=Core:toLocal(Box)
V+=Dif
}
elseif(!LockP){
V=Core:toLocal(Box)
}
#Angular locking
if(LockA & Entity & $LockA|!LockA){
A=Entity:angles()
}
Mass=Entity:mass() VelW=Entity:vel()
if(State==1){ #Positioning
holoColor(2,vec(0,1,0)*255)
V+=Dif*Vel #Application of applied velocity
Des=Core:toWorld(V)
Vec=Des-Box
Vec*=Mass
Vec-=VelW/2
Entity:applyForce(Vec*Mass)
}
elseif(State==2){ #Angling
holoColor(2,vec(1,0,1)*255)
Ine=Entity:inertia() AVel=Entity:angVelVector()
Ag=(LockA ? A : Ang)
Q1=quat(Entity)
Q2=quat(Ag)
Q=Q2/Q1
Torq=Entity:toLocal(rotationVector(Q)+Box)*Mass^2
Torq-=AVel*Mass
Torq*Ine
Entity:applyTorque(Torq)
}
else{
holoColor(2,vec(0,1,1)*255)
}
}
Monday, 15 February 2010
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:
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()
}
}
Thursday, 4 February 2010
Plans for the Future
I'm always working around with some complex stuff, however simple I may think it is. One of the things I'm most known for though is drones, and figuring out control systems and such for them to function and work together co-operatively.
With the gBrain, I'm basically producing a basis for any drone to think and operate effectively without the inherent need for the player to actually figure it out beforehand. At most they just need a few basic ideas for what the gBrain should encourage the drone to do.
With the holographic arm I've been toying around with, which moves to be close to a target point by rotating it's joints as little as possible, I'm making a basis for you to make chassise with few components that move around with applyTorque applied to ballsockets, meaning you can have more human-sized and simplistic drones.
And very recently I've been looking at different patterns and styles for creating an effective "eye" for a drone to gather information about it's environment through, including a simple light spread method and a more complex focal point-based version mirroring the human eye's function. This means you can add it to a drone and it'll already have a strong idea of what's going on around it.
So the full picture should perhaps come into frame now. I don't expect to make a fully-functional science-fiction AI in Garry's Mod, but if I can eventually put together a little humanoid or whatever robot that I can plug gBrain into with a basic identification process for the holo-arm applyTorque joint system and a pair or so of eyes and have it run along without me needing to interfere with it at all, I'll be a very happy man.
I've made contraptions that almost every gmodder has made, I've made some very neat and sometimes primitive (in hindsight at least) drones, and I've toyed with the basis processes of the gmod physics engine and the real universe.
I think the next step for Garry's Mod contraptions is to make them self-sufficient. It's time we turned over the reigns to the contraptions themselves and took the seat of God in this virtual world. I think it's time we, the players, became the observers more than the builders.
And what's more, I think our ability to do so is right around the corner.
With the gBrain, I'm basically producing a basis for any drone to think and operate effectively without the inherent need for the player to actually figure it out beforehand. At most they just need a few basic ideas for what the gBrain should encourage the drone to do.
With the holographic arm I've been toying around with, which moves to be close to a target point by rotating it's joints as little as possible, I'm making a basis for you to make chassise with few components that move around with applyTorque applied to ballsockets, meaning you can have more human-sized and simplistic drones.
And very recently I've been looking at different patterns and styles for creating an effective "eye" for a drone to gather information about it's environment through, including a simple light spread method and a more complex focal point-based version mirroring the human eye's function. This means you can add it to a drone and it'll already have a strong idea of what's going on around it.
So the full picture should perhaps come into frame now. I don't expect to make a fully-functional science-fiction AI in Garry's Mod, but if I can eventually put together a little humanoid or whatever robot that I can plug gBrain into with a basic identification process for the holo-arm applyTorque joint system and a pair or so of eyes and have it run along without me needing to interfere with it at all, I'll be a very happy man.
I've made contraptions that almost every gmodder has made, I've made some very neat and sometimes primitive (in hindsight at least) drones, and I've toyed with the basis processes of the gmod physics engine and the real universe.
I think the next step for Garry's Mod contraptions is to make them self-sufficient. It's time we turned over the reigns to the contraptions themselves and took the seat of God in this virtual world. I think it's time we, the players, became the observers more than the builders.
And what's more, I think our ability to do so is right around the corner.
Subscribe to:
Posts (Atom)
