lacas
lacas

Reputation: 14066

Opengl Real world Camera Shake algorithm

I d like to make my Camera shake in opengl

my old algorithm is:

setCamPosXYZ(x+randx,y+randy,z+randz);

but it is not the best. What is a better solution, a real world camera shake?

Upvotes: 1

Views: 3003

Answers (3)

Guffa
Guffa

Reputation: 700562

A real world camera shake is a reaction to some force, like a bumb or a shockwave, so it's a movement in one direct, then a countermovement in the other direction, moving back and forth until it stabilises.

So start with a sinus wave that dissipates, and then you might add some random to this to make it a bit more jerky.

Also, you should add a slight rotation of the camera along with the movement.

Upvotes: 1

David Brown
David Brown

Reputation: 13526

I have found a sin function with a high frequency and a gradually decreasing amplitude looks very convincing. If you want it to appear more random you can have different frequencies for each direction and it will bounce around more randomly. A sin function is also makes sense physically because if you think of the camera being mounted on a very stiff spring with some damping, then it's going to oscillate like a damped sin curve.

Upvotes: 4

seahorse
seahorse

Reputation: 2470

Generate x+randx,y+randy,z+randz and then animate smoothly (liner interpolation) between existing camera pos and x+randx,y+randy,z+randz for a smooth shake.

To animate smoothly set your new x at each time step to xinitial + k(randx)

Once you reach the random shake point generate a new random point and again animate using linear interpolation

Upvotes: 1

Related Questions