whitechaos35

Member

2

100 Neutral

• Rank
Newbie
1. N64 Quality Water...

Every point within some radius of the impact point is going to oscillate. Points at an equal distance from the impact are going to be at the same value, which is determined by the phase at that distance and the attenuation value for that distance. A nice looking attenuation wave would look Gaussian. If you can get the DDS algorithm I provided to work for you, then you can get phase-continuous samples for a sine wave (meaning if you want the frequency to decrease over time it will look perfect). By taking each of these samples and multiplying it by the corresponding attenuation sample, you will construct a "ripple wave". You can then map the distance from impact into a phase-lookup in the ripple table. This solution eliminates your sine computation *for every value*, so long as you can output a sine wave from the DDS algorithm, which itself doesn't even compute sine values. You also mention that you were having trouble implementing the DDS algorithm. Are you calling the "UpdateSineWaves" equivalent function at an exact frequency? If so, what is that frequency (500Hz, 1KHz, 10KHz)? Is this value defined as INC_FREQ? Is the accumulator variable 32 bits? If not, you need to set ACC_BITS to the number of bits. Is it unsigned (This algorithm works because of wraparound)? Is ACC_VALUES 2^(ACC_BITS)? If SAMPLE_BITS is 8, do you have a sine wave with 2^8 (256) values? If you still can't get it to work, post what you have and I'll be happy to take a look.
2. N64 Quality Water...

Take a look at Direct Digital Synthesis. No need to even calculate sine values, just keep them in a lookup table. If a function call at a fixed frequency is available to you, this is an efficient way to calculate sine values: #define INC_FREQ 10000 // hertz #define ACC_BITS 32 #define ACC_VALUES 4294967296 #define SAMPLE_BITS 8 // There are 2^(SAMPLE_BITS) samples #define FREQ_INCR(f) ((long)f * (long)ACC_VALUES) / INC_FREQ void UpdateSineWaves() { for( int i=0; i<numSineWaves; i++ ) { sineWaves.accumulator += sineWaves.frequencyIncrement; sineWaves.amplitude = sineWave[sineWaves.accumulator>>(ACC_BITS-SAMPLE_BITS)]; } } To adjust the frequency of a sine wave, just change the frequency increment. This doesn't affect the phase, so the result is very smooth, like what might be wanted for water waves. ;)