POV-Ray : Newsgroups : povray.animations : Animation block...acceleration on the x axis. Server Time
28 Mar 2024 05:17:37 EDT (-0400)
  Animation block...acceleration on the x axis. (Message 1 to 10 of 23)  
Goto Latest 10 Messages Next 10 Messages >>>
From: RC
Subject: Animation block...acceleration on the x axis.
Date: 23 Feb 2009 16:45:01
Message: <web.49a3163629ff894ce1acfc5e0@news.povray.org>
Hello,

I know this question is going to be a head slapper but I can't seem to get an
object to increase in speed. I need this object to increase in speed every x
clock cycles, so I'm using an if statement. Problem is I can get it to enter
the 'else' section, but it never returns to my original condition after I reset
my variable counting to x (num).

        #declare num = clock*60;
        //60 being the total number of frames
        #declare speed = clock;
        #if (num <= 3)
              object { Ball
                scale 0.7
                translate <-5.5, 0, 0>
                translate <speed, 0, 0>
                #declare num = num + 1;
               }
              #debug "speed the same\n"
        #else
              #declare speed = speed + 1;
              #declare num = clock;
              #debug"speed increased\n"
        #end

This is hurting my brain, and I know the answer is staring me down I just can't
see it. Any input? I have a feeling its related to the declare statements.


Post a reply to this message

From: clipka
Subject: Re: Animation block...acceleration on the x axis.
Date: 23 Feb 2009 17:00:01
Message: <web.49a31c0321b0f15abc3331700@news.povray.org>
"RC" <nomail@nomail> wrote:
> I know this question is going to be a head slapper but I can't seem to get an
> object to increase in speed. I need this object to increase in speed every x
> clock cycles, so I'm using an if statement. Problem is I can get it to enter
> the 'else' section, but it never returns to my original condition after I reset
> my variable counting to x (num).

Unless I got you wrong, the head slapper is probably the fact that animations
aren't run in a loop as you seem to expect. Instead, the whole SDL is restarted
for each frame, with different values for clock and frame number.

To pass values from one frame to the next, you need to #write them to a file. Or
re-compute everything from the frame number. For example, you could change your
code to:

#declare elapsedClock = 0;
#while (elapsedClock < clock)

  //... re-compute what you did in those previous frames...

  #declare elapsedClock = elapsedClock + (clocksPerFrame)
#end


Post a reply to this message

From: RC
Subject: Re: Animation block...acceleration on the x axis.
Date: 23 Feb 2009 17:25:00
Message: <web.49a321e821b0f15ae1acfc5e0@news.povray.org>
"clipka" <nomail@nomail> wrote:
> "RC" <nomail@nomail> wrote:
> > I know this question is going to be a head slapper but I can't seem to get an
> > object to increase in speed. I need this object to increase in speed every x
> > clock cycles, so I'm using an if statement. Problem is I can get it to enter
> > the 'else' section, but it never returns to my original condition after I reset
> > my variable counting to x (num).
>
> Unless I got you wrong, the head slapper is probably the fact that animations
> aren't run in a loop as you seem to expect. Instead, the whole SDL is restarted
> for each frame, with different values for clock and frame number.
>
> To pass values from one frame to the next, you need to #write them to a file. Or
> re-compute everything from the frame number. For example, you could change your
> code to:
>
> #declare elapsedClock = 0;
> #while (elapsedClock < clock)
>
>   //... re-compute what you did in those previous frames...
>
>   #declare elapsedClock = elapsedClock + (clocksPerFrame)
> #end

Hmmm, I thought as long as my variables were functions of the clock it would
work. Isn't mine essentially the same? A conditional based on the clock that
changes every clock cycle? The issue I see, is that I need to be able to render
x number of times before changing the speed, but I can't find a way of counting
to x that can be reset back to the initial value. Bahh, am I missing something
fundamental?


Post a reply to this message

