線を描く
とりあえず一本の線はこんな感じ。複数をいっぺんに書くには?
points配列を3次元にしてmovep配列を二次元にして、vx,vy,vzを配列化するんですか?センスないですよね。
/**
* Copyright Nowloading_ ( http://wonderfl.net/user/Nowloading_ )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ef7E
*/
package{
import org.papervision3d.core.geom.Lines3D;
import org.papervision3d.materials.special.LineMaterial;
import org.papervision3d.view.*;
import flash.events.Event;
[SWF(backgroundColor = 0x000000)]
public class linebox extends BasicView{
private var a:LineMaterial = new LineMaterial(0xff0000);
private var axis:Lines3D = new Lines3D(a);
private var material:LineMaterial = new LineMaterial(0xffff00);
private var lines:Lines3D = new Lines3D(material);
//points = [[x1,x2,,,xn],[y1,,,yn][z1,,,zn]]
private var points:Array = [[-200,200,200,200,-200,-200,-200,-200,200,200],
[-200,-200,-200,200,200,-200,-200,200,200,-200],
[-200,-200,200,200,200,200,-200,-200,-200,-200],
];
//movep = [x,y,z]
private var movep:Array = [-200,-200,-200];
private var rad:int = 0;
private var i:int =0;
private var j:int =0;
private var vx:int;
private var vy:int;
private var vz:int;
private var pn:int = 10;
public function linebox(){
init();
}
private function init():void{
//軸を描く
axis.addNewLine(3,-1000,0,0,1000,0,0);
axis.addNewLine(3,0,-1000,0,0,1000,0);
axis.addNewLine(3,0,0,-1000,0,0,1000);
scene.addChild(axis);
scene.addChild(lines);
camera.x = -600;
camera.y = 600;
camera.lookAt(lines);
startRendering();
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
private function onEnterFrame(e:Event):void{
camera.x = 1000*Math.sin(rad*Math.PI/180);
camera.z = 1000*Math.cos(rad*Math.PI/180);
rad+=3;
if(rad >= 360){
rad =0;
}
if ( i ==0 ){
vx = (points[0][j+1]-points[0][j])/pn;
vy = (points[1][j+1]-points[1][j])/pn;
vz = (points[2][j+1]-points[2][j])/pn;
i = 1;
}
lines.addNewLine(3,movep[0],movep[1],movep[2],
movep[0]+vx,movep[1]+vy,movep[2]+vz)
movep[0]+=vx;
movep[1]+=vy;
movep[2]+=vz;
if((movep[0] == points[0][j+1]) && (movep[1] == points[1][j+1])
&& (movep[2] == points[2][j+1])){
j+=1;
i=0;
}
}
}
}