Camera Class Reference

#include <camera.hpp>

Inherits GameObject, and ScriptInterface.

List of all members.

Public Types

enum  CameraMode { NORMAL, AUTOSCROLL, SCROLLTO, MANUAL }

Public Member Functions

 Camera (Sector *sector, std::string name="")
virtual ~Camera ()
void parse (const Reader &reader)
 parse camera mode from lisp file
void reset (const Vector &tuxpos)
 reset camera position
const Vectorget_translation () const
 return camera position
virtual void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.
virtual void draw (DrawingContext &)
 The GameObject should draw itself onto the provided DrawingContext if this function is called.
virtual void expose (HSQUIRRELVM vm, SQInteger table_idx)
virtual void unexpose (HSQUIRRELVM vm, SQInteger table_idx)
void shake (float speed, float x, float y)
void set_scrolling (int scroll_x, int scroll_y)
void scroll_to (const Vector &goal, float scrolltime)
 scroll the upper left edge of the camera in scrolltime seconds to the position goal
void reload_config ()
Vector get_center () const
 get the coordinates of the point directly in the center of this camera

Public Attributes

CameraMode mode

Private Types

enum  LookaheadMode { LOOKAHEAD_NONE, LOOKAHEAD_LEFT, LOOKAHEAD_RIGHT }
 The camera basically provides lookahead on the left or right side or is undecided. More...

Private Member Functions

void update_scroll_normal (float elapsed_time)
void update_scroll_autoscroll (float elapsed_time)
void update_scroll_to (float elapsed_time)
void keep_in_bounds (Vector &vector)
void shake ()
 Camera (const Camera &)
Cameraoperator= (const Camera &)

Private Attributes

Vector translation
Sectorsector
LookaheadMode lookahead_mode
float changetime
Vector lookahead_pos
Vector peek_pos
Vector cached_translation
std::auto_ptr< Pathautoscroll_path
std::auto_ptr< PathWalkerautoscroll_walker
Timer shaketimer
float shakespeed
float shakedepth_x
float shakedepth_y
Vector scroll_from
Vector scroll_goal
float scroll_to_pos
float scrollspeed
CameraConfigconfig


Detailed Description

Definition at line 33 of file camera.hpp.


Member Enumeration Documentation

enum Camera::CameraMode

Enumerator:
NORMAL 
AUTOSCROLL 
SCROLLTO 
MANUAL 

Definition at line 73 of file camera.hpp.

00074   {
00075     NORMAL, AUTOSCROLL, SCROLLTO, MANUAL
00076   };

enum Camera::LookaheadMode [private]

The camera basically provides lookahead on the left or right side or is undecided.

Enumerator:
LOOKAHEAD_NONE 
LOOKAHEAD_LEFT 
LOOKAHEAD_RIGHT 

Definition at line 96 of file camera.hpp.


Constructor & Destructor Documentation

Camera::Camera ( Sector sector,
std::string  name = "" 
)

Definition at line 114 of file camera.cpp.

References config, and reload_config().

00114                                                 :
00115   mode(NORMAL),
00116   translation(),
00117   sector(newsector), 
00118   lookahead_mode(LOOKAHEAD_NONE),
00119   changetime(),
00120   lookahead_pos(),
00121   peek_pos(),
00122   cached_translation(),
00123   autoscroll_path(),
00124   autoscroll_walker(),
00125   shaketimer(),
00126   shakespeed(),
00127   shakedepth_x(),
00128   shakedepth_y(),
00129   scroll_from(),
00130   scroll_goal(),
00131   scroll_to_pos(),
00132   scrollspeed(),
00133   config()
00134 {
00135   this->name = name;
00136   config = new CameraConfig();
00137   reload_config();
00138 }

Camera::~Camera (  )  [virtual]

Definition at line 140 of file camera.cpp.

References config.

00141 {
00142   delete config;
00143 }

Camera::Camera ( const Camera  )  [private]


Member Function Documentation

void Camera::parse ( const Reader reader  ) 

parse camera mode from lisp file

Definition at line 172 of file camera.cpp.

References AUTOSCROLL, autoscroll_path, autoscroll_walker, lisp::Lisp::get(), lisp::Lisp::get_lisp(), MANUAL, mode, and NORMAL.

Referenced by Sector::parse_object().

