Sign in to follow this  

Vibration Routines

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this