first commit
This commit is contained in:
59
include/framework/geometry/sat.h
Normal file
59
include/framework/geometry/sat.h
Normal file
@ -0,0 +1,59 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NSAT__
|
||||
#define __NSAT__
|
||||
|
||||
|
||||
#include <float.h>
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace SAT {
|
||||
|
||||
/// SAT overlap test results.
|
||||
enum Overlap
|
||||
{
|
||||
Outside = 0,
|
||||
Inside, // B inside A
|
||||
Clipped
|
||||
};
|
||||
|
||||
/// Helper function to test overlap on a given axis.
|
||||
Overlap TestOverlap(const Vector4 &axis, int ca, const Vector4 *a, int cb, const Vector4 *b)
|
||||
{
|
||||
// A interval.
|
||||
float a_mn = FLT_MAX, a_mx = -FLT_MAX;
|
||||
for (int n = 0; n < ca; ++n)
|
||||
{
|
||||
float d = axis.Dot(a[n]);
|
||||
if (d < a_mn) a_mn = d;
|
||||
if (d > a_mx) a_mx = d;
|
||||
}
|
||||
|
||||
// B interval.
|
||||
float b_mn = FLT_MAX, b_mx = -FLT_MAX;
|
||||
for (int n = 0; n < cb; ++n)
|
||||
{
|
||||
float d = axis.Dot(b[n]);
|
||||
if (d < b_mn) b_mn = d;
|
||||
if (d > b_mx) b_mx = d;
|
||||
}
|
||||
|
||||
// Test overlap.
|
||||
if ((a_mx < b_mn) || (a_mn > b_mx))
|
||||
return Outside;
|
||||
if ((b_mn > a_mn) && (b_mx < a_mx))
|
||||
return Inside;
|
||||
|
||||
return Clipped;
|
||||
}
|
||||
|
||||
} // SAT
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NSAT__
|
||||
Reference in New Issue
Block a user