图片的粒子形式及其变形

三维粒子 everyinch 4043℃ 0评论

package{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.events.MouseEvent;

import org.papervision3d.core.effects.utils.BitmapClearMode;
import org.papervision3d.core.geom.Pixels;
import org.papervision3d.core.geom.renderables.Pixel3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.view.BasicView;
import org.papervision3d.view.layer.BitmapEffectLayer;
import org.papervision3d.view.layer.util.ViewportLayerSortMode;

[SWF(width=”800″, height=”600″, frameRate=”31″,backgroundColor=”0x000000″)]
public class Pixel3DTest3 extends BasicView{
[Embed(source=”assets/ten.jpg”)]
private var image:Class;

private var pixels:Pixels;
private var isDown:Boolean;
private var container:DisplayObject3D;

public function Pixel3DTest3(){
super(800, 600, true, true);
init3D();
startRendering();
}

private function init3D():void{
camera.focus=4800;
camera.zoom=2;
camera.z=-6000;

var bfx:BitmapEffectLayer=new BitmapEffectLayer(viewport, 800, 600, true, 0, BitmapClearMode.CLEAR_POST, true, true);
viewport.containerSprite.addLayer(bfx);
bfx.sortMode=ViewportLayerSortMode.Z_SORT;
pixels=new Pixels(bfx);
createPixels();

stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}

private function createPixels():void{
var bmp:Bitmap=new image();
var bmpd:BitmapData=bmp.bitmapData;

var halfWidth:Number=-bmpd.width >> 1;
var halfHeight:Number=-bmpd.height >> 1;

var focus:Number=camera.focus; //4800
var focusZoom:Number=camera.focus * camera.zoom; //9600
var h:int=0;
var w:int=1;
while (w <= bmpd.width){ h=1; while (h < bmpd.height){ var xpos:Number=(w + halfWidth) * 2;// var ypos:Number=-(h + halfHeight) * 2; var distance:Number=xpos * xpos + ypos * ypos; var zpos:Number=Math.sin(distance / 3000) * 20; var scale:Number=focusZoom / (focus + zpos); // scale = fl / (fl+z) var pixel:Pixel3D=new Pixel3D(0xFF000000|bmpd.getPixel32(w, h), xpos / scale, ypos / scale, zpos); pixels.addPixel3D(pixel); h++; } w++; } container=new DisplayObject3D(); container.addChild(pixels) scene.addChild(container); } private function onMouseUp(event:MouseEvent):void{ isDown=false; } private function onMouseDown(event:MouseEvent):void{ isDown=true; } protected override function onRenderTick(event:Event=null):void{ if(isDown){ container.localRotationY=viewport.containerSprite.mouseX / 2; container.localRotationX=viewport.containerSprite.mouseY / 2; } super.onRenderTick(event); } } } [/code]

分享&收藏

转载请注明:陈童的博客 » 图片的粒子形式及其变形

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
'; } if( dopt('d_footcode_b') ) echo dopt('d_footcode'); ?>