# Defining a Camera Projection Matrix

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

## Recommended Posts

I know the DX SDK has helper functions for this, but I'm using an engine built on DX9, so I only have access to what they give me. At the moment, there is no ability to call D3DXMatrixPerspectiveFovLH() so I need to define my own projection matrix and set that. I've searched high and low ( including two DX9 books I already own, which helpfully skip over the subject completely by pointing me to D3DXMatrixPerspectiveFovLH instead of telling me anything useful ) and been googling on and off all day, and I really haven't come up with much. I found one article which was heavy on mathematical notation ( I'm entirely self taught, I can't follow mathematical notation very well ) and light on explanation. It also split everything up, showing you matrices for aspect ratio and near and far clipping planes, but not in the same matrix. Does anyone have a fairly simple explanation or heck, just a formula for what to put in each cell. Basically, I just want to use D3DXMatrixPerspectiveFovLH without using D3DXMatrixPerspectiveFovLH. So if I could find an explanation which told me how to get from the values you pass to D3DXMatrixPerspectiveFovLH to a projection matrix, that would be just perfect.

##### Share on other sites
The SDK help pages tell you exactly what goes into each matrix element... in theory. Some of the SDK entries on projection matrices have some errors. These errors are minor enough that watching two matrix variables, one with what they say it does, and one actually created via D3DX calls, should be enough to solve any problems in your own implementation. As far as I remember, the only thing that wasn't crystal clear to a non-math person like me was when they say cotangent, or cot, they mean 1/tan.

Regardless of engine, you should be able to include the d3dx9.h file, and call the function yourself. If the engine has it's own matrix class, just copy the results from the D3DXMATRIX to the engine's matrix. I'd assume the engine would provide projection matrix creation calls too.

##### Share on other sites

I guess I could download the SDK for the help files, although if there are errors, I'm not sure I'll be able to spot them because I won't be able to use the helper functions to compare, for the reason I'm about to explain.

Unfortunately, I'm not using C++ to do this, so just including the headers is not an option for me. Indeed my knowledge of C++ is pretty rudimentary and certainly doesn't extend to DX9 in any form, so it's not even like I could knock up a quick demo in C++ to find the errors.

##### Share on other sites
Check this, all the D3D docs are available online. Luckily, these docs are correct.

In the following snippet, a, and b end up identical.
D3DXMATRIX a,b;D3DXMatrixPerspectiveFovLH(&a, D3DX_PI/4, 1.1, 10, 1000);float yscale = 1.0f / (tanf((D3DX_PI/4)/2));float xscale = yscale / 1.1;D3DXMatrixIdentity(&b);b._11 = xscale;b._22 = yscale;b._34 = 1;b._33 = 1000.0f/(1000.0f - 10.0f);b._43 = -10.0f*1000.0f/(1000.0f - 10.0f);b._44 = 0;

##### Share on other sites
Beautiful, that's just what I needed. Thanks!

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628714
• Total Posts
2984353

• 23
• 11
• 10
• 13
• 14