# How to create a perspective field of view matrix?

Hey, hello. I am learning a little of WebGL (OpenGL ES 2.0) through the http://learningwebgl.com tutorials, but it uses a third party library to create the View, Projection and transformation matrices (glutils.js). Well, I don't really like the idea of depending on a non standard library, so I am trying to learn how to create these matrices by myself.

I've already managed to understand most of it, and although I can't really tell why these matrices work if someone asks me, at least I know how to build them when I need to. Now I have my own lib to work with 4x4 matrices. I can create translation, scale, rotation and the lookAt matrix, but, I am having a hard time finding out how to create the perspective matrix. Anyone could help me out?

Here is my lib: http://pastebin.com/csMi9GuC

• You should totally learn about Matrix mathematics, it will make your life in 3D land that much easier. It would also make it obvious why it is a 4x4 matrix instead of a 3x3 one that you might expect in a setting with only three dimensions. – Robert Massaioli Mar 24 '11 at 0:46

• What does that "cot" function does? in yScale = cot(fovY/2) – Delta Mar 23 '11 at 22:47