• Create Account

## How to position a textured quad in screen coordinates?

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

### #1CdrTomalak  Members

272
Like
0Likes
Like

Posted 14 August 2012 - 08:36 AM

I am experimenting with different matrices, studying their effect on a textured quad. So far I have implemented Scaling, Rotation, and Translation matrices fairly easily - by using the following method against my position vectors:

for(int a=0;a<noOfVertices;a++)
{
myVectorPositions[a] = SlimDX.Vector3.TransformCoordinate(myVectorPositions[a],myPerspectiveMatrix);
}

However, I what I want to do is be able to position my vectors using world-space coordinates, not object-space.
At the moment my position vectors are declared thusly:

[source lang="csharp"] myVectorPositions[0] = new Vector3(-0.1f, 0.1f, 0.5f); myVectorPositions[1] = new Vector3(0.1f, 0.1f, 0.5f); myVectorPositions[2] = new Vector3(-0.1f, -0.1f, 0.5f); myVectorPositions[3] = new Vector3(0.1f, -0.1f, 0.5f);[/source]

On the other hand (and as part of learning about matrices) I have read that I need to apply a matrix to get to screen coordinates. I've been looking through the SlimDX API docs and can't seem to pin down the one I should be using.
In any case, hopefully the above makes sense and what I am trying to achieve is clear. I'm aiming for a simple 1024 x 768 window as my application area, and want to position a my textured quad at 10,10. How do I go about this? Most confused right now.

### #2Ripiz  Members

538
Like
0Likes
Like

Posted 14 August 2012 - 09:27 AM

Screen space is from (-1, -1) to (+1, +1), where (-1, 1) is top left corner, and (0, 0) is center, basically it's like cartesian plane.

If you want quad at (10, 10) from top left corner, it would look about
Vector2 pos(10, 10);
pos += Vector2(-width / 2, height / 2);
pos /= Vector2(width, height);


However, I'm unsure about the approach with matrices.

### #3SiCrane  Moderators

11523
Like
0Likes
Like

Posted 14 August 2012 - 09:42 AM

With SlimDX you can use Matrix.OrthoOffCenterLH()/Matrix.OrthoOffCenterRH() to create an orthographic projection matrix for a given set of screen dimensions (LH/RH specifies left-handed/right-handed coordinate systems). Whatever you specify as left becomes the x coordinate for the left side of the screen, right becomes the x coordinate for the right side of the screen, etc.

### #4CdrTomalak  Members

272
Like
0Likes
Like

Posted 14 August 2012 - 11:05 AM

I've had a crack at using the Ortho matrix you suggested. However my quad is invisible at the moment.

[source lang="csharp"] float oLeft = 0; float oRight = screenwidth; float oBottom = 0; float oTop = screenheight; float oZnear = 0.0f; float oZfar = 1.0f; myOrthoMatrix = SlimDX.Matrix.OrthoOffCenterLH(oLeft,oRight,oBottom,oTop,oZnear,oZfar);[/source]

[source lang="csharp"] for(int a=0;a<noOfVertices;a++) { myVectorPositions[a] = SlimDX.Vector3.TransformCoordinate(myVectorPositions[a],myOrthoMatrix); } [/source]

I'm not sure if my matrix definition is correct though, or my idea about how to use it is correct. I've interpreted the left and right parameters to mean the minimum and maximum X screen coordinates. Is that correct?

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.