Brian Chia
       
 
categories
actionscript
actionscript 1.0
actionscript 2.0
misc
 
processing
 
links
brian chia
kelvin zhao
ronald leong
 
 
Coordinate Rotation v02
 

Since the rotate() method in my Vector Class is also using the basic formula of:

newX=cos(angle)*x-sin(angle)*y;
newY=cos(angle)*y+sin(angle)*x;

Thus, i tried to modify the previous Coordinate Rotation so that it look more simplifed. Do take note that due to the way i wrote my Vector Class, now the rotation will rotate in anti-clockwise direction if it a positive angle.


import Vector;

// angle to rotate in degrees
var a:Number=1;

// define center pts
var centerX:Number=cross._x;
var centerY:Number=cross._y;

this.onEnterFrame=function():Void{

rotate();

}

function rotate():Void{

// return ball position in vector form relative to center pt
var v:Vector=new Vector(ball._x-centerX,ball._y-centerY);

// rotate vector relative to center pt
v.rotate(a);

// add vector to center pt to get final position
ball._x=centerX+v.vx;
ball._y=centerY+v.vy;

}



suggestion

 
 
 
         
  © copyright 2007 THINKLUNATIC.    
Brian Chia Jonathan Ng