[osflash] drift problem rotating an object around an arbitrary axis
larry kirschner
larrykirschner at gmail.com
Thu Feb 15 21:57:01 EST 2007
That does help. Thank you!
On 2/15/07, David Holroyd <osflash at badgers-in-foil.co.uk> wrote:
>
> On Wed, Feb 14, 2007 at 04:54:30PM -0800, larry kirschner wrote:
> > This approach seems to work, except that on each rotation the object
> > slightly off the axis.
>
> It looks like you are updating the transform every iteration by rotating
> adding a rotation by the same angle each time, yes..?
>
> > private function axisRotate(obj:DisplayObject, axis:Point,
> > angle:Number):void
> > {
> > validateAxisLen(axis);
> >
> > var temp:Matrix = obj.transform.matrix;
> >
> > var pivotX:Number = obj.x + axis.x;
> > var pivotY:Number = obj.y + axis.y;
> >
> > temp.translate(0 - pivotX, 0 - pivotY);
> >
> > temp.rotate(angle);
> >
> > temp.translate(pivotX, pivotY);
> >
> > obj.transform.matrix = temp;
> > }
>
> If I've read the code correctly, this is your problem. Rounding errors
> will build up in these calculations over time and cause problems like
> those you've seen (object gradually heading towards (0,0) etc.)
>
> Normal practice is to 'set' rather than 'update' the transform on every
> frame, so at the top of the above method, you should reset the transform
> to the identity-metrix. Then you just need to arrange that the 'angle'
> value changes over time, i.e. it doesn't represent the change per frame
> any more, but the absolute rotation for the given point in time.
>
>
> Hope that helps, and that I understood your code correctly!
> dave
>
> --
> http://david.holroyd.me.uk/
>
> _______________________________________________
> osflash mailing list
> osflash at osflash.org
> http://osflash.org/mailman/listinfo/osflash_osflash.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/osflash_osflash.org/attachments/20070215/b836904e/attachment.htm
More information about the osflash
mailing list