|
|
"RusHHouR" <gee### [at] mailnu> wrote in message
news:web.445cc6ee24781bb447d3ae5e0@news.povray.org...
> Hmmmm.... Chris! Would you mind helping me a bit more? please...?
>
> http://download.yousendit.com/75D992413B17076C
>
> If i blink in a constant rythm, it looks ok! ;)
>
> Seriously though, what needs to be added to make it move a bit smoother in
> both directions? I dont understand this code (which of course bothers me)
> so Im a bit afraid of trying to tweak it out of control...
>
> Used:
>
Hi,
Ah yes. My apologies. I was in a bit of a hurry at the time and should have
tested it with a range of values. By coincidence it worked with the first
values I tried and I just assumed I'd therefore got my maths right (an
incorrect assumption as it turned out). Also now I've got a bit more time
I'll try and explain what's going on a little better. (I like your animation
by the way). The following code should work and is explained below.
// +kfi0 +kff50 Use 320*240,No AA
camera {location <3.2,4.5,0> look_at <0.2,3.9,0>}
light_source {<30, 10, -300> color rgb 2}
#include "math.inc"
#declare MyClock = clock*5;
#declare SecondsPerCycle = 1; // One complete flap every 1 second
#declare skylt = cylinder {0,-y,0.05 pigment {color rgb <1,1,0>}}
// Calculate a number that varies linearly between -1 and +1 over the cycle
#declare CyclePosition = mod(MyClock,SecondsPerCycle)*2/SecondsPerCycle-1;
// Apply a sine function to give a value that stays out at the extremes
// for longer
#declare CycleFactor = sind(180*CyclePosition);
object {skylt
rotate x*(CycleFactor*7.5-2.5)
translate <0.2,3.9,0>
}
Step 1.
The clock variable changes from 0 to 1 in a linear way as POV-Ray renders
each of the frames you tell it to render. If you use the command line
options shown at the top of the example above, then POV-Ray will render 51
frames and the clock passes from 0 to 1 in steps of 0.02.
MyClock is set to clock*5 to represent 5 seconds for the animation which
would represent about 10 frames per second. The value of MyClock therefore
passes from 0 to 5.
Step 2.
Using mod() gives the remainder after an integer division, so, the result
passes from 0 to SecondsPerCycle, then starts again at 0 and repeats this
'MyClock/SecondsPerCycle' times (in this case 5 times).
My first mistake was in forgetting to divide this value by SecondsPerCycle,
which is needed to give a number that cycles from 0 to 1 and does so 5 times
during the animation sequence.
Multiplying by 2 and subtracting 1 gives a number that cycles from -1 to 1
in a linear way.
You could use this value to swing your sign back and forth, but it would
give abrupt changes at the extremes of the swing, whereas a freely swinging
pendulum slows down at the top ends of its swing.
Step 3.
A standard representation of a sine wave passes from 0 to -1 up to 1 and
back down to 0 in the 'y' axis as the 'x' value changes from -180 to +180
degrees (This was my second mistake where I originally had 90 degrees which
compensated for the first mistake, but only when the value of SecondPerCycle
was set to 2).
With a sine wave, for a given linear step in the 'x' direction, the step in
the 'y' direction varies in a sinusoidal manner taking smaller steps as 'y'
approaches the extremes (-1 and 1) and larger steps as 'y' passes through
y=0. This is what you want to use for rotating your sign so that the sign
moves less between each frame as it nears the extremes of its swing and more
between each frame as it passes through the middle of the swing.
Step 4.
Multiplying by 7.5 makes the value pass from -7.5 to +7.5 and subtracting
2.5 gives -10 to +5.
Hope this helps and I hope I didn't make any mistakes this time.
Any questions? :-)
Regards,
Chris B.
Post a reply to this message
|
|