02 forked from: JigLibFlash Test
forked from 01 forked from: JigLibFlash Test (diff: 66)
JigLibFlash が Papervision 以外の 3D エンジンに対応して、書き方が変わっていたので新 JigLibFlash をいじってみた。 ... @author tkinjo
ActionScript3 source code
/**
* Copyright vuking_p ( http://wonderfl.net/user/vuking_p )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/dsNS
*/
// forked from vuking_p's forked from: JigLibFlash Test_01
package
{
/**
* JigLibFlash が Papervision 以外の 3D エンジンに対応して、書き方が変わっていたので新 JigLibFlash をいじってみた。
*/
import flash.display.Sprite;
import flash.events.Event;
import jiglib.math.JNumber3D;
import jiglib.physics.RigidBody;
import jiglib.plugin.papervision3d.Papervision3DPhysics;
import org.papervision3d.core.proto.CameraObject3D;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.core.proto.LightObject3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.AbstractView;
import org.papervision3d.view.BasicView;
[SWF(width = "465", height = "465", frameRate = "60", backgroundColor = "#cfcfff")]
/**
* ...
* @author tkinjo
*/
public class Main extends Sprite
{
private const speed:Number = 9.8;
private const rotateSpeed:Number = 3;
private const moveSpeed:Number = 3;
private var view:AbstractView;
private var scene:Scene3D;
private var camera:CameraObject3D;
private var cameraTarget:DisplayObject3D;
private var physics:Papervision3DPhysics;
private var moveBox:RigidBody;
private var velocity:JNumber3D;
private var frameCounter:Number;
/*
//light & material
light = new LightObject3D();
light.y = 600;
light.z = -1000;
var mat:FlatShadeMaterial = new FlatShadeMaterial(light, 0x508DC5, 0x224488);
*/
/**
*
*/
public function Main()
{
frameCounter = 0;
view = new BasicView( stage.stageWidth, stage.stageHeight );
addChild( view );
scene = view.scene;
camera = view.camera;
/** --------------------------------------------------
* カメラ設定
*/
camera.x = 1000
camera.y = 1000;
cameraTarget = new DisplayObject3D();
camera.lookAt( cameraTarget );
/** --------------------------------------------------
* jiglib 設定
*/
physics = new Papervision3DPhysics( scene, speed );
// 地面の作成
var wireframeMaterial:WireframeMaterial = new WireframeMaterial( 0 );
var ground:RigidBody = physics.createGround( wireframeMaterial, 1000, 0 );
// ボックスの作成
var materials:MaterialsList = new MaterialsList();
materials.addMaterial( new WireframeMaterial( 0 ), "all" );
var box:RigidBody;
for (var j:int = 0; j < 6; j++) {
for (var i:int = 0; i < 6; i++) {
box = physics.createCube( materials, 100, 100, 100 );
box.x = 105 * ( i + 1 )-300;
box.y = 50;
box.z = 105 * ( j + 1 )-300;
}
}
moveBox = physics.createCube( materials, 100, 100, 100 );
moveBox.y = 150;
/** --------------------------------------------------
* レンダリングとか
*/
addEventListener( Event.ENTER_FRAME, enterFrameHandler );
view.startRendering();
}
/**
*
* @param event
*/
private function enterFrameHandler( event:Event ):void
{
if (frameCounter < 60)//0--60
{
moveBox.x += moveSpeed;
}
else if (frameCounter < 90)//60--90
{
moveBox.rotationY -= rotateSpeed;
}
else if (frameCounter < 150)//90--150
{
moveBox.z += moveSpeed;
}
else if (frameCounter < 180)//150--180
{
moveBox.rotationY -= rotateSpeed;
}
else if (frameCounter < 240)//180--240
{
moveBox.x -= moveSpeed;
}
else if (frameCounter < 270)//240--270
{
moveBox.rotationY -= rotateSpeed;
}
else if (frameCounter < 330)//270--330
{
moveBox.z -= moveSpeed;
}
else if (frameCounter < 360)//330--360
{
moveBox.rotationY -= rotateSpeed;
}
frameCounter++;
if(frameCounter>360)
{
frameCounter = 0;
}
physics.step();
}
}
}