Gel2D - The free/open source game creation suite

gelCollision.h
Go to the documentation of this file.
00001 /*
00002 Gel2D Game Engine - Cross-platform 2D gaming middleware
00003 Copyright (C) 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 __GELCOLLISION_H__
00017 #define __GELCOLLISION_H__
00018 
00019 #include "gelVector.h"
00020 
00021 namespace gel
00022 {
00025 
00026         class GelCircle
00027         {
00028                 public:
00030 
00031                         GelCircle() : pos(0.0f), radius(0.0f) {}
00032 
00034 
00036                         GelCircle( Gel2dVec _pos, float _radius ) : pos(_pos), radius(_radius) {}
00037 
00038                 public:
00039                         Gel2dVec pos;
00040                         float radius;
00041         };
00042 
00044         class GelAABB
00045         {
00046                 public:
00048 
00049                         GelAABB() { min = 0.0f; max = 1.0f; }
00050 
00052 
00054                         GelAABB( Gel2dVec minpos, Gel2dVec maxpos ) { min = minpos; max = maxpos; }
00055 
00056                 public:
00057                         Gel2dVec min;
00058                         Gel2dVec max;
00059         };
00060 
00062         class GelOBB
00063         {
00064                 public:
00066 
00067                         GelOBB() : pos(0.0f), extent(1.0f) {}
00068 
00070 
00072                         GelOBB( Gel2dVec _pos, Gel2dVec _extent ) : pos(_pos), extent(_extent) {}
00073 
00074                 public:
00075                         Gel2dVec pos;
00076                         Gel2dVec extent;
00077         };
00078 
00079         class GelRay
00080         {
00081                 public:
00083 
00084                         GelRay() : start(0.0f), end(1.0f) {}
00085 
00087 
00089                         GelRay( Gel2dVec _start, Gel2dVec _end ) : start(_start), end(_end) {}
00090 
00091                 public:
00092                         Gel2dVec start;
00093                         Gel2dVec end;
00094         };
00095 
00097         class GelCdtPoint
00098         {
00099                 public:
00100                         GelCdtPoint() : pos(0.0f) {}
00101 
00102                         GelCdtPoint( float x, float y ) : pos(x, y) {}
00103 
00104                         GelCdtPoint( Gel2dVec coords ) : pos(coords) {}
00105 
00106                 public:
00107                         Gel2dVec pos;
00108         };
00109 
00111         class GelCollision
00112         {
00113                 public:
00115 
00118                         static bool collides( const GelCircle &cir1, const GelCircle &cir2 );
00119 
00121 
00124                         static bool collides( const GelCircle &cir, const GelAABB &box );
00125 
00126                         static bool collides( const GelCircle &cir, const GelOBB &box );
00127 
00128                         static bool collides( const GelCircle &cir, const GelRay &ray );
00129 
00131 
00134                         static bool collides( const GelCircle &cir, const GelCdtPoint &point );
00135 
00137 
00140                         static bool collides( const GelAABB &box1, const GelAABB &box2 );
00141 
00143 
00145                         static bool collides( const GelAABB &box, const GelCircle &cir );
00146 
00147                         static bool collides( const GelAABB &box1, const GelOBB &box2 );
00148 
00149                         static bool collides( const GelAABB &box, const GelRay &ray );
00150 
00152 
00155                         static bool collides( const GelAABB &box, const GelCdtPoint &point );
00156 
00157 
00158                         static bool collides( const GelOBB &box1, const GelOBB &box2 );
00159 
00160                         static bool collides( const GelOBB &box, const GelCircle &cir );
00161 
00162                         static bool collides( const GelOBB &box, const GelRay &ray );
00163 
00164                         static bool collides( const GelOBB &box, const GelCdtPoint &point );
00165 
00166 
00167                         static bool collides( const GelRay &ray1, const GelRay &ray2 );
00168 
00169                         static bool collides( const GelRay &ray, const GelCircle &cir );
00170 
00171                         static bool collides( const GelRay &ray, const GelOBB &box );
00172 
00173                         static bool collides( const GelRay &ray, const GelCdtPoint &point );
00174 
00175 
00177 
00180                         static bool collides( const GelCdtPoint &point1, const GelCdtPoint &point2 );
00181 
00183 
00185                         static bool collides( const GelCdtPoint &point, const GelCircle &cir );
00186 
00188 
00190                         static bool collides( const GelCdtPoint &point, const GelAABB &box );
00191 
00192                         static bool collides( const GelCdtPoint &point, const GelOBB &box );
00193 
00194                         static bool collides( const GelCdtPoint &point, const GelRay &ray );
00195         };
00197 }
00198 
00199 #endif // __GELCOLLISION_H__