From: Warp
Subject: Re: Animation block...acceleration on the x axis.
Date: 23 Feb 2009 18:00:26
Message: <49a32a8a@news.povray.org>
I think that you are using the wrong approach for the effect you are
trying to achieve.

  What you probably want is a function which gives you the position of
the object as a function of time. We could do this literally with a
function, like this:

#declare ObjectXPosition = function(t) { <a function of t here> };
object { Ball translate <ObjectXPosition(clock*60), 0, 0> }

  Now it's only a question of writing the proper implementation for that
"<a function of t here>". If you wrote it like this:

#declare ObjectXPosition = function(t) { 0 };

then you would have a static object at x = 0, which doesn't move. If you
wrote this:

#declare ObjectXPosition = function(t) { t };

then the object would move at a fixed speed, as its x coordinate would be
linear with respect to time. If you wrote this:

#declare ObjectXPosition = function(t) { t*t };

now the speed of the object doubles for each unit of time. In other words,
you get a constant acceleration. You can get a slower acceleration by using
powers smaller than 2, eg:

#declare ObjectXPosition = function(t) { pow(t, 1.5) };

  You said that you wanted speed which changes depending on the time.
In other words, if clock*60 <= 3, the speed is linear, but for larger
values it's accelerating. Creating one single function to do this becomes
quite complicated, but you can achieve the same effect by using two
functions for those two cases, and adding them appropriately, like this:

#declare LinearSpeed = function(t) { t };
#declare AcceleratingSpeed = function(t) { pow(t, 1.5) };

#declare num = clock*60;
#declare ObjectX = LinearSpeed(num);
#if(num > 3)
  #declare ObjectX = ObjectX + AcceleratingSpeed(num - 3);
#end

  (Note that the parameter to the latter function has to be shifted so
that it starts from 0 forwards.)

-- 
                                                          - Warp


Post a reply to this message

From: Chris B
Subject: Re: Animation block...acceleration on the x axis.
Date: 23 Feb 2009 18:14:25
Message: <49a32dd1$1@news.povray.org>
"RC" <nomail@nomail> wrote in message 
news:web.49a3163629ff894ce1acfc5e0@news.povray.org...
> Hello,
>
> I know this question is going to be a head slapper but I can't seem to get 
> an
> object to increase in speed. I need this object to increase in speed every 
> x
> clock cycles, so I'm using an if statement. Problem is I can get it to 
> enter
> the 'else' section, but it never returns to my original condition after I 
> reset
> my variable counting to x (num).
>
>        #declare num = clock*60;
>        //60 being the total number of frames
>        #declare speed = clock;
>        #if (num <= 3)
>              object { Ball
>                scale 0.7
>                translate <-5.5, 0, 0>
>                translate <speed, 0, 0>
>                #declare num = num + 1;
>               }
>              #debug "speed the same\n"
>        #else
>              #declare speed = speed + 1;
>              #declare num = clock;
>              #debug"speed increased\n"
>        #end
>
> This is hurting my brain, and I know the answer is staring me down I just 
> can't
> see it. Any input? I have a feeling its related to the declare statements.
>

I think there are a few misconceptions evident from this code snippet.

The Ball object is only placed in the scene if num<=3. Else the ball is not 
added into the scene at all by this code. I suspect you need to place the 
ball object in the scene after the #if, #else, #end clause that calculates 
the distance travelled.

The comparison 'num<=3' is dodgy in a number of respects. Firstly, if you 
truly do have 60 frames then, as the frame number passes from 0 to 59, num 
will pass from 0 to 60, so won't go up in integer values. Secondly it's a 
calculated decimal value so it can't be  reliably used in this sort of 
comparison anyway (on frame 3 it may or may not be 3 to within the precision 
of the calculation). It would seem more appropriate to use the frame_number 
variable for this sort of comparison, which is an integer.

