更新内容:
1.强化引擎结构,大幅度提升引擎性能和开发弹性.
2.相机增加自动跟踪功能.
3.视口系统加入边界盒功能.
4.加入多视口功能.
从1.0.2起,zerO3d得到了全面的提升,从今往后,zerO3d无论是画质还是功能体系,将敢于与世界各引擎相并足.性能更是从各方面超越了极限.
很多朋友问我zerO3d的优势是什么.
下面更新了粒子系统DEMO(虽然还是半成品...因为春节时间少...汗),请看看zerO3d的强大吧.
如果你的Flash Player是Debug,可能会跳出错误,那是Debug自身Timer堆栈过度,点继续即可.
源代码在下面:
_______________________________________BuildParticles_________________________________
/**
* Copyright 2009 (c) Lin Fuqing,zerO3D
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
{
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.utils.Timer;
import zerO.particles.simplesprite.Ball;
import zerO.render.Zsort;
import zerO.scenes.Scene3D;
import zerO.veiw.Camera3D;
import zerO.veiw.Viewport3D;
[SWF(backgroundColor="0xffffff")]
public class BuildParticles extends Sprite
{
//相机,可以不用.
private var camera:Camera3D = new Camera3D();
//半径,球分散的半径
private var radius:Number;
//球的数量
private var numBalls:uint;
//场景,必须
private var scene:Scene3D = new Scene3D();
//视口,必须
private var viewport:Viewport3D = new Viewport3D( stage.stageWidth,stage.stageHeight,scene );
//渲染器,必须,这里采用ZSORT,方便又便捷,娃哈哈.
private var render:Zsort = new Zsort( viewport );
private var field:TextField = new TextField();
/**
* 粒子系统实例
*/
public function BuildParticles( numBalls:uint = 1000,radius:Number = 500 )
{
stage.scaleMode = StageScaleMode.NO_SCALE;
//视口连接相机,后面还有个参数是相机切换插值,使用可以生成很华丽的动画
viewport.onCamera( camera );
//将视口加入子对象,一定要加,不然你将看不到任何东西
addChild( viewport );
//初始化
this.numBalls = numBalls;
this.radius = radius;
init();
var timer1:Timer = new Timer( 2000 );
timer1.addEventListener( TimerEvent.TIMER,onTimer1 );
timer1.start();
field.autoSize = TextFieldAutoSize.LEFT;
addChild(field);
field.addEventListener( MouseEvent.CLICK,onClick );
addEventListener( Event.ENTER_FRAME,onEnterFrame );
}
/**
* 初始化,这里定义numBalls个球,加到场景中
*/
public function init():void
{
for( var i:uint = 0;i < numBalls;i++ )
{
var ball:Ball = new Ball(10,Math.random() * 0xffffff);
ball.x = Math.random() * radius * 2 - radius;
ball.y = Math.random() * radius * 2 - radius;
ball.z = Math.random() * radius * 2 - radius;
scene.add( ball );//记得定义完一定要加到场景里面
}
camera.directionBuffer = 0.05;//设置相机方向缓冲
}
/**
* OK,开始
*/
private function onEnterFrame( event:Event ):void
{
if( camera.distance > 2 )
{
camera.closeToTarget();//相机接近目标
}
field.text = "点击这里增加粒子,当前粒子数:" + numBalls.toString();
render.render();//渲染机渲染(必须).
}
/**
* 随机设置相机目标
*/
private function onTimer1( event:TimerEvent ):void
{
camera.target = scene.renderList[ Math.round( scene.renderList.length * Math.random() ) ].worldPosition;
}
/**
* 鼠标事件
*/
private function onClick( event:MouseEvent ):void
{
var ball:Ball = new Ball(10,0xffffff * Math.random());
ball.x = Math.random() * radius * 2 - radius;
ball.y = Math.random() * radius * 2 - radius;
ball.z = Math.random() * radius * 2 - radius;
scene.add( ball );
numBalls ++;
}
}
}