Sign in to follow this  

Problem with orhto matrix

This topic is 1910 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
[CODE]
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;
}[/CODE]

And:
[CODE]
mScreenMatrix = Matrix.OrthoLH(mViewport.Width, mViewport.Height, 0, 1);
[/CODE]

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:
[CODE]
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;
}
[/CODE]

And:
[CODE]
mScreenMatrix = Matrix.OrthoOffCenterLH(0, mViewport.Width, mViewport.Height, 0, 0, 1);
[/CODE]

Well, i cannot describe it, so ill post a picture:
[img]http://imagr.eu/up/50872cf3b65532_2D.jpg[/img]

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 Edited by Plerion

Share this post


Link to post
Share on other sites
Is the off-center orthographic providing a viewing frustum that can have independant semi-axes ?

eg
[code]
+-------------------------------------------+
|...........................................|
|...............+...........................|
|...........................................|
+-------------------------------------------+
[/code]
I've just tried using an off-center ortho camera, and i used

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

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. Edited by Gavin Williams

Share this post


Link to post
Share on other sites

This topic is 1910 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this