98 lines
4.4 KiB
C++
98 lines
4.4 KiB
C++
#include "CollisionTest.hpp"
|
|
|
|
#include "../UTest/UTest.hpp"
|
|
|
|
/*** TrooperEngine DLL Header Files ***/
|
|
#include "TrooperEngine.hpp"
|
|
|
|
using MathEngine::cCollision;
|
|
|
|
void CollisionTest()
|
|
{
|
|
/// cCollision
|
|
printf("\nTesting cCollision -----\n\n");
|
|
|
|
UTest u("cCollision");
|
|
SDL_Rect a = { 50, 50, 50, 50 };
|
|
SDL_Rect bLeftTouch = { 0, 50, 50, 50 };
|
|
SDL_Rect bRightTouch = { 100, 50, 50, 50 };
|
|
SDL_Rect bTopTouch = { 50, 0, 50, 50 };
|
|
SDL_Rect bBottomTouch = { 50, 100, 50, 50 };
|
|
|
|
SDL_Rect bxywhTouch = { 1, 1, 49, 49 };
|
|
SDL_Rect bxnotTouch = { 101, 101, 50, 50 };
|
|
|
|
cString boundingbox = "BoundingBox(SDL_Rect a, SDL_Rect b) Check two SDL_Rect ";
|
|
|
|
u.test(boundingbox + "that overlap, should return true.", cCollision::BoundingBox(a, a));
|
|
|
|
u.test(boundingbox + "that overlap on the left side only, should return true.", cCollision::BoundingBox(a, bLeftTouch));
|
|
|
|
u.test(boundingbox + "that overlap on the right side only, should return true.", cCollision::BoundingBox(a, bRightTouch));
|
|
|
|
u.test(boundingbox + "that overlap on the Top side only, should return true.", cCollision::BoundingBox(a, bTopTouch));
|
|
|
|
u.test(boundingbox + "that overlap on the Bottom side only, should return true.", cCollision::BoundingBox(a, bBottomTouch));
|
|
|
|
u.test(boundingbox + "one is inside the other, should return true.", cCollision::BoundingBox(a, bxywhTouch));
|
|
|
|
u.test(boundingbox + "that don't overlap, should return false.", !(cCollision::BoundingBox(a, bxnotTouch)));
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
/// Vector4
|
|
//////////////////////////////////////////////////////////////////////////
|
|
MathEngine::Vector4 Va = { 50.0, 50.0, 50.0, 50.0 };
|
|
MathEngine::Vector4 VbLeftTouch = { 0.0, 50.0, 50.0, 50.0 };
|
|
MathEngine::Vector4 VbRightTouch = { 100.0, 50.0, 50.0, 50.0 };
|
|
MathEngine::Vector4 VbTopTouch = { 50.0, 0.0, 50.0, 50.0 };
|
|
MathEngine::Vector4 VbBottomTouch = { 50.0, 100.0, 50.0, 50.0 };
|
|
|
|
MathEngine::Vector4 VbxywhTouch = { 1.0, 1.0, 49.0, 49.0 };
|
|
MathEngine::Vector4 VbxnotTouch = { 101.0, 101.0, 50.0, 50.0 };
|
|
|
|
boundingbox = "BoundingBox( const Vector4& a, const Vector4& b ) Check two Vector4 ";
|
|
|
|
u.test(boundingbox + "that overlap, should return true.", cCollision::BoundingBox(Va, Va));
|
|
|
|
u.test(boundingbox + "that overlap on the left side only, should return true.", cCollision::BoundingBox(Va, VbLeftTouch));
|
|
|
|
u.test(boundingbox + "that overlap on the right side only, should return true.", cCollision::BoundingBox(Va, VbRightTouch));
|
|
|
|
u.test(boundingbox + "that overlap on the Top side only, should return true.", cCollision::BoundingBox(Va, VbTopTouch));
|
|
|
|
u.test(boundingbox + "that overlap on the Bottom side only, should return true.", cCollision::BoundingBox(Va, VbBottomTouch));
|
|
|
|
u.test(boundingbox + "one is inside the other, should return true.", cCollision::BoundingBox(Va, VbxywhTouch));
|
|
|
|
u.test(boundingbox + "that don't overlap, should return false.", !(cCollision::BoundingBox(Va, VbxnotTouch)));
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
/// iVector4
|
|
//////////////////////////////////////////////////////////////////////////
|
|
MathEngine::iVector4 iVa = { 50, 50, 50, 50 };
|
|
MathEngine::iVector4 iVbLeftTouch = { 0, 50, 50, 50 };
|
|
MathEngine::iVector4 iVbRightTouch = { 100, 50, 50, 50 };
|
|
MathEngine::iVector4 iVbTopTouch = { 50, 0, 50, 50 };
|
|
MathEngine::iVector4 iVbBottomTouch = { 50, 100, 50, 50 };
|
|
|
|
MathEngine::iVector4 iVbxywhTouch = { 1, 1, 49, 49 };
|
|
MathEngine::iVector4 iVbxnotTouch = { 101, 101, 50, 50 };
|
|
|
|
boundingbox = "BoundingBox( const iVector4& a, const iVector4& b ) Check two iVector4 ";
|
|
|
|
u.test(boundingbox + "that overlap, should return true.", cCollision::BoundingBox(iVa, iVa));
|
|
|
|
u.test(boundingbox + "that overlap on the left side only, should return true.", cCollision::BoundingBox(iVa, iVbLeftTouch));
|
|
|
|
u.test(boundingbox + "that overlap on the right side only, should return true.", cCollision::BoundingBox(iVa, iVbRightTouch));
|
|
|
|
u.test(boundingbox + "that overlap on the Top side only, should return true.", cCollision::BoundingBox(iVa, iVbTopTouch));
|
|
|
|
u.test(boundingbox + "that overlap on the Bottom side only, should return true.", cCollision::BoundingBox(iVa, iVbBottomTouch));
|
|
|
|
u.test(boundingbox + "one is inside the other, should return true.", cCollision::BoundingBox(iVa, iVbxywhTouch));
|
|
|
|
u.test(boundingbox + "that don't overlap, should return false.", !(cCollision::BoundingBox(iVa, iVbxnotTouch)));
|
|
|
|
u.report();
|
|
} |