• Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

# DirectX 11 coordinate system question

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Lyev  Members   -  Reputation: 118

Like
0Likes
Like

Posted 31 May 2012 - 09:37 AM

How do I make the coordinate system in DirectX 11 relative to the top left of the screen? I've setup an orthographic projection matrix, so that I can use screen coordinates but it makes more sense to me to have a top left origin, since I come from working with OpenGl.

I setup my projection matrix like this:
ww = the width of the window
and wh = the height of the window

```projection = XMMatrixIdentity ();
projection = XMMatrixOrthographicLH (ww, wh, -1, 1);
```

Edited by Lyev, 31 May 2012 - 09:50 AM.

### #2clb  Members   -  Reputation: 1596

Like
0Likes
Like

Posted 31 May 2012 - 11:16 AM

The Direct3D post-projective normalized viewport coordinate space spans from [-1, 1] in X direction, +X being towards right, and [-1, 1] in Y direction, +Y being towards the top of the screen. See http://msdn.microsoft.com/en-us/library/windows/desktop/cc308049(v=vs.85).aspx
Assuming vector*matrix transformation order, to make an orthographic space that has (0,0) as top-left and (1,1) as bottom-right, (and depth range of [0,1]) you can use the matrix:
```2 0 0 0
0 -2 0 0
0 0 1 0
-1 1 0 1
```
If you use matrix*vector, transpose the above matrix.
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

### #3mhagain  Members   -  Reputation: 3830

Like
0Likes
Like

Posted 31 May 2012 - 11:37 AM

XMMatrixOrthographicOffCenterLH is what you want here (although coming from an OpenGL background I suspect that you'll find XMMatrixOrthographicOffCenterRH to be even better for you).

Edited by mhagain, 31 May 2012 - 11:41 AM.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

### #4Lyev  Members   -  Reputation: 118

Like
0Likes
Like

Posted 31 May 2012 - 11:40 AM

Thanks for your help. XMMatrixOrthographicOffCenterLH worked great.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS