+ Reply to Thread
Page 1 of 4 123 ... LastLast
Results 1 to 10 of 37

Thread: Digital Screen Scanner (Colour w/ hitNormal)

  1. #1
    Wire Noob Dingo2's Avatar
    Join Date
    Jan 2010
    Location
    Australia
    Posts
    8

    Red face Digital Screen Scanner (Colour w/ hitNormal)

    Pictures:
    This is a picture of what the exact code below can make (On the left obviously. It cant make those props )


    Below is a picture of the same set of props but with a code rewrite to make it work for a 512x512 screen


    Description:
    This code will use ranger functions to plot pixels on a digital screen (128x128) depending on the props infront of the E2 chip. So in effect its a scanner of props that then shows what they look like on a digital screen.

    Set-up:
    1. Create a digital screen with the Height and Width set to 128.
    2. Spawn the E2 chip on your choice of prop, or on the ground OR on the screen. It doesnt matter
    3: Get out the "Expression 2 - Wirelink" tool In Wire - Tools and left click on the digital screen with it
    4. Get out the Wire tool and wire the Ds [WIRELINK] input on the E2 to the digital screen's link [WIRELINK] output
    5. Place whatever you put the E2 chip on such that the E2 chip faces a contraption/prop/whatever
    6. Press E or whatever you have the Use key bound to and the scan will commence
    7. ENJOY YOUR PICTURE

    Code:
    @name Digital Scanner Colour (Dingo)
    @inputs Ds:wirelink
    @persist Y Range E:entity O:entity
    
    interval(100)       #Increase if hard quota is exceeded
    
    if(first() | changed(Ds)){ 
        Range = 500     #Set the range of the Ranger trace here
        Ds[1048569]=3   #Changes Number Format to RRRGGGBBB
        E = entity()
        Y = 129
        O = owner()
    }
    
    if(O:keyUse()){
        Ds[1048574]=1   #Clears Digital Screen
        Y = 0           #Reset Y Value
    }
        
        for(X = 0,128){ #Loop code from X = 0 to X = 128
            if(Y>128){
                exit()      #When done stop the for loop until reset
            }
        Ranger = ranger(Range,(X-64)/64,(Y-64)/64)                              #Set up Ranger with X Y skew
        LDir = (E:pos()-Ranger:position()):normalized()                         #Find the Light Direction
        DistSc = (Range - Ranger:distance())/Range                               #Generate a variable between 0 and 1 to darken into the distance
        Shade = Ranger:entity():getColor()*DistSc*LDir:dot(Ranger:hitNormal())  #Get the Shaded Colour of the pixel
        Clr = rgb2digi(Shade,3)                                                 #Turn Shade into the correct format
        Ds[X+ Y*128]= Clr                                                       #Plot pixel
    }
    
    Y++   #Goto next line
    Other Details:
    The Light Direction is currently from the E2 chip. I may change this at some point :mellow:

    If you're exceeding the hard quota increase the interval
    You can change the range of the scan where it says so in the code
    Try not to mess with the other lines unless you know what you're doing ^_^

    The code uses a ranger trace so it'll show what the props hitbox looks like which is not always exactly what see when you look at the prop, as you can see with the breen globe above.

    PS:
    I would appreciate any help with optimization. Thanks in advance


    [EDIT]: Newer, messier, less optimised, slower code. It now has Shadows, light sources and NO alpha blending since I killed it somehow
    Code:
    @name Digital Scanner Colour (Dingo)
    @inputs Ds:wirelink
    @persist Y Range E:entity O:entity LightA:array LCount Mul
    
    interval(100)
    
    if(first() | changed(Ds)){ 
        Range = 1500
        Ds[1048569]=3
        E = entity()
        Y = 129
        O = owner()
        findIncludePlayerProps(O)
    }
    
    if(O:keyUse()){
        Ds[1048574]=1
        Y = 0
        findByModel("models/hunter/misc/sphere025x025.mdl")
        LightA = findToArray()
        LCount = LightA:count()
    }
        
        for(X = Mul*64,(Mul+1)*64){ #Loop code from X = 0 to X = 128
            if(Y>128){
                exit()
            }
        Ranger = ranger(Range,(X-64)/128,(int(Y)-64)/128)
        Ent = Ranger:entity()
        TotL = 0
        TotS = 0
        Dist = Ranger:distance()
        Pos = Ranger:position()
        
        if(LCount){
        for(I = 1,LCount){
            LDir = (LightA:entity(I):pos() - Pos):normalized()
            TotL += abs(LDir:dot(Ranger:hitNormal()))
            
            rangerFilter(LightA)
            rangerFilter(Ent)
            LRanger = rangerOffset(LightA:entity(I):pos(),Pos)
            TotS += (LRanger:hit() ? 0.8 : 1 )
            if( I == LCount){
                AvgL = TotL/LCount
                AvgS = TotS/LCount
        }
        }
        }
        
        DistSc = -(Dist/Range)+1
        
        if(Ent:type():find("player")){FColor = (Ent:getColor() == vec(255,255,255)) ? teamColor(Ent:team()) : Ent:getColor()}
        elseif(!Ent:type():find("_") & Ranger:hit()){FColor = vec(0,255,0)}                            
        else{FColor = Ranger:entity():getColor()}
        
        Shade = FColor*DistSc*AvgL*AvgS
        DsColor = rgb2digi(Shade,3)
        Ds[X+ int(Y)*128]= DsColor
    }
    Mul = (Mul == 1 ? 0 : 1)
    Y+=0.5
    Last edited by Dingo2; 02-09-2010 at 03:59 AM. Reason: Adding newer code

  2. #2
    goluch
    Guest goluch's Avatar

    Default Re: Digital Screen Scanner (Colour w/ hitNormal)

    Wow this is the first scanner i have seen with 3d color.

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

    Default Re: Digital Screen Scanner (Colour w/ hitNormal)

    Yeah, but with the fact that its in color, your kinda loosing the distance perspective. But its cool.
    +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

  4. #4
    Wire Noob Dingo2's Avatar
    Join Date
    Jan 2010
    Location
    Australia
    Posts
    8

    Default Re: Digital Screen Scanner (Colour w/ hitNormal)

    The screen does darken the colours to black the further away the point the ranger trace hits. At least it should be, I'd say its because the props are quite close and the range is to big for the darkening to kick in much

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

    Default Re: Digital Screen Scanner (Colour w/ hitNormal)

    Quote Originally Posted by Dingo2 View Post
    The screen does darken the colours to black the further away the point the ranger trace hits. At least it should be, I'd say its because the props are quite close and the range is to big for the darkening to kick in much
    I get your point, you have some equations in there. I see that, but lets say we got a prop with color=[3,3,3], and 100 units away. on a normal screen you would see it quite white, but how would it look on yours?

    Still good job.
    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

  6. #6
    GUN
    GUN is offline
    Wire Sofaking GUN's Avatar
    Join Date
    Jan 2008
    Location
    California
    Posts
    668

    Default Re: Digital Screen Scanner (Colour w/ hitNormal)

    i have a fix for the tick quota,






    Code:
    @name Digital Scanner Colour (Dingo)
    @inputs Ds:wirelink
    @persist Y Range E:entity O:entity
    
    interval(100)       #Increase if hard quota is exceeded
    
    if(first() | changed(Ds)){ 
        Range = 500     #Set the range of the Ranger trace here
        Ds[1048569]=3   #Changes Number Format to RRRGGGBBB
        E = entity()
        Y = 129
        O = owner()
    }
    
    if(O:keyUse()){
        Ds[1048574]=1   #Clears Digital Screen
        Y = 0           #Reset Y Value
    }
        X=0
        while(X <,128){ #Loop code from X = 0 to X = 128
        if (ops()>maxquota()-1000|ops()>minquota()-1000 ) {continue} 
            if(Y>128){
                exit()      #When done stop the for loop until reset
            }
        Ranger = ranger(Range,(X-64)/64,(Y-64)/64)                              #Set up Ranger with X Y skew
        LDir = (E:pos()-Ranger:position()):normalized()                         #Find the Light Direction
       DistSc = (Range - Ranger:distance())/Range                               #Generate a variable between 0 and 1 to darken into the distance
        Shade = Ranger:entity():getColor()*DistSc*LDir:dot(Ranger:hitNormal())  #Get the Shaded Colour of the pixel
        Clr = rgb2digi(Shade,3)                                                 #Turn Shade into the correct format
        Ds[X+ Y*128]= Clr  
        X++                                                     #Plot pixel
    }
    
    Y++   #Goto next line

    useing a while loop and

    if (ops()>maxquota()-1000|ops()>minquota()-1000 ) {continue}

    will make it so if the loop gets close to the tick quota, itl skip the code for 1 cycle and resume on the next, if its still within the orange area, itl skip again, but it will do so very fast and i have yet to get it to the hard quota

    Maybe we're all gonna die, but we're gonna die in *really cool ways*.





  7. #7
    Wire Noob Dingo2's Avatar
    Join Date
    Jan 2010
    Location
    Australia
    Posts
    8

    Default Re: Digital Screen Scanner (Colour w/ hitNormal)

    Looking at that I'd say it would still add one to the Y value and therefore skip the rest of the digital screen line? [EDIT] Nvm I see it says continue now
    Regardless I'll put something similar in. Thankyou

    [EDIT2] Well for some reason if I use what you've got there, it exceeds the quota instantly and with a for loop it takes a a little bit but it still exceeded ...
    Not sure whats going on
    Last edited by Dingo2; 01-28-2010 at 05:03 AM.

  8. #8
    Master of Mars Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    852

    Default Re: Digital Screen Scanner (Colour w/ hitNormal)

    Quote Originally Posted by GUN View Post
    useing a while loop and

    if (ops()>maxquota()-1000|ops()>minquota()-1000 ) {continue}

    will make it so if the loop gets close to the tick quota, itl skip the code for 1 cycle and resume on the next, if its still within the orange area, itl skip again, but it will do so very fast and i have yet to get it to the hard quota
    I wonder why noone ever reads the docs on this. minquota() and maxquota() return how much is left of their respective quota, not the absolute size of the quota. Correct usage is to exit your loops if these functions get lower than a constant. Ideally the constant should be slightly more than the quota cost of one loop execution.

    Edit: To illustrate, compare
    Code:
    @persist A
    
    runOnTick(1)
    while(1){A++
        if (minquota() < 150) {break} 
        }
    and
    Code:
    @persist A
    
    runOnTick(1)
    while(1){A++
        if (ops()>maxquota()-1000|ops()>minquota()-1000 ) {break} 
        }
    The former stabilizes at 97% usage of the E2's capabilities, while the latter stops at a mere 40% (with default quotas).
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  9. #9
    Wire Sofaking Solece's Avatar
    Join Date
    Jul 2008
    Location
    Pittsburgh, PA
    Posts
    673

    Default Re: Digital Screen Scanner (Colour w/ hitNormal)

    Why use 97% when you can perfectly run at 100%?
    Code:
    while(opcounter()<5000){A++}
    I've always used this method and it runs perfectly at 100%.

  10. #10
    Master of Mars Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    852

    Default Re: Digital Screen Scanner (Colour w/ hitNormal)

    Because 5000 won't be the softquota for all servers at all times?
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

+ Reply to Thread
Page 1 of 4 123 ... LastLast

Similar Threads

  1. Expression 2 High Speed Digital Scanner :D
    By McLovin in forum Expression 2 Discussion & Help
    Replies: 19
    Last Post: 10-10-2009, 03:05 PM
  2. [E2] Map In Digital Screen
    By HellBoyUK in forum Expression 2 Discussion & Help
    Replies: 1
    Last Post: 08-10-2009, 12:07 AM
  3. Digital Screen
    By SpectreCat in forum Installation and Malfunctions Support
    Replies: 2
    Last Post: 08-04-2009, 06:34 PM
  4. Display RT Camera Screen on a Digital Screen?
    By LeonBlade in forum CPU, GPU, and Hi-speed Discussion & Help
    Replies: 5
    Last Post: 06-03-2009, 01:17 AM
  5. Colour digital screen
    By Tolyzor in forum Ideas & Suggestions
    Replies: 40
    Last Post: 03-25-2009, 10:24 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