+ Reply to Thread
Results 1 to 9 of 9

Thread: ToScreen() in E2 ~ Possible?

  1. #1
    Wire Noob lollybobi's Avatar
    Join Date
    Aug 2009
    Posts
    19

    Unhappy ToScreen() in E2 ~ Possible?

    Well, I already thought about something like toScreen()...
    But I didn't know how the ToScreen() in the lua actuelly works, and how it does calculate it

    All it does is:
    It takes an vector and outputs an vec2, which is the possition on the screen

  2. #2
    Wire Noob CmdrMatthew's Avatar
    Join Date
    Aug 2010
    Posts
    3

    Default Re: ToScreen() in E2 ~ Possible?

    Code:
    //Turns the World vec3 into the Screen vec2
    local screenPos = Vector( WorldxPos, WorldyPos, WorldzPos ):ToScreen()
    //Sets a variable for the x screen coordinate
    ScreenxPos = screenPos.x
    //Sets a variable for the y screen coordinate
    ScreenyPos = screenPos.y
    or just

    Code:
    //Turns a world vector directly into a screen vector
    local screenPos = WorldPos:ToScreen()
    There's some example LUA that you could use for it. It has to be run on the client for it to work. If you want, I could write a E2 addon for it.

    Edit: Nevermind. I misread Lolly's post.
    Last edited by CmdrMatthew; 08-31-2010 at 05:56 PM.

  3. #3
    aka Colonel Never Online Colonel Thirty Two's Avatar
    Join Date
    Oct 2009
    Posts
    2,683
    Blog Entries
    5

    Default Re: ToScreen() in E2 ~ Possible?

    -snip-
    EDIT: Crap, thought you were talking about in-game screens, like the Digital screen, GPU, EGP, ect.
    Last edited by Colonel Thirty Two; 09-01-2010 at 02:27 PM.

  4. #4
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: ToScreen() in E2 ~ Possible?

    Quote Originally Posted by initrd.gz View Post
    EGP already has this.
    No it doesn't
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  5. #5
    Ursus maritimus Drunkie's Avatar
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    5,661
    Blog Entries
    1

    Default Re: ToScreen() in E2 ~ Possible?

    This sounds like it would be interesting to have. I wonder what algorithm ToScreen() in Lua uses to calculate the vector.

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

    Default Re: ToScreen() in E2 ~ Possible?

    It's a clientside function, meaning if you were to call the toScreen() func in e2, the server has to send a request for it to the client, then the client has to send the vector2 back to the server, then e2 has to return it. This might become very resource intensive when being used every tick.

  7. #7
    ส็็็็็็็็็็็็็็็็ส็็ ็็็็็ Dav1d's Avatar
    Join Date
    May 2009
    Posts
    1,118

    Default Re: ToScreen() in E2 ~ Possible?

    Well it would have little to no use on the server anyway.
    If it's E2 HUD functions you're interested in, someone already made them, just search around a bit.
    Personally I'd just wait for HUD2 to be finished, as that's run clientside, meaning there is little network traffic after the HUD2 script is sent.

    But yes, it is possible, if not useless.

  8. #8
    aka Colonel Never Online Colonel Thirty Two's Avatar
    Join Date
    Oct 2009
    Posts
    2,683
    Blog Entries
    5

    Default Re: ToScreen() in E2 ~ Possible?

    Quote Originally Posted by Drunkie View Post
    I wonder what algorithm ToScreen() in Lua uses to calculate the vector.
    Well, same algorithm for plotting 3D vertices on a 2d plane (the screen). Not too sure exactly how to do that though.

  9. #9
    Wirererer viperfan7's Avatar
    Join Date
    Nov 2007
    Posts
    119

    Default Re: ToScreen() in E2 ~ Possible?

    I have a bit of code I tried to do this with, although it never did work properly, but here it is if someone could use it some how

    Code:
    @name 3D Projection
    @inputs CamPos:vector CamAng:angle WorldPos:vector 
    @outputs ScreenPos:vector2 ViewerPos:vector
    @persist FoV 
    @persist [Screen]:vector2
    @persist [ViewerPos ModPos]:vector
    @persist [CPM CYM CRM]:matrix
    @persist [FM]:matrix4 [PFV FV]:vector4
    @trigger 
    
    runOnTick(1)
    
    if(first())
    {
        FoV = 75 #Replace with your Field of View
        Screen = vec2(1280,960) #Replace with your resolution
        ViewerPos = vec(Screen/2,Screen:x()/(2*tan(FoV/2)))
    }
    
    CPM = matrix(
                vec(1,          0        ,          0         ),
                vec(0,cos(CamAng:pitch()),-sin(CamAng:pitch())),
                vec(0,sin(CamAng:pitch()),cos(CamAng:pitch()))
                )
                
    CYM = matrix(
                vec(cos(CamAng:yaw()),0,sin(CamAng:yaw())),
                vec(0,1,0),
                vec(-sin(CamAng:yaw()),0,cos(CamAng:yaw()))
                )
    
    CRM = matrix(
                vec(cos(CamAng:roll()),-sin(CamAng:roll()),0),
                vec(sin(CamAng:roll()), cos(CamAng:roll()),0),
                vec(        0         ,         0         ,1)
                )
                
    ModPos = (CPM*CYM*CRM)*(WorldPos-CamPos)
    
    PFV = vec4(ModPos,1)
    
    FM = matrix4(
                vec4(1,0,0,-ViewerPos:x()),
                vec4(0,1,0,-ViewerPos:y()),
                vec4(0,0,1,0),
                vec4(0,0,1/ViewerPos:z(),0)
                )
                
    FV = FM*PFV
    
    ScreenPos = vec2(FV:x()/FV:w(),FV:y()/FV:w())*Screen:x()
    using the math on wikipedia's page on 3D projection

    also, the math for both 3x3 matrices and 4x4 is there, its right now using the 4x4


    if someone gets it to work please send me the code
    Last edited by viperfan7; 09-12-2010 at 07:57 PM.

+ Reply to 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