JFASI
5th November 2005 03:27 UTC
Optimization
I've got some doodoo kaleidescope work. I'm rotating and mirroring and rotating and mirroring and so forth. How can I get it all into one hany dandy movement and save loads of fps?
Note: It's a six way kaleido, each rotation is by $pi/3.
StevenRoy
5th November 2005 07:45 UTC
A mirror basically does this:
x=abs(x);y=abs(y)
To rotate something 1/6 (in rectangular coordinates), use something like this:
xx=x*cos($pi/3)+y*sin($pi/3);
y=y*cos($pi/3)-x*sin($pi/3);
x=xx
These can easily be combined to achieve the desired effect.
Of course, if this is going into a Dynamic Movement, then it may be a good idea to optimize the code afterwards. I'll leave it to others to explain how to do that. (If necessary.)
Depending on what kind of effect you're trying to achieve, though, something as simple as a "r=r*3" might be close enough... or, horrors, "r=$pi*sin(r*3)" :D (Now I want to try that one somewhere!)
JFASI
5th November 2005 14:46 UTC
Thanks.
This raises another issue. Why
xx=x*cos($pi/3)+y*sin($pi/3);
y=y*cos($pi/3)-x*sin($pi/3);
x=xx
, and not just
x=x*cos($pi/3)+y*sin($pi/3);
y=y*cos($pi/3)-x*sin($pi/3);
?
What difference can that make??? I see it all over the place and I don't understand it.
^..^
5th November 2005 15:24 UTC
It's because you have to calculate the new x and y basing on the original (="untransformed") x and y.
In the y-line of your second example AVS will use "x*cos($pi/3)+y*sin($pi/3)" instead of just "x" because you previously assigned that to x.
You could also use this code to avoid that mistake (perhaps it explains it a bit better this way):
x1=x; y1=y;
x=x1*cos($pi/3)+y1*sin($pi/3);
y=y1*cos($pi/3)-x1*sin($pi/3);
Hope i could make it somewhat clearer for you...
JFASI
5th November 2005 16:46 UTC
Aha. I get it.
That explains a lot. I had used it without the x1 and y1 and it looked all distorted. Thanks.
^..^
5th November 2005 17:18 UTC
No Problem! That's what the forums are there for: gaining more insight every day! ;)