Question...smooth undulation?

Blitz3D Forums/Blitz3D Programming/Question...smooth undulation?

OrcSlayer(Posted 2006) [#1]
Ok, I'm trying to make a value go from say...1 to 3 and back again (looping of course), smoothly. This value is used to move an object move up and down, so as it gets closer to 1 or 3 the value needs to be smaller. The most common use I've seen is for making waves by moving vertexes up and down.

I believe the sin and cos commands are capable of doing what I'm after, but sadly that's one of those things that has always gone over my head.

So anyway, putting it simply:

I want an object to move on it's Y axis between 1 and 3 units. I want it to move up and down smoothly, with a wave-like motion.

Can anyone help me out here?


bytecode77(Posted 2006) [#2]
y = Sin(frame * 2)+2
hope this help :)

cya


Defoc8(Posted 2006) [#3]
sin(0)=0, sin(90)=1, sin(180)=0, sin(270)=-1, sin(360)=sin(0)

- im guessing you can see the pattern, the values produce
a smooth waveform.. the results are within unit range, so you can simply scale
the result by a const - so if you want the max height
of your wave to be 1000, sin(n)*1000.

with some experimenting you shouldnt have too many
problems putting something half decent together..
try passing time into the sin function... sin(millisecs())

EDIT: jst a small note, you should probably stick to using
time based movement...units per sec, using frame based
inputs will yield unpredictable ouput on fast/slow
machines.

hope that helped a little.


OrcSlayer(Posted 2006) [#4]
Currently my engine is on a frame limiter (60 FPS), using Mark's framework example, though I'm not sure if that's the best route to take.

Thanks for the examples guys, I'll expirement a bit with sin and see what the results are in game!

I may start another thread later about going with time based engine instead of frame based...now that you've brought the topic up in my mind...

-Jonathan


OrcSlayer(Posted 2006) [#5]
Well I tried it out...using milisecs in it caused some really obvious jerkiness, so what I did was create a looping step value for the items, which increases by one every update up to 180, then resets to 0. This value is fed into the sin function, then 2 is added to the result. The items undulate up and down exactly as I wanted!

I suppose the other method might be better if I used a time based engine instead of frame based...


Defoc8(Posted 2006) [#6]
I used millisecs as a hint - no a solution.
- its jerky cuz the steps are big..it wont take long for
90 millisecs() to elapse ;)

The solution is to rewrite your system - make it time based,
and update a step var in small increments every so many
millisecs...how you implment such a system is up to you,
but i imagine there are plenty of resources around that
will help you create a "per sec" type system.

anyway - glad you got it working ;)