Here’s an example with the capsule…
package
{
import away3d.cameras.*;
import away3d.containers.*;
import away3d.controllers.HoverController;
import away3d.debug.*;
import away3d.lights.*;
import away3d.materials.ColorMaterial;
import away3d.primitives.*;
import flash.display.*;
import flash.display3D.*;
import flash.events.*;
import flash.geom.Vector3D;
[SWF(backgroundColor="#000000", frameRate="60", quality="LOW")]
public class Primitive_Test extends Sprite
{
//Material variables
private var _material1:ColorMaterial;
//Light variables
private var _light1:PointLight;
private var _light2:PointLight;
//Object variables
private var _trident:Trident;
private var _capsule:Capsule;
//engine variables
private var scene:Scene3D;
private var view:View3D;
//private var camera:HoverCamera3D;
private var camera:Camera3D;
private var camcontroller:HoverController;
//navigation variables
private var move:Boolean = false;
private var lastPanAngle:Number;
private var lastTiltAngle:Number;
private var lastMouseX:Number;
private var lastMouseY:Number;
public function Primitive_Test()
{
init();
}
private function init():void
{
initEngine();
initLights();
initMaterials();
initObjects();
initListeners();
}
private function initEngine():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
scene = new Scene3D();
camera = new Camera3D();
camcontroller = new HoverController(camera);
view = new View3D();
view.scene = scene;
view.camera = camera;
addChild(view);
}
private function initLights():void
{
_light1 = new PointLight();
_light1.color = 0xff8888; // redish color
_light1.position = new Vector3D(3000,3000,3000);
_light2 = new PointLight();
_light2.color = 0xffff88;// yellowish color
_light2.position = new Vector3D(-3000,-3000,3000);
scene.addChild(_light1);
scene.addChild(_light2);
}
private function initMaterials():void
{
_material1 = new ColorMaterial(0x0000ff);
_material1.lights = [_light1,_light2];
}
private function initObjects():void
{
//trident for debug
_trident = new Trident(400, true);
scene.addChild(_trident);
//capsule primitive
_capsule = new Capsule(_material1,150,300,12,12,true);
scene.addChild(_capsule);
camcontroller.distance = _capsule.height*2;
}
private function initListeners():void
{
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}
private function onEnterFrame(event:Event):void
{
if (move) {
camcontroller.panAngle = 0.2 * (stage.mouseX - lastMouseX) + lastPanAngle;
camcontroller.tiltAngle = 0.2 * (stage.mouseY - lastMouseY) + lastTiltAngle;
}
view.render();
}
private function onMouseDown(event:MouseEvent):void
{
lastPanAngle = camcontroller.panAngle;
lastTiltAngle = camcontroller.tiltAngle;
lastMouseX = stage.mouseX;
lastMouseY = stage.mouseY;
move = true;
stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
private function onMouseUp(event:MouseEvent):void
{
move = false;
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
private function onStageMouseLeave(event:Event):void
{
move = false;
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
private function onResize(event:Event = null):void
{
view.x = stage.stageWidth / 2;
view.y = stage.stageHeight / 2;
}
}
}
Hope it helps.