00001
00002
00003
00004
00005
00007
00012 #ifndef HGEPOLYGON__
00013 #define HGEPOLYGON__
00014
00015
00016 #include "hgeShape.h"
00017
00018
00019 #include "hgeLine.h"
00020 #include "hgeTriangle.h"
00021 #include "hgeProperties.h"
00022
00023
00024 #include "hgeResourceReader.h"
00025
00026
00027 #include <hge.h>
00028 #include <hgevector.h>
00029 #include <hgesprite.h>
00030
00031
00032 #include <vector>
00033
00034 class hgeEntityEx;
00035
00037
00038
00039 struct hgePolyTextureData
00040 {
00041 HTEXTURE tex;
00042 hgeVector original_size;
00043 };
00044
00046
00047
00048 struct hgePolyData
00049 {
00050 hgePolyTextureData tex;
00051
00052 int blend;
00053 DWORD color;
00054
00055 bool tiled;
00056 float xoffset;
00057 float yoffset;
00058 float scale;
00059
00060 bool bordered;
00061 hgePolyTextureData bordertex;
00062 float bordermin;
00063 float bordermax;
00064 float borderheight;
00065 float borderscale;
00066
00067 bool shadowed;
00068 bool shadow_follow_border;
00069 hgePolyTextureData shadowtex;
00070 float shadowheight;
00071 float shadowscale;
00072 DWORD shadowcolor;
00073
00074 };
00075
00077
00078
00079
00089 struct hgePVertex
00090 {
00091 hgeVector pos;
00092 hgePVertex * next;
00093 float normal;
00094
00095 hgePVertex(hgeVector p)
00096 {
00097 normal = 0;
00098 pos = p;
00099 next = NULL;
00100 }
00101 };
00102
00104
00105
00117 class hgePolygon : public hgeShape
00118 {
00119 private:
00120
00121
00122 std::vector<hgeQuad *> borderquads;
00123 std::vector<hgeTriple *> bordertris;
00124 std::vector<hgeQuad *> shadowquads;
00125
00126
00127 hgePolyTextureData GetTexture(const char *filename);
00128
00129
00130 hgeVector hotspot;
00131
00133
00134
00135
00136 inline int TriCount() { return (int)triangles.size(); }
00137
00138
00139 void ClearTris();
00140
00141
00142 inline void AddTri(hgeTriangle * t) { triangles.push_back(t); }
00143
00145
00146
00147
00148 void CalcNormals();
00149
00151 void CalcAABB();
00152
00153
00154 bool GenerateMesh(bool testc = true);
00155
00156
00157 void GenerateBorder();
00158
00159
00160 void CalcTexCoords(bool calcall = true);
00161
00162 protected:
00163
00165 bool is_entity;
00166
00168 hgeRect aabb;
00169
00171 hgeVector center;
00172
00174 hgeSprite *sprite;
00175
00177 HGE *hge;
00178
00180 class hgePolygonMap * map;
00181
00182 public:
00183
00185
00186
00188 std::vector<hgePVertex *>vertices;
00189
00191 std::vector<hgeTriangle *>triangles;
00192
00194 hgePolyData texture_data;
00195
00197 hgeProperties entity_data;
00198
00199
00201
00202
00203
00204 void Load(hgeResourceReader *file);
00205
00206
00207 virtual void Render();
00208
00209
00210 void RenderOutline();
00211
00213 inline bool IsPoint() { return vertices.size() <= 1; }
00214
00216 inline bool IsPoly() { return !IsPoint(); }
00217
00219 inline bool IsEntity() { return is_entity; }
00220
00221
00223 void Copy(hgePolygon *);
00224
00226 inline void SetMap(hgePolygonMap *m_Map) { map = m_Map; }
00227
00229
00230
00231 hgeIntersect Intersects(hgeCircle circle, hgeVector offset = hgeVector(0,0));
00232 hgeIntersect Intersects(hgeCircle *circle, hgeVector offset = hgeVector(0,0));
00233 hgeIntersect Intersects(hgeLine line, hgeVector offset = hgeVector(0,0));
00234 hgeIntersect Intersects(hgeLine *line, hgeVector offset = hgeVector(0,0));
00235 hgeIntersect Intersects(hgePolygon *p, hgeVector offset = hgeVector(0,0));
00236 hgeIntersect Intersects(hgeEntityEx *p, hgeVector offset = hgeVector(0,0), float rot = 0);
00237
00238
00239 hgeTriangle * TestGetTriangle(hgeVector point);
00240
00243 inline bool TestPoint(hgeVector point)
00244 {
00245 if (IsPoint())
00246 return aabb.TestPoint(point.x, point.y);
00247 else
00248 return TestGetTriangle( point ) != NULL;
00249 }
00250
00251
00253
00254
00256 inline hgeSprite *GetSprite() { return sprite; }
00257
00259 inline hgeRect GetAABB() { return aabb; }
00260
00262 inline hgeVector GetCenter() { return center; }
00263
00265 inline void SetAABBSize(hgeVector m_size)
00266 {
00267 aabb.x2 = aabb.x1 + m_size.x;
00268 aabb.y2 = aabb.y1 + m_size.y;
00269 center = hgeVector(aabb.x1 + (m_size.x / 2), aabb.y1 + (m_size.y / 2));
00270 }
00271
00274 inline void SetAABB(hgeVector m_position, hgeVector m_size)
00275 {
00276 aabb.x1 = m_position.x;
00277 aabb.y1 = m_position.y;
00278 SetAABBSize(m_size);
00279 }
00280
00281
00282 void SetTexture(HTEXTURE m_texture, int m_blend = -1);
00283
00295 inline void SetHotSpot(hgeVector m_hotspot) { hotspot = m_hotspot; }
00296
00298 inline hgeVector GetHotSpot() { return hotspot; }
00299
00300
00301 void Shift(hgeVector amount);
00302
00313 inline hgeVector GetPosition() { return hgeVector(aabb.x1, aabb.y1) + hotspot; }
00314
00325 inline void SetPosition(hgeVector pos) { Shift(pos - (hgeVector(aabb.x1, aabb.y1) + hotspot)); }
00326
00327
00329
00330
00331
00332 hgePVertex * AddVertex(hgeVector pos);
00333
00334
00335 void RemoveVertex(hgePVertex * which);
00336
00337
00338 void ClearVertices();
00339
00340
00341 inline int VertexCount() { return (int)vertices.size(); }
00342
00343
00345
00346
00347 hgePolygon(class hgePolygonMap *pmap = NULL) : hgeShape(HGESHAPE_POLYGON)
00348 {
00349 map = pmap;
00350 hge = hgeCreate(HGE_VERSION);
00351 is_entity = false;
00352 aabb.x1 = 0; aabb.y1 = 0;
00353 aabb.x2 = 0; aabb.y2 = 0;
00354 sprite = NULL;
00355 }
00356
00357 ~hgePolygon()
00358 {
00359 ClearVertices();
00360 ClearTris();
00361
00362
00363 for (unsigned i=0; i<borderquads.size(); i++)
00364 delete borderquads[i];
00365
00366 for (unsigned i=0; i<bordertris.size(); i++)
00367 delete bordertris[i];
00368
00369 for (unsigned i=0; i<shadowquads.size(); i++)
00370 delete shadowquads[i];
00371
00372 hge->Release();
00373 };
00374 };
00375
00376
00377
00378 #endif