| 1 |
package |
|---|
| 2 |
{ |
|---|
| 3 |
import as3d.camera.Camera3D; |
|---|
| 4 |
import as3d.display.*; |
|---|
| 5 |
import as3d.display.primitive.*; |
|---|
| 6 |
import as3d.geom.*; |
|---|
| 7 |
import flash.display.*; |
|---|
| 8 |
import flash.events.*; |
|---|
| 9 |
import mx.core.BitmapAsset; |
|---|
| 10 |
|
|---|
| 11 |
[SWF(width=300, height=300, backgroundColor=0x000000, frameRate=30)] |
|---|
| 12 |
public class Sample01 extends Sprite |
|---|
| 13 |
{ |
|---|
| 14 |
[Embed(source="images/texture01.gif")] |
|---|
| 15 |
private var Texture:Class; |
|---|
| 16 |
|
|---|
| 17 |
public function Sample01():void |
|---|
| 18 |
{ |
|---|
| 19 |
var viewPort:ViewPort3D = |
|---|
| 20 |
new ViewPort3D(0, 0, stage.stageWidth, stage.stageHeight); |
|---|
| 21 |
var scene:Scene3D = Scene3D(addChild(new Scene3D(viewPort))); |
|---|
| 22 |
scene.startRendering(); |
|---|
| 23 |
|
|---|
| 24 |
var plane:Plane = Plane(scene.addChild3D(new Plane())); |
|---|
| 25 |
|
|---|
| 26 |
var cone:Cone = Cone(scene.addChild3D(new Cone(100, 50))); |
|---|
| 27 |
cone.shadingType = ShadingType.FLAT; |
|---|
| 28 |
|
|---|
| 29 |
var torus:Torus = Torus(scene.addChild3D(new Torus(20, 40))); |
|---|
| 30 |
torus.shadingType = ShadingType.GOURAUD; |
|---|
| 31 |
torus.texture = BitmapAsset(new Texture()).bitmapData; |
|---|
| 32 |
|
|---|
| 33 |
var camera:Camera3D = scene.camera; |
|---|
| 34 |
camera.lookAt = torus.position; |
|---|
| 35 |
|
|---|
| 36 |
var dld:Vector3D = scene.directionalLight.direction; |
|---|
| 37 |
|
|---|
| 38 |
var angle:Number = 0; |
|---|
| 39 |
|
|---|
| 40 |
addEventListener(Event.ENTER_FRAME, function ():void |
|---|
| 41 |
{ |
|---|
| 42 |
torus.rotationX += 2; |
|---|
| 43 |
torus.rotationZ += 4; |
|---|
| 44 |
|
|---|
| 45 |
torus.x = Math.cos(angle ) * 200; |
|---|
| 46 |
torus.y = Math.sin(angle / 2) * 100 + 150; |
|---|
| 47 |
torus.z = Math.sin(angle ) * 100; |
|---|
| 48 |
|
|---|
| 49 |
camera.x = Math.cos(-angle / 2) * 400; |
|---|
| 50 |
camera.y = Math.sin(-angle / 4) * 200 + 300; |
|---|
| 51 |
camera.z = Math.sin(-angle / 2) * 200; |
|---|
| 52 |
|
|---|
| 53 |
dld.x = Math.cos(angle); |
|---|
| 54 |
dld.z = Math.sin(angle); |
|---|
| 55 |
|
|---|
| 56 |
angle += 0.05; |
|---|
| 57 |
}); |
|---|
| 58 |
} |
|---|
| 59 |
} |
|---|
| 60 |
} |
|---|