actionscript 3 - Continuous object rotation around point -


i want make function similar rotatearoundinternalpoint(). far solution this:

import flash.events.event; import flash.geom.matrix; import flash.geom.point;  addeventlistener( event.enter_frame, onframe );  function onframe(e:event):void {     var m:matrix = item.transform.matrix.clone();     var point:point = new point( 50, 50 ); // object's width , height 100px, 50 center     point = m.transformpoint( point );     m.translate( -point.x, -point.y );      m.rotate( 5 * ( math.pi / 180 ) );     m.translate( point.x, point.y );      item.transform.matrix = m; } 

however there fundamental flaw in code - gets less , less precise each iteration.

could point out what's causing , solution be?

i've solved problem introducing reference matrix not change, mistake initial iteration non-existent.

here's implementation:

import flash.events.event; import flash.geom.matrix; import flash.geom.point;  var referencematrix:matrix = item.transform.matrix.clone();  addeventlistener( event.enter_frame, onframe );  var i:number = 0; // you'll need because referencematrix rotation go 1 step, instead need increase rotation  function onframe(e:event):void {     var m:matrix = referencematrix.clone();     var point:point = new point( 100, 100 ); // pivot point local object's coordinates      point = m.transformpoint( point );     m.translate( -point.x, -point.y );     m.rotate( * ( math.pi / 180 ) );     m.translate( point.x, point.y );     item.transform.matrix = m;      += 1.2; // rotation step } 

please note code written in frame , isn't well-optimized real use, rather illustrates algorithm.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -