Hello,
I just thought I would share my latest experiment with you It has been a while since I have messed with 3d so I thought it was about time. Here a basic 3D engine is set up and then movieclips revolve three dimensionally around the center (0,0,0) using some pretty basic math.
Camera=function(X,Y,Z,focalLength){
this.fL=focalLength;
this.X=X;
this.Y=Y;
this.Z=Z;
}
Camera.prototype.Move=function(X,Y,Z){
this.X+=X;
this.Y+=Y;
this.Z+=Z;
this.engine.Render();
}
Engine3D=function(Camera,Centerx,Centery){
this.camera=Camera;
this.camera.engine=this;
this.vertexBuffer = _root.createEmptyMovieClip("3Dcontainer"+(containerdepth++),containerdepth);
this.vertexBuffer._x=Centerx;
this.vertexBuffer._y=Centery;
this.depth=0;
}
Engine3D.prototype.Render=function(){
for(i in this.vertexBuffer){
this.vertexBuffer*.Draw();
}
}
Engine3D.prototype.Attach3DPoint=function(X,Y,Z){
this.depth++;
var mc=this.vertexBuffer.attachMovie("point","point"+this.depth,this.depth);
mc.parentEngine=this;
mc.X=X;
mc.Y=Y;
mc.Z=Z;
mc.Draw();
return mc;
}
MovieClip.prototype.Draw=function(){
var focalRatio=this.parentEngine.camera.fL/(this.parentEngine.camera.fL+(this.Z-this.parentEngine.camera.z))
this._x=focalRatio*(this.parentEngine.camera.X-this.X);
this._y=focalRatio*(this.parentEngine.camera.Y-this.Y);
this.swapDepths(10000-this.Z);
this._xscale=this._yscale=this._alpha=focalRatio*100;
}
Camera1 = new Camera(0,0,-20,70);
Engine1=new Engine3D(Camera1,150,150);
//These are the variables that you will want to manipulate
Radius = 1;
Count=5;
OutwardVelocity =.1
RotationalVelocity =.015;
UpwardVelocity=3;
_root.createEmptyMovieClip("line",-1);
for(var n = 0;n<Count;n++){
var mc = Engine1.attach3DPoint(0,0,0);
mc.T=n/Count*Math.PI*2;
mc.a=1+Math.random()*5;
mc.b=1+Math.random()*5;
mc.c=1+Math.random()*5;
mc.R=50;
mc.line=line.createEmptyMovieClip("line"+n,n+1);
mc.line.lineStyle(1,0,100);
mc.line.moveTo(mc.parentEngine.vertexBuffer._x,mc.parentEngine.vertexBuffer._y);
mc.onEnterFrame=function(){
this.T+=RotationalVelocity;
this.X=this.R*Math.cos(this.T*this.a)*Math.sin(this.T);
this.Z=this.R*Math.sin(this.T*this.b)*Math.sin(this.T);//this.Z;
this.Y=this.R*Math.sin(this.T*this.c)*Math.sin(this.T);//UpwardVelocity*=.995//this.R*Math.sin(this.T);//1//this.Z;
}
}
onEnterFrame=function(){
Engine1.Render();
}