/**
* 基本的控制属性
*/
public var x:Number=0;
public var y:Number=0;
public var z:Number=0;
public var rotation:Number=0;
public var width:Number=0;
public var height:Number=0;
public var scaleX:Number=1;
public var scaleY:Number=1;
//缓冲顶点数据
private var buffer:VertexBuffer3D;
//矩阵
private var matrix:Matrix3D;
public function Model2D(context:Context3D)
{
//创建一个顶点缓冲4行4列
buffer = context.createVertexBuffer(4, 4); //x, y, u, v
//创建一个试图矩阵
matrix = new Matrix3D();
//上传顶点坐标从0开始,顶点元素数量为4
buffer.uploadFromVector(Vector.<Number>
([
-1.0, 1.0, 0.0, 1.0,
-1.0,-1.0, 0.0, 0.0,
1.0,-1.0, 1.0, 0.0,
1.0, 1.0, 1, 1.0
]), 0, 4);
}
/**
* 绘制
* @param context
* @param texture
*/
public function paint(context:Context3D, texture:Texture):void
{
public class Sprite2D
{
private var _x:int = 0;
private var _y:int = 0;
private var _rotation:int = 0;
private var _scaleX:Number = 1;
private var _scaleY:Number = 1;
private var W:Number = 1024;
private var H:Number =768;
private var sprite:Model2D;
private var context3D:Context3D;
private var texture:Texture;
private var texture2:Texture;
private var shaderProgramrogram3D;
private var indexBuffer:IndexBuffer3D;
//渲染矩阵
private var spriteMatrix:Matrix3D = new Matrix3D();
//视图矩阵
private var viewMatrix:Matrix3D = new Matrix3D();
public function Sprite2D(context3D:Context3D,resClss:Class):void
{
this.context3D = context3D;
//着色器语言
var vertexShader:Array =
[
"m44 op, va0, vc0", //矩阵相乘把3D矩阵转换为2D坐标输出给顶点着色器
"mov v0, va1" //移动UV信息到v0
];
//汇编解释器
var vertexAssembler:AGALMiniAssembler = new AGALMiniAssembler();
//获得指定的解释器内容
vertexAssembler.assemble(flash.display3D.Context3DProgramType.VERTEX, vertexShader.join("\n"));
private function initBitmap(resClass:Class,w:int):Texture
{
//创建位图对象
var bitmap:Bitmap = new resClass();
//创建贴图缓冲区
var texture:Texture = context3D.createTexture(w,w, Context3DTextureFormat.BGRA, true);
//填充位图到贴图缓冲区
texture.uploadFromBitmapData(bitmap.bitmapData);
//创建显示对象,填入主场景
sprite = new Model2D(context3D);
//设置显示对象的场景和贴图缓冲区
return texture
}