00173 {
00174   std::string modename;
00175 
00176   reader.get("mode", modename);
00177   if(modename == "normal") {
00178     mode = NORMAL;
00179   } else if(modename == "autoscroll") {
00180     mode = AUTOSCROLL;
00181 
00182     const lisp::Lisp* pathLisp = reader.get_lisp("path");
00183     if(pathLisp == NULL)
00184       throw std::runtime_error("No path specified in autoscroll camera.");
00185 
00186     autoscroll_path.reset(new Path());
00187     autoscroll_path->read(*pathLisp);
00188     autoscroll_walker.reset(new PathWalker(autoscroll_path.get()));
00189   } else if(modename == "manual") {
00190     mode = MANUAL;
00191   } else {
00192     std::stringstream str;
00193     str << "invalid camera mode '" << modename << "'found in worldfile.";
00194     throw std::runtime_error(str.str());
00195   }
00196 }

void Camera::reset ( const Vector tuxpos  ) 

reset camera position

Definition at line 199 of file camera.cpp.

References cached_translation, keep_in_bounds(), SCREEN_HEIGHT, SCREEN_WIDTH, shakespeed, shaketimer, Timer::stop(), translation, Vector::x, and Vector::y.

Referenced by Sector::activate(), TitleScreen::make_tux_jump(), and FlipLevelTransformer::transform_sector().

00200 {
00201   translation.x = tuxpos.x - SCREEN_WIDTH/2;
00202   translation.y = tuxpos.y - SCREEN_HEIGHT/2;
00203 
00204   shakespeed = 0;
00205   shaketimer.stop();
00206   keep_in_bounds(translation);
00207 
00208   cached_translation = translation;
00209 }

const Vector & Camera::get_translation (  )  const

return camera position

Definition at line 166 of file camera.cpp.

References translation.

Referenced by Sector::draw(), Player::draw(), Sector::get_active_region(), SpriteParticle::update(), RainParticleSystem::update(), Particles::update(), MagicBlock::update(), Fireworks::update(), CometParticleSystem::update(), and Bullet::update().

00167 {
00168   return translation;
00169 }

void Camera::update ( float  elapsed_time  )  [virtual]

This function is called once per frame and allows the object to update it's state.

The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)

Implements GameObject.

Definition at line 236 of file camera.cpp.

References AUTOSCROLL, mode, NORMAL, SCROLLTO, shake(), update_scroll_autoscroll(), update_scroll_normal(), and update_scroll_to().

00237 {
00238   switch(mode) {
00239     case NORMAL:
00240       update_scroll_normal(elapsed_time);
00241       break;
00242     case AUTOSCROLL:
00243       update_scroll_autoscroll(elapsed_time);
00244       break;
00245     case SCROLLTO:
00246       update_scroll_to(elapsed_time);
00247       break;
00248     default:
00249       break;
00250   }
00251   shake();
00252 }

void Camera::draw ( DrawingContext  )  [virtual]

The GameObject should draw itself onto the provided DrawingContext if this function is called.

Implements GameObject.

Definition at line 161 of file camera.cpp.

00162 {
00163 }

void Camera::expose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 146 of file camera.cpp.

References scripting::expose_object(), and GameObject::name.

00147 {
00148   if(name.empty()) return;
00149   scripting::Camera* _this = new scripting::Camera(this);
00150   expose_object(vm, table_idx, _this, name, true);
00151 }

void Camera::unexpose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 154 of file camera.cpp.

References GameObject::name, and scripting::unexpose_object().

00155 {
00156   if(name.empty()) return;
00157   scripting::unexpose_object(vm, table_idx, name);
00158 }

void Camera::shake ( float  speed,
float  x,
float  y 
)

Definition at line 212 of file camera.cpp.

References shakedepth_x, shakedepth_y, shakespeed, shaketimer, and Timer::start().

Referenced by Player::collision_solid(), IceCrusher::collision_solid(), and Yeti::drop_stalactite().

00213 {
00214   shaketimer.start(time);
00215   shakedepth_x = x;
00216   shakedepth_y = y;
00217   shakespeed = M_PI/2 / time;
00218 }

void Camera::set_scrolling ( int  scroll_x,
int  scroll_y 
) [inline]

Definition at line 59 of file camera.hpp.

References translation, Vector::x, and Vector::y.

00060   {
00061     translation.x = scroll_x;
00062     translation.y = scroll_y;
00063   }

void Camera::scroll_to ( const Vector goal,
float  scrolltime 
)

