Gel2D - The free/open source game creation suite

gelObject.h
Go to the documentation of this file.
00001 /*
00002 Gel2D Game Engine - Cross-platform 2D gaming middleware
00003 Copyright (C) 2010-2011 Mark D. Procarione
00004 
00005 Gel2D is free software: you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation, either version 3 of the License, or
00008 (at your option) any later version.
00009 
00010 Gel2D is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __GELOBJECT_H__
00017 #define __GELOBJECT_H__
00018 
00019 #include "gelMath.h"
00020 #include "gelVector.h"
00021 #include "gelTexture.h"
00022 #include "gelWindow.h"
00023 #include "gelViewport.h"
00024 #include "gelRenderSystem.h"
00025 #include "gelInput.h"
00026 #include "gelCollision.h"
00027 #include "gelEvent.h"
00028 
00029 namespace gel
00030 {
00032     class GelObject : public GelEventReceiver
00033     {
00034         public:
00036             GelObject();
00037 
00039 
00043             GelObject( Gel2dVec obj_pos, float obj_rot, Gel2dVec obj_scl );
00044 
00046 
00047             Gel2dVec getPos() const { return pos; }
00048 
00050 
00051             void setPos( const Gel2dVec &vecPos ) { pos = vecPos; }
00052 
00054 
00056             float getRot() const { return rot; }
00057 
00059 
00063             void setRot( float deg ) { rot = GelMath::clampDeg(deg); }
00064 
00066 
00067             Gel2dVec getScale() const { return scl; }
00068 
00070 
00072             void setScale( const Gel2dVec &vecScale ) { scl = vecScale; }
00073 
00075 
00076             Gel2dVec getHotSpot() const { return hotSpot; }
00077 
00079 
00080             void setHotSpot( const Gel2dVec &vecHotSpot ) { hotSpot = vecHotSpot; }
00081 
00083 
00084             void move( const Gel2dVec &trans ) { pos += trans; }
00085 
00087 
00088             void rotate( float deg ) { rot += GelMath::clampDeg(deg); }
00089 
00091 
00092             void scale( const Gel2dVec &scale ) { scl += scale; }
00093 
00095 
00100             void moveTo( const Gel2dVec &vec, int frames );
00101 
00103 
00108             void scaleTo( const Gel2dVec &vec, int frames );
00109 
00111 
00112             float getDistanceTo( const GelObject &obj ) const;
00113 
00115 
00116             float getDistanceTo( const Gel2dVec &vec ) const;
00117 
00118             void setParent( GelObject *par, int delay  );
00119             GelObject getParent() const { if(parent != NULL) return *parent; }
00120 
00121             void removeParent();
00122             bool hasParent() const;
00123 
00125 
00126             bool isMouseOver();
00127 
00129 
00136             bool isMouseOver( int width, int height, int mousex, int mousey );
00137 
00138             Gel2dVec getLocalCoords( int screenx, int screeny ) const;
00139             Gel2dVec getLocalCoords( int width, int height, int screenx, int screeny ) const;
00140 
00141             CollisionBounds getCollisionBounds() const { return collisionBounds; }
00142             void setCollisionBounds( CollisionBounds type ) { collisionBounds = type; }
00143 
00145             virtual GelCircle getCircle() const;
00146 
00148             virtual GelAABB getAABB() const;
00149 
00150             virtual void render();
00151 
00152         protected:
00153                         void fix();
00154                         int _testMouseIntersect();
00155                         virtual int _pointIntersect( float locx, float locy );
00156 
00157         protected:
00159             Gel2dVec pos;
00161             float    rot;
00163             Gel2dVec scl;
00165             Gel2dVec hotSpot;
00167             GelObject *parent;
00168 
00169                 int isCursorOver;
00170             int bMouseTest;
00171 
00172                 int view[4];      // Already unnecessary. Use GelRenderSystem::getViewport().getAbsRect()
00173                         double model[16];
00174                         double proj[16];
00175 
00176                 int customParam; // Probably won't need this after removing other crap
00177             int wndWidth, wndHeight; // These don't belong here
00178             int mouseX, mouseY; // Neither do these
00179 
00180                 CollisionBounds collisionBounds;
00181                 float radius;
00182 
00183             Gel2dVec par_pos;
00184             Gel2dVec chd_pos;
00185             float    par_rot;
00186             float    chd_rot;
00187             Gel2dVec par_scl;
00188             int      par_delay;
00189 
00190     };
00191 
00193     class GelTextureObject
00194     {
00195                 public:
00197             GelTextureObject();
00198 
00200 
00201             GelTexture *getTexture() const;
00202 
00204 
00205                         bool hasTexture() const;
00206 
00208 
00209                         int getBlendMode() const { return blendMode; }
00210 
00212 
00213             void setBlendMode( int mode ) { blendMode = mode; }
00214 
00215         protected:
00217             GelTexture *texture;
00219             int blendMode;
00220         };
00221 }
00222 
00223 #endif // __GELOBJECT_H__