Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post

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

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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!