scroll the upper left edge of the camera in scrolltime seconds to the position goal

Definition at line 221 of file camera.cpp.

References keep_in_bounds(), mode, scroll_from, scroll_goal, scroll_to_pos, scrollspeed, SCROLLTO, and translation.

00222 {
00223   scroll_from = translation;
00224   scroll_goal = goal;
00225   keep_in_bounds(scroll_goal);
00226 
00227   scroll_to_pos = 0;
00228   scrollspeed = 1.0 / scrolltime;
00229   mode = SCROLLTO;
00230 }

void Camera::reload_config (  ) 

Definition at line 255 of file camera.cpp.

References config, CameraConfig::load(), log_debug, and log_info.

Referenced by Camera().

00256 {
00257   if(PHYSFS_exists("camera.cfg")) {
00258     try {
00259       config->load("camera.cfg");
00260       log_info << "Loaded camera.cfg." << std::endl;
00261     } catch(std::exception &e) {
00262       log_debug << "Couldn't load camera.cfg, using defaults ("
00263                 << e.what() << ")" << std::endl;
00264     }
00265   }
00266 }

Vector Camera::get_center (  )  const

get the coordinates of the point directly in the center of this camera

Definition at line 632 of file camera.cpp.

References SCREEN_HEIGHT, SCREEN_WIDTH, and translation.

Referenced by GameSession::update(), and AmbientSound::update().

