Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: EGP Artificial Horizon and Altimeter

  1. #1
    Wire Noob schmoller's Avatar
    Join Date
    Sep 2009
    Posts
    11

    Lightbulb EGP Artificial Horizon and Altimeter

    Name: *UPDATED* EGP Artificial Horizon and Altimeter

    Description:
    This Expression 2 script draws the Altitude, Pitch, and Roll of the E2 chip in a graphical airplane like display on a EGP Screen

    How to Use:
    1. Place an EGP screen
    2. Use the Wirelink tool on the screen
    3. Place the script in an E2 chip and place it somewhere
    4. Wire the 'S' input of the E2 to the screen
    5. Done

    Notes:
    If you find the Roll and/or Pitch is opposite to what you expect, you need to rotate the chip 180 degrees

    Code:
    Code:
    @name EGP Artificial Horizon and Altimeter - by Schmoller 
    @inputs S:wirelink
    @outputs 
    @persist 
    @trigger 
    
    interval(30)
    I = 0
    
    Altitude = toUnit("ft",entity():pos():z())
    
    Pitch = entity():angles():pitch()
    Roll = entity():angles():roll()
    
    
    #Altitude Gauge
    S:egpLine(I,60,10,60,502,255,255,255,255)
    I++
    S:egpBoxoutline(I,5,240,53,32,255,255,255,255)
    I++
    
    A = -5
    B = Altitude - (floor(Altitude / 20)*20)
    B *= -1
    
    while(A <= 5)
    {
        Dist = ((A * 20) - B)  * 8 
        S:egpLine(I,40,256 + Dist,60,256 + Dist,255,255,255,255)
        I++
        S:egpText(I,toString(round((floor(Altitude / 20)*20) - (A * 20))),10,256 + Dist,180,180,180,255)
        S:egpSetFont(I,"arial",20)
        I++
        
        A += 1
    }
    
    S:egpText(I,toString(round(Altitude)),10,246,(Altitude < 100 ? 255 : 180),(Altitude < 100 ? 100 : 180),(Altitude < 100 ? 100 : 180),255)
    S:egpSetFont(I,"arial",20)
    I++
    
    #Horizon (Pitch and Roll)
    S:egpCircle(I,256,256,350,350,255,255,255,255)
    I++
    S:egpCircle(I,256,256,348,348,90,90,200,255)
    I++
    
    
    Roll = (Roll < 0 ? Roll + 360 : Roll)
    Roll += 90
    
    #Ground Level Lines
    #S:egpLine(I,256 - 150 * (sin(Roll)),256 - 150 * cos(Roll),256 - 50 * (sin(Roll)),256 - 50 * cos(Roll),90,90,0,255)
    #I++
    #S:egpLine(I,256 + 50 * (sin(Roll)),256 + 50 * cos(Roll),256 + 150 * (sin(Roll)),256 + 150 * cos(Roll),90,90,0,255)
    #I++
    
    #Ground
    
    if(Pitch*4 >= 174)
    {
        S:egpCircle(I,256,256,348,348,90,90,0,255)
        I++ 
    }
    elseif(Pitch*4 >= -174)
    {
        #Calc Ground Level
        ZeroPosX = 256 - (Pitch * 4) * sin(Roll - 90)
        ZeroPosY = 256 - (Pitch * 4) * cos(Roll - 90)
        
        MaxPosX = 256 + 174 * sin(Roll - 90)
        MaxPosY = 256 + 174 * cos(Roll - 90)
        
        Theta = 2 * acos(-(Pitch * 4) / 174)
        CordLength = 2 * 174 * sin(Theta / 2)
        
        Point1 = vec2(ZeroPosX - (CordLength / 2) * (sin(Roll)),ZeroPosY - (CordLength / 2) * cos(Roll))
        Point2 = vec2(ZeroPosX + (CordLength / 2) * (sin(Roll)),ZeroPosY + (CordLength / 2) * cos(Roll))
        
        #Calc for quater way down
        H = 174 * (1 - cos(Theta / 2))
        Theta = 2 * acos(((Pitch * 4) - H/4) / 174)
        CordLength = 2 * 174 * sin(Theta / 2)
        ZeroPosX = 256 - ((Pitch * 4) - H/4) * sin(Roll - 90)
        ZeroPosY = 256 - ((Pitch * 4) - H/4) * cos(Roll - 90)
        
        Point3 = vec2(ZeroPosX + (CordLength / 2) * (sin(Roll)),ZeroPosY + (CordLength / 2) * cos(Roll))
        Point11  = vec2(ZeroPosX - (CordLength / 2) * (sin(Roll)),ZeroPosY - (CordLength / 2) * cos(Roll))
        
        #Calc for half way down
        Theta = 2 * acos(((Pitch * 4) - (H/4)*2) / 174)
        CordLength = 2 * 174 * sin(Theta / 2)
        ZeroPosX = 256 - ((Pitch * 4) - (H/4)*2) * sin(Roll - 90)
        ZeroPosY = 256 - ((Pitch * 4) - (H/4)*2) * cos(Roll - 90)
        
        Point4 = vec2(ZeroPosX + (CordLength / 2) * (sin(Roll)),ZeroPosY + (CordLength / 2) * cos(Roll))
        Point10 = vec2(ZeroPosX - (CordLength / 2) * (sin(Roll)),ZeroPosY - (CordLength / 2) * cos(Roll))
        
        #Calc for 3 quater way down
        Theta = 2 * acos(((Pitch * 4) - (H/4)*3) / 174)
        CordLength = 2 * 174 * sin(Theta / 2)
        ZeroPosX = 256 - ((Pitch * 4) - (H/4)*3) * sin(Roll - 90)
        ZeroPosY = 256 - ((Pitch * 4) - (H/4)*3) * cos(Roll - 90)
        
        Point5 = vec2(ZeroPosX + (CordLength / 2) * (sin(Roll)),ZeroPosY + (CordLength / 2) * cos(Roll))
        Point9 = vec2(ZeroPosX - (CordLength / 2) * (sin(Roll)),ZeroPosY - (CordLength / 2) * cos(Roll))
        
        #Calc for whole way down
        Theta = 2 * acos(((Pitch * 4) - (H/4)*3.75) / 174)
        CordLength = 2 * 174 * sin(Theta / 2)
        ZeroPosX = 256 - ((Pitch * 4) - (H/4)*3.75) * sin(Roll - 90)
        ZeroPosY = 256 - ((Pitch * 4) - (H/4)*3.75) * cos(Roll - 90)
        
        Point6 = vec2(ZeroPosX + (CordLength / 2) * (sin(Roll)),ZeroPosY + (CordLength / 2) * cos(Roll))
        Point8 = vec2(ZeroPosX - (CordLength / 2) * (sin(Roll)),ZeroPosY - (CordLength / 2) * cos(Roll))
        
        Point7 = vec2(MaxPosX,MaxPosY)
        #Makes the ground visible
        GroundArr = array(Point1,Point2,Point3,Point4,Point5,Point6,Point7,Point8,Point9,Point10,Point11)
        
        S:egpPoly(I,GroundArr,vec4(90,90,0,255))
        I++
    }
    
    #S:egpLine(I,ZeroPosX - (CordLength / 2) * (sin(Roll)),ZeroPosY - (CordLength / 2) * cos(Roll),ZeroPosX + (CordLength / 2) * (sin(Roll)),ZeroPosY + (CordLength / 2) * cos(Roll),150,150,0,255)
    #I++
    
    #Pitch
    #3 lines above and below the horizon
    
    A = floor(Pitch / 10)
    
    B = -2
    
    while(B <= 2)
    {
        Dist = (Pitch + (10*(B - A))) * 4
        
        X = 256 - (Dist * sin(Roll - 90))
        Y = 256 - (Dist * cos(Roll - 90))
        
        S:egpLine(I,X - 50 * sin(Roll),Y - 50 * cos(Roll),X + 50 * sin(Roll),Y + 50 * cos(Roll),200,180,0,255)
        I++
        S:egpText(I,toString((B-A) * 10),X -55 * sin(Roll),Y - 55 * cos(Roll),255,255,255,255)
        S:egpSetFont(I,"arial",20)
        I++
        B++
    }
    
    S:egpLine(I,106,256,190,256,255,255,255,255)
    I++
    S:egpLine(I,322,256,406,256,255,255,255,255)
    I++
    S:egpCircle(I,256,256,8,8,255,255,255,255)
    I++
    S:egpDraw()
    Screen shots:


    Last edited by schmoller; 02-11-2010 at 09:43 PM. Reason: UPDATE

  2. #2
    Wire Sofaking Unsmart's Avatar
    Join Date
    Dec 2008
    Location
    Belgium OR BANland
    Posts
    1,965

    Default Re: EGP Artificial Horizon and Altimeter

    AMAZING! Cant really describe how epic it is. it TOTALLY beats the GPU hud fighter.

    +rep
    New server IP: 89.238.160.17:27018
    Hologram contraptions 1 Holo contraptions 2 EGP stuff Holo minigun Holo javelin rocket launcher
    Unsmart: I doubt the intelligence of some people.
    Drunkie: Nobody could have said that any better than Unsmart.

    Unsmart: Solece, I totally did your mom yesterday
    Solece: Who hasnt

    Divran: there are more retarded people than there are clever people in this world

  3. #3
    Banned Nicolai1's Avatar
    Join Date
    Nov 2008
    Location
    Denmark.
    Posts
    1,251

    Default Re: EGP Artificial Horizon and Altimeter

    Quote Originally Posted by Unsmart View Post
    AMAZING! Cant really describe how epic it is. it TOTALLY beats the GPU hud fighter.

    +rep
    BP's HUD Fighter was made to be like the ones in real life, not some sci-fi stuff.

  4. #4
    billywitchdoctor.com Schilcote's Avatar
    Join Date
    Jan 2009
    Location
    There.
    Posts
    2,006

    Default Re: EGP Artificial Horizon and Altimeter

    Quote Originally Posted by Nicolai1 View Post
    BP's HUD Fighter was made to be like the ones in real life, not some sci-fi stuff.
    This is real. They have PYR displays exactly like this in commercial aircraft.

    Very, very nice work. Very.


    [19:16:47]Client "rcdraco" spawned in server
    [19:17:10]rcdraco: hamburgertime
    [19:18:04]rcdraco was killed by worldspawn
    [19:21:50]Dropped "rcdraco" from server

  5. #5
    Wire Noob TTFTCUTS's Avatar
    Join Date
    Aug 2008
    Location
    York/Middlesbrough, England
    Posts
    28

    Default Re: EGP Artificial Horizon and Altimeter

    Great work, looks good and is a good example of EGP...

    I might be wrong here, but isn't it meant to roll the other way, to keep the artificial horizon level with the real one?

  6. #6
    Wirererer Pangamini's Avatar
    Join Date
    Feb 2009
    Location
    Slovakia
    Posts
    358

    Default Re: EGP Artificial Horizon and Altimeter

    Quote Originally Posted by TTFTCUTS View Post
    Great work, looks good and is a good example of EGP...

    I might be wrong here, but isn't it meant to roll the other way, to keep the artificial horizon level with the real one?
    Yep, it is :-P

  7. #7
    Banned SGT_KILL's Avatar
    Join Date
    Apr 2009
    Location
    Tasmania,Australia
    Posts
    86

    Default Re: EGP Artificial Horizon and Altimeter

    the reason it is in planes is so they always know where lv is this you could be spun any witch way and have no clue how to get back or where you are

    there should be a perm line that is lv and then a marker that shows the angle of where the plane is

    i recommend you fire up a flight simulator then try again (the Microsoft 1 is ok) tricky to fly but fun

  8. #8
    Wire Noob schmoller's Avatar
    Join Date
    Sep 2009
    Posts
    11

    Default Re: EGP Artificial Horizon and Altimeter

    Thanks for the feedback guys. Sorry for the Roll being back the front, I haven't played a flight simulator in ages so I forgot which way it was supposed to go :P

    I have now updated the code to fix that and I decided to add in an extra feature, the ground is now shown as well as the level of the aircraft.

  9. #9
    Wirererer Lancelot's Avatar
    Join Date
    Feb 2009
    Posts
    292

    Default Re: EGP Artificial Horizon and Altimeter

    This looks good! Well done!
    You know what I hate? Sentences with ridiculous and very purposefully implanted subliminal messages.

    Chinoto: I just explained an idea that requires no parenting or bacon sensor.

    MOOCOW Admin Mod Beta Tester

  10. #10
    Banned SGT_KILL's Avatar
    Join Date
    Apr 2009
    Location
    Tasmania,Australia
    Posts
    86

    Default Re: EGP Artificial Horizon and Altimeter

    The fix looks sick now im trying to think if a way to use it... doh.....

Closed Thread
Page 1 of 2 12 LastLast

LinkBacks (?)

  1. 03-13-2010, 10:53 PM
  2. 02-13-2010, 08:17 AM

Tags for this Thread

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