Within the #if statement, the variable 'speed' is used to translate a 
distance controlled by the clock, but this is a very small distance = 1/60 
POV-Ray units in the first 4 frames, so you may not even notice this 
distance unless your camera is really close to the ball. It'll move from 
x=-5.5 to x=-5.434 in those 4 frames.

Even if the ball appeared beyond the 4th frame (frame 3), which it doesn't 
in this code, the increase in 'speed' isn't really that at all. You're just 
adding 1 unit to the variable you've been using for distance, so it would 
jump forward during one frame transition and would then continue at the 
snails pace it was doing before. It would travel a total of 2 units in the 
60 frames, with 1 unit of that distance being added in a single step between 
frames 3 and 4.

All of the calculations you do after adding the Ball object to the scene 
have no impact at all on the Ball object., so the num=num+1 doesn't do 
anything to the ball in any of the frames.

I see Warp has given you an example using a function to calculate the X 
displacement of an object that you can then use to translate your Ball 
object while I've been writing this, which is probably all you really need, 
but I hope this explanation also helps.

Regards,
Chris B.


Post a reply to this message

From: RC
Subject: Re: Animation block...acceleration on the x axis.
Date: 23 Feb 2009 18:30:01
Message: <web.49a3309d21b0f15ae1acfc5e0@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:
> "RC" <nomail@nomail> wrote in message
> news:web.49a3163629ff894ce1acfc5e0@news.povray.org...
> > Hello,
> >
> > I know this question is going to be a head slapper but I can't seem to get
> > an
> > object to increase in speed. I need this object to increase in speed every
> > x
> > clock cycles, so I'm using an if statement. Problem is I can get it to
> > enter
> > the 'else' section, but it never returns to my original condition after I
> > reset
> > my variable counting to x (num).
> >
> >        #declare num = clock*60;
> >        //60 being the total number of frames
> >        #declare speed = clock;
> >        #if (num <= 3)
> >              object { Ball
> >                scale 0.7
> >                translate <-5.5, 0, 0>
> >                translate <speed, 0, 0>
> >                #declare num = num + 1;
> >               }
> >              #debug "speed the same\n"
> >        #else
> >              #declare speed = speed + 1;
> >              #declare num = clock;
> >              #debug"speed increased\n"
> >        #end
> >
> > This is hurting my brain, and I know the answer is staring me down I just
> > can't
> > see it. Any input? I have a feeling its related to the declare statements.
> >
>
> I think there are a few misconceptions evident from this code snippet.
>
> The Ball object is only placed in the scene if num<=3. Else the ball is not
> added into the scene at all by this code. I suspect you need to place the
> ball object in the scene after the #if, #else, #end clause that calculates
> the distance travelled.
>
> The comparison 'num<=3' is dodgy in a number of respects. Firstly, if you
> truly do have 60 frames then, as the frame number passes from 0 to 59, num
> will pass from 0 to 60, so won't go up in integer values. Secondly it's a
> calculated decimal value so it can't be  reliably used in this sort of
> comparison anyway (on frame 3 it may or may not be 3 to within the precision
> of the calculation). It would seem more appropriate to use the frame_number
> variable for this sort of comparison, which is an integer.
>
> Within the #if statement, the variable 'speed' is used to translate a
> distance controlled by the clock, but this is a very small distance = 1/60
> POV-Ray units in the first 4 frames, so you may not even notice this
> distance unless your camera is really close to the ball. It'll move from
> x=-5.5 to x=-5.434 in those 4 frames.
>
> Even if the ball appeared beyond the 4th frame (frame 3), which it doesn't
> in this code, the increase in 'speed' isn't really that at all. You're just
> adding 1 unit to the variable you've been using for distance, so it would
> jump forward during one frame transition and would then continue at the
> snails pace it was doing before. It would travel a total of 2 units in the
> 60 frames, with 1 unit of that distance being added in a single step between
> frames 3 and 4.
>
> All of the calculations you do after adding the Ball object to the scene
> have no impact at all on the Ball object., so the num=num+1 doesn't do
> anything to the ball in any of the frames.
>
> I see Warp has given you an example using a function to calculate the X
> displacement of an object that you can then use to translate your Ball
> object while I've been writing this, which is probably all you really need,
> but I hope this explanation also helps.
>
> Regards,
> Chris B.


