# Vibration Routines

This topic is 4002 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Wondering if anyone had any insight into writing vibration routines. Such as a jagged pattern of power on the controller vibrations over X seconds. Other things suchs as power could be built into it. I am using a 360 controller with XInput, I have no problem getting them to vibrate, just with routines for the vibrations. I was thinking of using sin and cos waves, but I wasn't sure if there was another way to do them. Any insight would help. Thanks.

##### Share on other sites
You could use the sum of sinusoids with durations determined by normal curve.

ie.
vibration = sum(X = 0..N) of sinusoid[X] * normal curve[X] * amplitude[X].

Something like:
struct component {    double frequency;    double amplitude;    double duration;};add_vibrations(double* samples, int num_samples, const std::vector<component> &components, double start_time, double sample_period, int start_sample) {    for(int sample_no = 0; sample_no < num_samples; sample_no++) {        double amplitude = 0;        double offset = start_time + (sample_no + start_sample) * sample_period;        for(int n = 0; n < components.size(); n++) {            amplitude += cos(components[n].frequency * offset)                       * exp(1/pow(components[n].duration * offset, 2))                      * components[n].amplitude;        }        pos[sample_no] = amplitude;    }}

Just add a component to the components vector when it's generated, and remove it once it's far enough beyond the peak of the normal curve to make no difference.

This isn't optimal efficiency tho.

But yea, sinusoids would feel more natural than anything else.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001833
×