Rotating diamond, the 3d mesh implementation
by ericlin

As Flash becomes more popular, many good programmers from 3d fields contribute the algorithm for 3d mesh from other language. There are well established functions for manipulation of 3d points, curling and lightening of the mesh.

Things becomes easier. If we can create mesh and points then the manipulation is not difficult.

jonmack explained the application of dot-product to me. shipstern explained the lightening and curling of 3d mesh to me.

So, here is a simple movie demonstrating how to render 3d mesh in Flash.

I would simply explained the basic principles to handle 3d mesh. Well, most of the explanation is just a repeat of what shipstern told me.

Diamond is a regular polygon. We define coordinates at one corner, then rotate them along z axis will obtain the other coordinates in other 7 corners.

So, we need a function to rotate 3d coordinates around an axis. Be careful, instead of returning a new cordindates, that function changes the coordinates permanently.

Then we define the face by array of points. Be careful, the order of points in the array for each face should be arranged counter-Clockwise.

The first 3 points will be used to define a "3d plane". Two vectors are created from these 3 points and we calculate the surface norm by these two vector. The surface norm is a unit vector perpendicular to the plane. My movie put the light and view angle at the same direction. So, if the surface norm is facing us, it is rendered brighter. If the surface norm is pointing slightly oblique, the brightness is determined by the angle between view angle and surface norm. If the surface norm is pointing away from us, then the face is not rendered.

So, we need a function to calculate a surface norm of a plane defined by 3 points.

Also, we need a function to calculate the angle between two vectors (the surface norm and view angle).