[ascoders] Schnelle Rotation mit globalToLocal

  • From: André Michelle <am@xxxxxxxxxxxxxxxxxx>
  • To: <ascoders@xxxxxxxxxxxxx>
  • Date: Fri, 30 Jan 2004 20:52:59 +0100

Mal was nettes für zwischendurch. Mit globalToLocal kann man schneller
Vektoren drehen. Leider ist das Ergebnis nur zweistellig.

Vector = { x: 0, y: -100 };

mc = createEmptyMovieClip( "r" , 1 )
rotate = function ( v , degree ) { // 692ms - 45degrees
 tellTarget ( mc ) {
  _rotation = degree;
  globalToLocal( v );
 }
}

Dagegen mein optimiertes Script:

rotate = function ( v , rad ) { // 725mc - Math.PI/4 radians
 var sn,cs,vx,vy,tx;
 tx = ( vy = v.y ) * ( sn = Math.sin ( rad ) ) + ( vx = v.x ) * (cs =
Math.cos ( rad ));
 v.y = vy * cs - vx * sn;
 v.x = tx;
}

Test:
for ( var i = 0 ; i < 10001 ; i++ ) {
 rotate( Vector , 45 );
 //rotate( Vector , Math.PI/4 );
}



--
aM

------------------------------------------------------
Archiv   : //www.freelists.org/archives/ascoders/
Optionen : //www.freelists.org/list/ascoders
------------------------------------------------------

Other related posts:

  • » [ascoders] Schnelle Rotation mit globalToLocal