Problem with orhto matrix

Started by
0 comments, last by Gavin Williams 11 years, 6 months ago
Hey everyone

For my 2D framework im using ortho matrices in the vertex shader to project my coordinates. Now when im using OrthOffCenterLH something is not really going as it should.

Method 1:

void VertexMain(in VertexShaderInput vsInput, out PixelShaderInput output)
{
output = (PixelShaderInput)0;

float4 posTransformed = mul(float4(vsInput.position, 1), transformMatrix);
float xbase = -viewportSize.x / 2.0f;
float ybase = viewportSize.y / 2.0f;
posTransformed.x += xbase;
posTransformed.y = ybase - posTransformed.y;

output.position = mul(posTransformed, orthoProjMatrix);
output.texCoord = vsInput.texCoord;
output.color = vsInput.color;
}


And:

mScreenMatrix = Matrix.OrthoLH(mViewport.Width, mViewport.Height, 0, 1);


Everything is fine, the UI is at its correct place (except if transformMatrix is not Matrix.Identity, then its not on the screen...)

Method 2:

void VertexMain(in VertexShaderInput vsInput, out PixelShaderInput output)
{
output = (PixelShaderInput)0;

float4 posTransformed = mul(float4(vsInput.position, 1), transformMatrix);

output.position = mul(posTransformed, orthoProjMatrix);
output.texCoord = vsInput.texCoord;
output.color = vsInput.color;
}


And:

mScreenMatrix = Matrix.OrthoOffCenterLH(0, mViewport.Width, mViewport.Height, 0, 0, 1);


Well, i cannot describe it, so ill post a picture:
50872cf3b65532_2D.jpg

What is going on there? Isnt that supposed to be an offseted version of OrthoLH? Somehow it looks like a very weird perspectivic transformation...

Thank you for your advise!

Cromon
Advertisement
Is the off-center orthographic providing a viewing frustum that can have independant semi-axes ?

eg

+-------------------------------------------+
|...........................................|
|...............+...........................|
|...........................................|
+-------------------------------------------+

I've just tried using an off-center ortho camera, and i used


ProjMatrix = Matrix.OrthoOffCenterRH(-17, 17, -17, 17, zNear, zFar);
// (left,right,bottom,top,znear,zfar)


to view the cell covering 0,0 to 32,32, given that my camera has the following view matrix

Vector3 eye = new Vector3(16, 16, 24);
Vector3 target = new Vector3(16, 16, 0);
Vector3 up = new Vector3(0, 1, 0);

I don't know if that helps you check values or get a sense of orientations. I think at first it didn't work for me because I disregarded that the ViewMatrix is the same, and
hence the position and target are the same, so I had it offcentre, because the left/top/right/bottom are in relation to the eye vector.

This topic is closed to new replies.

Advertisement