00632                          {
00633   return translation + Vector(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
00634 }

void Camera::update_scroll_normal ( float  elapsed_time  )  [private]

Definition at line 304 of file camera.cpp.

References cached_translation, CAMERA_EPSILON, changetime, clamp(), CameraConfig::clamp_x, CameraConfig::clamp_y, config, Player::dir, CameraConfig::dirchange_time, DOWN, CameraConfig::dynamic_max_speed_x, CameraConfig::dynamic_speed_sm, CameraConfig::edge_x, Player::fall_mode, Player::FALLING, game_time, MovingObject::get_bbox(), Rectf::get_bottom(), Rectf::get_height(), Sector::get_height(), Rectf::get_middle(), Sector::get_width(), Player::is_dying(), Player::JUMPING, keep_in_bounds(), CameraConfig::kirby_rectsize_x, CameraConfig::kirby_rectsize_y, Player::last_ground_y, LEFT, LOOKAHEAD_LEFT, lookahead_mode, LOOKAHEAD_NONE, lookahead_pos, LOOKAHEAD_RIGHT, CameraConfig::max_speed_x, CameraConfig::max_speed_y, Rectf::p2, PEEK_ARRIVE_RATIO, peek_pos, Player::peeking_direction_x(), Player::peeking_direction_y(), Sector::player, RIGHT, SCREEN_HEIGHT, SCREEN_WIDTH, sector, CameraConfig::sensitive_x, CameraConfig::target_x, CameraConfig::target_y, Player::TRAMPOLINE_JUMP, translation, UP, Vector::x, CameraConfig::xmode, Vector::y, and CameraConfig::ymode.

Referenced by update().

00305 {
00306   const CameraConfig& config = *(this->config);
00307   Player* player = sector->player;
00308   // TODO: co-op mode needs a good camera
00309   Vector player_pos(player->get_bbox().get_middle().x,
00310                                     player->get_bbox().get_bottom());
00311   static Vector last_player_pos = player_pos;
00312   Vector player_delta = player_pos - last_player_pos;
00313   last_player_pos = player_pos;
00314 
00315   // check that we don't have division by zero later
00316   if(elapsed_time < CAMERA_EPSILON)
00317     return;
00318 
00319   /****** Vertical Scrolling part ******/
00320   int ymode = config.ymode;
00321 
00322   if(player->is_dying() || sector->get_height() == 19*32) {
00323     ymode = 0;
00324   }
00325   if(ymode == 1) {
00326     cached_translation.y = player_pos.y - SCREEN_HEIGHT * config.target_y;
00327   }
00328   if(ymode == 2) {
00329     // target_y is the high we target our scrolling at. This is not always the
00330     // high of the player, but if he is jumping upwards we should use the
00331     // position where he last touched the ground. (this probably needs
00332     // exceptions for trampolines and similar things in the future)
00333     float target_y;
00334     if(player->fall_mode == Player::JUMPING)
00335       target_y = player->last_ground_y + player->get_bbox().get_height();
00336     else
00337       target_y = player->get_bbox().p2.y;
00338     target_y -= SCREEN_HEIGHT * config.target_y;
00339 
00340     // delta_y is the distance we'd have to travel to directly reach target_y
00341     float delta_y = cached_translation.y - target_y;
00342     // speed is the speed the camera would need to reach target_y in this frame
00343     float speed_y = delta_y / elapsed_time;
00344 
00345     // limit the camera speed when jumping upwards
00346     if(player->fall_mode != Player::FALLING
00347        && player->fall_mode != Player::TRAMPOLINE_JUMP) {
00348       speed_y = clamp(speed_y, -config.max_speed_y, config.max_speed_y);
00349     }
00350 
00351     // scroll with calculated speed
00352     cached_translation.y -= speed_y * elapsed_time;
00353   }
00354   if(ymode == 3) {
00355     float halfsize = config.kirby_rectsize_y * 0.5f;
00356     cached_translation.y = clamp(cached_translation.y,
00357                                  player_pos.y - SCREEN_HEIGHT * (0.5f + halfsize),
00358                                  player_pos.y - SCREEN_HEIGHT * (0.5f - halfsize));
00359   }
00360   if(ymode == 4) {
00361     float upperend = SCREEN_HEIGHT * config.edge_x;
00362     float lowerend = SCREEN_HEIGHT * (1 - config.edge_x);
00363 
00364     if (player_delta.y < -CAMERA_EPSILON) {
00365       // walking left
00366       lookahead_pos.y -= player_delta.y * config.dynamic_speed_sm;
00367 
00368       if(lookahead_pos.y > lowerend) {
00369         lookahead_pos.y = lowerend;
00370       }
00371     } else if (player_delta.y > CAMERA_EPSILON) {
00372       // walking right
00373       lookahead_pos.y -= player_delta.y * config.dynamic_speed_sm;
00374       if(lookahead_pos.y < upperend) {
00375         lookahead_pos.y = upperend;
00376       }
00377     }
00378 
00379     // adjust for level ends
00380     if (player_pos.y < upperend) {
00381       lookahead_pos.y = upperend;
00382     }
00383     if (player_pos.y > sector->get_width() - upperend) {
00384       lookahead_pos.y = lowerend;
00385     }
00386 
00387     cached_translation.y = player_pos.y - lookahead_pos.y;
00388   }
00389 
00390   translation.y = cached_translation.y;
00391 
00392   if(ymode != 0) {
00393     float top_edge, bottom_edge;
00394     if(config.clamp_y <= 0) {
00395       top_edge = 0;
00396       bottom_edge = SCREEN_HEIGHT;
00397     } else {
00398       top_edge = SCREEN_HEIGHT*config.clamp_y;
00399       bottom_edge = SCREEN_HEIGHT*(1-config.clamp_y);
00400     }
00401 
00402     float peek_to = 0;
00403     float translation_compensation = player_pos.y - translation.y;
00404 
00405     if(player->peeking_direction_y() == ::UP) {
00406       peek_to = bottom_edge - translation_compensation;
00407     } else if(player->peeking_direction_y() == ::DOWN) {
00408       peek_to = top_edge - translation_compensation;
00409     }
00410 
00411     float peek_move = (peek_to - peek_pos.y) * PEEK_ARRIVE_RATIO;
00412     if(fabs(peek_move) < 1.0) {
00413       peek_move = 0.0;
00414     }
00415 
00416     peek_pos.y += peek_move;
00417 
00418     translation.y -= peek_pos.y;
00419 
00420     if(config.clamp_y > 0) {
00421       translation.y = clamp(translation.y,
00422                             player_pos.y - SCREEN_HEIGHT * (1-config.clamp_y),
00423                             player_pos.y - SCREEN_HEIGHT * config.clamp_y);
00424       cached_translation.y = clamp(cached_translation.y,
00425                                    player_pos.y - SCREEN_HEIGHT * (1-config.clamp_y),
00426                                    player_pos.y - SCREEN_HEIGHT * config.clamp_y);
00427     }
00428   }
00429 
00430   /****** Horizontal scrolling part *******/
00431   int xmode = config.xmode;
00432 
00433   if(player->is_dying())
00434     xmode = 0;
00435 
00436   if(xmode == 1) {
00437     cached_translation.x = player_pos.x - SCREEN_WIDTH * config.target_x;
00438   }
00439   if(xmode == 2) {
00440     // our camera is either in leftscrolling, rightscrolling or
00441     // nonscrollingmode.
00442     //
00443     // when suddenly changing directions while scrolling into the other
00444     // direction abort scrolling, since tux might be going left/right at a
00445     // relatively small part of the map (like when jumping upwards)
00446 
00447     // Find out direction in which the player moves
00448     LookaheadMode walkDirection;
00449     if (player_delta.x < -CAMERA_EPSILON) walkDirection = LOOKAHEAD_LEFT;
00450     else if (player_delta.x > CAMERA_EPSILON) walkDirection = LOOKAHEAD_RIGHT;
00451     else if (player->dir == ::LEFT) walkDirection = LOOKAHEAD_LEFT;
00452     else walkDirection = LOOKAHEAD_RIGHT;
00453 
00454     float LEFTEND, RIGHTEND;
00455     if(config.sensitive_x > 0) {
00456       LEFTEND = SCREEN_WIDTH * config.sensitive_x;
00457       RIGHTEND = SCREEN_WIDTH * (1-config.sensitive_x);
00458     } else {
00459       LEFTEND = SCREEN_WIDTH;
00460       RIGHTEND = 0;
00461     }
00462 
00463     if(lookahead_mode == LOOKAHEAD_NONE) {
00464       /* if we're undecided then look if we crossed the left or right
00465        * "sensitive" area */
00466       if(player_pos.x < cached_translation.x + LEFTEND) {
00467         lookahead_mode = LOOKAHEAD_LEFT;
00468       } else if(player_pos.x > cached_translation.x + RIGHTEND) {
00469         lookahead_mode = LOOKAHEAD_RIGHT;
00470       }
00471       /* at the ends of a level it's obvious which way we will go */
00472       if(player_pos.x < SCREEN_WIDTH*0.5) {
00473         lookahead_mode = LOOKAHEAD_RIGHT;
00474       } else if(player_pos.x >= sector->get_width() - SCREEN_WIDTH*0.5) {
00475         lookahead_mode = LOOKAHEAD_LEFT;
00476       }
00477 
00478       changetime = -1;
00479     } else if(lookahead_mode != walkDirection) {
00480       /* player changed direction while camera was scrolling...
00481        * he has to do this for a certain time to add robustness against
00482        * sudden changes */
00483       if(changetime < 0) {
00484         changetime = game_time;
00485       } else if(game_time - changetime > config.dirchange_time) {
00486         if(lookahead_mode == LOOKAHEAD_LEFT &&
00487            player_pos.x > cached_translation.x + RIGHTEND) {
00488           lookahead_mode = LOOKAHEAD_RIGHT;
00489         } else if(lookahead_mode == LOOKAHEAD_RIGHT &&
00490                   player_pos.x < cached_translation.x + LEFTEND) {
00491           lookahead_mode = LOOKAHEAD_LEFT;
00492         } else {
00493           lookahead_mode = LOOKAHEAD_NONE;
00494         }
00495       }
00496     } else {
00497       changetime = -1;
00498     }
00499 
00500     LEFTEND = SCREEN_WIDTH * config.edge_x;
00501     RIGHTEND = SCREEN_WIDTH * (1-config.edge_x);
00502 
00503     // calculate our scroll target depending on scroll mode
00504     float target_x;
00505     if(lookahead_mode == LOOKAHEAD_LEFT)
00506       target_x = player_pos.x - RIGHTEND;
00507     else if(lookahead_mode == LOOKAHEAD_RIGHT)
00508       target_x = player_pos.x - LEFTEND;
00509     else
00510       target_x = cached_translation.x;
00511 
00512     // that's the distance we would have to travel to reach target_x
00513     float delta_x = cached_translation.x - target_x;
00514     // the speed we'd need to travel to reach target_x in this frame
00515     float speed_x = delta_x / elapsed_time;
00516 
00517     // limit our speed
00518     float player_speed_x = player_delta.x / elapsed_time;
00519     float maxv = config.max_speed_x + (fabsf(player_speed_x * config.dynamic_max_speed_x));
00520     speed_x = clamp(speed_x, -maxv, maxv);
00521 
00522     // apply scrolling
00523     cached_translation.x -= speed_x * elapsed_time;
00524   }
00525   if(xmode == 3) {
00526     float halfsize = config.kirby_rectsize_x * 0.5f;
00527     cached_translation.x = clamp(cached_translation.x,
00528                                  player_pos.x - SCREEN_WIDTH * (0.5f + halfsize),
00529                                  player_pos.x - SCREEN_WIDTH * (0.5f - halfsize));
00530   }
00531   if(xmode == 4) {
00532     float LEFTEND = SCREEN_WIDTH * config.edge_x;
00533     float RIGHTEND = SCREEN_WIDTH * (1 - config.edge_x);
00534 
00535     if (player_delta.x < -CAMERA_EPSILON) {
00536       // walking left
00537       lookahead_pos.x -= player_delta.x * config.dynamic_speed_sm;
00538       if(lookahead_pos.x > RIGHTEND) {
00539         lookahead_pos.x = RIGHTEND;
00540       }
00541 
00542     } else if (player_delta.x > CAMERA_EPSILON) {
00543       // walking right
00544       lookahead_pos.x -= player_delta.x * config.dynamic_speed_sm;
00545       if(lookahead_pos.x < LEFTEND) {
00546         lookahead_pos.x = LEFTEND;
00547       }
00548     }
00549 
00550     // adjust for level ends
00551     if (player_pos.x < LEFTEND) {
00552       lookahead_pos.x = LEFTEND;
00553     }
00554     if (player_pos.x > sector->get_width() - LEFTEND) {
00555       lookahead_pos.x = RIGHTEND;
00556     }
00557 
00558     cached_translation.x = player_pos.x - lookahead_pos.x;
00559   }
00560 
00561   translation.x = cached_translation.x;
00562 
00563   if(xmode != 0) {
00564     float left_edge, right_edge;
00565     if(config.clamp_x <= 0) {
00566       left_edge = 0;
00567       right_edge = SCREEN_WIDTH;
00568     } else {
00569       left_edge = SCREEN_WIDTH*config.clamp_x;
00570       right_edge = SCREEN_WIDTH*(1-config.clamp_x);
00571     }
00572 
00573     float peek_to = 0;
00574     float translation_compensation = player_pos.x - translation.x;
00575 
00576     if(player->peeking_direction_x() == ::LEFT) {
00577       peek_to = right_edge - translation_compensation;
00578     } else if(player->peeking_direction_x() == ::RIGHT) {
00579       peek_to = left_edge - translation_compensation;
00580     }
00581 
00582     float peek_move = (peek_to - peek_pos.x) * PEEK_ARRIVE_RATIO;
00583     if(fabs(peek_move) < 1.0) {
00584       peek_move = 0.0;
00585     }
00586 
00587     peek_pos.x += peek_move;
00588 
00589     translation.x -= peek_pos.x;
00590 
00591     if(config.clamp_x > 0) {
00592       translation.x = clamp(translation.x,
00593                             player_pos.x - SCREEN_WIDTH * (1-config.clamp_x),
00594                             player_pos.x - SCREEN_WIDTH * config.clamp_x);
00595 
00596       cached_translation.x = clamp(cached_translation.x,
00597                                    player_pos.x - SCREEN_WIDTH * (1-config.clamp_x),
00598                                    player_pos.x - SCREEN_WIDTH * config.clamp_x);
00599     }
00600   }
00601 
00602   keep_in_bounds(translation);
00603   keep_in_bounds(cached_translation);
00604 }

void Camera::update_scroll_autoscroll ( float  elapsed_time  )  [private]

Definition at line 607 of file camera.cpp.

References autoscroll_walker, Player::is_dying(), keep_in_bounds(), Sector::player, sector, and translation.

Referenced by update().

00608 {
00609   Player* player = sector->player;
00610   if(player->is_dying())
00611     return;
00612 
00613   translation = autoscroll_walker->advance(elapsed_time);
00614 
00615   keep_in_bounds(translation);
00616 }

void Camera::update_scroll_to ( float  elapsed_time  )  [private]

Definition at line 619 of file camera.cpp.

References MANUAL, mode, scroll_from, scroll_goal, scroll_to_pos, scrollspeed, and translation.

Referenced by update().

00620 {
00621   scroll_to_pos += elapsed_time * scrollspeed;
00622   if(scroll_to_pos >= 1.0) {
00623     mode = MANUAL;
00624     translation = scroll_goal;
00625     return;
00626   }
00627 
00628   translation = scroll_from + (scroll_goal - scroll_from) * scroll_to_pos;
00629 }

void Camera::keep_in_bounds ( Vector vector  )  [private]

Definition at line 279 of file camera.cpp.

References clamp(), Sector::get_height(), Sector::get_width(), SCREEN_HEIGHT, SCREEN_WIDTH, sector, translation, Vector::x, and Vector::y.

Referenced by reset(), scroll_to(), update_scroll_autoscroll(), and update_scroll_normal().

00280 {
00281   float width = sector->get_width();
00282   float height = sector->get_height();
00283 
00284   // don't scroll before the start or after the level's end
00285   translation.x = clamp(translation.x, 0, width - SCREEN_WIDTH);
00286   translation.y = clamp(translation.y, 0, height - SCREEN_HEIGHT);
00287 
00288   if (height < SCREEN_HEIGHT)
00289     translation.y = height/2.0 - SCREEN_HEIGHT/2.0;
00290   if (width < SCREEN_WIDTH)
00291     translation.x = width/2.0 - SCREEN_WIDTH/2.0;
00292 }

void Camera::shake (  )  [private]

Definition at line 295 of file camera.cpp.

References Timer::get_timegone(), shakedepth_x, shakedepth_y, shakespeed, shaketimer, Timer::started(), translation, Vector::x, and Vector::y.

Referenced by update().

00296 {
00297   if(shaketimer.started()) {
00298     translation.x -= sin(shaketimer.get_timegone() * shakespeed) * shakedepth_x;
00299     translation.y -= sin(shaketimer.get_timegone() * shakespeed) * shakedepth_y;
00300   }
00301 }

Camera& Camera::operator= ( const Camera  )  [private]


Member Data Documentation

CameraMode Camera::mode

Definition at line 77 of file camera.hpp.

Referenced by parse(), scroll_to(), update(), and update_scroll_to().

Vector Camera::translation [private]

Definition at line 101 of file camera.hpp.

Referenced by get_center(), get_translation(), keep_in_bounds(), reset(), scroll_to(), set_scrolling(), shake(), update_scroll_autoscroll(), update_scroll_normal(), and update_scroll_to().

Sector* Camera::sector [private]

Definition at line 103 of file camera.hpp.

Referenced by keep_in_bounds(), update_scroll_autoscroll(), and update_scroll_normal().

LookaheadMode Camera::lookahead_mode [private]

Definition at line 106 of file camera.hpp.

Referenced by update_scroll_normal().

float Camera::changetime [private]

Definition at line 107 of file camera.hpp.

Referenced by update_scroll_normal().

Vector Camera::lookahead_pos [private]

Definition at line 108 of file camera.hpp.

Referenced by update_scroll_normal().

Vector Camera::peek_pos [private]

Definition at line 109 of file camera.hpp.

Referenced by update_scroll_normal().

Vector Camera::cached_translation [private]

Definition at line 110 of file camera.hpp.

Referenced by reset(), and update_scroll_normal().

std::auto_ptr<Path> Camera::autoscroll_path [private]

Definition at line 113 of file camera.hpp.

Referenced by parse().

std::auto_ptr<PathWalker> Camera::autoscroll_walker [private]

Definition at line 114 of file camera.hpp.

Referenced by parse(), and update_scroll_autoscroll().

Timer Camera::shaketimer [private]

Definition at line 117 of file camera.hpp.

Referenced by reset(), and shake().

float Camera::shakespeed [private]

Definition at line 118 of file camera.hpp.

Referenced by reset(), and shake().

float Camera::shakedepth_x [private]

Definition at line 119 of file camera.hpp.

Referenced by shake().

float Camera::shakedepth_y [private]

Definition at line 120 of file camera.hpp.

Referenced by shake().

Vector Camera::scroll_from [private]

Definition at line 123 of file camera.hpp.

Referenced by scroll_to(), and update_scroll_to().

Vector Camera::scroll_goal [private]

Definition at line 124 of file camera.hpp.

Referenced by scroll_to(), and update_scroll_to().

float Camera::scroll_to_pos [private]

Definition at line 125 of file camera.hpp.

Referenced by scroll_to(), and update_scroll_to().

float Camera::scrollspeed [private]

Definition at line 126 of file camera.hpp.

Referenced by scroll_to(), and update_scroll_to().

CameraConfig* Camera::config [private]

Definition at line 128 of file camera.hpp.

Referenced by Camera(), reload_config(), update_scroll_normal(), and ~Camera().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:29 2014 for SuperTux by  doxygen 1.5.1