package
{
import away3d.containers.View3D;
import away3d.entities.Mesh;
import away3d.events.MouseEvent3D;
import away3d.materials.TextureMaterial;
import away3d.primitives.PlaneGeometry;
import away3d.utils.Cast; import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event; /**
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @create 2015-9-23 下午2:58:55
*
*/
[SWF(width='800',height='600',frameRate="60", backgroundColor="0x000000")] public class Away3dRoll extends Sprite
{
//floor的贴图图片
[Embed(source = "assets/1.jpg")]
private static var FloorMaterial:Class;
//创建视口
private var _view:View3D;
//创建平面几何对象
private var _planeGeometry:PlaneGeometry;
//创建平面几何对象的容器
private var _planeMesh:Mesh;
//控制旋转方向的变量
private var _direction:Boolean;
public function Away3dRoll()
{
//侦听舞台初始化完毕
if (stage) {
init();
}else {
this.addEventListener(Event.ADDED_TO_STAGE, init);
} }
private function init(e:Event=null):void {
//trace("舞台初始化完成!");
//设置舞台缩放模式和对齐方式
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
this.removeEventListener(Event.ADDED_TO_STAGE, init); //实例化视口
_view = new View3D();
addChild(_view);
//设置抗锯齿参数
_view.antiAlias = 2; //实例化一个长宽都是300的平面对象
_planeGeometry = new PlaneGeometry(300, 300);
//实例化平面几何对象的容器,第一个参数是平面几何对象,第二个参数是贴图数据
_planeMesh = new Mesh(_planeGeometry, new TextureMaterial(Cast.bitmapTexture(FloorMaterial)));
//设置容器可交互
_planeMesh.mouseEnabled = true;
//容器侦听鼠标点击事件
_planeMesh.addEventListener(MouseEvent3D.CLICK, clickHandler); //将容器添加到视口的场景中
_view.scene.addChild(_planeMesh); //设置摄像机的位置
_view.camera.z = -400;
_view.camera.y = 260; //可以把这个值改成1试试看,这样可以有更加直观的感受
//_view.camera.x = 90;
//设置摄像机始终指向平面
_view.camera.lookAt(_planeMesh.position);
//_view.camera.lookAt(new Vector3D()); this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(Event.RESIZE, onResize);
onResize();
} private function clickHandler(e:MouseEvent3D):void {
//鼠标点击变换运动方向
_direction = !_direction;
} private function onResize(e:Event = null):void {
//调整视口尺寸以适应新的窗口大小
_view.width = stage.stageWidth;
_view.height = stage.stageHeight;
} private function onEnterFrame(e:Event):void {
//判断方向旋转
if (!_direction) {
_planeMesh.rotationY += 1;
}else {
_planeMesh.rotationY -= 1;
}
//渲染3D世界
_view.render();
} }
}

[ActionScript 3.0] Away3D 旋转效果的更多相关文章

  1. [ActionScript 3.0] Away3D 官网实例

    /* Dynamic tree generation and placement in a night-time scene Demonstrates: How to create a height ...

  2. [ActionScript 3.0] Away3D 灯光的使用

    package { import away3d.containers.View3D; import away3d.entities.Mesh; import away3d.events.MouseEv ...

  3. [ActionScript 3.0] Away3D 非skybox的全景例子

    package { import away3d.containers.View3D; import away3d.controllers.HoverController; import away3d. ...

  4. [ActionScript 3.0] Away3D 天空盒(skybox)例子2

    所谓skybox就是六个面即六张图能够无缝的拼成一个正方体的盒子. package { import away3d.cameras.Camera3D; import away3d.cameras.le ...

  5. [ActionScript 3.0] Away3D 天空盒(skybox)例子

    /* SkyBox example in Away3d Demonstrates: How to use a CubeTexture to create a SkyBox object. How to ...

  6. ActionScript 3.0入门:Hello World、文件读写、数据存储(SharedObject)、与JS互调

    近期项目中可能要用到Flash存取数据,并与JS互调,所以就看了一下ActionScript 3.0,现把学习结果分享一下,希望对新手有帮助. 目录 ActionScript 3.0简介 Hello ...

  7. ActionScript 3.0 for the Lunder Algorithm

    package com.feiruo.Calendar.LunderCalendar { /* *@ClassName: package:com.feiruo.Calendar.LunderCalen ...

  8. [转]ActionScript 3.0入门:Hello World、文件读写、数据存储(SharedObject)、与JS互调

    本文转自:http://www.cnblogs.com/artwl/p/3396330.html 近期项目中可能要用到Flash存取数据,并与JS互调,所以就看了一下ActionScript 3.0, ...

  9. [ActionScript 3.0] AS3.0 动态加载显示内容

    可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...

随机推荐

  1. XML 命名空间(XML Namespaces)

    XML 应用程序 XML CDATA XML 命名空间提供避免元素命名冲突的方法. 命名冲突 在 XML 中,元素名称是由开发者定义的,当两个不同的文档使用相同的元素名时,就会发生命名冲突. 这个 X ...

  2. 深入浅出Attribute (转载)

    原文地址:http://blog.csdn.net/FantasiaX/article/details/1627694 正文: 什么是Attribute?Attribute是干什么使的?Attribu ...

  3. Open vSwitch

    https://github.com/openvswitch/ovs/blob/master/INSTALL.RHEL.md

  4. unity vr sample on htc vive

    http://forum.unity3d.com/threads/unity-vr-samples-now-available.372753/

  5. unity, eulerAngle

    unity中欧拉角规定如下: A rotation that rotates euler.z degrees around the z axis, euler.x degrees around the ...

  6. android模拟器不能用键盘

    android模拟器不能用键盘?咋整啊?

  7. Android ImageButton android:scaleType

    ImageView的属性android:scaleType,即 ImageView.setScaleType(ImageView.ScaleType). android:scaleType是控制图片如 ...

  8. VBA実績表

    VBA 插入一行保留样式 VBA 打开一个string指定的文件 VBA 按照文件类型名称打开一个文件 VBA excel中表示列的字母换成数字

  9. (转)关于List中FindAll用法的一些简单示例

    本文转载自:http://blog.csdn.net/luoxufeng/article/details/6925982 using System; using System.Collections. ...

  10. js封常用类

    ajax刷 下拉框联动 /*基础初始化类*/ $.EBC = { setCourse:function(obj){ $(obj).empty(); $.get('../Index/getCoursei ...