 # Using UV coordinates for Affine Transform?

After hitting what I see now was an inevitable wall using drawTriangles() for 3d rendering, I find myself forced to write my own UV mapping function… and this has made me realize that I’m as thick as a log.

Oh I’ve tried and tried, but I can’t seem to get my brain around it and the interweb isn’t helping me any. So I’m asking… and then I’m walking away for a good-long ****ing while.

The question is how can I resolve UV coords to 3d space and apply an affine transform to render it appropriately? It’s a pretty broad question, isn’t it? Well, that’s just how confused I’ve become.

I just don’t seem to understand how I can use UV data mathematically to resolve the 2d with the 3d. Here’s what I’ve got for my affine transform of the bitmapData… to date it ignores UV entirely.

``````transMat.a=(B.x - A.x)/thisSkin.width;
transMat.b=(B.y - A.y)/thisSkin.width;
transMat.c=(C.x - B.x)/thisSkin.height;
transMat.d=(C.y - B.y)/thisSkin.height;
transMat.tx=A.x;
transMat.ty=A.y;
``````

A, B, and C are the flattened vertices of a triangle. They have no relation to UV.

Consider a two triangle plane being skinned with 100% of the image. In that case, this transform works well enough for the first triangle in the plane. But inside the second triangle, instead of rendering the bottom-left half of the image, draws the upper right again, albeit skewed, scaled, and rotated to fit - the skin’s top border is drawn along the diagonal line of AB.

I’ve found I can invert this effect, so that the second triangle draws correctly, while the first receives the unwanted skew, if I change the transform like this:

``````transMat.a=(B.x - C.x)/thisSkin.width;
transMat.b=(B.y - C.y)/thisSkin.width;
transMat.c=(C.x - A.x)/thisSkin.height;
transMat.d=(C.y - A.y)/thisSkin.height;
transMat.tx=A.x;
transMat.ty=A.y;
``````

I can see that the problem is in the slope of Y at the Matrix’s b and d. And I’m sure my UV data is intended to straighten this mess out for me. I certainly can’t imagine such a simple affine transform being too ■■■■■■ complicated or requiring too many steps in flash’s vector environment. Moreso, you would think with all this information in hand I could deduce what needed to happen here, mathematically; Especially as I’ve been studying the trig functions of 3d and doing all manner of 4x4 matrix math for some time now. Well, I can’t. I’ve tried, I’ve read, I’ve searched… I’m spent.

Send help. And alcohol. Send alcohol too.