POV-Ray : Newsgroups : povray.animations : Animation macros Server Time
28 Mar 2024 14:50:07 EDT (-0400)
  Animation macros (Message 1 to 4 of 4)  
From: Shadowbeast007
Subject: Animation macros
Date: 8 Apr 2022 05:35:00
Message: <web.62500182b4fba1694d9e99e1b6cb3c0c@news.povray.org>
Hi,

to get smooth transitions in animations i thought about writing a macro that
changes values depending on the time in three ranges. However, I can't get a
switch statement in a macro running.
How can i let a part of code run as a macro and then define a return value?
My macro code looks like that:

#macro Soft_Transition(time,t1,t2,V1,V2,theta)
    #local a=(V2-V1)/(2*(t2-t1)*(t2-t1)*(theta-theta*theta));
    #local b=2*a*theta*(t2-t1);
    #switch(time)
        #range(t1,t1+theta*(t2-t1))//soft transition at beginning
            V1-a*(time-t1)*(time-t1)
        #break
        #range(t1+theta*(t2-t1)+0.001,t2-theta*(t2-t1))//linear center range
            V1-a*theta*theta*(t2-t1)*(t2-t1)-b*(time-t1-theta*(t2-t1))
        #break
        #range(t2-theta*(t2-t1)+0.001,t2)//soft transition at end
            V2+a*(t2-time)*(t2-time)
        #break
    #end
#end

Any help would really be appreciated


Post a reply to this message

From: jr
Subject: Re: Animation macros
Date: 8 Apr 2022 06:25:00
Message: <web.62500c7152a008d55834ab476cde94f1@news.povray.org>
hi,

"Shadowbeast007" <nomail@nomail> wrote:
> Hi,
>
> to get smooth transitions in animations i thought about writing a macro that
> changes values depending on the time in three ranges. However, I can't get a
> switch statement in a macro running.
> How can i let a part of code run as a macro and then define a return value?
> My macro code looks like that:
>
> #macro Soft_Transition(time,t1,t2,V1,V2,theta)
>     #local a=(V2-V1)/(2*(t2-t1)*(t2-t1)*(theta-theta*theta));
>     #local b=2*a*theta*(t2-t1);
>     #switch(time)
>         #range(t1,t1+theta*(t2-t1))//soft transition at beginning
>             V1-a*(time-t1)*(time-t1)
>         #break
>         #range(t1+theta*(t2-t1)+0.001,t2-theta*(t2-t1))//linear center range
>             V1-a*theta*theta*(t2-t1)*(t2-t1)-b*(time-t1-theta*(t2-t1))
>         #break
>         #range(t2-theta*(t2-t1)+0.001,t2)//soft transition at end
>             V2+a*(t2-time)*(t2-time)
>         #break
>     #end
> #end
>
> Any help would really be appreciated

you have two options I think.  either supply another parameter and use that to
return the value in, or, having calculated the return value 'r_', return that
directly, ie

#macro x()
  #local r_ = ... ;
  ...
  r_
#end


regards, jr.


Post a reply to this message

From: Cousin Ricky
Subject: Re: Animation macros
Date: 8 Apr 2022 09:50:00
Message: <web.62503bfd52a008d560e0cc3d949c357d@news.povray.org>
"Shadowbeast007" <nomail@nomail> wrote:
>
> How can i let a part of code run as a macro and then define a return value?

When in doubt, wrap the macro in parentheses.  See if this works:

#macro Soft_Transition(time,t1,t2,V1,V2,theta)
(
    #local a=(V2-V1)/(2*(t2-t1)*(t2-t1)*(theta-theta*theta));
    #local b=2*a*theta*(t2-t1);
    #switch(time)
        #range(t1,t1+theta*(t2-t1))//soft transition at beginning
            V1-a*(time-t1)*(time-t1)
        #break
        #range(t1+theta*(t2-t1)+0.001,t2-theta*(t2-t1))//linear center range
            V1-a*theta*theta*(t2-t1)*(t2-t1)-b*(time-t1-theta*(t2-t1))
        #break
        #range(t2-theta*(t2-t1)+0.001,t2)//soft transition at end
            V2+a*(t2-time)*(t2-time)
        #break
    #end
)
#end

P.S.  The word 'time' shows up in a different color in my editor, which means
that someone, somewhere, used 'time' as a keyword in a well-known unofficial
patch.  I would change it to 'Time' in case the POV development team decides to
make it official.  It is recommended that all identifiers contain at least one
capital letter.


Post a reply to this message

From: Kenneth
Subject: Re: Animation macros
Date: 8 Apr 2022 21:25:00
Message: <web.6250df6652a008d54cef624e6e066e29@news.povray.org>
The macro appears to run OK as-is in v3.8.0 beta 1 (in Windows), at least no
fatal errors-- if I'm testing it correctly. I used these arbitrary values when
calling the macro, without any other code...

Soft_Transition(8,3,4,6,5,.1)

... although I have no idea what the result of those values is, since I didn't
actually use the macro for anything ;-)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.