pv3d勉強100428
転がってるように作りたかったけど、X軸周りが逆になるときがある。
@author atsu
package
{
import flash.display.*;
import flash.events.*;
import flash.filters.BlurFilter;
import org.papervision3d.core.effects.view.ReflectionView;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.view.*;
/**
* 転がってるように作りたかったけど、X軸周りが逆になるときがある。
* @author atsu
*/
[SWF(frameRate = "50")]
public class Main extends ReflectionView
{
private var sw:Number;
private var sh:Number;
private var cx:Number;
private var cy:Number;
private var light:PointLight3D;
private var material:FlatShadeMaterial;
private var sphere:Sphere;
private var a:Number = 100 * Math.PI;
public function Main()
{
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.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.showDefaultContextMenu = false;
}
private function getStageSize():void
{
sw = stage.stageWidth;
sh = stage.stageHeight;
cx = sw / 2;
cy = sh / 2;
}
private function setDO3D():void
{
light = new PointLight3D(true);
trace(light.x, light.y, light.z);
light.y = 600;
material = new FlatShadeMaterial(light, 0xFFFFFF, 0x000000, 1);
sphere = new Sphere(material, 100, 30, 30);
scene.addChild(sphere);
sphere.y = 100;
camera.focus = 40;
camera.y = 960;
camera.z = -1280;
//camera.z = -Math.sqrt(1920000);
surfaceHeight = 0;
viewportReflection.filters = [new BlurFilter(10, 10, 2)];
viewportReflection.alpha = 0.3;
addEventListener(Event.ENTER_FRAME, loop);
stage.addEventListener(Event.RESIZE, resizeEvent);
}
private function loop(e:Event):void
{
singleRender();
sphere.x += ((stage.mouseX - cx) - sphere.x) / 50;
sphere.rotationZ = -sphere.x / a * 360;
sphere.z += ( -(stage.mouseY - cy) - sphere.z) / 50;
//sphere.z += -(((stage.mouseY - cy) - sphere.z) / 50);
sphere.rotationX = sphere.z / a * 360;
}
private function resizeEvent(e:Event):void
{
getStageSize();
}
}
}