Oh no, I don't want to just rotate an object, that would be to easy

I want that an object rotate correctly (a ball for example) in dependance of it's current movement. I've tried a lot but I've never get it.
Here's my current code:
vec_set(last_pos,my.x);
wait(1);
my.tilt-=(my.x-last_pos.x)*17*cos(my.pan);
my.pan+=(my.y-last_pos.y)*17*sin(my.roll);
my.roll+=(my.y-last_pos.y)*17*sin(my.tilt);
I hope you understand what I mean.
Regards
TSGames