qafGeom.h

00001 /* 
00002 ** Qaf Framework 1.2
00003 ** June 2006
00004 ** 
00005 ** Pedro Luchini de Moraes, Public Domain - Free Lunch Code
00006 */
00007 
00008 #ifndef QAF_UTIL_GEOM_H
00009 #define QAF_UTIL_GEOM_H
00010 
00011 #include "qafContainer.h"
00012 #include "qafVector2D.h"
00013 #include "../qafDef.h"
00014 
00015 
00016 namespace qaf {
00017 
00021     class Geom {
00022         public:
00023             
00034             static bool segmentIntersection ( float s1x1, float s1y1,
00035                                               float s1x2, float s1y2,
00036                                               float s2x1, float s2y1, 
00037                                               float s2x2, float s2y2,
00038                                               Vector2D * point = NULL );
00039             
00040             
00042 
00049             static bool insidePolygon ( const Vector2D & p, const Vector2D * points, int nPoints);
00050             
00051             static inline bool insidePolygon ( const Vector2D & p, const Container<Vector2D> & points ) {
00052                 return insidePolygon( p, points.getData(), points.getCount() );
00053             }
00055             
00056             
00058 
00062             static void renderPolygon ( const Vector2D * points, int nPoints, float translateX, float translateY, unsigned long color );
00063             
00064             static inline void renderPolygon ( const Container<Vector2D> & points, float translateX, float translateY, unsigned long color ) {
00065                 renderPolygon( points.getData(), points.getCount(), translateX, translateY, color );
00066             }
00068             
00069             
00096             static int segmentCircleIntersection ( float xCenter, float yCenter,
00097                                                    float radius,
00098                                                    float x1, float y1,
00099                                                    float x2, float y2,
00100                                                    Vector2D * pvIntPoint1 = NULL,
00101                                                    Vector2D * pvIntPoint2 = NULL );
00102             
00103             
00109             static void renderCircle ( float xCenter, float yCenter, float radius, unsigned int color );
00110             
00111             
00115             static inline float invSqrt ( float x ) {
00116                 float xhalf = 0.5f*x;
00117                 int i = *(int*)&x; // get bits for floating value
00118                 i = 0x5f3759df - (i>>1); // gives initial guess y0
00119                 x = *(float*)&i; // convert bits back to float
00120                 x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
00121                 
00122                 return x;
00123             }
00124             
00125             
00134             static void clipPolygon ( Container<Vector2D> * poly,
00135                                       const Vector2D & planeP,
00136                                       const Vector2D & planeN );
00137             
00138     };
00139     
00140 }
00141 
00142 
00143 
00144 #endif

Generated on Sun Mar 25 12:32:12 2007 for Qaf Framework by  doxygen 1.5.1-p1