AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzGeometry.h
Go to the documentation of this file.
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_BOX2D_GEOMETRY_H_)
00015 #define _CZ_BOX2D_GEOMETRY_H_
00016 
00017 #include "CzUtil.h"
00018 #include "CzString.h"
00019 #include "CzXoml.h"
00020 #include "IzPlatformRender.h"
00021 
00022 /**
00023  @addtogroup Display
00024  @{
00025  */
00026 
00027 
00028 /**
00029  @struct    CzGeometry
00030 
00031  @brief CzGeometry - A renderable geometry shape or collection of shapes.
00032 
00033  Geometries are resources that contain collections of vertices, UV texture coordinates, RGBA colours and face vertex index lists that can be used to 
00034  create 2D geometry that can be attached to Actors to modify their visual shape. Currently 3 types of geometry are supported by XOML:
00035  - Poly – A convex polygon with any number of vertices
00036  - TriList – A list of triangles
00037  - QuadList – A list of quadrangles
00038 
00039  Note that concave polygons are not supported however you can create the same concave shape using a triangle list. A geometry resource is declared 
00040  using the Geometry XOML tag, e.g:
00041 
00042  @par XOML Example:
00043  @code
00044 <!--Create a single triangle-->
00045 <Geometry Name="Geoms1" Vertices="-200,-200,200,200,-200,200" UV="0,0,1,1,0,1" Type="TriList" />
00046 <!--Create two triangles-->
00047 <Geometry Name="Geoms2" Vertices="-200,-200,200,200,-200,200,-400,-400,-200,-400,-200,0" Type="TriList" />
00048 <!--Create a house shape -->
00049 <Geometry Name="Geoms3" Vertices="-200,-200,0,-300,200,-200,200,200,-200,200"  Indices="0,1,2,3,4" Colours="255,0,0,255,0,255,0,255,0,0,255,255,255,255,255,255,255,255,255,255" Type="Poly"/>
00050  @endcode
00051 
00052  The above XOML shows 3 different examples of creating geometries.
00053 
00054  The Geometry XOML tag has the following properties:
00055 
00056  - Name (string) – The name of the geometry
00057  - Tag (string) – Resource tag name
00058  - Vertices (vec2 list) – A list of pairs of x,y coordinates that describe the shape of the geometry in 2D
00059  - UV (vec2 list) – A list of pairs of x,y texture coordinates that describe how the assigned image is mapped to the polygon(s) vertices. If this 
00060  not supplied then it is automatically calculated
00061  - Colours (vec4 list) – A list of RGBA colours that are assigned to each vertex. If this is not supplied then all vertices will be assigned RGBA 
00062  of 255,255,255,255
00063  - Indices (list of numbers)– The face index list which determines the order in which vertices form face. If this is not supplied then this will 
00064  be automatically be generated
00065  - Type (geometry-type) – The type of geometry:
00066    - Poly – A polygon
00067    - TriList – A list of triangles
00068    - QuadList – A list of quadrangles
00069  - PercVerts (boolean) – If set to true then the geometries vertices will be treated as proportional percentage based. The geometry when attached 
00070  to an actor will be resized to fit the width and height of the host actor.
00071 
00072  Assigning a geometry to an Actor will force the actor to render the geometry in place of its default rectangular shape, e.g:
00073 
00074  @code
00075 <Icon Name="Sprite1" Position="200,0" Background="bg1" Geometry="Geoms1" />
00076  @endcode
00077 
00078  Note that hit detection and overlap detection is supported for all types of geometry, including disconnected geometry.
00079 
00080  */
00081 
00082 struct CzGeometry : public IzXomlResource
00083 {
00084 public:
00085     // Properties
00086     eCzPrimType         Type;           ///< Type of primitive
00087     CzVec2*             Verts;          ///< Screen vertices
00088     CzVec2*             UVs;            ///< Texture UV coordinmaes
00089     CzColour*           Colours;        ///< Colour vertices
00090     uint16*             Indices;        ///< Face indices
00091     uint16              VertCount;      ///< Vertex count
00092     uint16              FaceCount;      ///< Face count
00093     uint16              IndicesCount;   ///< indices count
00094     bool                PercBased;      ///< If true then the vertices are pecentage based
00095     // Properties end
00096 public:
00097     CzGeometry() : Verts(NULL), UVs(NULL), Colours(NULL), Indices(NULL), VertCount(0), FaceCount(0), IndicesCount(0), PercBased(false) { setClassType("geometry"); }
00098     ~CzGeometry();
00099 
00100     // Implementation of IzXomlResource interface
00101     int                 LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00102 
00103     void                CalculateDimensions(float& min_x, float& max_x, float& min_y, float& max_y);
00104 };
00105 
00106 /**
00107  @class CzGeometryCreator
00108 
00109  @brief CzGeometryCreator - Creates an instance of a geometry shape.
00110 
00111  */
00112 
00113 class CzGeometryCreator : public IzXomlClassCreator
00114 {
00115 public:
00116     CzGeometryCreator()
00117     {
00118         setClassName("geometry");
00119     }
00120     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzGeometry(); }
00121 };
00122 
00123 /// @}
00124 
00125 
00126 #endif // _CZ_BOX2D_GEOMETRY_H_