Jump to content
  • Advertisement
Sign in to follow this  
Plerion

Problem with orhto matrix

This topic is 2162 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:

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

Share this post


Link to post
Share on other sites
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. Edited by Gavin Williams

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!