Sign in to follow this  
victoryismine06

Camera Shake Help

Recommended Posts

Hey all, Ok so I'm trying to add a camera shake method to my camera class and I'm having a few problems. First off I'm using Directx 9.0c and its basically a 2D Side Scroller so I want the camera to shake when a bomb or explosion happens within a certain distance from the player. So does anyone have an algorithm or any suggestions on how to correctly "shake" the camera? Anyone? Thanks!

Share this post


Link to post
Share on other sites
just move the camera from side to side, press smartbomb in my latest demo (see journal)

use_mv_mat.a03 += sin( shake_horizontal_speed ) * shake_horizontal_magnitude;
shake_horizontal_magnitude *= shake_dampening_amount;

Share this post


Link to post
Share on other sites
simple harmonic motion (SHM)
zedz has shown a SHM of shearing

u could also try rotation about the local z-axis (not world axis)

cam.rotz = D3DX_PI/18;

while(shaking)
{
if(cam.rotz > 0)
rotspeed.z -= rate;

else
rotspeed.z += rate;
}


cam.zrot += rotspeed.z;

Share this post


Link to post
Share on other sites
I advice against moving the camera since this could move the camera through objects (walls etc) unless you also add a collision avoidance step.
It's better IMO to rotate the camera.

Share this post


Link to post
Share on other sites
Quote:
Original post by eq
I advice against moving the camera since this could move the camera through objects (walls etc) unless you also add a collision avoidance step.
It's better IMO to rotate the camera.
It sounds to me like it's a 2-d game (side-scroller), in which case camera-obstacle interference isn't likely to be an issue.

Share this post


Link to post
Share on other sites
Yea there is no worry about the camera having any collision issues. I'll try moving it back and forth like you suggested. I guess I'm still a little confused on how it works. Won't it have to do something like this:

Move Camera
Render Scence
Move Camera
Render Scene
Move Camera
Render Scene

Do I just do this for a certain amount of specified time or until the DeltaMove is equal to zero? Thanks!

Share this post


Link to post
Share on other sites
Quote:

Yea there is no worry about the camera having any collision issues. I'll try moving it back and forth like you suggested. I guess I'm still a little confused on how it works. Won't it have to do something like this:

Move Camera
Render Scence
Move Camera
Render Scene
Move Camera
Render Scene


nah, assuming u are using win32 application,
u should hv a main message loop, where u update and render everything
its a bad habit to update and render things one by one IMO

// main msg loop
while(...)
{
everything.update();

device->beginScene(...);
everything.render();
device->...
...
}

Quote:

Do I just do this for a certain amount of specified time or until the DeltaMove is equal to zero? Thanks!


its all up to u
if u are going to use zedz's equations,

if(shake_horizontal_magnitude <= "a certain amount")
{
shake_horizontal_magnitude = 0;
SHAKING = false;
}

Share this post


Link to post
Share on other sites
cheers for the rotation on the z axis idea (I didnt think of that)
though I've just now tried it + personally it doesnt look as good as side to side

shaking shouldnt affect clipping into the scenery as if clipping is an issue u should already be handling it.

>>if(shake_horizontal_magnitude <= "a certain amount")
...
...

I wouldnt even worry about if the camera is shaking or not, I apply shaking to the camera every frame, i.e. even if visually 99.99% u dont see it.
KISS

Share this post


Link to post
Share on other sites
Quote:
Original post by clivehk
nah, assuming u are using win32 application,
u should hv a main message loop, where u update and render everything
its a bad habit to update and render things one by one IMO

// main msg loop
while(...)
{
everything.update();

device->beginScene(...);
everything.render();
device->...
...
}


Ok, I think I have it setup somewhat correctly. I have my "everything" class and a music class in my main message loop. Then in my "everything" class I call the rest of my objects so I think I'm good there. I'll try to implement the camera class like u suggested and see what happens. Thanks for the help!

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