Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Real screen coordinates..

  1. #1

    Real screen coordinates..

    Hi fellow-programmers

    I am using left-handed orthogonal projection... on the screen it looks like this:
    .................+Y
    ..................|
    ..................|
    ..................|
    -X _______0.0 ______ +X
    ..................|
    ..................|
    ..................|
    .................-Y
    I want normal screen coordinate which should look like this:

    0.0___________ +X
    .|
    .|
    .|
    .|
    +Y

    What matrix do i need to convert this.
    I was thinking of flipping the Y axis and translating the origin to the upper-left corner of the screen, but things aren't that simple

    e.g when i use text, it is visible in the ortho view but not in my screen coordinate system. Propably because flipping Y, makes the mesh normals flip

    Does someone know a way of converting to screen-coordinates... is it possible :?

    Thank you in advance

    P.S i cant ASCII draw something with much spaces... this stupid editor removes them
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #2

    Real screen coordinates..

    in opengl?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  3. #3

    Real screen coordinates..

    Yea, what API are you using?

    OpenGL provides the very convenient

    glOrtho() command which does all this for you.
    My site: DelphiTuts.com (coming soon)...

    Download Font Studio 4.21 here.

  4. #4

    Real screen coordinates..

    Code:
    // Dwarf with Axe - GAMEDEV forums: 18 July 2002 6:12:57 PM
    //
    // There have been thousands of posts along the lines of
    // "How do I do 2d in OpenGL" to "Duuuhde, I wunt too maek
    // a two dee gaem in ohpun jee el; how do eye set uhp two dee???!?"
    //
    // I have developed a simple, nice, pretty way for all of you to have your 2D fun.
    
    procedure GlEnable2D;
    var
      vport: array[0..3] of integer;
    begin
      glGetIntegerv(GL_VIEWPORT, @vPort);
    
      glMatrixMode(GL_PROJECTION);
      glPushMatrix;
      glLoadIdentity;
      glOrtho(0, vPort[2], 0, -vPort[3], -1, 1);
    
      glMatrixMode(GL_MODELVIEW);
      glPushMatrix;
      glLoadIdentity;
    
      // flip Y axis
      glTranslatef(0, -vPort[3], 0);
    end;
    
    procedure GlDisable2D;
    begin
      glMatrixMode(GL_PROJECTION);
      glPopMatrix;
      glMatrixMode(GL_MODELVIEW);
      glPopMatrix;
    end;
    this will turn on & off windows-like coordinate system in opengl which has coordinate system like you described and uses 1 unit = 1 pixel.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  5. #5

    Real screen coordinates..

    Sorry... i should have told you guy's, i'm using DirectX
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  6. #6

    Real screen coordinates..

    anyone.. :? Such things should also be possible with DX isn't it?? :think:
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  7. #7

    Real screen coordinates..

    sorry but most people use opengl since it works "better" with delphi than dx, but i'm sure you could make your own orthogonal projection matrix function based on opengl reference implementation on sgi's website.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  8. #8

    Real screen coordinates..

    [pascal]function orthomatrix(l,r,b,t: integer; zn,zf: single): tmatrix4x4;
    begin
    result := identitymatrix;
    result[0] := 2.0 / (r-l);
    result[5] := 2.0 / (t-b);
    result[10] := -2.0 / (zf-zn);
    result[12] := -(r+l) / (r-l);
    result[13] := -(t+b) / (t-b);
    result[14] := -(zf+zn) / (zf-zn);
    result[15] := 1.0;
    end;[/pascal]
    This will probably work for you. It might need transposing as you use directx as it's made for opengl
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  9. #9

    Real screen coordinates..

    That will create the following matrix:

    [2.0 / (r-l),0----------,0----------,0----------]
    [0----------,2.0 / (t-b) ,0----------,0----------]
    [0----------,0----------,-2.0 / (zf-zn) ,0----------]
    [-(r+l) / (r-l),-(t+b) / (t-b),-(zf+zn) / (zf-zn),1]

    The Orthogonal Matrix for D3D can be found here
    (I'm targetting the D3DXMatrixOrthoLH function)

    I dont think it needs transposing, does it??

    Maybe a stupid question but what do the (r,l,t,b) parameters mean :? (i think it has something to do with the size of the window, but i need a more specific definition) :razz:
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  10. #10

    Real screen coordinates..

    right,left,top,bottom

    with a 640x480 windows you would call it with params:
    (0,640,480,0,znear,zfar)

    This will ofcourse not produce exactly the result you want as the coordinate system will start in the bottomleft corner of the screen. I think that call it with the params: (0,640,0,480,znear,zfar) is what you want but I think that might invert the z-axis
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

Page 1 of 2 12 LastLast

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
  •