Add MathEngineTest and Commects and clean ups

This commit is contained in:
2018-08-18 20:50:06 -04:00
parent bd3c111fa1
commit a815367c9d
52 changed files with 386 additions and 144 deletions
@@ -45,6 +45,21 @@ cCollision::~cCollision()
return true; /// bounding boxes intersect
}
/*static*/ const bool cCollision::BoundingBox(const iVector4& a, const iVector4& b)
{
if ((b.x + b.z) < a.x)
return false; /// just checking if their
if ((a.x + a.z) < b.x)
return false; /// bounding boxes even touch
if ((b.y + b.w) < a.y)
return false;
if ((a.y + a.w) < b.y)
return false;
return true; /// bounding boxes intersect
}
/*static*/ const bool cCollision::BoundingBox( const SDL_Rect& a, const Vector4& b )
{
Vector4 temp = a;
@@ -57,21 +72,6 @@ cCollision::~cCollision()
return cCollision::BoundingBox(b, a);
}
/*static*/ const bool cCollision::BoundingBox( const iVector4& a, const iVector4& b )
{
if ((b.x + b.z) < a.x)
return false; /// just checking if their
if ((a.x + a.z) < b.x )
return false; /// bounding boxes even touch
if ((b.y + b.w) < a.y)
return false;
if ((a.y + a.w) < b.y)
return false;
return true; /// bounding boxes intersect
}
/*static*/ const bool cCollision::BoundingBox( const SDL_Rect& a, const iVector4& b )
{
iVector4 temp = a;
@@ -96,28 +96,6 @@ cCollision::~cCollision()
return cCollision::BoundingBox( b, a );
}
/*static*/ const Vector2 cCollision::Inside( const SDL_Rect& a, const SDL_Rect& b )
{
Vector2 rtn;
rtn.x = 0.0f;
rtn.y = 0.0f;
/// Check if left side of b is inside of a
if (b.x < a.x)
rtn.x = (float)(b.x - a.x);
/// Check if right side of b is inside of a
if ((b.x + b.w) > (a.x + a.w))
rtn.x = (float)((b.x + b.w) - (a.x + a.w));
/// Check if top side of b is inside of a
if (b.y < a.y)
rtn.y = (float)(b.y - a.y);
/// Check if bottom side of b is inside of a
if ((b.y + b.h) > (a.y + a.h))
rtn.y = (float)((b.y + b.h) - (a.y + a.h));
return rtn;
}
/*static*/ const Vector2 cCollision::Inside( const Vector4& a, const Vector4& b )
{
Vector2 rtn;
@@ -154,6 +132,44 @@ cCollision::~cCollision()
return cCollision::Inside(a, temp);
}
/*static*/ const bool cCollision::isInside( const signed long int x, const signed long int y, const SDL_Rect& inside )
{
iVector4 temp = inside;
return cCollision::isInside(x, y, temp);
}
/*static*/ const bool cCollision::isInside( const signed long int x, const signed long int y, const iVector4& inside )
{
bool rtn = false;
if ((inside.x < x) && (inside.w > x)) {
if ((inside.y < y) && (inside.z > y))
rtn = true;
}
return rtn;
}
/*static*/ const iVector2 cCollision::Inside(const SDL_Rect& a, const SDL_Rect& b)
{
iVector2 rtn;
rtn.x = 0.0f;
rtn.y = 0.0f;
/// Check if left side of b is inside of a
if (b.x < a.x)
rtn.x = (float)(b.x - a.x);
/// Check if right side of b is inside of a
if ((b.x + b.w) > (a.x + a.w))
rtn.x = (float)((b.x + b.w) - (a.x + a.w));
/// Check if top side of b is inside of a
if (b.y < a.y)
rtn.y = (float)(b.y - a.y);
/// Check if bottom side of b is inside of a
if ((b.y + b.h) > (a.y + a.h))
rtn.y = (float)((b.y + b.h) - (a.y + a.h));
return rtn;
}
/*static*/ const iVector2 cCollision::Inside( const iVector4& a, const iVector4& b )
{
iVector2 rtn;
@@ -20,31 +20,52 @@ namespace MathEngine {
private:
cCollision();
~cCollision();
public:
/// Functions
/* returns true if a is touching b */
static const bool BoundingBox( const SDL_Rect& a, const SDL_Rect& b );
/* returns true if a is touching b */
static const bool BoundingBox( const Vector4& a, const Vector4& b );
static const bool BoundingBox( const SDL_Rect& a, const Vector4& b );
static const bool BoundingBox( const Vector4& a, const SDL_Rect& b );
/* returns true if a is touching b */
static const bool BoundingBox(const iVector4& a, const iVector4& b);
static const bool BoundingBox( const iVector4& a, const iVector4& b );
/* returns true if a is touching b */
static const bool BoundingBox( const SDL_Rect& a, const Vector4& b );
/* returns true if a is touching b */
static const bool BoundingBox( const Vector4& a, const SDL_Rect& b );
/* returns true if a is touching b */
static const bool BoundingBox( const SDL_Rect& a, const iVector4& b );
/* returns true if a is touching b */
static const bool BoundingBox( const iVector4& a, const SDL_Rect& b );
/* returns true if a is touching b */
static const bool BoundingBox( const iVector4& a, const Vector4& b );
/* returns true if a is touching b */
static const bool BoundingBox( const Vector4& a, const iVector4& b );
static const Vector2 Inside( const SDL_Rect& a, const SDL_Rect& b );
/* returns the Vector2 were a over laps b */
static const Vector2 Inside( const Vector4& a, const Vector4& b );
/* returns the Vector2 were a over laps b */
static const Vector2 Inside( const SDL_Rect& a, const Vector4& b );
/* returns the Vector2 were a over laps b */
static const Vector2 Inside( const Vector4& a, const SDL_Rect& b );
/* returns true if xy are inside SDL_Rect */
static const bool isInside( const signed long int x, const signed long int y, const SDL_Rect& inside );
/* returns true if xy are inside iVector4 */
static const bool isInside( const signed long int x, const signed long int y, const iVector4& inside );
/* returns the iVector2 were a over laps b */
static const iVector2 Inside(const SDL_Rect& a, const SDL_Rect& b);
/* returns the iVector2 were a over laps b */
static const iVector2 Inside( const iVector4& a, const iVector4& b );
/* returns the iVector2 were a over laps b */
static const iVector2 Inside( const SDL_Rect& a, const iVector4& b );
/* returns the iVector2 were a over laps b */
static const iVector2 Inside( const iVector4& a, const SDL_Rect& b );
static const Vector2 Inside( const iVector4& a, const Vector4& b );
static const Vector2 Inside( const Vector4& a, const iVector4& b );
};/// END CLASS DEFINITION cCollision
}/// END NAMESPACE DEFINITION MathEngine
#endif/// END IFNDEF _CCOLLISION_HPP_
@@ -26,6 +26,7 @@ namespace MathEngine {
const float Rand( const float max, const float min = 0.0f ) const;
private:
/// Variables
static cRandom* sp_inst;/// = nullptr
};/// END CLASS DEFINITION cRandom
}/// END NAMESPACE DEFINITION MathEngine