![]() |
AppEasy Core SDK
1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
|
00001 // 00002 // 00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine 00004 // 00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk 00006 // 00007 // For updates, tutorials and more details check out www.appeasymobile.com 00008 // 00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin. 00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support 00011 // 00012 // 00013 00014 #if !defined(_CZ_CAMERA_H_) 00015 #define _CZ_CAMERA_H_ 00016 00017 #include "CzUtil.h" 00018 #include "CzXoml.h" 00019 #include "CzAnim.h" 00020 00021 /** 00022 @addtogroup Display 00023 @{ 00024 */ 00025 00026 /** 00027 @class CzCamera 00028 00029 @brief A camera is generally used to display aa area of a game scene, usually tracking some actor. 00030 00031 A camera is a view into the scene from a specific position, angle and scale. In order to move, rotate and scale a scene a camera should be created 00032 and attached to it. To create a camera you use the Camera XOML tag: 00033 00034 @par XOML Example: 00035 @code 00036 <!-- Create a camera --> 00037 <Camera Name="Camera1" /> 00038 @endcode 00039 00040 To attach the camera to the scene we add the Camera attribute to the scene definition: 00041 00042 @code 00043 <Scene Name="Scene1" Current="true" Camera="Camera1"> 00044 @endcode 00045 00046 When we move, scale or rotate a scene we are actually modifying the camera view within the scene. When we move the camera objects tend to move in 00047 the opposite direction, for example moving the camera left moves the scene actors to the right. If you think about how a real camera works, when 00048 you move the camera in one direction the view seen by the camera moves in the opposite direction. 00049 00050 Its possible to create a number of different cameras and switch between them to offer different views into the scene. 00051 00052 Cameras offer a great out of the box feature called touch panning, which enables the user to pan the camera around a scene on the x and y axis by 00053 dragging their finger around the scene. Take a look at the ScenePanning example for an example showing how to use touch panning. 00054 00055 Lets take a look at what properties the Camera tag supports: 00056 00057 - Name (string) - Cameras resource name 00058 - Position (x, y) - Start position of the camera 00059 - Angle (degrees) - Rotation of the camera 00060 - Scale (scale factor) - Scale of the camera (can be used for zoom effects) 00061 - TouchPanX / TouchPanY (boolean) - Setting true causes the camera to move around when the user drags their finger on the screen using velocity 00062 obtained from the speed of the users drag. Separate X and Y axis panning can be enabled / disabled. 00063 - VelocityDamping (x, y) - Amount of damping to apply to the cameras velocity (x, y) each frame. This value when set to a value of less than 1.0, 00064 1.0 will cause the camera to slow down over time. 00065 - IgnoreActors (boolean) - When set to true and touch panel is enabled, dragging a finger over an actor will still be classed as a touch pan drag. 00066 This option basically allows the user to touch pan the scene regardless of what the user touches on the screen. 00067 - TargetX (actor name, write-only) – An actor that the camera will be used to track its x-axis position 00068 - TargetY (actor name, write-only) – An actor that the camera will be used to track its y-axis position 00069 - FollowSpeed (x, y) – The speed at which the camera should track the specified actor(s). Higher values will catch the camera up to the actors 00070 target position faster 00071 - Tag (string) - Group tag 00072 00073 Some of these properties can be modified via the scene such as Position, Angle and Scale as changes to these properties go straight to the 00074 attached camera. You can set all properties for a camera via LUA using the camera.set() function. 00075 00076 00077 */ 00078 00079 class CzCamera : public IzXomlResource 00080 { 00081 public: 00082 // Properties 00083 protected: 00084 CzScene* Scene; ///< Parent scene 00085 CzMatrix3 Transform; ///< The combined camera transform 00086 CzVec2 Position; ///< Position of camera within scene 00087 CzVec2 Velocity; ///< Velocity of camera 00088 CzVec2 VelocityDamping; ///< Velocity cadmping applied to slow the camera 00089 CzVec2 FollowSpeed; ///< Speed at which to follow target (1.0 is max) 00090 float Scale; ///< Cameras scale 00091 float Angle; ///< Cameras angle 00092 bool TransformDirty; ///< Marks camera transform needs rebuilding 00093 CzActor* TargetX; ///< Object that the camera is targeting on the x axis 00094 CzActor* TargetY; ///< Object that the camera is targeting on the y axis 00095 unsigned int TargetXHash; ///< Hash of object that the camera is targeting on the x axis 00096 unsigned int TargetYHash; ///< Hash of object that the camera is targeting on the y axis 00097 bool TouchPanX; ///< If true then the camera will pan along the x-axis with the users touch 00098 bool TouchPanY; ///< If true then the camera will pan along the y-axis with the users touch 00099 bool IgnoreActors; ///< if an actor is currently focused then it will usually prevent touch panning, this will disable that 00100 public: 00101 CzMatrix3& getTransform() { return Transform; } 00102 void setPosition(float x, float y) { Position.x = x; Position.y = y; TransformDirty = true; } 00103 CzVec2 getPosition() const { return Position; } 00104 void setVelocity(float x, float y) { Velocity.x = x; Velocity.y = y; } 00105 CzVec2 getVelocity() const { return Velocity; } 00106 void setVelocityDamping(float x, float y) { VelocityDamping.x = x; VelocityDamping.y = y; } 00107 CzVec2 getVelocityDamping() const { return VelocityDamping; } 00108 void setFollowSpeed(float x, float y) { FollowSpeed.x = x; FollowSpeed.y = y; } 00109 CzVec2 getFollowSpeed() const { return FollowSpeed; } 00110 void setScale(float scale) { Scale = scale; TransformDirty = true; } 00111 float getScale() const { return Scale; } 00112 void setAngle(float angle) { Angle = angle; TransformDirty = true; } 00113 float getAngle() const { return Angle; } 00114 void setTargetX(const char* target_name); 00115 void setTargetX(CzActor* target); 00116 void setTargetY(const char* target_name); 00117 void setTargetY(CzActor* target); 00118 void setTransformDirty(bool dirty) { TransformDirty = dirty; } 00119 bool isTransformDirty() const { return TransformDirty; } 00120 void setTouchPanX(bool pan) { TouchPanX = pan; } 00121 bool isTouchPanX() const { return TouchPanX; } 00122 void setTouchPanY(bool pan) { TouchPanY = pan; } 00123 bool isTouchPanY() const { return TouchPanY; } 00124 void setIgnoreActors(bool ignore) { IgnoreActors = ignore; } 00125 bool getIgnoreActors() const { return IgnoreActors; } 00126 virtual bool setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta); 00127 bool setProperty(const char* property_name, const CzString& data, bool delta); 00128 virtual bool setProperty(unsigned int property_name, const CzString& data, bool delta); 00129 bool getProperty(const char* property_name, CzXomlProperty& prop); 00130 virtual bool getProperty(unsigned int property_name, CzXomlProperty& prop); 00131 // Properties end 00132 00133 private: 00134 00135 public: 00136 CzCamera() : IzXomlResource(), Scene(NULL), Position(0, 0), Scale(1.0f), Angle(0), Velocity(0, 0), VelocityDamping(0.8f, 0.8f), FollowSpeed(1.0f, 1.0f), TargetX(0), TargetY(0), TargetXHash(0), TargetYHash(0), TransformDirty(true), TouchPanX(false), TouchPanY(false), IgnoreActors(true) { setClassType("camera"); } 00137 virtual ~CzCamera() {} 00138 00139 // Updates the camera 00140 virtual void Update(float dt); 00141 00142 // Implementation of IzXomlClass interface 00143 int LoadFromXoml(IzXomlResource* parebt, bool load_children, CzXmlNode* node); 00144 00145 // Internal (used by XOML system to setup and cleanup the XOML class properties system 00146 protected: 00147 static CzXomlClassDef* CameraClassDef; // XOML class definition 00148 public: 00149 static void InitClass(); 00150 static void ReleaseClass(); 00151 00152 static bool _setName(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00153 static CzXomlProperty _getName(IzXomlResource* target); 00154 static bool _setTag(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00155 static bool _setPosition(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00156 static CzXomlProperty _getPosition(IzXomlResource* target); 00157 static bool _setScale(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00158 static CzXomlProperty _getScale(IzXomlResource* target); 00159 static bool _setAngle(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00160 static CzXomlProperty _getAngle(IzXomlResource* target); 00161 static bool _setVelocity(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00162 static CzXomlProperty _getVelocity(IzXomlResource* target); 00163 static bool _setVelocityDamping(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00164 static CzXomlProperty _getVelocityDamping(IzXomlResource* target); 00165 static bool _setTouchPanX(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00166 static CzXomlProperty _getTouchPanX(IzXomlResource* target); 00167 static bool _setTouchPanY(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00168 static CzXomlProperty _getTouchPanY(IzXomlResource* target); 00169 static bool _setIgnoreActors(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00170 static CzXomlProperty _getIgnoreActors(IzXomlResource* target); 00171 static bool _setTargetX(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00172 static bool _setTargetY(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00173 static bool _setFollowSpeed(IzXomlResource* target, const CzXomlProperty& prop, bool add); 00174 static CzXomlProperty _getFollowSpeed(IzXomlResource* target); 00175 00176 }; 00177 00178 /** 00179 @class CzCameraCreator 00180 00181 @brief Creates an instance of a camera 00182 00183 */ 00184 00185 class CzCameraCreator : public IzXomlClassCreator 00186 { 00187 public: 00188 CzCameraCreator() 00189 { 00190 setClassName("camera"); 00191 } 00192 IzXomlResource* CreateInstance(IzXomlResource* parent) { return new CzCamera(); } 00193 }; 00194 00195 00196 /// @} 00197 00198 00199 #endif // _CZ_CAMERA_H_