Sign in to follow this  
Raptisoft

Turn this projection matrix orthographic

Recommended Posts

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;


Edited by Raptisoft

Share this post


Link to post
Share on other sites

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