3D Polar Revolution

Hello,

I just thought I would share my latest experiment with you :slight_smile: 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();
 }

why not just use tweens as well as motion guides :slight_smile:
be alotttt easier

I beg to differ.

  1. Any sort of flexibility would be lost.
  2. I think writing about an hours worth of code is much more enjoyable than working with cough tweens.
  3. Please try to tween the same effect and I would love see what you come out with :D.
  4. Just plain > :lol:

[whisper]Are you serious?[/whisper]

Edit: Here is what the motion guides would look like! Have fun drawing them :). (They were drawn with CODE).

Yeah, really. You kinda missed the point (and the significance!) of what he’s got there, Icehawk. Don’t take it for just what you see in his example, think about the script.

Btw, pretty cool thing ya got there, freeskier89!

-Fenrir

nice piece of code… good work…

Too good! :stare:

Neat :thumb:

Very Nice, I usally code stuff like that in 5 mins before i go to bed :lol:, I cant even code AS :stuck_out_tongue: :run:

I code best in the middle of the night…

Thanks guys! Here is another little add on. I am thinking that a 3d Fractal Tree is in order in the near future :D.

That’s really neat, too. For some reason it’s way off to the top right… :frowning:

Try moving your mouse :thumb:. It now positions the camera based on the cursor.

last example shows better what you got there
really nice

Oh, I see. I feel dumb, now. :lol:

Yeah, great work freeskier.

:slight_smile: i like it

Impressive…educative. Thanks for sharing with all of us.

wow, that’s awesome, any chance we can have the source for that?:azn:

Sure thing! Sorry about not posting earlier. I will edit my post in a few minutes with the source. Thanks btw :smiley:

hey freeskier! Man that second effect is great!- that is exactly the kinda thing that would work for my glowy ribbons on the intro dont ya think? :P!