# World, View, and Projection Matrices

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

## Recommended Posts

I have quite the trouble with the world, view, and projection matrices. I understand how the world matrix works, but I don't know how to implement it can you give an example? also for the perspective projection I use the following method:
[source lang="csharp"] public static Matrix3D ProjectionMatrix(double angle, double aspect, double near, double far)
{
double size = near * Math.Tan(MathUtils.DegreeToRadian(angle) / 2.0);
double left = -size, right = size, bottom = -size / aspect, top = size / aspect;
Matrix3D m = new Matrix3D(new double[,] {
{2*near/(right-left),0,(right + left)/(right - left),0},
{0,2*near/(top-bottom),(top+bottom)/(top-bottom),0},
{0,0,-(far+near)/(far-near),-(2 * far * near) / (far - near)},
{0,0,-1,0}
});
return m;
}
[/source]is there anything wrong here?
and the last question how do I use the camera matrix? Edited by Belos

##### Share on other sites
I don't know if it will help you, but you might read my Matrix tutorial. It's written for XNA and XNA does a lot of work for setting up you matrices for you. I haven't had to think about manually loading a matrix in a long time.

Here's the tutorial:

http://xna-3d-101.co...s/Matrices.html

It looks like you're working in C++ with DirectX. So, this may not be terribly helpful if you have to load your own matrices.

But Khan Academy has lessons on Matrices.

I swear that I saw a good video on YouTube on the subject of using Matrices in game creation the other day. I thought I book marked it, but apparently I didn't and I can't find it.

For 3D, you are going to be using 4 by 4 matrices.

The camera matrix (called a View Matrix in XNA) should store your camera position and facing.

Hopefully someone else will post something more helpful.

Post Script: Ah HA! I found it. I think this guy does a pretty good job of explaining how matrices are loaded for 3D games.

Edited by XNA-3D-101

##### Share on other sites
[color=#5A5A5A][font=tahoma, helvetica, arial, sans-serif]