①: AGAL ----3D 步骤整理

1,contextd3D.configureBackBuffer(swfWidth,swfHeight,0,true);

说明: 3D后备缓冲区的像素的大小

2,initShaders()

Ps: var vertexShaderAssembler : AGALMiniAssembler = new AGALMiniAssembler();

  vertexShaderAssembler.assemble(

Context3DProgramType.VERTEX,

m44 op,va0,vc0\n +

mov v0, va0\n+

mov v1,va1\n

);

var fragmentShaderAssembler : AGALMiniAssembler = new AGALMiniAssembler();

fragmentSahderAssembler.assemble(

Context3DProgramType.FRAGMENT,

tex ft0, v1,fs0<2d,repeat,miplinear>\n+

mov oc, ft0\n

);

shaderProgram = context3D.createProgram();

shaderProgram.upload(vertexShaderAssembler.agal,fragmentShaderAssembler.agal);

3,indexBuffer3D = context3D.createIndexBuffer(meshIndexData.lenght);

indexBuffer3D.uploadFromVector(meshIndexData,0,meshIndexData.lenght);

vertexBuffer3D= context3D.createVertexBuffer(meshVertexData.lenght/8,8);

vertexBuffer3D.uploadFromVector(meshVertexData,0,meshIndexData.lenght/8);

4,Texture

myTexture= context3D.createTexture(textureSize,textureSize,Context3DTextureFormat.BGRA,false);

uploadTextureWithMipmaps(myTexture,myTextureData.bitmapData);//产生Map映射

5,3D透视矩阵

PrespectiveMatrix3D.indentity();

PrespectiveMatrix3D.perspectiveFieldOfViewRH(

45.0,

swfWidth/swfHeight,

0.01,

100

);

//定义相机位置的矩阵

viewMatrix.indentity();

viewMatrix.appendTranslation(0,0,-4);//相机后移

6,适时地渲染

//添加新的角度 --目标

modelViewProjection.identify();

modelViewProjection.append(modelMatrix);

modelViewProjection.append(veiwMatrix);

modelViewProjection.append(PrespectiveMatrix3D);


Context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX,0,modelViewProjection,true);//制造vc0

①://设置各个渲染时的数据:


Context3D.setVertexBufferAt(0,vertexBuffer3D,0,Context3DVertexBufferFormat.FLOAT_3);//三角形的3个顶点 ---va0

②://绘制三角形

Context3D.drawTrianggles(indexBuffer3D,0,meshIndexData.length/3);

Context3D,present();