Shake without effecting the real camera pos

The camera shake effect does not manipulate the real camera pos anymore, 
just the Opengl campos is effected by it. By this all camera pos related caches 
don't need to refresh just beause the camera shakes.
This commit is contained in:
titiger 2014-02-04 21:14:52 +01:00
parent 497ea1734e
commit 341c7ce46f
3 changed files with 11 additions and 3 deletions

View File

@ -73,6 +73,7 @@ GameCamera::GameCamera() : pos(0.f, defaultHeight, 0.f),
shakeDecrement=0.f;
currentShakeIntensity=0;
shakeOffset= Vec2f(0.f);
//maxRenderDistance = Config::getInstance().getFloat("RenderDistanceMax","64");
maxHeight = Config::getInstance().getFloat("CameraMaxDistance","20");
@ -173,8 +174,11 @@ void GameCamera::shake(int shakeDuration, int shakeStartIntensity , bool cameraD
void GameCamera::shakeCamera(){
//RandomGen random;
if(currentShakeIntensity > 0.f) {
pos.x += (((float) (rand() % 50)) / 50.f - 0.5f) * currentShakeIntensity;
pos.z += (((float) (rand() % 50)) / 50.f - 0.5f) * currentShakeIntensity;
// pos.x += (((float) (rand() % 50)) / 50.f - 0.5f) * currentShakeIntensity;
// pos.z += (((float) (rand() % 50)) / 50.f - 0.5f) * currentShakeIntensity;
shakeOffset.x = (((float) (rand() % 50)) / 50.f - 0.5f) * currentShakeIntensity;
shakeOffset.y = (((float) (rand() % 50)) / 50.f - 0.5f) * currentShakeIntensity;
currentShakeIntensity -= shakeDecrement;
}
}

View File

@ -62,6 +62,7 @@ public:
private:
Vec3f pos;
Vec3f destPos;
Vec2f shakeOffset;
float hAng; //YZ plane positive -Z axis
float vAng; //XZ plane positive +Z axis
@ -118,6 +119,7 @@ public:
void setPos(Vec2f pos);
void setPos(Vec3f pos);
const Vec2f &getShakeOffset() const {return shakeOffset;}
void shake(int shakeDuration, int shakeStartIntensity , bool cameraDistanceAffected, Vec3f unitVector);
void setMoveX(float f) {this->move.x= f;}

View File

@ -1128,7 +1128,9 @@ void Renderer::loadGameCameraMatrix() {
if(gameCamera != NULL) {
glRotatef(gameCamera->getVAng(), -1, 0, 0);
glRotatef(gameCamera->getHAng(), 0, 1, 0);
glTranslatef(-gameCamera->getPos().x, -gameCamera->getPos().y, -gameCamera->getPos().z);
glTranslatef(-(gameCamera->getPos().x + gameCamera->getShakeOffset().x),
-gameCamera->getPos().y,
-(gameCamera->getPos().z + gameCamera->getShakeOffset().y));
}
}