i was trying to build a 2d sprite class that working in stage3d,the scale and translation was ok, but rotation is not right.when i use matrix3d to append a rotation,like these one.
var m:Matrix3D = new Matrix3D();
m.appendRotation(getTimer()/40, Vector3D.Z_AXIS);
context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, m, true);
it seems like it rotate the whole 3d context,since 3d context has it own width and height,so the picture looks like being stretched ,ha i got the answer when i write to here,so set context3D to a square size solved the problem
context3D.configureBackBuffer(1600, 1600, 1, true);
so my new question is how to set context3D only present in a specific area.if the swf stage size is 1900x1000 i configure a back buffer 1900x1900, hope it only present in rectangle(200,200,1200,600),any content out of the area would be clipped ,what can i do?
draw four block on the 2d stage would solve the problem,need better approaches.
use a scissor api can solve this problem too
context3D.setScissorRectangle(new Rectangle(0,0,1600,900));
but it's still a huge waste for build a square,need better approaches
finally i got the right answer.you need to use matrix3d to transform every pixel from((0,0),(1,0),(0,1)) coordinate world to ((0,0),(0.5/stage3dwidth,0),(-0.5/stage3dHeight,0)) cordinate world.here's the translate matrix,suggest the 3d stage size is 1600x900
var m2:Matrix3D = new Matrix3D();
m2.appendScale(1,-1,1);
m2.appendTranslation(-800,450,0);
m2.appendScale(1/800,1/450,1);
m.append(m2);
finally i got the right answer.you need to use matrix3d to transform every pixel from((0,0),(1,0),(0,1)) coordinate world to ((0,0),(0.5/stage3dwidth,0),(-0.5/stage3dHeight,0)) cordinate world.here's the translate matrix,suggest the 3d stage size is 1600x900
var m2:Matrix3D = new Matrix3D();
m2.appendScale(1,-1,1);
m2.appendTranslation(-800,450,0);
m2.appendScale(1/800,1/450,1);
m.append(m2);