Thank you both loads. I think I understand and Chris B, what you wrote is
exactly whats happening. I'll give it a whirl...


Post a reply to this message

From: RC
Subject: Re: Animation block...acceleration on the x axis.
Date: 24 Feb 2009 10:55:00
Message: <web.49a417c221b0f15ae1acfc5e0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> I think that you are using the wrong approach for the effect you are
> trying to achieve.
>
>   What you probably want is a function which gives you the position of
> the object as a function of time. We could do this literally with a
> function, like this:
>
> #declare ObjectXPosition = function(t) { <a function of t here> };
> object { Ball translate <ObjectXPosition(clock*60), 0, 0> }
>
>   Now it's only a question of writing the proper implementation for that
> "<a function of t here>". If you wrote it like this:
>
> #declare ObjectXPosition = function(t) { 0 };
>
> then you would have a static object at x = 0, which doesn't move. If you
> wrote this:
>
> #declare ObjectXPosition = function(t) { t };
>
> then the object would move at a fixed speed, as its x coordinate would be
> linear with respect to time. If you wrote this:
>
> #declare ObjectXPosition = function(t) { t*t };
>
> now the speed of the object doubles for each unit of time. In other words,
> you get a constant acceleration. You can get a slower acceleration by using
> powers smaller than 2, eg:
>
> #declare ObjectXPosition = function(t) { pow(t, 1.5) };
>
>   You said that you wanted speed which changes depending on the time.
> In other words, if clock*60 <= 3, the speed is linear, but for larger
> values it's accelerating. Creating one single function to do this becomes
> quite complicated, but you can achieve the same effect by using two
> functions for those two cases, and adding them appropriately, like this:
>
> #declare LinearSpeed = function(t) { t };
> #declare AcceleratingSpeed = function(t) { pow(t, 1.5) };
>
> #declare num = clock*60;
> #declare ObjectX = LinearSpeed(num);
> #if(num > 3)
>   #declare ObjectX = ObjectX + AcceleratingSpeed(num - 3);
> #end
>
>   (Note that the parameter to the latter function has to be shifted so
> that it starts from 0 forwards.)
>
> --
>                                                           - Warp
Ok, so I'm trying this out, but I find I'm still hitting the same fundamental
block. "In other words, if clock*60 <= 3, the speed is linear, but for larger
> values it's accelerating." Not quite. I want the speed to increase lets say every
three frames.
So frames 1->3 = t 4->6 = t+1 7->9 = t+2 etc. At what point in the code would I
include a variable that changes the "function of t" value every three frames?
My apologies, I'm not a 3D animator nor am I much of a programmer. ;(


Post a reply to this message

From: Chris B
Subject: Re: Animation block...acceleration on the x axis.
Date: 24 Feb 2009 11:33:33
Message: <49a4215d$1@news.povray.org>
"RC" <nomail@nomail> wrote in message 
news:web.49a417c221b0f15ae1acfc5e0@news.povray.org...
> Warp <war### [at] tagpovrayorg> wrote:
>>   #declare ObjectX = ObjectX + AcceleratingSpeed(num - 3);
>
> Ok, so I'm trying this out, but I find I'm still hitting the same 
> fundamental
> block. "In other words, if clock*60 <= 3, the speed is linear, but for 
> larger
>> values it's accelerating." Not quite. I want the speed to increase lets 
>> say every three frames.
> So frames 1->3 = t 4->6 = t+1 7->9 = t+2 etc. At what point in the code 
> would I
> include a variable that changes the "function of t" value every three 
> frames?
> My apologies, I'm not a 3D animator nor am I much of a programmer. ;(
>

