src/object/camera.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef HEADER_SUPERTUX_OBJECT_CAMERA_HPP
00018 #define HEADER_SUPERTUX_OBJECT_CAMERA_HPP
00019 
00020 #include <memory>
00021 
00022 #include "math/vector.hpp"
00023 #include "supertux/game_object.hpp"
00024 #include "supertux/script_interface.hpp"
00025 #include "supertux/timer.hpp"
00026 #include "util/reader_fwd.hpp"
00027 
00028 class Sector;
00029 class Path;
00030 class PathWalker;
00031 class CameraConfig;
00032 
00033 class Camera : public GameObject, 
00034                public ScriptInterface
00035 {
00036 public:
00037   Camera(Sector* sector, std::string name = "");
00038   virtual ~Camera();
00039 
00041   void parse(const Reader& reader);
00042     
00044   void reset(const Vector& tuxpos);
00045 
00047   const Vector& get_translation() const;
00048 
00049   virtual void update(float elapsed_time);
00050 
00051   virtual void draw(DrawingContext& );
00052 
00053   virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
00054   virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
00055 
00056   // shake camera in a direction 1 time
00057   void shake(float speed, float x, float y);
00058 
00059   void set_scrolling(int scroll_x, int scroll_y)
00060   {
00061     translation.x = scroll_x;
00062     translation.y = scroll_y;
00063   }
00064 
00069   void scroll_to(const Vector& goal, float scrolltime);
00070 
00071   void reload_config();
00072 
00073   enum CameraMode
00074   {
00075     NORMAL, AUTOSCROLL, SCROLLTO, MANUAL
00076   };
00077   CameraMode mode;
00078 
00082   Vector get_center() const;
00083 
00084 private:
00085   void update_scroll_normal(float elapsed_time);
00086   void update_scroll_autoscroll(float elapsed_time);
00087   void update_scroll_to(float elapsed_time);
00088   void keep_in_bounds(Vector& vector);
00089   void shake();
00090 
00091 private:
00096   enum LookaheadMode {
00097     LOOKAHEAD_NONE, LOOKAHEAD_LEFT, LOOKAHEAD_RIGHT
00098   };
00099 
00100 private:
00101   Vector translation;
00102 
00103   Sector* sector;
00104 
00105   // normal mode
00106   LookaheadMode lookahead_mode;
00107   float changetime;
00108   Vector lookahead_pos;
00109   Vector peek_pos;
00110   Vector cached_translation;
00111 
00112   // autoscroll mode
00113   std::auto_ptr<Path> autoscroll_path;
00114   std::auto_ptr<PathWalker> autoscroll_walker;
00115 
00116   // shaking
00117   Timer shaketimer;
00118   float shakespeed;
00119   float shakedepth_x;
00120   float shakedepth_y;
00121 
00122   // scrollto mode
00123   Vector scroll_from;
00124   Vector scroll_goal;
00125   float scroll_to_pos;
00126   float scrollspeed;
00127 
00128   CameraConfig *config;
00129 
00130 private:
00131   Camera(const Camera&);
00132   Camera& operator=(const Camera&);
00133 };
00134 
00135 #endif /*SUPERTUX_CAMERA_H*/
00136 
00137 /* EOF */

Generated on Mon Jun 9 03:38:19 2014 for SuperTux by  doxygen 1.5.1