Created
September 25, 2012 03:16
-
-
Save jonathantorres/3779789 to your computer and use it in GitHub Desktop.
A simple cube in Away3D
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 com.jonathantorres.practices | |
{ | |
import away3d.entities.Mesh; | |
import away3d.materials.TextureMaterial; | |
import away3d.primitives.CubeGeometry; | |
import away3d.textures.BitmapTexture; | |
import away3d.utils.Cast; | |
import flash.display.StageAlign; | |
import flash.display.StageScaleMode; | |
import flash.events.Event; | |
import flash.geom.Vector3D; | |
/** | |
* @author Jonathan Torres | |
*/ | |
[SWF(backgroundColor="#000000", frameRate="31", width="800", height="600")] | |
public class InteractiveCube extends AwayTemplate | |
{ | |
[Embed(source="../../../../assets/material.jpeg")] | |
private var Material : Class; | |
private var _cube : Mesh; | |
private var _cubeTexture : TextureMaterial; | |
public function InteractiveCube() | |
{ | |
stage.scaleMode = StageScaleMode.NO_SCALE; | |
stage.align = StageAlign.TOP_LEFT; | |
super(); | |
initEngine(); | |
view.antiAlias = 4; | |
camera.z = -500; | |
camera.y = 300; | |
camera.lookAt(new Vector3D(0, 0, 0)); | |
_cubeTexture = new TextureMaterial(new BitmapTexture(Cast.bitmapData(Material))); | |
_cubeTexture.bothSides = true; | |
_cube = new Mesh(new CubeGeometry(200, 200, 200, 30, 30, 30), _cubeTexture); | |
scene.addChild(_cube); | |
initListeners(); | |
} | |
override protected function onEnterFrame(event : Event) : void | |
{ | |
_cube.rotationY = (mouseX - stage.stageWidth * 0.5) / 5; | |
_cube.rotationX = (mouseY - stage.stageHeight * 0.5) / 5; | |
super.onEnterFrame(event); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment