Jump to content

  • Log In with Google      Sign In   
  • Create Account

Problem with orhto matrix


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.

  • You cannot reply to this topic
1 reply to this topic

#1 Plerion   Members   -  Reputation: 368

Like
0Likes
Like

Posted 23 October 2012 - 05:50 PM

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:
Posted Image

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, 23 October 2012 - 05:53 PM.


Sponsor:

#2 Gavin Williams   Members   -  Reputation: 664

Like
0Likes
Like

Posted 24 October 2012 - 04:12 AM

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, 24 October 2012 - 04:23 AM.





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.



PARTNERS