0 Replies Latest reply on May 24, 2009 10:10 PM by MasaMune69

    how to make work a perspective matrix

    MasaMune69 Level 1
      I'm trying to get my head around some 3D graphics, but ran into trouble.

       

      I have a number of points that make up a cube. Very simple.

       

      I use an orthographic projection matrix to display it.

       

      But when I try to apply a perspective projection matrix it looks like anything but a cube. I've tried multiple ways to get it to work but it still doesn't.

       

      You can download the source code here: http://www.bastardindustries.com/temp/example.zip

       

      It is written in ActionScript 3.0. But the code is very basic and straight forward so I don't think it's will be a problem even if you are not familiar with ActionScript.

       

      By commenting an uncommenting the following lines (in 3DGraphics.as) you can switch between the orthographic projection and perspective projection matrix. As you can see when just using the orthographic projection matrix it works fine. But with the perspective it doesn't.

       

      // Ortographic and perspective
      // mP = mPers.multiplyMatrix(mOrto);

       

      // Just ortographic
      mP = mOrto;

       

      Any help on why my perspective matrix isn't working is appreciated.

       

      The perspective matrix looks like this. In a column major order:

       

      n is the near plane and f the far plane.

       

      mA[0] = n;
      mA[5] = n;
      mA[10] = n+f;
      mA[11] = 1;
      mA[14] = -(f*n);
      mA[15] = 0;

       

      Thanks!

      this thread was writting in another website since it was left unanswered

       

      / Magnus