Skip to main content
GameDev.net gamedev.net
🔒 Locked

Animating to a Sine Wave?

Started by chefgon_ign Jul 6, 2007 at 1:06 PM 0 replies 900+ views
Original Post
chefgon_ign
chefgon_ign
I have a part in my program that shows water moving up and down. Right now it just goes straight up, then straight down, with no change in speed. Is it possible to use a Sine Wave calculation to give the water some more realistic movement? I'm programming in C#.
nobodynews
nobodynews
Well, it depends on how you animate the water. If you just give it a height h at time t then a sine wave should work perfect. You just substitute h for the equation Amplitute * sin(angular_freq * t + angular_offset) + height_offset

So if you wanted the wave to fluctuate between a height 1 and 11 you'd give it an amplitude of ( (11-1)/2 ) and a height_offset of 6 (-Amplitude + height_offset = 1 implies height_offset = 1+Amplitude = 6). If you wanted the wave to repeat its cycle every 10 seconds, that gives it a frequency of 1/10. However, we want angular frequency which equals 2*Pi*f. angular_offset is only important if you care whether the wave starts low, high, or in between so we'll ignore it. Your equations becomes:

height = 5 * sin( 2 * Pi * (1 / 10) * t ) + 6

t is in seconds (and should be a floating type as you'll call this multiple times a second).

Hope that helps.
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) ,

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.