#include "camera.h" #include "deathball.h" #include "game.h" #include #include #include "types.h" #define MOVE_SPEED 20 #define TURN_SPEED 30 #define ALPHA .6 using namespace std; Camera::Camera(DeathBall* death_ball) : _pos(0,0,0) , _dir(0,0,1) , _death_ball(death_ball) { } void Camera::update(double time_elapsed) { STVector3 target_pos; STVector3 target_dir; target_pos = _death_ball->_pos - _death_ball->_dir * 2 + STVector3::eY * 1; target_dir = _death_ball->_dir; STVector3 old_pos = _pos; _pos = ALPHA*_pos + (1-ALPHA) * target_pos; _dir = ALPHA*_dir + (1-ALPHA) * target_dir; STVector3 vel = (_pos - old_pos) / time_elapsed; // set matrix glLoadIdentity(); double eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ; eyeX = _pos.x; eyeY = _pos.y; eyeZ = _pos.z; centerX = _pos.x + _dir.x; centerY = _pos.y + _dir.y; centerZ = _pos.z + _dir.z; upX = 0; upY = 1; upZ = 0; gluLookAt (eyeX,eyeY,eyeZ, centerX,centerY,centerZ, upX,upY,upZ); // update 3d sound const FMOD_VECTOR fpos = { _pos.x, _pos.y, _pos.z }; const FMOD_VECTOR fvel = { vel.x, vel.y, vel.z }; const FMOD_VECTOR fdir = { _dir.x, _dir.y, _dir.z }; const FMOD_VECTOR fup = { upX, upY, upZ }; Game::get_singleton()._sound_sys->set3DListenerAttributes (0, &fpos, &fvel, &fdir, &fup ); // update light GLfloat light_pos[] = {_pos.x, _pos.y, _pos.z, 1.0f}; glLightfv(GL_LIGHT0, GL_POSITION, light_pos); }