pv3d勉強100420
...
@author atsu
package
{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import org.papervision3d.view.*;
import org.papervision3d.cameras.*;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.materials.*;
import org.papervision3d.materials.shadematerials.*;
/**
* ...
* @author atsu
*/
[SWF(frameRate = "50")]
public class FlashTest extends BasicView
{
private var sw:Number;
private var sh:Number;
private var cx:Number;
private var cy:Number;
private var do3d:DisplayObject3D;
private var light:PointLight3D;
public function FlashTest()
{
super(0, 0, true, true);
addEventListener(Event.ADDED_TO_STAGE, addToStage);
}
private function addToStage(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, addToStage);
setStage();
getStageSize();
setDO3D();
}
private function setStage():void
{
stage.quality = StageQuality.MEDIUM;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.showDefaultContextMenu = false;
}
private function getStageSize():void
{
sw = stage.stageWidth;
sh = stage.stageHeight;
cx = sw / 2;
cy = sh / 2;
}
private function setDO3D():void
{
do3d = new DisplayObject3D();
scene.addChild(do3d);
light = new PointLight3D(true);
var material:PhongMaterial = new PhongMaterial(light,0xfe8637,0xb45f27,1);
var material2:PhongMaterial = new PhongMaterial(light,0x44c1f0,0x2b7b99,1);
var plane:Plane = new Plane(material, 240, 160); plane.x = -160; plane.y = 120; plane.z = -100;
var plane2:Plane = new Plane(material2, 240, 160); plane2.x = 160; plane2.y = 120; plane2.z = -100;
var plane3:Plane = new Plane(material2, 240, 160); plane3.x = -160; plane3.y = -120; plane3.z = -100;
var plane4:Plane = new Plane(material2, 240, 160); plane4.x = 160; plane4.y = -120; plane4.z = -100;
do3d.addChild(plane);
do3d.addChild(plane2);
do3d.addChild(plane3);
do3d.addChild(plane4);
camera.z = -600;
light.z = -400;
startRendering();
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event):void
{
light.x = stage.mouseX - cx;
light.y = -(stage.mouseY - cy);
if (stage.mouseX > cx) {
do3d.rotationY += (Math.min((stage.mouseX - cx) / 15, 15) - do3d.rotationY) / 10;
}else if (stage.mouseX < cx) {
do3d.rotationY += (Math.max((stage.mouseX - cx) / 15, -15) - do3d.rotationY) / 10;
}
if (stage.mouseY > cy) {
do3d.rotationX += (Math.min((stage.mouseY - cy) / 15, 15) - do3d.rotationX) / 10;
}else if (stage.mouseY < cy) {
do3d.rotationX += (Math.max((stage.mouseY - cy) / 15, -15) - do3d.rotationX) / 10;
}
}
}
}