Turn this projection matrix orthographic

Started by
0 comments, last by NumberXaero 10 years, 4 months ago

Hi all,

I have a projection matrix that I'm building manually...

Can anyone tell me how I can turn this to an orthographic view matrix? I keep trying examples online, but always get non-orthographic, sometimes hilarious, results.

(Note: For reasons of a tyrannical co-programmer, I can't simply use the Direct3DX functions to do this)

Thanks!


	float aAspect = (float)gPageWidth/(float)gPageHeight;
	float aNear = gZNear;
	float aFar = GetZDepth();

	float aWidth=COS(theFOV / 2.0f);
	float aHeight=COS(theFOV / 2.0f);
	if (aAspect > 1.0) aWidth /= aAspect;
	else aHeight *= aAspect;


	float s  = SIN(theFOV / 2.0f);
	float d  = 1.0f - aNear/aFar;

	float aMatrix[4][4];
	aMatrix[0][0]=aWidth;
	aMatrix[1][0]=0;
	aMatrix[2][0]=0;
	aMatrix[3][0]=0;
	aMatrix[0][1]=0;
	aMatrix[1][1]=aHeight;
	aMatrix[2][1]=0;
	aMatrix[3][1]=0;
	aMatrix[0][2]=0;
	aMatrix[1][2]=0;
	aMatrix[2][2]=s/d;
	aMatrix[3][2]=-(s * aNear / d);
	aMatrix[0][3]=0;
	aMatrix[1][3]=0;
	aMatrix[2][3]=s;
	aMatrix[3][3]=0;


Advertisement

Well you cant really "convert" it, they are calculated differently, there wont be any trig functions used because orthographic projection is a box, not a frustum, why not just use the formula for d3dx

http://msdn.microsoft.com/en-us/library/windows/desktop/bb205349%28v=vs.85%29.aspx

This topic is closed to new replies.

Advertisement