diff --git a/include/eepp/gaming/clight.hpp b/include/eepp/gaming/clight.hpp index 7229932c2..a9b5c34db 100644 --- a/include/eepp/gaming/clight.hpp +++ b/include/eepp/gaming/clight.hpp @@ -35,7 +35,7 @@ class EE_API cLight { void UpdatePos( const eeVector2f& newPos ); - const eeAABB& GetAABB() const; + eeAABB GetAABB() const; const eeFloat& Radius() const; diff --git a/include/eepp/math/line2.hpp b/include/eepp/math/line2.hpp index 0fb756ed1..4c7b2d6b8 100644 --- a/include/eepp/math/line2.hpp +++ b/include/eepp/math/line2.hpp @@ -9,10 +9,21 @@ template class Line2 { public: Line2(); + Line2( const Vector2& v1, const Vector2& v2 ); + Vector2 V[2]; + Vector2& p1() { return V[0]; } + + Vector2& p2() { return V[1]; } + Vector2 GetNormal(); + + /** @return The angle of the line against the x axis-aligned line */ + T GetAngle(); + + bool Intersect( Line2& line, T* X = NULL, T* Y = NULL ); }; template @@ -34,6 +45,53 @@ Vector2 Line2::GetNormal() { return tV; } +template +T Line2::GetAngle() { + return eeatan2( (V[1].y - V[0].y), (V[1].x - V[0].x) ) * EE_180_PI; +} + + +/** Determine if two lines are intersecting +* @param X Optional Pointer returning the X point position of intersection +* @param Y Optional Pointer returning the Y point position of intersection +* @return True if the lines are intersecting +*/ +template +bool Line2::Intersect( Line2& line, T* X, T* Y ) { + T distAB, theCos, theSin, newX, ABpos; + + if ( ( V[0].x==V[1].x && V[0].y==V[1].y ) || ( line.V[0].x==line.V[1].x && line.V[0].y==line.V[1].y ) ) return false; + + if ( ( V[0].x==line.V[0].x && V[0].y==line.V[0].y ) || ( V[1].x==line.V[0].x && V[1].y==line.V[0].y ) + || ( V[0].x==line.V[1].x && V[0].y==line.V[1].y ) || ( V[1].x==line.V[1].x && V[1].y==line.V[1].y ) ) { + return false; } + + V[1].x-=V[0].x; V[1].y-=V[0].y; + line.V[0].x-=V[0].x; line.V[0].y-=V[0].y; + line.V[1].x-=V[0].x; line.V[1].y-=V[0].y; + + distAB=eesqrt(V[1].x*V[1].x+V[1].y*V[1].y); + + theCos=V[1].x/distAB; + theSin=V[1].y/distAB; + newX=line.V[0].x*theCos+line.V[0].y*theSin; + line.V[0].y =line.V[0].y*theCos-line.V[0].x*theSin; line.V[0].x=newX; + newX=line.V[1].x*theCos+line.V[1].y*theSin; + line.V[1].y =line.V[1].y*theCos-line.V[1].x*theSin; line.V[1].x=newX; + + if ( ( line.V[0].y<0. && line.V[1].y<0. ) || ( line.V[0].y>=0. && line.V[1].y>=0. ) ) return false; + + ABpos=line.V[1].x+(line.V[0].x-line.V[1].x)*line.V[1].y/(line.V[1].y-line.V[0].y); + + if (ABpos<0. || ABpos>distAB) return false; + + if (X != NULL && Y != NULL) { + *X=V[0].x + ABpos * theCos; + *Y=V[0].y + ABpos * theSin; + } + return true; +} + typedef Line2 eeLine2f; }} diff --git a/include/eepp/math/math.hpp b/include/eepp/math/math.hpp index 49973a427..f39d000b1 100755 --- a/include/eepp/math/math.hpp +++ b/include/eepp/math/math.hpp @@ -2,17 +2,16 @@ #define EE_MATH_HPP #include -#include -#include -#include -#include -#include -#include +#include +#include namespace EE { namespace Math { /** Set a Random Seed to the Randomizer */ -Uint32 EE_API SetRandomSeed(); +inline Uint32 SetRandomSeed( Uint32 seed ) { + srand(seed); + return seed; +} /** Generate a floating point random number * @param fMin The minimun value @@ -72,424 +71,15 @@ T IsPow2( T v ) { } template -T LineAngle( const T& X1, const T& Y1, const T& X2, const T& Y2 ) { - return eeatan2( (eeFloat)(Y2 - Y1), (eeFloat)(X2 - X1) ) * EE_180_PI; -} - -#ifndef EE_64BIT -inline eeDouble Round( eeDouble r ) { - return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5); -} -#endif - -inline eeFloat Round( eeFloat r ) { +inline T Round( T r ) { return (r > 0.0f) ? floor(r + 0.5f) : ceil(r - 0.5f); } -#ifndef EE_64BIT -inline eeDouble RoundUp( eeDouble r ) { - return (r > 0.0) ? ceil(r) : ceil(r - 0.5); -} -#endif - -inline eeFloat RoundUp( eeFloat r ) { +template +inline T RoundUp( T r ) { return (r > 0.0f) ? ceil(r) : ceil(r - 0.5f); } -inline eeFloat RotatePointFromX ( const eeFloat& x, const eeFloat& y, const eeFloat& Angle ) { - return x * cosAng(Angle) - y * sinAng(Angle); -} - -inline eeFloat RotatePointFromY ( const eeFloat& x, const eeFloat& y, const eeFloat& Angle ) { - return y * cosAng(Angle) + x * sinAng(Angle); -} - -inline eeFloat RotatePointFromX ( const eeVector2f& p, const eeFloat& Angle ) { - return RotatePointFromX( p.x, p.y, Angle ); -} - -inline eeFloat RotatePointFromY ( const eeVector2f& p, const eeFloat& Angle ) { - return RotatePointFromY( p.x, p.y, Angle ); -} - -inline eeVector2f RotateVector( const eeVector2f& p, const eeFloat& Angle ) { - return eeVector2f( RotatePointFromX( p, Angle ), RotatePointFromY( p, Angle ) ); -} - -inline void RotateVector( eeVector2f* p, const eeFloat& Angle ) { - eeFloat x = p->x; - x = p->x * cosAng(Angle) - p->y * sinAng(Angle); - p->y = p->y * cosAng(Angle) + p->x * sinAng(Angle); - p->x = x; -} - -inline void RotateVectorCentered( eeVector2f* p, const eeFloat& Angle, const eeVector2f& RotationCenter ) { - *p -= RotationCenter; - RotateVector( p, Angle ); - *p += RotationCenter; -} - -inline eeVector2f RotateVectorCentered( const eeVector2f& p, const eeFloat& Angle, const eeVector2f& RotationCenter ) { - return RotationCenter + RotateVector( (p - RotationCenter), Angle ); -} - -inline eeQuad2f RotateQuadCentered( const eeQuad2f& p, const eeFloat& Angle, const eeVector2f& RotationCenter ) { - return eeQuad2f( RotateVectorCentered( p.V[0], Angle, RotationCenter ), RotateVectorCentered( p.V[1], Angle, RotationCenter ), RotateVectorCentered( p.V[2], Angle, RotationCenter ), RotateVectorCentered( p.V[3], Angle, RotationCenter ) ); -} - -template -T Distance( T x1, T y1, T x2, T y2 ) { - return eesqrt( (eeFloat)( (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) ) ); -} - -inline eeVector2f GetQuadCenter( const eeQuad2f& Q ) { - eeVector2f QCenter; - eeFloat MinX = Q.V[0].x, MaxX = Q.V[0].x, MinY = Q.V[0].y, MaxY = Q.V[0].y; - - for (Uint8 i = 1; i < 4; i++ ) { - if ( MinX > Q.V[i].x ) MinX = Q.V[i].x; - if ( MaxX < Q.V[i].x ) MaxX = Q.V[i].x; - if ( MinY > Q.V[i].y ) MinY = Q.V[i].y; - if ( MaxY < Q.V[i].y ) MaxY = Q.V[i].y; - } - - QCenter.x = MinX + ( MaxX - MinX ) * 0.5f; - QCenter.y = MinY + ( MaxY - MinY ) * 0.5f; - - return QCenter; -} - -inline eeQuad2f ScaleQuadCentered( const eeQuad2f& Quad, const eeFloat& Scale, const eeVector2f& RotationCenter ) { - eeQuad2f mQ = Quad; - eeVector2f QCenter = RotationCenter; - - for (Uint8 i = 0; i < 4; i++ ) { - if ( mQ.V[i].x < QCenter.x ) - mQ.V[i].x = QCenter.x - eeabs(QCenter.x - mQ.V[i].x) * Scale; - else - mQ.V[i].x = QCenter.x + eeabs(QCenter.x - mQ.V[i].x) * Scale; - - if ( mQ.V[i].y < QCenter.y ) - mQ.V[i].y = QCenter.y - eeabs(QCenter.y - mQ.V[i].y) * Scale; - else - mQ.V[i].y = QCenter.y + eeabs(QCenter.y - mQ.V[i].y) * Scale; - } - - return mQ; -} - -inline eeFloat LineAngle( const eeVector2f& p1, const eeVector2f& p2 ) { - return LineAngle( p1.x, p1.y, p2.x, p2.y ); -} - -inline eeFloat Distance( const eeVector2f& p1, const eeVector2f& p2 ) { - return Distance( p1.x, p1.y, p2.x, p2.y ); -} - -template -bool Intersect( const tRECT& a, const tRECT& b ) { - return !(a.Left > b.Right || a.Right < b.Left || a.Top > b.Bottom || a.Bottom < b.Top); -} - -/** @return If a contains b */ -template -bool Contains( const tRECT& a, const tRECT& b ) { - return ( a.Left <= b.Left && a.Right >= b.Right && a.Top <= b.Top && a.Bottom >= b.Bottom ); -} - -template -bool Contains( const tRECT& a, const Vector2& b) { - return ( a.Left <= b.x && a.Right >= b.x && a.Top <= b.y && a.Bottom >= b.y ); -} - -template -bool IntersectCircles( const tRECT& a, const tRECT& b ) { - eeFloat ra = (eeFloat)(a.Right - a.Left) * 0.5f; - eeFloat rb = (eeFloat)(b.Right - b.Left) * 0.5f; - eeFloat dist = ra + rb; - eeFloat dx = (b.Left + rb) - (a.Left + ra); - eeFloat dy = (b.Top + rb) - (a.Top + ra); - eeFloat res = (dx * dx) + (dy * dy); - - if ( res <= (dist * dist)) - return true; - return false; -} - -/** Determine if a RECT and a Circle are intersecting -* @param obj Object RECT -* @param cx Circle x axis position -* @param cy Circle y axis position -* @param radius Circle Radius -* @return True if are intersecting -*/ -template -bool IntersectRectCircle(const tRECT& obj, const eeFloat& cx, const eeFloat& cy, const eeFloat& radius) { - eeFloat tx = cx; - eeFloat ty = cy; - - if (tx < obj.Left) tx = (eeFloat)obj.Left; - if (tx > obj.Right) tx = (eeFloat)obj.Right; - if (ty < obj.Top) ty = (eeFloat)obj.Top; - if (ty > obj.Bottom) ty = (eeFloat)obj.Bottom; - - if (Distance( cx, cy, tx, ty ) < radius) - return true; - - return false; -} - -/** Determine if two lines are intersecting -* @param Ax First Line Fist Point X axis -* @param Ay First Line Fist Point Y axis -* @param Bx Fist Line Second Point X axis -* @param By Fist Line Second Point Y axis -* @param Cx Second Line Fist Point X axis -* @param Cy Second Line Fist Point Y axis -* @param Dx Second Line Second Point X axis -* @param Dy Second Line Second Point Y axis -* @param X Optional Pointer returning the X point position of intersection -* @param Y Optional Pointer returning the Y point position of intersection -* @return True if the lines are intersecting -*/ -template -bool IntersectLines( T Ax, T Ay, T Bx, T By, T Cx, T Cy, T Dx, T Dy, T* X, T* Y ) { - T distAB, theCos, theSin, newX, ABpos; - - if ( ( Ax==Bx && Ay==By ) || ( Cx==Dx && Cy==Dy ) ) return false; - - if ( ( Ax==Cx && Ay==Cy ) || ( Bx==Cx && By==Cy ) - || ( Ax==Dx && Ay==Dy ) || ( Bx==Dx && By==Dy ) ) { - return false; } - - Bx-=Ax; By-=Ay; - Cx-=Ax; Cy-=Ay; - Dx-=Ax; Dy-=Ay; - - distAB=eesqrt(Bx*Bx+By*By); - - theCos=Bx/distAB; - theSin=By/distAB; - newX=Cx*theCos+Cy*theSin; - Cy =Cy*theCos-Cx*theSin; Cx=newX; - newX=Dx*theCos+Dy*theSin; - Dy =Dy*theCos-Dx*theSin; Dx=newX; - - if ( ( Cy<0. && Dy<0. ) || ( Cy>=0. && Dy>=0. ) ) return false; - - ABpos=Dx+(Cx-Dx)*Dy/(Dy-Cy); - - if (ABpos<0. || ABpos>distAB) return false; - - if (X != NULL && Y != NULL) { - *X=Ax + ABpos * theCos; - *Y=Ay + ABpos * theSin; - } - return true; -} - -inline bool IntersectLines( const eeFloat& Ax, const eeFloat& Ay, const eeFloat& Bx, const eeFloat& By, const eeFloat& Cx, const eeFloat& Cy, const eeFloat& Dx, const eeFloat& Dy, eeFloat * X = NULL, eeFloat * Y = NULL ) { - return IntersectLines (Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, X, Y); -} - -inline bool IntersectLines( const eeVector2f& l1p1, const eeVector2f& l1p2, const eeVector2f& l2p1, const eeVector2f& l2p2, eeFloat * X = NULL, eeFloat * Y = NULL ) { - return IntersectLines (l1p1.x, l1p1.y, l1p2.x, l1p2.y, l2p1.x, l2p1.y, l2p2.x, l2p2.y, X, Y); -} - -/** @return The Dot Product of two Vectors */ -template -T VectorDotProduct( const Vector2& A, const Vector2& B) { - return A.x * B.x + A.y * B.y; -} - -template -Quad2 AABBtoQuad2( const tRECT& R ) { - return Quad2( Vector2( R.Left, R.Top ), Vector2( R.Left, R.Bottom ), Vector2( R.Right, R.Bottom ), Vector2( R.Right, R.Top ) ); -} - -template -tRECT Quad2toAABB( const Quad2& Q, const T& OffsetX = 0, const T& OffsetY = 0 ) { - tRECT TmpR; - - eeFloat MinX = Q.V[0].x, MaxX = Q.V[0].x, MinY = Q.V[0].y, MaxY = Q.V[0].y; - - for (Uint8 i = 1; i < 4; i++ ) { - if ( MinX > Q.V[i].x ) MinX = Q.V[i].x; - if ( MaxX < Q.V[i].x ) MaxX = Q.V[i].x; - if ( MinY > Q.V[i].y ) MinY = Q.V[i].y; - if ( MaxY < Q.V[i].y ) MaxY = Q.V[i].y; - } - - TmpR.Left = MinX + OffsetX; - TmpR.Right = MaxX + OffsetX; - TmpR.Top = MinY + OffsetY; - TmpR.Bottom = MaxY + OffsetY; - - return TmpR; -} - -/** Polygon Polygon Collision */ -template -bool IntersectPolygon2( const Polygon2& p0, const Polygon2& p1 ) { - T min0, max0, min1, max1, sOffset, t; - Vector2 vAxis, vOffset; - eeUint i = 0, j = 0, n; - - vOffset = Vector2( p0.X() - p1.X(), p0.Y() - p1.Y() ); - - for (i = 0; i < p0.Size(); i++) { - n = i + 1; - if ( n >= p0.Size() ) n = 0; - - vAxis = Line2( p0[i], p0[n] ).GetNormal(); - - min0 = VectorDotProduct( vAxis, p0[0] ); - max0 = min0; - for (j = 1; j < p0.Size(); j++) { - t = VectorDotProduct( vAxis, p0[j] ); - if (t < min0) min0 = t; - if (t > max0) max0 = t; - } - - min1 = VectorDotProduct( vAxis, p1[0] ); - max1 = min1; - for (j = 1; j < p1.Size(); j++) { - t = VectorDotProduct( vAxis, p1[j] ); - if (t < min1) min1 = t; - if (t > max1) max1 = t; - } - - sOffset = VectorDotProduct( vAxis, vOffset ); - min0 += sOffset; - max0 += sOffset; - - if ( ( (min0 - max1) > 0) || ( (min1 - max0) > 0) ) { - return false; // Found a seperating axis, they can't possibly be touching - } - } - - for (i = 0; i < p1.Size(); i++) { - n = i + 1; - if ( n >= p1.Size() ) n = 0; - - vAxis = Line2( p1[i], p1[n] ).GetNormal(); - - min0 = VectorDotProduct( vAxis, p0[0] ); - max0 = min0; - for (j = 1; j < p0.Size(); j++) { - t = VectorDotProduct( vAxis, p0[j] ); - if (t < min0) min0 = t; - if (t > max0) max0 = t; - } - - min1 = VectorDotProduct( vAxis, p1[0] ); - max1 = min1; - for (j = 1; j < p1.Size(); j++) { - t = VectorDotProduct( vAxis, p1[j] ); - if (t < min1) min1 = t; - if (t > max1) max1 = t; - } - - sOffset = VectorDotProduct( vAxis, vOffset ); - min0 += sOffset; - max0 += sOffset; - - if ( ( (min0 - max1) > 0) || ( (min1 - max0) > 0) ) { - return false; // Found a seperating axis, they can't possibly be touching - } - } - - return true; -} - -/** Quad Quad Collision */ -template -bool IntersectQuad2( const Quad2& q0, const Quad2& q1, const Vector2& q0Pos = Vector2(0,0), const Vector2& q1Pos = Vector2(0,0) ) { - Polygon2 Tmp1 = Polygon2( q0 ); - Polygon2 Tmp2 = Polygon2( q1 ); - Tmp1.Position( q0Pos ); - Tmp1.Position( q1Pos ); - - return IntersectPolygon2( Tmp1, Tmp2 ); -} - -/** -Copyright (c) 1970-2003, Wm. Randolph Franklin - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. -Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution. -The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without specific prior written permission. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -template -bool PointInsidePolygon2( const Polygon2& poly, const Vector2& point ) { - int i, j, c = 0; - - Int32 nvert = (Int32)poly.Size(); - - for ( i = 0, j = nvert - 1; i < nvert; j = i++ ) { - if ( ( ( poly[i].y > point.y ) != ( poly[j].y > point.y ) ) && ( point.x < ( poly[j].x - poly[i].x ) * ( point.y - poly[i].y ) / ( poly[j].y - poly[i].y ) + poly[i].x ) ) - c = !c; - } - - return 0 != c; -} - -template -Polygon2 CreateRoundedPolygon( const T& x, const T& y, const T& width, const T& height, const eeUint& Radius = 8 ) { - T PI05 = EE_PI * 0.5f; - T PI15 = EE_PI * 1.5f; - T PI20 = EE_PI2; - T sx, sy; - T t; - - Polygon2 Poly; - - Poly.PushBack( Vector2( x, y + height - Radius) ); - Poly.PushBack( Vector2( x, y + Radius ) ); - - for( t = EE_PI; t < PI15; t += 0.1f ) { - sx = x + Radius + (eeFloat)cosf(t) * Radius; - sy = y + Radius + (eeFloat)sinf(t) * Radius; - - Poly.PushBack( Vector2 (sx, sy) ); - } - - Poly.PushBack( Vector2( x + Radius, y ) ); - Poly.PushBack( Vector2( x + width - Radius, y ) ); - - for( t = PI15; t < PI20; t += 0.1f ) { - sx = x + width - Radius + (eeFloat)cosf(t) * Radius; - sy = y + Radius + (eeFloat)sinf(t) * Radius; - - Poly.PushBack( Vector2 (sx, sy) ); - } - - Poly.PushBack( Vector2 ( x + width, y + Radius ) ); - Poly.PushBack( Vector2 ( x + width, y + height - Radius ) ); - - for( t = 0; t < PI05; t += 0.1f ){ - sx = x + width - Radius + (eeFloat)cosf(t) * Radius; - sy = y + height -Radius + (eeFloat)sinf(t) * Radius; - - Poly.PushBack( Vector2 (sx, sy) ); - } - - Poly.PushBack( Vector2 ( x + width - Radius, y + height ) ); - Poly.PushBack( Vector2 ( x + Radius, y + height ) ); - - for( t = PI05; t < EE_PI; t += 0.1f ) { - sx = x + Radius + (eeFloat)cosf(t) * Radius; - sy = y + height - Radius + (eeFloat)sinf(t) * Radius; - - Poly.PushBack( Vector2 (sx, sy) ); - } - - return Poly; -} - }} #endif diff --git a/include/eepp/math/polygon2.hpp b/include/eepp/math/polygon2.hpp index 08dfed0e5..843be74e5 100755 --- a/include/eepp/math/polygon2.hpp +++ b/include/eepp/math/polygon2.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -12,13 +13,19 @@ template class Polygon2 { public: Polygon2(); + ~Polygon2(); + Polygon2( const Triangle2& fromTrig ); + Polygon2( const Quad2& fromQuad ); + Polygon2( const tRECT& fromRect ); + Polygon2( const std::vector< Vector2 >& theVecs ); Uint32 PushBack( const Vector2& V ); + void PopBack(); void Reset(); @@ -27,17 +34,29 @@ class Polygon2 { std::size_t Size() const; - Vector2 Position() { return Vector2(cOffsetX, cOffsetY); }; - T X() const { return cOffsetX; }; - T Y() const { return cOffsetY; }; + Vector2 Position() { return Vector2(cOffsetX, cOffsetY); } + + T X() const { return cOffsetX; } + + T Y() const { return cOffsetY; } void Position( const Vector2& V ) { cOffsetX = V.x; cOffsetY = V.y; } + T X( const T& x ) { cOffsetX = x; } + T Y( const T& y ) { cOffsetY = y; } + bool Intersect( const Polygon2& p1 ); + void Rotate( const T& Angle, const Vector2& Center ); void Scale( const T& scale, const Vector2& Center ); + + bool PointInside( const Vector2& point ); + + static Polygon2 CreateRoundedPolygon( const T& x, const T& y, const T& width, const T& height, const eeUint& Radius = 8 ); + + static bool IntersectQuad2( const Quad2& q0, const Quad2& q1, const Vector2& q0Pos = Vector2(0,0), const Vector2& q1Pos = Vector2(0,0) ); private: std::vector< Vector2 > Vector; T cOffsetX, cOffsetY; @@ -134,6 +153,172 @@ void Polygon2::Scale( const T& scale, const Vector2& Center ) { } } +template +Polygon2 Polygon2::CreateRoundedPolygon( const T& x, const T& y, const T& width, const T& height, const eeUint& Radius ) { + T PI05 = EE_PI * 0.5f; + T PI15 = EE_PI * 1.5f; + T PI20 = EE_PI2; + T sx, sy; + T t; + + Polygon2 Poly; + + Poly.PushBack( Vector2( x, y + height - Radius) ); + Poly.PushBack( Vector2( x, y + Radius ) ); + + for( t = EE_PI; t < PI15; t += 0.1f ) { + sx = x + Radius + (eeFloat)cosf(t) * Radius; + sy = y + Radius + (eeFloat)sinf(t) * Radius; + + Poly.PushBack( Vector2 (sx, sy) ); + } + + Poly.PushBack( Vector2( x + Radius, y ) ); + Poly.PushBack( Vector2( x + width - Radius, y ) ); + + for( t = PI15; t < PI20; t += 0.1f ) { + sx = x + width - Radius + (eeFloat)cosf(t) * Radius; + sy = y + Radius + (eeFloat)sinf(t) * Radius; + + Poly.PushBack( Vector2 (sx, sy) ); + } + + Poly.PushBack( Vector2 ( x + width, y + Radius ) ); + Poly.PushBack( Vector2 ( x + width, y + height - Radius ) ); + + for( t = 0; t < PI05; t += 0.1f ){ + sx = x + width - Radius + (eeFloat)cosf(t) * Radius; + sy = y + height -Radius + (eeFloat)sinf(t) * Radius; + + Poly.PushBack( Vector2 (sx, sy) ); + } + + Poly.PushBack( Vector2 ( x + width - Radius, y + height ) ); + Poly.PushBack( Vector2 ( x + Radius, y + height ) ); + + for( t = PI05; t < EE_PI; t += 0.1f ) { + sx = x + Radius + (eeFloat)cosf(t) * Radius; + sy = y + height - Radius + (eeFloat)sinf(t) * Radius; + + Poly.PushBack( Vector2 (sx, sy) ); + } + + return Poly; +} + + +/** +Copyright (c) 1970-2003, Wm. Randolph Franklin + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. +Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution. +The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without specific prior written permission. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +template +bool Polygon2::PointInside( const Vector2& point ) { + int i, j, c = 0; + int nvert = (int)Size(); + + for ( i = 0, j = nvert - 1; i < nvert; j = i++ ) { + if ( ( ( Vector[i].y > point.y ) != ( Vector[j].y > point.y ) ) && ( point.x < ( Vector[j].x - Vector[i].x ) * ( point.y - Vector[i].y ) / ( Vector[j].y - Vector[i].y ) + Vector[i].x ) ) { + c = !c; + } + } + + return 0 != c; +} + +/** Polygon Polygon Collision ( SAT ) */ +template +bool Polygon2::Intersect( const Polygon2& p1 ) { + T min0, max0, min1, max1, sOffset, t; + Vector2 vAxis, vOffset; + eeUint i = 0, j = 0, n, size = Size(); + + vOffset = Vector2( X() - p1.X(), Y() - p1.Y() ); + + for (i = 0; i < size; i++) { + n = i + 1; + if ( n >= Size() ) n = 0; + + vAxis = Line2( Vector[i], Vector[n] ).GetNormal(); + + min0 = vAxis.Dot( Vector[0] ); + max0 = min0; + for (j = 1; j < Size(); j++) { + t = vAxis.Dot( Vector[j] ); + if (t < min0) min0 = t; + if (t > max0) max0 = t; + } + + min1 = vAxis.Dot( p1[0] ); + max1 = min1; + for (j = 1; j < p1.Size(); j++) { + t = vAxis.Dot( p1[j] ); + if (t < min1) min1 = t; + if (t > max1) max1 = t; + } + + sOffset = vAxis.Dot( vOffset ); + min0 += sOffset; + max0 += sOffset; + + if ( ( (min0 - max1) > 0) || ( (min1 - max0) > 0) ) { + return false; // Found a seperating axis, they can't possibly be touching + } + } + + for (i = 0; i < p1.Size(); i++) { + n = i + 1; + if ( n >= p1.Size() ) n = 0; + + vAxis = Line2( p1[i], p1[n] ).GetNormal(); + + min0 = vAxis.Dot( Vector[0] ); + max0 = min0; + for (j = 1; j < Size(); j++) { + t = vAxis.Dot( Vector[j] ); + if (t < min0) min0 = t; + if (t > max0) max0 = t; + } + + min1 = vAxis.Dot( p1[0] ); + max1 = min1; + for (j = 1; j < p1.Size(); j++) { + t = vAxis.Dot( p1[j] ); + if (t < min1) min1 = t; + if (t > max1) max1 = t; + } + + sOffset = vAxis.Dot( vOffset ); + min0 += sOffset; + max0 += sOffset; + + if ( ( (min0 - max1) > 0) || ( (min1 - max0) > 0) ) { + return false; // Found a seperating axis, they can't possibly be touching + } + } + + return true; +} + + +/** Quad Quad Collision */ +template +bool Polygon2::IntersectQuad2( const Quad2& q0, const Quad2& q1, const Vector2& q0Pos, const Vector2& q1Pos ) { + Polygon2 Tmp1 = Polygon2( q0 ); + Polygon2 Tmp2 = Polygon2( q1 ); + + Tmp1.Position( q0Pos ); + Tmp1.Position( q1Pos ); + + return Tmp1.Intersect( Tmp2 ); +} + + typedef Polygon2 eePolygon2f; }} diff --git a/include/eepp/math/quad2.hpp b/include/eepp/math/quad2.hpp index 6314d292b..5c8f5b4da 100644 --- a/include/eepp/math/quad2.hpp +++ b/include/eepp/math/quad2.hpp @@ -2,6 +2,7 @@ #define EE_MATHQUAD2_HPP #include +#include namespace EE { namespace Math { @@ -9,11 +10,13 @@ template class Quad2 { public: Quad2(); + Quad2( const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4 ); const Vector2& operator[] ( const Uint32& Pos ) const; Vector2 V[4]; + /** Vector2 V[0]; //! Left - Top Vector Vector2 V[1]; //! Left - Bottom Vector @@ -22,9 +25,16 @@ class Quad2 { */ Vector2 GetCenter(); + static Quad2 FromAABB( const tRECT& R ); + + tRECT ToAABB( const T& OffsetX = 0, const T& OffsetY = 0 ); + void Rotate( const T& Angle, const Vector2& Center ); + void Rotate( const T& Angle ); + void Scale( const T& scale ); + void Scale( const T& scale, const Vector2& Center ); }; @@ -70,15 +80,43 @@ void Quad2::Scale( const T& scale ) { template Vector2 Quad2::GetCenter() { eeFloat MinX = V[0].x, MaxX = V[0].x, MinY = V[0].y, MaxY = V[0].y; + for (Uint8 i = 1; i < 4; i++ ) { if ( MinX > V[i].x ) MinX = V[i].x; if ( MaxX < V[i].x ) MaxX = V[i].x; if ( MinY > V[i].y ) MinY = V[i].y; if ( MaxY < V[i].y ) MaxY = V[i].y; } + return Vector2( MinX + (MaxX - MinX) * 0.5f, MinY + (MaxY - MinX) * 0.5f ); } +template +Quad2 Quad2::FromAABB( const tRECT& R ) { + return Quad2( Vector2( R.Left, R.Top ), Vector2( R.Left, R.Bottom ), Vector2( R.Right, R.Bottom ), Vector2( R.Right, R.Top ) ); +} + +template +tRECT Quad2::ToAABB( const T& OffsetX, const T& OffsetY ) { + tRECT TmpR; + + eeFloat MinX = V[0].x, MaxX = V[0].x, MinY = V[0].y, MaxY = V[0].y; + + for (Uint8 i = 1; i < 4; i++ ) { + if ( MinX > V[i].x ) MinX = V[i].x; + if ( MaxX < V[i].x ) MaxX = V[i].x; + if ( MinY > V[i].y ) MinY = V[i].y; + if ( MaxY < V[i].y ) MaxY = V[i].y; + } + + TmpR.Left = MinX + OffsetX; + TmpR.Right = MaxX + OffsetX; + TmpR.Top = MinY + OffsetY; + TmpR.Bottom = MaxY + OffsetY; + + return TmpR; +} + template const Vector2& Quad2::operator[] ( const Uint32& Pos ) const { if ( Pos <= 3 ) diff --git a/include/eepp/math/rect.hpp b/include/eepp/math/rect.hpp index 4574f1a69..a4ed695f1 100755 --- a/include/eepp/math/rect.hpp +++ b/include/eepp/math/rect.hpp @@ -35,6 +35,16 @@ class tRECT { bool IntersectsSegment( const Vector2& a, const Vector2& b ); + /** Determine if a RECT and a Circle are intersecting + * @param pos Circle position + * @param radius Circle Radius + * @return True if are intersecting + */ + bool IntersectCircle( Vector2 pos, const T& radius ); + + /** Determine if a RECT ( representing a circle ) is intersecting another RECT ( also representing a circle ) */ + bool IntersectCircles( const tRECT& b ); + Vector2 ClampVector( const Vector2& Vect ); Vector2 WrapVector( const Vector2& Vect ); @@ -141,6 +151,35 @@ bool tRECT::IntersectsSegment( const Vector2& a, const Vector2& b ) { return false; } +template +bool tRECT::IntersectCircle( Vector2 pos, const T& radius ) { + Vector2 tPos( pos ); + + if (tPos.x < Left) tPos.x = Left; + if (tPos.x > Right) tPos.x = Right; + if (tPos.y < Top) tPos.y = Top; + if (tPos.y > Bottom) tPos.y = Bottom; + + if ( pos.Distance( tPos ) < radius ) + return true; + + return false; +} + +template +bool tRECT::IntersectCircles( const tRECT& b ) { + eeFloat ra = (eeFloat)(Right - Left) * 0.5f; + eeFloat rb = (eeFloat)(b.Right - b.Left) * 0.5f; + eeFloat dist = ra + rb; + eeFloat dx = (b.Left + rb) - (Left + ra); + eeFloat dy = (b.Top + rb) - (Top + ra); + eeFloat res = (dx * dx) + (dy * dy); + + if ( res <= (dist * dist)) + return true; + return false; +} + template Vector2 tRECT::ClampVector( const Vector2& Vect ) { T x = eemin( eemax( Left , Vect.x ), Right ); diff --git a/include/eepp/ui/cuicontrol.hpp b/include/eepp/ui/cuicontrol.hpp index fda540d78..93044a89f 100644 --- a/include/eepp/ui/cuicontrol.hpp +++ b/include/eepp/ui/cuicontrol.hpp @@ -209,7 +209,7 @@ class EE_API cUIControl { bool IsMouseOverMeOrChilds(); - const eePolygon2f& GetPolygon() const; + eePolygon2f &GetPolygon(); const eeVector2f& GetPolygonCenter() const; diff --git a/include/eepp/ui/tuiitemcontainer.hpp b/include/eepp/ui/tuiitemcontainer.hpp index 951439ccf..08f74f289 100644 --- a/include/eepp/ui/tuiitemcontainer.hpp +++ b/include/eepp/ui/tuiitemcontainer.hpp @@ -62,7 +62,7 @@ cUIControl * tUIItemContainer::OverFind( const eeVector2f& Point ) { if ( mEnabled && mVisible && tParent->mItems.size() ) { UpdateQuad(); - if ( Math::PointInsidePolygon2( mPoly, Point ) ) { + if ( mPoly.PointInside( Point ) ) { WriteCtrlFlag( UI_CTRL_FLAG_MOUSEOVER_ME_OR_CHILD, 1 ); for ( Uint32 i = tParent->mVisibleFirst; i <= tParent->mVisibleLast; i++ ) { diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index c25fe2f2f..c752f95fa 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 710a74198..bb7d12357 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -174,7 +174,6 @@ ../../include/eepp/math/math.hpp ../../include/eepp/math/cmtrand.hpp ../../include/eepp/math/base.hpp -../../src/eepp/math/math.cpp ../../src/eepp/math/cmtrand.cpp ../../include/eepp/physics/settings.hpp ../../include/eepp/physics/physicshelper.hpp diff --git a/src/eepp/gaming/cisomap.cpp b/src/eepp/gaming/cisomap.cpp index df1e3f3c7..52ef499bc 100755 --- a/src/eepp/gaming/cisomap.cpp +++ b/src/eepp/gaming/cisomap.cpp @@ -56,7 +56,7 @@ void cIsoMap::CreateBaseVertexBuffer() { T->Layers.resize( mMapLayers ); T->Q = TileQBaseCoords( x, y ); - T->Box = Math::Quad2toAABB( T->Q ); + T->Box = T->Q.ToAABB(); T->TilePosStr = String::ToStr( x) + " - " + String::ToStr( y ); for ( i = 0; i < 4; i++ ) @@ -128,10 +128,10 @@ void cIsoMap::Draw() { if ( L == 0 ) { TileAABB = T->Box; - if ( Math::Intersect( mScreenAABB, TileAABB ) ) { + if ( mScreenAABB.Intersect( TileAABB ) ) { T->Color[0] = T->Color[1] = T->Color[2] = T->Color[3] = mMapAmbientColor; - if ( Math::Intersect( mLight.GetAABB(), TileAABB ) ) { + if ( mLight.GetAABB().Intersect( TileAABB ) ) { T->Color[0] = mLight.ProcessVertex( T->Q.V[0].x, T->Q.V[0].y, T->Color[0], T->Color[0] ); // Left - Top Vertex T->Color[1] = mLight.ProcessVertex( T->Q.V[1].x, T->Q.V[1].y, T->Color[1], T->Color[1] ); // Left - Bottom Vertex T->Color[2] = mLight.ProcessVertex( T->Q.V[2].x, T->Q.V[2].y, T->Color[2], T->Color[2] ); // Right - Bottom Vertex @@ -141,7 +141,7 @@ void cIsoMap::Draw() { T->Layers[L]->Draw( T->Q, 0.f, 0.f, 0.f, 1.f, T->Color[0], T->Color[1], T->Color[2], T->Color[3] ); if ( TileAABB.Contains( mMouseMapPos ) ) { - if ( Math::IntersectQuad2( T->Q, eeQuad2f( mMouseMapPos, mMouseMapPos, mMouseMapPos, mMouseMapPos ) ) ) { + if ( eePolygon2f::IntersectQuad2( T->Q, eeQuad2f( mMouseMapPos, mMouseMapPos, mMouseMapPos, mMouseMapPos ) ) ) { mMouseTilePos.x = x; mMouseTilePos.y = y; } @@ -158,11 +158,11 @@ void cIsoMap::Draw() { eeAABB LayerAABB( TileCenter.x - SubTexture->DestWidth() * 0.5f, TileCenter.y - SubTexture->DestHeight(), TileCenter.x + SubTexture->DestWidth() * 0.5f, TileCenter.y ); eeAABB ShadowAABB( ObjPos.x, TileCenter.y - SubTexture->DestHeight(), TileCenter.x + SubTexture->DestWidth(), TileCenter.y ); - if ( Math::Intersect( mScreenAABB, ShadowAABB ) ) { + if ( mScreenAABB.Intersect( ShadowAABB ) ) { SubTexture->Draw( mOffsetX + ObjPos.x, mOffsetY + ObjPos.y, 0, 1, SC, SC, SC, SC, ALPHA_NORMAL, RN_ISOMETRIC ); } - if ( Math::Intersect( mScreenAABB, LayerAABB ) ) { + if ( mScreenAABB.Intersect( LayerAABB ) ) { SubTexture->Draw( mOffsetX + TileCenter.x - (eeFloat)SubTexture->DestWidth() * 0.5f, mOffsetY + TileCenter.y - (eeFloat)SubTexture->DestHeight(), 0, 1, eeColorA(T->Color[0]), eeColorA(T->Color[1]), eeColorA(T->Color[2]), eeColorA(T->Color[3]) ); } } @@ -270,7 +270,7 @@ void cIsoMap::VertexChangeHeight( const eeInt& MapTileX, const eeInt& MapTileY, if ( ( JointUp && T->Q.V[JointNum].y >= NewJointHeight ) || ( !JointUp && T->Q.V[JointNum].y <= NewJointHeight ) ) { T->Q.V[JointNum].y += Height; - T->Box = Math::Quad2toAABB( T->Q ); + T->Box = T->Q.ToAABB(); } } } diff --git a/src/eepp/gaming/clight.cpp b/src/eepp/gaming/clight.cpp index 58331e506..c05b9b7f5 100755 --- a/src/eepp/gaming/clight.cpp +++ b/src/eepp/gaming/clight.cpp @@ -32,7 +32,7 @@ eeColor cLight::ProcessVertex( const eeFloat& PointX, const eeFloat& PointY, con if ( mActive ) { if ( mType == LIGHT_NORMAL ) - VertexDist = eeabs( Math::Distance( mPos.x, mPos.y, PointX, PointY ) ); + VertexDist = eeabs( mPos.Distance( eeVector2f( PointX, PointY ) ) ); else { eeFloat XDist = eeabs(mPos.x - PointX) * 0.5f; eeFloat YDist = eeabs(mPos.y - PointY); @@ -72,7 +72,7 @@ eeColorA cLight::ProcessVertex( const eeFloat& PointX, const eeFloat& PointY, co if ( mActive ) { if ( mType == LIGHT_NORMAL ) - VertexDist = eeabs( Math::Distance( mPos.x, mPos.y, PointX, PointY ) ); + VertexDist = eeabs( mPos.Distance( eeVector2f( PointX, PointY ) ) ); else { eeFloat XDist = eeabs(mPos.x - PointX) * 0.5f; eeFloat YDist = eeabs(mPos.y - PointY); @@ -133,7 +133,7 @@ void cLight::Move( const eeFloat& addtox, const eeFloat& addtoy ) { UpdatePos( mPos.x + addtox, mPos.y + addtoy ); } -const eeAABB& cLight::GetAABB() const { +eeAABB cLight::GetAABB() const { return mAABB; } diff --git a/src/eepp/gaming/clightmanager.cpp b/src/eepp/gaming/clightmanager.cpp index b1215dbb2..0ec6120d6 100644 --- a/src/eepp/gaming/clightmanager.cpp +++ b/src/eepp/gaming/clightmanager.cpp @@ -49,7 +49,7 @@ void cLightManager::UpdateByVertex() { for ( LightsList::iterator it = mLights.begin(); it != mLights.end(); it++ ) { cLight * Light = (*it); - if ( firstLight || Math::Intersect( VisibleArea, Light->GetAABB() ) ) { + if ( firstLight || VisibleArea.Intersect( Light->GetAABB() ) ) { for ( Int32 x = start.x; x < end.x; x++ ) { for ( Int32 y = start.y; y < end.y; y++ ) { if ( firstLight ) { @@ -63,7 +63,7 @@ void cLightManager::UpdateByVertex() { eeAABB TileAABB( Pos.x, Pos.y, Pos.x + TileSize.x, Pos.y + TileSize.y ); - if ( Math::Intersect( TileAABB, Light->GetAABB() ) ) { + if ( TileAABB.Intersect( Light->GetAABB() ) ) { if ( y > 0 ) mTileColors[x][y][0]->Assign( *mTileColors[x][y - 1][1] ); else @@ -102,7 +102,7 @@ void cLightManager::UpdateByTile() { for ( LightsList::iterator it = mLights.begin(); it != mLights.end(); it++ ) { cLight * Light = (*it); - if ( firstLight || Math::Intersect( VisibleArea, Light->GetAABB() ) ) { + if ( firstLight || VisibleArea.Intersect( Light->GetAABB() ) ) { for ( Int32 x = start.x; x < end.x; x++ ) { for ( Int32 y = start.y; y < end.y; y++ ) { if ( firstLight ) { @@ -116,7 +116,7 @@ void cLightManager::UpdateByTile() { eeAABB TileAABB( Pos.x, Pos.y, Pos.x + TileSize.x, Pos.y + TileSize.y ); - if ( Math::Intersect( TileAABB, Light->GetAABB() ) ) { + if ( TileAABB.Intersect( Light->GetAABB() ) ) { mTileColors[x][y][0]->Assign( Light->ProcessVertex( Pos.x + HalfTileSize.Width(), Pos.y + HalfTileSize.Height(), *(mTileColors[x][y][0]), *(mTileColors[x][y][0]) ) ); } } @@ -136,7 +136,7 @@ eeColorA cLightManager::GetColorFromPos( const eeVector2f& Pos ) { for ( LightsList::iterator it = mLights.begin(); it != mLights.end(); it++ ) { cLight * Light = (*it); - if ( Math::Contains( Light->GetAABB(), Pos ) ) { + if ( Light->GetAABB().Contains( Pos ) ) { Col = Light->ProcessVertex( Pos, Col, Col ); } } @@ -159,7 +159,7 @@ void cLightManager::RemoveLight( const eeVector2f& OverPos ) { for ( LightsList::reverse_iterator it = mLights.rbegin(); it != mLights.rend(); it++ ) { cLight * Light = (*it); - if ( Math::Contains( Light->GetAABB(), OverPos ) ) { + if ( Light->GetAABB().Contains( OverPos ) ) { mLights.remove( Light ); eeSAFE_DELETE( Light ); break; @@ -243,7 +243,7 @@ cLight * cLightManager::GetLightOver( const eeVector2f& OverPos, cLight * LightC for ( LightsList::reverse_iterator it = mLights.rbegin(); it != mLights.rend(); it++ ) { cLight * Light = (*it); - if ( Math::Contains( Light->GetAABB(), OverPos ) ) { + if ( Light->GetAABB().Contains( OverPos ) ) { if ( NULL == FirstLight ) { FirstLight = Light; } @@ -268,7 +268,7 @@ cLight * cLightManager::GetLightOver( const eeVector2f& OverPos, cLight * LightC return FirstLight; } - if ( NULL == PivotLight && NULL != LightCurrent && Math::Contains( LightCurrent->GetAABB(), OverPos ) ) { + if ( NULL == PivotLight && NULL != LightCurrent && LightCurrent->GetAABB().Contains( OverPos ) ) { return LightCurrent; } diff --git a/src/eepp/gaming/cobjectlayer.cpp b/src/eepp/gaming/cobjectlayer.cpp index d64b1e5e8..cddb7cd35 100644 --- a/src/eepp/gaming/cobjectlayer.cpp +++ b/src/eepp/gaming/cobjectlayer.cpp @@ -95,7 +95,9 @@ cGameObject * cObjectLayer::GetObjectOver( const eeVector2i& pos ) { tPos = tObj->Pos(); tSize = tObj->Size(); - if ( Math::Contains( eeRecti( tPos.x, tPos.y, tPos.x + tSize.x, tPos.y + tSize.y ), pos ) ) + eeRecti objR( tPos.x, tPos.y, tPos.x + tSize.x, tPos.y + tSize.y ); + + if ( objR.Contains( pos ) ) return tObj; } diff --git a/src/eepp/gaming/mapeditor/cuimap.cpp b/src/eepp/gaming/mapeditor/cuimap.cpp index 85ee945f0..a7df750b9 100644 --- a/src/eepp/gaming/mapeditor/cuimap.cpp +++ b/src/eepp/gaming/mapeditor/cuimap.cpp @@ -68,7 +68,7 @@ void cUIMap::Update() { mSelLight = NULL; } else if ( NULL != mSelLight ) { - if ( Math::Contains( mSelLight->GetAABB(), mMap->GetMouseMapPosf() ) ) { + if ( mSelLight->GetAABB().Contains( mMap->GetMouseMapPosf() ) ) { mMap->GetLightManager()->RemoveLight( mSelLight ); eeSAFE_DELETE( mSelLight ); diff --git a/src/eepp/graphics/cbatchrenderer.cpp b/src/eepp/graphics/cbatchrenderer.cpp index 3619329c1..afb1885f2 100755 --- a/src/eepp/graphics/cbatchrenderer.cpp +++ b/src/eepp/graphics/cbatchrenderer.cpp @@ -477,7 +477,7 @@ void cBatchRenderer::BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, cons } if ( Angle != 0 ) - mQ = Math::RotateQuadCentered( mQ, Angle, QCenter ); + mQ.Rotate( Angle, QCenter ); SetBlendMode( DM_QUADS, mForceBlendMode ); diff --git a/src/eepp/graphics/cprimitives.cpp b/src/eepp/graphics/cprimitives.cpp index dac11c9be..310257af0 100755 --- a/src/eepp/graphics/cprimitives.cpp +++ b/src/eepp/graphics/cprimitives.cpp @@ -22,7 +22,8 @@ void cPrimitives::DrawRoundedRectangle(const eeFloat& x, const eeFloat& y, const eeVector2f poly; eeVector2f Center( x + width * 0.5f + xscalediff, y + height * 0.5f + yscalediff ); - eePolygon2f Poly = Math::CreateRoundedPolygon( x - xscalediff, y - yscalediff, width + xscalediff, height + yscalediff, Corners ); + eePolygon2f Poly = eePolygon2f::CreateRoundedPolygon( x - xscalediff, y - yscalediff, width + xscalediff, height + yscalediff, Corners ); + Poly.Rotate( Angle, Center ); switch(fillmode) { diff --git a/src/eepp/math/math.cpp b/src/eepp/math/math.cpp deleted file mode 100755 index 3942a68c1..000000000 --- a/src/eepp/math/math.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -using namespace EE::System; - -namespace EE { namespace Math { - -Uint32 SetRandomSeed() { - Uint32 Seed = static_cast( Sys::GetSystemTime() * 1000 ); - srand(Seed); - return Seed; -} - -}} diff --git a/src/eepp/ui/cuicontrol.cpp b/src/eepp/ui/cuicontrol.cpp index 9de3a7039..2af23b6c1 100644 --- a/src/eepp/ui/cuicontrol.cpp +++ b/src/eepp/ui/cuicontrol.cpp @@ -733,7 +733,7 @@ cUIControl * cUIControl::OverFind( const eeVector2f& Point ) { if ( mEnabled && mVisible ) { UpdateQuad(); - if ( Math::PointInsidePolygon2( mPoly, Point ) ) { + if ( mPoly.PointInside( Point ) ) { WriteCtrlFlag( UI_CTRL_FLAG_MOUSEOVER_ME_OR_CHILD, 1 ); cUIControl * ChildLoop = mChildLast; @@ -795,7 +795,7 @@ Uint32 cUIControl::IsClipped() { return mFlags & UI_CLIP_ENABLE; } -const eePolygon2f& cUIControl::GetPolygon() const { +eePolygon2f& cUIControl::GetPolygon() { return mPoly; } diff --git a/src/examples/external_shader/external_shader.cpp b/src/examples/external_shader/external_shader.cpp index 0c692072b..f45724230 100644 --- a/src/examples/external_shader/external_shader.cpp +++ b/src/examples/external_shader/external_shader.cpp @@ -44,7 +44,7 @@ void videoResize() { GLi->LoadMatrixf( perspectiveMatrix ); GLi->MatrixMode( GL_MODELVIEW ); - /// eepp enables some this client states by default, and textures by default + /// eepp enables some client states by default, and textures by default GLi->Disable( GL_TEXTURE_2D ); GLi->DisableClientState( GL_TEXTURE_COORD_ARRAY ); @@ -140,8 +140,8 @@ EE_MAIN_FUNC int main (int argc, char * argv []) for (i = 0; i < ParticlesNum; i++ ) { vertices[i] = eeVector3ff( 0, 0, 1.83 ); - velocities[i] = eeVector3ff( (Randf() * 2 - 1)*.05, (Randf() * 2 - 1)*.05, .93 + Randf()*.02 ); - colors[i] = eeColorAf( Randf() * 0.5, 0.1, 0.8, 0.5 ); + velocities[i] = eeVector3ff( (Math::Randf() * 2 - 1)*.05, (Math::Randf() * 2 - 1)*.05, .93 + Math::Randf()*.02 ); + colors[i] = eeColorAf( Math::Randf() * 0.5, 0.1, 0.8, 0.5 ); } while ( win->Running() ) @@ -213,8 +213,8 @@ EE_MAIN_FUNC int main (int argc, char * argv []) if ( d < 2.f ) { if ( d < 0.03f ) { - vertices[i+1].x = Randf( -1, 1 ) * aspectRatio; - vertices[i+1].y = Randf( -1, 1 ); + vertices[i+1].x = Math::Randf( -1, 1 ) * aspectRatio; + vertices[i+1].y = Math::Randf( -1, 1 ); velocities[i].x = 0; velocities[i].y = 0; } else { diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 86fa3e8ce..558405180 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -79,7 +79,7 @@ void cEETest::Init() { InBuf.Start(); InBuf.SupportNewLine( true ); - SetRandomSeed(); + SetRandomSeed( static_cast( Sys::GetSystemTime() * 1000 ) ); LoadTextures(); @@ -114,7 +114,7 @@ void cEETest::Init() { if ( NULL != mFBO ) mFBO->ClearColor( eeColorAf( 0, 0, 0, 0.5f ) ); - eePolygon2f Poly = CreateRoundedPolygon( 0, 0, 256, 50 ); + eePolygon2f Poly = eePolygon2f::CreateRoundedPolygon( 0, 0, 256, 50 ); mVBO = cVertexBuffer::Create( VERTEX_FLAG_GET( VERTEX_FLAG_POSITION ) | VERTEX_FLAG_GET( VERTEX_FLAG_COLOR ), DM_TRIANGLE_FAN ); @@ -1080,12 +1080,12 @@ void cEETest::Screen2() { #ifndef EE_GLES CL1.RenderType( RN_ISOMETRIC ); - if (IntersectRectCircle( CL1.GetAABB(), Mousef.x, Mousef.y, 80.f )) + if ( CL1.GetAABB().IntersectCircle( Mousef, 80.f ) ) CL1.Color( eeColorA(255, 0, 0, 200) ); else CL1.Color( eeColorA(255, 255, 255, 200) ); - if ( IntersectQuad2( CL1.GetQuad() , CL2.GetQuad() ) ) { + if ( eePolygon2f::IntersectQuad2( CL1.GetQuad() , CL2.GetQuad() ) ) { CL1.Color( eeColorA(0, 255, 0, 255) ); CL2.Color( eeColorA(0, 255, 0, 255) ); } else @@ -1113,11 +1113,20 @@ void cEETest::Screen2() { PR.SetColor( eeColorA(0, 255, 0, 50) ); - if (IntersectLines( eeVector2f(0.f, 0.f), eeVector2f( (eeFloat)mWindow->GetWidth(), (eeFloat)mWindow->GetHeight() ), eeVector2f(Mousef.x - 80.f, Mousef.y - 80.f), eeVector2f(Mousef.x + 80.f, Mousef.y + 80.f) ) ) - iL1 = true; else iL1 = false; + eeLine2f Line( eeVector2f(0.f, 0.f), eeVector2f( (eeFloat)mWindow->GetWidth(), (eeFloat)mWindow->GetHeight() ) ); + eeLine2f Line2( eeVector2f(Mousef.x - 80.f, Mousef.y - 80.f), eeVector2f(Mousef.x + 80.f, Mousef.y + 80.f) ); + eeLine2f Line3( eeVector2f((eeFloat)mWindow->GetWidth(), 0.f), eeVector2f( 0.f, (eeFloat)mWindow->GetHeight() ) ); + eeLine2f Line4( eeVector2f(Mousef.x - 80.f, Mousef.y + 80.f), eeVector2f(Mousef.x + 80.f, Mousef.y - 80.f) ); - if (IntersectLines( eeVector2f((eeFloat)mWindow->GetWidth(), 0.f), eeVector2f( 0.f, (eeFloat)mWindow->GetHeight() ), eeVector2f(Mousef.x - 80.f, Mousef.y + 80.f), eeVector2f(Mousef.x + 80.f, Mousef.y - 80.f) ) ) - iL2 = true; else iL2 = false; + if ( Line.Intersect( Line2 ) ) + iL1 = true; + else + iL1 = false; + + if ( Line3.Intersect( Line4 ) ) + iL2 = true; + else + iL2 = false; if (iL1 && iL2) PR.SetColor( eeColorA(255, 0, 0, 255) ); @@ -1156,7 +1165,7 @@ void cEETest::Screen3() { Batch.SetTexture( TNP[3] ); Batch.LineLoopBegin(); for ( eeFloat j = 0; j < 360; j++ ) { - Batch.BatchLineLoop( HWidth + 350 * sinAng(j), HHeight + 350 * cosAng(j), HWidth + AnimVal * sinAng(j+1), HHeight + AnimVal * cosAng(j+1) ); + Batch.BatchLineLoop( HWidth + 350 * Math::sinAng(j), HHeight + 350 * Math::cosAng(j), HWidth + AnimVal * Math::sinAng(j+1), HHeight + AnimVal * Math::cosAng(j+1) ); } Batch.Draw(); } @@ -1492,7 +1501,7 @@ void cEETest::Input() { eeVector2i P = Map.GetMouseTilePos(); if ( NULL != mTerrainBut ) { - if ( !PointInsidePolygon2( mTerrainBut->GetPolygon(), KM->GetMousePosf() ) ) { + if ( !mTerrainBut->GetPolygon().PointInside( KM->GetMousePosf() ) ) { if ( mTerrainUp ) { Map.SetTileHeight( P.x, P.y ); } else { @@ -1581,8 +1590,8 @@ void cEETest::Particles() { PS[1].Position( Mousef ); PS[2].Position( HWidth, HHeight ); - PS[3].Position( cosAng(Ang) * 220.f + HWidth + Math::Randf(0.f, 10.f), sinAng(Ang) * 220.f + HHeight + Math::Randf(0.f, 10.f) ); - PS[4].Position( -cosAng(Ang) * 220.f + HWidth + Math::Randf(0.f, 10.f), -sinAng(Ang) * 220.f + HHeight + Math::Randf(0.f, 10.f) ); + PS[3].Position( Math::cosAng(Ang) * 220.f + HWidth + Math::Randf(0.f, 10.f), Math::sinAng(Ang) * 220.f + HHeight + Math::Randf(0.f, 10.f) ); + PS[4].Position( -Math::cosAng(Ang) * 220.f + HWidth + Math::Randf(0.f, 10.f), -Math::sinAng(Ang) * 220.f + HHeight + Math::Randf(0.f, 10.f) ); for ( Uint32 i = 0; i < PS.size(); i++ ) PS[i].Draw();