I am writing a 3D engine for AS3.0… And I ran into an annoying problem. AS3.0 currently supports only affine Bitmap transformations (the 3D is far too hard to manage, that is why I am writing the engine) – which means that I can not achieve true perspective on big vertices.
I could do a loop and render each pixel of the Bitmap based on its Z position… But that is something 1000 times more than most computers can do, because perspective is non-linear…
So – the solution would be – to split up the vertex automatically (so the programmer / modeler does not have to do it) into smaller triangles.
Unfortunately this is… choppy…? The affine transforms won’t be precise enough, or would be, but they won’t fit on the other triangles… An image to demonstrate:
(dead image)
As you can see on the red parts, they are very choppy, most noticeable in the front middle column.
So – what am I doing wrong? How is this done in Sandy, away3D, Alternativa to name a few with some perspective?
EDIT 1: The code I am using for transforming to triangles looks like this:
public static function transformTriangle(bd:BitmapData, pts:Vector.<Point>, gfx:Graphics):void {
var matrix:Matrix = new Matrix();
matrix.tx = pts[0].x;
matrix.ty = pts[0].y;
matrix.a = (pts[1].x - pts[0].x) / bd.width;
matrix.b = (pts[1].y - pts[0].y) / bd.height;
matrix.c = (pts[2].x - pts[0].x) / bd.width;
matrix.d = (pts[2].y - pts[0].y) / bd.height;
gfx.beginBitmapFill(bd, matrix, false, true);
gfx.moveTo(pts[0].x, pts[0].y);
gfx.lineTo(pts[0].x, pts[0].y);
gfx.lineTo(pts[1].x, pts[1].y);
gfx.lineTo(pts[2].x, pts[2].y);
gfx.lineTo(pts[0].x, pts[0].y);
gfx.endFill();
}
EDIT 2: Here is a small demo of the transformer:
CLICK HERE (dead link)
(arrows to control the blue points, 1-3 to change selected handle – try both numpad and top numeric keys)
I think if you try using drawTriangles instead it will fix your problem. Here are some posts related to drawTriangles and z-sorting link