-
-
Save JohnBrookes/357822f0df1f0dc9b0b8 to your computer and use it in GitHub Desktop.
Quick test for arrow.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import away3d.cameras.Camera3D; | |
import away3d.containers.ObjectContainer3D; | |
import away3d.containers.Scene3D; | |
import away3d.containers.View3D; | |
import away3d.controllers.HoverController; | |
import away3d.debug.AwayStats; | |
import away3d.debug.Trident; | |
import away3d.entities.Mesh; | |
import away3d.library.AssetLibrary; | |
import away3d.lights.DirectionalLight; | |
import away3d.materials.ColorMaterial; | |
import away3d.materials.lightpickers.StaticLightPicker; | |
import away3d.primitives.CylinderGeometry; | |
import awayphysics.collision.shapes.AWPSphereShape; | |
import awayphysics.debug.AWPDebugDraw; | |
import awayphysics.dynamics.AWPDynamicsWorld; | |
import awayphysics.dynamics.AWPRigidBody; | |
import flash.display.Sprite; | |
import flash.display.StageAlign; | |
import flash.display.StageScaleMode; | |
import flash.events.Event; | |
import flash.events.MouseEvent; | |
import flash.geom.Vector3D; | |
public class AW4TestArrow extends Sprite | |
{ | |
private var view:View3D; | |
private var scene:Scene3D; | |
private var camera:Camera3D; | |
// | |
private var timeStep : Number = 1.0 / 60; | |
private var physics:AWPDynamicsWorld; | |
private var debugDraw:AWPDebugDraw; | |
private var arrowRb:AWPRigidBody; | |
private var arrow:Mesh; | |
private var lastPostion:Vector3D; | |
public function AW4TestArrow() | |
{ | |
if (stage) init(); | |
else addEventListener(Event.ADDED_TO_STAGE, init); | |
} | |
private function init(e:Event = null):void | |
{ | |
removeEventListener(Event.ADDED_TO_STAGE, init); | |
// entry point | |
stage.scaleMode = StageScaleMode.NO_SCALE; | |
stage.align = StageAlign.TOP_LEFT; | |
init3D(); | |
initPhysics(); | |
initObjects(); | |
initListeners(); | |
} | |
private function init3D():void | |
{ | |
view = new View3D(); | |
view.backgroundColor = 0x0; | |
scene = view.scene; | |
camera = view.camera; | |
addChild(view); | |
camera.lens.far = 10000; | |
camera.z = -7000; | |
} | |
private function initPhysics():void | |
{ | |
physics = AWPDynamicsWorld.getInstance(); | |
physics.initWithDbvtBroadphase(); | |
debugDraw = new AWPDebugDraw(view, physics); | |
} | |
private function initObjects():void | |
{ | |
scene.addChild(new Trident()); | |
arrow = new Mesh(new CylinderGeometry(20, 20, 300,16,1,true,true,true,false), new ColorMaterial(0xff0000)); | |
scene.addChild(arrow) | |
arrowRb = new AWPRigidBody(new AWPSphereShape(), null, 10); | |
physics.addRigidBody(arrowRb); | |
} | |
private function fireArrow(e:MouseEvent):void | |
{ | |
arrowRb.linearVelocity = (new Vector3D());//kill any previous velocity | |
arrowRb.position = new Vector3D(-4000,0,0) | |
arrowRb.applyCentralImpulse(new Vector3D(200,200,0)); | |
} | |
private function handleEnterFrame(e:Event):void | |
{ | |
if (lastPostion) | |
arrow.position = lastPostion; | |
physics.step(timeStep); | |
//debugDraw.debugDrawWorld(); | |
arrow.lookAt(arrowRb.position) | |
view.render(); | |
lastPostion = arrowRb.position; | |
} | |
private function onStageResize(event : Event) : void | |
{ | |
view.width = stage.stageWidth; | |
view.height = stage.stageHeight; | |
} | |
private function initListeners():void | |
{ | |
addEventListener(Event.ENTER_FRAME, handleEnterFrame); | |
stage.addEventListener(Event.RESIZE, onStageResize); | |
stage.addEventListener(MouseEvent.DOUBLE_CLICK, fireArrow); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment