Matrix3D Perspective Projection

// April 2nd, 2009 // Experiments, Flash 3D, Source code & tutorials

I used to calculated the 3D projection with this classic formula:

scale = focalLength / (focalLength + posZ)
targetX = posX * scale
targetY = posY * scale

But there are actually some great 3D classes for that in the FP10 API. Like the Utils3D class, with that class you can project your 3D vertices into 2D vertices.
There all based around the Matrix3D class. You can prepend and append a rotation, translation or scale to the matrix (useful to simulate camera movements etc.) But also create a perspective matrix with the help of the PerspectiveProjection class. Definitely worth checking out.

Today I played around with them: view experiment Click to switch between Perlin noise and good old sine waves.
You need the latest FlashPlayer 10 to make it work! (10.0.22.87)

Source code: drawingAPIPerlin

flashPlayer drawing API

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

6 Responses to “Matrix3D Perspective Projection”

  1. Ronny says:

    The image above rises a lot of expectations, however looking at the flash preview movie, there’s not a lot of detail to look at (it’s very tiny :( ). Too bad.

    Very cool experiment nontheless :)
    keep it up

  2. Kris says:

    Hey Ronny,
    If it don’t looks like the image, I think you don’t have the latest FlashPlayer (10.0.22.87). There where some bugs in Marix3D class with previous versions.

  3. Ronny says:

    You’re right. I updated my Flash Player to the latest version, and it looks the same now. Awesome! I’ll look into this! Thanks for sharing!

  4. Stéphane Rainville says:

    Really cool sample. I did not believe FLASH could push that many triangles.

    Is there a way to have graphics.drawTriangles paint the triangles in order so the the last ones overdraw the previous to add depth drawing.

    I played with your sample and even if I add beginFill() before drawTriangles I can see the triangles vertices underneath.

  5. tlecoz says:

    Hello !
    I guess something changed in Matrix3D with flashPlayer 10.1 because your demo desn’t work anymore (totally bugged on my computer, it worked well few months ago).
    By the way, your blog is amazing !

  6. Kris says:

    yes, your right, its acting strange..

Leave a Reply