Skip to content

Instantly share code, notes, and snippets.

@jonathantorres
Created January 22, 2012 19:55
Show Gist options
  • Save jonathantorres/1658517 to your computer and use it in GitHub Desktop.
Save jonathantorres/1658517 to your computer and use it in GitHub Desktop.
See some default primitives of Away3D
package com.practices.onaway.chapter2
{
import away3d.primitives.GeodesicSphere;
import away3d.primitives.Triangle;
import away3d.primitives.Torus;
import away3d.primitives.SeaTurtle;
import away3d.primitives.Plane;
import away3d.primitives.Cylinder;
import away3d.primitives.Cube;
import away3d.primitives.Cone;
import away3d.primitives.Arrow;
import flash.events.MouseEvent;
import away3d.primitives.Sphere;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import away3d.core.base.Object3D;
import flash.events.Event;
import com.practices.onaway.Away3DTemplate;
/**
* @author Jonathan Torres
*/
[SWF(backgroundColor="#FFFFFF", frameRate="31", width="800", height="600")]
public class PrimitivesDemo extends Away3DTemplate
{
private var _primitives : Array;
private var _currentPrimitive : Object3D;
private var _arrow : Arrow;
private var _cone : Cone;
private var _cube : Cube;
private var _cylinder : Cylinder;
private var _plane : Plane;
private var _turtle : SeaTurtle;
private var _torus : Torus;
private var _triangle : Triangle;
private var _sphere : Sphere;
private var _geoSphere : GeodesicSphere;
private var _index : uint = 0;
private var _speed : Number = 3.0;
public function PrimitivesDemo()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
_primitives = new Array();
_currentPrimitive = null;
super();
}
override protected function initScene() :void
{
_arrow = new Arrow( { bothsides : true } );
_cone = new Cone();
_cube = new Cube();
_cylinder = new Cylinder();
_plane = new Plane( { bothsides : true } );
_turtle = new SeaTurtle( { scale : 0.5 } );
_torus = new Torus();
_triangle = new Triangle( { bothsides : true } );
_geoSphere = new GeodesicSphere();
_sphere = new Sphere();
_primitives.push(_sphere);
_primitives.push(_arrow);
_primitives.push(_cone);
_primitives.push(_cube);
_primitives.push(_cylinder);
_primitives.push(_plane);
_primitives.push(_turtle);
_primitives.push(_torus);
_primitives.push(_triangle);
_primitives.push(_geoSphere);
_currentPrimitive = _sphere;
scene.addChild(_sphere);
}
override protected function initListeners() : void
{
super.initListeners();
stage.addEventListener(MouseEvent.CLICK, onStageMouseClick);
}
private function onStageMouseClick(event : MouseEvent) : void
{
scene.removeChild(_currentPrimitive);
_index++;
if (_index > _primitives.length - 1) _index = 0;
_currentPrimitive = _primitives[_index];
scene.addChild(_currentPrimitive);
}
override protected function onEnterFrame(event : Event) :void
{
if (_currentPrimitive is Arrow || _currentPrimitive is Plane || _currentPrimitive is Triangle || _currentPrimitive is Torus) {
_currentPrimitive.rotationX += _speed;
} else {
_currentPrimitive.rotationY += _speed;
}
super.onEnterFrame(event);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment