Skip to main content
gamedev.net
🔒 Locked

[C++] View Matrix?

Started by SouthernMunk Dec 9, 2005 at 7:53 PM 1 replies 700+ views
Original Post
SouthernMunk
SouthernMunk
I have two questions: 1) When programming in DirectX, how do you know the 'range' of the X and Y axis? For example, if I was to define a quad like so:

/*
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)

struct CUSTOMVERTEX
{
    float x, y, z;
    DWORD colour;
};

A---------B
|       / |
|    /    |
| /       |
C---------D
*/

CUSTOMVERTEX quad[] =
{
    -1.0, 1.0, 1.0, 0x00ff0000,
    1.0, 1.0, 1.0, 0x00ff0000,
    -1.0, -1.0, 1.0, 0x00ff0000,
    1.0, -1.0, 1.0, 0x00ff0000,
};


How would I know how the red quad would appear on the screen? Does an X value of 1.0 mean the right edge of the display area and an X value of -1.0 mean the left edge of the display area? Does a Y value of 1.0 and -1.0 mean the top and bottom edge of the display area, respectively? 2) What do the w and h parameters of the D3DXMatrixOrthoLH() function do? Do they refer to the width and height of the display area in pixels, or is it an arbitary unit which the programmer must convert between? Thanks.
Woooooooot!
mdias
mdias
1) You should read this.

2)D3DXMatrixOrthoLH()'s w, and h, components are indeed an arbitary unit. If you think a little you're render target quad (usually a window) will not change no matter what projection matrix you use. So, if you want to match those units to pixels, you'd do something like this:

D3DXMATRIX matProj;D3DXMatrixOrthoLH( &matProj,                   (float)backbuffer.width,                   (float)backbuffer.height,                    nearClipPlane, farClipPlane );


backbuffer.width and backbuffer.height are your backbuffer's current width and height respectively.

note: I'm not taking into account window size changes, which will stretch the output image and not change the actual size of the backbuffer.
Armadon
Armadon
Quote:
How would I know how the red quad would appear on the screen? Does an X value of 1.0 mean the right edge of the display area and an X value of -1.0 mean the left edge of the display area? Does a Y value of 1.0 and -1.0 mean the top and bottom edge of the display area, respectively?


The (-1.0, 1.0, 1.0, 0x00ff0000) defines that, that particular vertex is 100% red. This means that you cannot get more red than that. The coordinates that you have specified for the vertex and the particular projection you have chosen (D3DXMatrixOrthoLH()) shows that this vertex is located at 1 unit left of the center(0.0f, 0.0f, 0.0f) of the world, 1 unit above the center of the world and 1 unit behind the center of the world. Read this for more information on coordinate systems.

Quote:

What do the w and h parameters of the D3DXMatrixOrthoLH() function do? Do they refer to the width and height of the display area in pixels, or is it an arbitary unit which the programmer must convert between?

The SDK Docs describes what the parameters mean. I suggest you look at the related MSDN SDK Documentation on D3DXMatrixOrthoLH here.
w is the width of the view volume
h is the height of the view volume.

I hope this helps.
Take care.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.