5
\$\begingroup\$

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

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Mar 24, 2011 at 0:46

1 Answer 1

3
\$\begingroup\$

Very well. That is fine approach. Sadly lots of game programmers do not understand their matrices, so don't worry about it now. Personally i use directx documentation as my personal reference if i'm not sure.

There is perspective matrix.

\$\endgroup\$
5
  • \$\begingroup\$ What does that "cot" function does? in yScale = cot(fovY/2) \$\endgroup\$
    – Delta
    Mar 23, 2011 at 22:47
  • \$\begingroup\$ Figured it out, it's cotangent (1 / tangent). It works, thank you! \$\endgroup\$
    – Delta
    Mar 23, 2011 at 23:00
  • \$\begingroup\$ Don't forget to transpose that DirectX matrix for use in OpenGL \$\endgroup\$
    – Steve H
    Mar 24, 2011 at 1:35
  • \$\begingroup\$ I have no idea why, but if I transpose it then it doesn't work, I also thought that I was supposed to transpose it, but it works fine the way it is on the msdn page. \$\endgroup\$
    – Delta
    Mar 24, 2011 at 2:38
  • 1
    \$\begingroup\$ OpenGL expects a right-handed, column-major matrix. DirectX spits out a left-handed, row-major matrix. You would need to transpose the matrix twice (once to fix the 'handedness' and once to fix the 'majorness'). Transposing it a second time cancels out the first transpose. Using this logic, the way DirectX uses a matrix in memory is the same as OpenGL's matrix. \$\endgroup\$
    – MarkP
    Aug 26, 2011 at 14:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .