Coordinate System

Hi  everyone!

I need some help here... I am trying to write a D3D-application which renders different objects depending on choises from a menu..

I just want to know:

How do I change the inbuilt( ) coordinate system in d3dx to a more standard one:
like 400,300 would be the center of the screen (using 800x600 px resolution)

any help or redirection would be appriciated!


Answer this question

Coordinate System

  • AvalonNewbie

    In Direct3D, there are no screen coordinates (like 400,300). You set up your scene in "world coordinates", and DirectX transforms those to screen coordinates for you when it renders the scene.

  • Franco Robles

    Not true Daniel Smile

    When you define your vertex format (FVF) you can specify D3DFVF_XYZRHW which tells D3D to use screen coords for the vertices instead of "model" coords. So you might have a vertex structure like:

    struct MYVERTEX
    {
        float x;    // 0 to MAXSCREENWIDTH
        float y;    // 0 to MAXSCREENHEIGHT
        float z;    // 0.0f
        float rhw;  // 1.0f
        D3DCOLOR colour; // 0xARGB
      };

    The rhw stands for "reciprocal of homogenous W" (obvious eh !) and should always be 1.0f. The z field is not used in screen coords and should be set to 0.0f. x and y are the standard Windows screen coords with x increasing left to right and y increasing top to bottom.

    Set your FVF with:

    DWORD D3DFVF_MYVERTEX = D3DFVF_XYZRHW | D3DFVF_DIFFUSE;
    pd3d9device->SetFVF(D3DFVF_MYVERTEX);

    The D3D9 SDK tutorial goes into this in more detail.

    20thCB





  • Michael-Thomson

    Likewise, if you are using managed DX9, then you should also be able to use CustomVertex.Transformed for you vertices. They are supposed to already be transformed into screen coordinates for your display, 0,0 being upper left.

    They have the same structure as 20thCentury's MYVERTEX structure

    For a C# example, look at Tutorial #2 in the sdk.

  • vc56522

    I have a question about this,
       is there a math formula that I can use to place objects in world space to make sure they are spaced out right, all the objects will be the same size.   

  • Coordinate System