Followers 0

# How to position a textured quad in screen coordinates?

## 3 posts in this topic

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.
0

##### Share on other sites
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
[CODE]
Vector2 pos(10, 10);
pos += Vector2(-width / 2, height / 2);
pos /= Vector2(width, height);
[/CODE]

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

##### Share on other sites
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.
0

##### Share on other sites
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?
0

## Create an account

Register a new account