00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
00106 LookaheadMode lookahead_mode;
00107 float changetime;
00108 Vector lookahead_pos;
00109 Vector peek_pos;
00110 Vector cached_translation;
00111
00112
00113 std::auto_ptr<Path> autoscroll_path;
00114 std::auto_ptr<PathWalker> autoscroll_walker;
00115
00116
00117 Timer shaketimer;
00118 float shakespeed;
00119 float shakedepth_x;
00120 float shakedepth_y;
00121
00122
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
00136
00137