Ah. So you do want a stepwise change. You might like to try something like 
the following ( I still think you'll find it easier using the frame_number 
variable rather than the clock variable):

#declare ObjectX = frame_number*0.1+div(frame_number+1,3)*0.9;
#debug concat("ObjectX: ",str(ObjectX,3,3),"\n")

This creates a displacement that moves a small amount (0.1 units) each frame 
and adds a larger amount (0.9 units) every 3rd frame. The div function is 
just an integer divide. I added 1 to frame_number because it runs from 0 to 
59, so frames 2, 5, 8, etc. get the stepwise change applied.

Regards
Chris B.


Post a reply to this message

From: RC
Subject: Re: Animation block...acceleration on the x axis.
Date: 24 Feb 2009 12:30:00
Message: <web.49a42d8221b0f15ae1acfc5e0@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:
> "RC" <nomail@nomail> wrote in message
> news:web.49a417c221b0f15ae1acfc5e0@news.povray.org...
> > Warp <war### [at] tagpovrayorg> wrote:
> >>   #declare ObjectX = ObjectX + AcceleratingSpeed(num - 3);
> >
> > Ok, so I'm trying this out, but I find I'm still hitting the same
> > fundamental
> > block. "In other words, if clock*60 <= 3, the speed is linear, but for
> > larger
> >> values it's accelerating." Not quite. I want the speed to increase lets
> >> say every three frames.
> > So frames 1->3 = t 4->6 = t+1 7->9 = t+2 etc. At what point in the code
> > would I
> > include a variable that changes the "function of t" value every three
> > frames?
> > My apologies, I'm not a 3D animator nor am I much of a programmer. ;(
> >
>
> Ah. So you do want a stepwise change. You might like to try something like
> the following ( I still think you'll find it easier using the frame_number
> variable rather than the clock variable):
>
> #declare ObjectX = frame_number*0.1+div(frame_number+1,3)*0.9;
> #debug concat("ObjectX: ",str(ObjectX,3,3),"\n")
>
> This creates a displacement that moves a small amount (0.1 units) each frame
> and adds a larger amount (0.9 units) every 3rd frame. The div function is
> just an integer divide. I added 1 to frame_number because it runs from 0 to
> 59, so frames 2, 5, 8, etc. get the stepwise change applied. Thank you by the way,
this is all incredibly helpful...
>
> Regards
> Chris B.

Ahhh, interesting, and it works, but with this the motion of each frame changes,
its always 0.1 in between and a full 0.9 on the third. I'm looking to have them
move more evenly. If frames 1,2,3 are moving 1.0, 4,5,6 all should move the
same amount as what ever value the 4th frame was incremented. Does that make
sense?


Post a reply to this message

From: Chris B
Subject: Re: Animation block...acceleration on the x axis.
Date: 24 Feb 2009 14:11:21
Message: <49a44659@news.povray.org>
"RC" <nomail@nomail> wrote in message 
news:web.49a42d8221b0f15ae1acfc5e0@news.povray.org...
> "Chris B" <nom### [at] nomailcom> wrote:
>>
>> #declare ObjectX = frame_number*0.1+div(frame_number+1,3)*0.9;
>
> Ahhh, interesting, and it works, but with this the motion of each frame 
> changes,
> its always 0.1 in between and a full 0.9 on the third. I'm looking to have 
> them
> move more evenly. If frames 1,2,3 are moving 1.0, 4,5,6 all should move 
> the
> same amount as what ever value the 4th frame was incremented. Does that 
> make
> sense?
>

Maybe it would help if you could list the values you'd like to generate for 
the x-displacement for say the first 12 frames.
In fact, if all else fails you could list the 60 displacements into an array 
and simply index the array using the frame_number variable.

Regards,
Chris B.


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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