+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: [E2-Holo] Holographic interface

  1. #1
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default [E2-Holo] Holographic interface

    Ok, I have made a little holo interface, which is just a slider and a joystick (meant for a spaceship, thrust with slider and pitch/roll with joystick).
    The slider and joystick ranges from -1 to 1, and the joystick outputs a 2d vector where x is roll and y is pitch.

    I got a slight problem though, with the holos "shaking" when you use them, and it is (probably) because of my initial equation not being exact for it, making the outcome a slight overshoot. If you for example press far from the joystick it will shake much at start, then clsoe into where you actually hold (so the shake is also based on range from holo). The slider got same problem, just not as noticable.
    If anyone could help me with this part I would be happy.
    I figured this out myself, by reading up on line-point intersection.


    Credits:
    myself - as I codedeverything
    adadr - can get credit for almost anything I done with holos so far (he gave me a code I use as "holotraces"). I used his code at first, but now I figured out how to use line-plane intersection math. So he get credit for giving me some code I used at start when I coded this.


    The code:
    Code:
    @name Holographic Interface
    @outputs JoystickValue:vector2 SliderValue Toggle
    @persist [Pod Slider SliderHead Field Joystick Button]:entity
    
    #########################################################
    ################# Holographic Interface #################
    #################        By Feha        #################
    #########################################################
    ##### Line-Point intersection explanation at bottom #####
    #########################################################
    
    if (first() | duped()) {
        runOnTick(1)
        
        Pod = entity():isWeldedTo()
        
        #Create the base field
        holoCreate(1)
        holoScaleUnits(1,vec(1,55,48))
        holoPos(1,Pod:toWorld(vec(0,50,25)))
        holoAng(1,Pod:toWorld(ang(25,90,0)))
        holoMaterial(1,"models/props_lab/tank_glass001")
        holoParent(1,Pod)
        Base = holoEntity(1)
        
        #Create arrays over all the other holos
        SpawnModel = array("","","hqcylinder","dome","dome")
        SpawnScale = array(vec(1,2,30),vec(2,10,5),vec(30,30,1),vec(8,8,5),vec(10,10,5))
        SpawnPos = array(vec(-2,-20,-5),vec(-2,-20,-5),vec(-2,10,-7),vec(-2,10,-7),vec(-2,-8,16))
        SpawnAng = array(ang(0,0,0),ang(0,0,0),ang(90,0,0),ang(-90,0,0),ang(-90,0,0))
        SpawnMaterial = array("models/props_lab/tank_glass001_dx60","models/props_lab/xencrystal_sheet","models/props_lab/tank_glass001_dx60","models/props_lab/xencrystal_sheet","spacebuild/fusion")
        
        #Loop the arrays and create them local to the holo base field
        for (I=2,6) {
            holoCreate(I)
            holoModel(I,SpawnModel[I-1,string])
            holoScaleUnits(I,SpawnScale[I-1,vector]*1.04) #I heard this mult fixes holoScaleUnits()
            holoPos(I,Base:toWorld(SpawnPos[I-1,vector]))
            holoAng(I,Base:toWorld(SpawnAng[I-1,angle]))
            holoMaterial(I,SpawnMaterial[I-1,string])
            
            holoParent(I,1)
        }
        
        #The slider entities
        Slider = holoEntity(2)
        SliderHead = holoEntity(3)
        
        #The joystick entities
        Field = holoEntity(4)
        Joystick = holoEntity(5)
        
        #The button entity
        Button = holoEntity(6)
    }
    
    #Stuff
    Driver = Pod:driver()
    LMB = Driver:keyAttack1()
    
    Origin = Driver:shootPos()
    OriginDirVec = Driver:eye()
    
    
    ################################
    ########    Button    ##########
    ################################
    ButtonPos = Button:pos()
    
    Plane = ButtonPos
    P1 = Origin
    P2 = Origin+OriginDirVec
    N = Button:up()
    U = (N:dot(Plane-P1))/(N:dot(P2-P1))
    Vec = P1+U*(P2-P1)
    
    Aim = Vec:distance(ButtonPos) < 5  #Do you aim less then 5 units away from the button center?
    
    if (Aim & changed(LMB) & LMB) {
        Toggle = !Toggle
        holoMaterial(6,"spacebuild/fusion"+toString(3*Toggle):replace("0",""))
    }
    
    
    ################################
    ########    Slider    ##########
    ################################
    SliderPos = Slider:pos()
    
    Plane = SliderPos
    P1 = Origin
    P2 = Origin+OriginDirVec
    N = Slider:forward()
    U = (N:dot(Plane-P1))/(N:dot(P2-P1))
    Vec = P1+U*(P2-P1)
    
    Dir = Slider:toLocal(Vec) #Where on sliders local Z axis do you aim
    Aim = inrange(Dir:y(),-5,5) #Do you aim within the sliders width?
    
    if (Aim & LMB) {
        #The code I used before I checked up on line-plane intersection math.
    #    Vec = Driver:eye()*Origin:distance(SliderHead:pos())+Origin
    #    DirZ = SliderHead:toLocal(Vec):z()
    #    Z = Vec:distance(SliderHead:pos())*(DirZ/abs(DirZ))
    #    Vec = SliderHead:toWorld(vec(0,0,Z))
        
        Vec = Slider:toWorld(vec(0,0,Dir:z())) #Turn the local Z into world?
        Dist = Vec:distance(SliderPos)
        if (Dist < 15) {
            holoPos(3,Vec)
        } else {
            holoPos(3,SliderPos+(Vec-SliderPos):normalized()*15) #Set slider heap at top/bottom if you aim to far up/down on slider
        }
    }
    
    #Get the slider value
    DirZ = (Slider:toLocal(SliderHead:pos())):z() #Get the local Z
    Dist = SliderHead:pos():distance(SliderPos)*(DirZ/abs(DirZ)) #Turn it into a distance (which can be negative)
    if (abs(Dist) > 3) { #Is it more than 3 units from sliders center (to make setting stuff 0 easyer)?
        SliderValue = (Dist/15) #Turn distance to a value ranging from -1 to 1
    } else {
        SliderValue = 0 #Otherwise make it 0
    }
    
    ################################
    ########   Joystick   ##########
    ################################
    FieldPos = Field:pos()
    
    Plane = FieldPos
    P1 = Origin
    P2 = Origin+OriginDirVec
    N = Field:up()
    U = (N:dot(Plane-P1))/(N:dot(P2-P1))
    Vec = P1+U*(P2-P1)
    
    Aim = Vec:distance(FieldPos) < 22 #Do you aim less then 22 units away from the joystick center?
    #Bigger field to let you ctrl joystick even when not aiming at field (easyer getting max value).
    
    if (Aim & LMB) {
        #The code I used before I checked up on line-plane intersection math.
    #    Vec = Driver:eye()*Origin:distance(Joystick:pos())+Origin
    #    Dir = Joystick:toLocal(Vec)
    #    DirY = Dir:y()
    #    DirZ = Dir:z()
    #    Y = Vec:distance(Joystick:pos())*(DirY/abs(DirY))
    #    Z = Vec:distance(Joystick:pos())*(DirZ/abs(DirZ))
    #    Vec = Joystick:toWorld(vec(Z,Y,0))
    
        Dist = Vec:distance(FieldPos)
        if (Dist < 14) { #Do you aim less then 14 units away from the joystick center?
            holoPos(5,Vec) #Position the joystick where you aim
        } else { #Otherwise make it at edge of field, but towards where you aim
            Vec = FieldPos+(Vec-FieldPos):normalized()*14
            holoPos(5,Vec)
        }
    } else {
        holoPos(5,FieldPos) #Snap back joystick to 0 when you stop hold it or aim to far away
    }
    
    #Get the joysticks value (vector2)
    Dir = -Field:toLocal(Joystick:pos())/14 #Get where joystick is locally to field and make it into a value ranging from -1 to 1
    JoystickValue = vec2(Dir:y(),Dir:x()) #Turn it into a vector2
    
    
    
    #How does line-plane intersection work?
    
    #Plane = HoloPos #Get the planes center
    #P1 = Origin #Get a point on the line
    #P2 = Origin+OriginDirVec #Get a point on the line "after" point 1
    #N = Holo:up() #Get the normal (a vector pointin straight out of the surface) of the plane
    #U = (N:dot(Plane-P1))/(N:dot(P2-P1)) #Not really sure how, but it returns how many times the distance from point 1 to point 2 you need to go from point 1 to reach the intersection
    #Vec = P1+U*(P2-P1) #Get the intersections position
    [E2-Holo] Holographic interface-.jpg
    [E2-Holo] Holographic interface-.jpg

    EDIT:
    Updated code with a button, some repositioning, and positioning stuff now is made local to the base holo, not pod.

    EDIT2:
    I added screens, so ppl know what it is.

    EDIT3:
    Updated code with point-line intersection code, some tweaking to positions and scale, some other tweaks and a hell lot of comments (including explanation of line-point intersection).
    Last edited by feha; 03-16-2010 at 03:26 PM.

  2. #2
    Banned Samantha Fangs's Avatar
    Join Date
    Nov 2009
    Location
    Tulsa,oklahoma,USA
    Posts
    18

    Default Re: [E2-Holo] Holographic interface

    You need pictures, So people know what it is and what it looks like, Or else no picy picy no clicky clicky.

  3. #3
    Wirererer Aura's Avatar
    Join Date
    Sep 2008
    Posts
    165

    Default Re: [E2-Holo] Holographic interface

    What is there to click... It's an E2 code. Try harder at following that little bandwagon.

  4. #4
    Banned Samantha Fangs's Avatar
    Join Date
    Nov 2009
    Location
    Tulsa,oklahoma,USA
    Posts
    18

    Default Re: [E2-Holo] Holographic interface

    I am, Because if its a Holo he needs to post picture's so we know what it is, so be quiet, You haven't even read the rules have you.

  5. #5
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default Re: [E2-Holo] Holographic interface

    The rules doesnt say I need pictures, just suggest it. Tho I agree it is needed, because without around 5% actually tries the code, and the rest wont even see what it does. Kind of reason rules suggests it.

    I was tired at the timeo f posting though, so I forgott it, I will add it today, soon.

  6. #6
    Wirererer ben1066's Avatar
    Join Date
    Aug 2009
    Posts
    151

    Default Re: [E2-Holo] Holographic interface

    Nice advertising for mcbuilds feha On topic though it looks quite nice.

  7. #7
    Banned Samantha Fangs's Avatar
    Join Date
    Nov 2009
    Location
    Tulsa,oklahoma,USA
    Posts
    18

    Default Re: [E2-Holo] Holographic interface

    Heres the rules.
    Proper description.
    What is it, what does it do?
    Picture(s) or video.
    Unless there is nothing see of course. There is no need to post a picture of a single E2.

  8. #8
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default Re: [E2-Holo] Holographic interface

    And as you see there is nothing to see rly, unless I got a video of it, and I cant make videos. Besides, there is dozens of threads with no pictures, and I never seen one getting punished for it (other then the fact almost noone actualyl tries it out). But I got pictures, so there is no need to continue this discussion...

  9. #9
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default Re: [E2-Holo] Holographic interface

    Woot! I have learnt collission detection, or as it also is called, line-plane intersection. I now made my code work so well as if I actually had used rangers on the holograms! It is perfect, it is smooth, and all it need is some minor adjustements (so its even more smooth).

    I will post the new code very soon.

  10. #10
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default Re: [E2-Holo] Holographic interface

    *bump*
    Ok, I updated code now, edit # 3 contains info on what I done.

+ Reply to Thread
Page 1 of 2 12 LastLast

LinkBacks (?)

  1. 07-08-2010, 10:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots