void ShakeCamera(void)
{
if (!m_iShakeCam)
return;
CEngine * pEngine = CEngine::GetInst();
float frameTime = 0.001f * pEngine->GetFrameTime();
CCamera * pCamera = pEngine->GetCamera();
//
// Do shake
int shakeDir = 2 - (rand() % 5);
pCamera->Pos = m_InitialCamPos + pCamera->GetRight() * shakeDir * m_fShakePower;
pCamera->Pos += pCamera->GetUp() * shakeDir * m_fShakePower;
//
// Update shake duration time
m_fShakeDuration -= frameTime;
if (m_fShakeDuration < 0.0f)
{
//
// Shake done, reset data
m_iShakeCam = 0;
pCamera->SetPos(m_InitialCamPos);
}
}
Help "shaking" the camera...
Hello,
I am coding a game but I want to "shake" the camera when a explosion ocurrs,
I have implemented a simple test but I am not really happy with it, because
my current method is not frameTime sync, and show some image "tear"
so I appreciate if someone could help me with about it.
Here is my current code:
Thanks in advance,
Oscar
[Edited by - ogracian on August 9, 2005 2:25:22 AM]
maybe its because you got VSync disabled?
turn vsync on, if it doesn't disappear, try using sin functions to translate the camera... <- works great! :)
turn vsync on, if it doesn't disappear, try using sin functions to translate the camera... <- works great! :)
Hi,
Thanks for your help, I have turned on vsync and no more tears : ). But my
current method is not frame time sync so I am not very happy with it.
About the SIN methdo you suggest, could you develop a little about it?
Thanks,
Oscar
Thanks for your help, I have turned on vsync and no more tears : ). But my
current method is not frame time sync so I am not very happy with it.
About the SIN methdo you suggest, could you develop a little about it?
Thanks,
Oscar
I've implemented screen shakes in two ways in the past, one is better then the other, but I don't have the code in front of me so pseudo code will have to work.
void shakeCamera(){ shaking = true;}void updateShake( float timeDelta ){ if ( !shaking ) return; //accumulate time timePassed += timeDelta; // timeDelta is between frames if ( !(timePassed >= timeToUpdateShake) ) //the smaller timetoupdateshake is, the faster it will shake { return; } timePassed = 0; //keep count of number of shakes numShakes++; //random x offset float xoff = rnd( range of offsets, shakeMagnitude or power ); //same for y float yoff = rnd(...); //maybe create these points as a vector? depends on how your camer is set up. camera->setView( xoff, yoff ); //only shake for a certain amount of time (timePassed * numShakes) if ( numShakes >= shakeNumber ) { shaking = false; camera->setView( 0,0 ); }}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement