You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-22 15:06:45 +00:00
Move other lone thirdparty files to thirdparty/misc
Also move Box2D ConvexDecomposition contrib code to thirdparty/b2d_convexdecomp.
This commit is contained in:
@@ -4,4 +4,13 @@ Import('env')
|
||||
|
||||
env.add_source_files(env.drivers_sources, "*.cpp")
|
||||
|
||||
# Thirdparty dependencies
|
||||
thirdparty_dir = "#thirdparty/b2d_convexdecomp/"
|
||||
thirdparty_sources = [
|
||||
"b2Polygon.cpp",
|
||||
"b2Triangle.cpp",
|
||||
]
|
||||
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
|
||||
env.add_source_files(env.drivers_sources, thirdparty_sources)
|
||||
|
||||
Export('env')
|
||||
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2GLUE_H
|
||||
#define B2GLUE_H
|
||||
|
||||
#include "math_2d.h"
|
||||
#include <limits.h>
|
||||
|
||||
namespace b2ConvexDecomp {
|
||||
|
||||
typedef real_t float32;
|
||||
typedef int32_t int32;
|
||||
|
||||
static inline float32 b2Sqrt(float32 val) { return Math::sqrt(val); }
|
||||
#define b2_maxFloat FLT_MAX
|
||||
#define b2_epsilon CMP_EPSILON
|
||||
#define b2_pi 3.14159265359f
|
||||
#define b2_maxPolygonVertices 16
|
||||
#define b2Max MAX
|
||||
#define b2Min MIN
|
||||
#define b2Clamp CLAMP
|
||||
#define b2Abs ABS
|
||||
/// A small length used as a collision and constraint tolerance. Usually it is
|
||||
/// chosen to be numerically significant, but visually insignificant.
|
||||
#define b2_linearSlop 0.005f
|
||||
|
||||
/// A small angle used as a collision and constraint tolerance. Usually it is
|
||||
/// chosen to be numerically significant, but visually insignificant.
|
||||
#define b2_angularSlop (2.0f / 180.0f * b2_pi)
|
||||
|
||||
/// A 2D column vector.
|
||||
struct b2Vec2
|
||||
{
|
||||
/// Default constructor does nothing (for performance).
|
||||
b2Vec2() {}
|
||||
|
||||
/// Construct using coordinates.
|
||||
b2Vec2(float32 x, float32 y) : x(x), y(y) {}
|
||||
|
||||
/// Set this vector to all zeros.
|
||||
void SetZero() { x = 0.0f; y = 0.0f; }
|
||||
|
||||
/// Set this vector to some specified coordinates.
|
||||
void Set(float32 x_, float32 y_) { x = x_; y = y_; }
|
||||
|
||||
/// Negate this vector.
|
||||
b2Vec2 operator -() const { b2Vec2 v; v.Set(-x, -y); return v; }
|
||||
|
||||
/// Read from and indexed element.
|
||||
float32 operator () (int32 i) const
|
||||
{
|
||||
return (&x)[i];
|
||||
}
|
||||
|
||||
/// Write to an indexed element.
|
||||
float32& operator () (int32 i)
|
||||
{
|
||||
return (&x)[i];
|
||||
}
|
||||
|
||||
/// Add a vector to this vector.
|
||||
void operator += (const b2Vec2& v)
|
||||
{
|
||||
x += v.x; y += v.y;
|
||||
}
|
||||
|
||||
/// Subtract a vector from this vector.
|
||||
void operator -= (const b2Vec2& v)
|
||||
{
|
||||
x -= v.x; y -= v.y;
|
||||
}
|
||||
|
||||
/// Multiply this vector by a scalar.
|
||||
void operator *= (float32 a)
|
||||
{
|
||||
x *= a; y *= a;
|
||||
}
|
||||
|
||||
/// Get the length of this vector (the norm).
|
||||
float32 Length() const
|
||||
{
|
||||
return b2Sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
/// Get the length squared. For performance, use this instead of
|
||||
/// b2Vec2::Length (if possible).
|
||||
float32 LengthSquared() const
|
||||
{
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
bool operator==(const b2Vec2& p_v) const {
|
||||
return x==p_v.x && y==p_v.y;
|
||||
}
|
||||
b2Vec2 operator+(const b2Vec2& p_v) const {
|
||||
return b2Vec2(x+p_v.x,y+p_v.y);
|
||||
}
|
||||
b2Vec2 operator-(const b2Vec2& p_v) const {
|
||||
return b2Vec2(x-p_v.x,y-p_v.y);
|
||||
}
|
||||
|
||||
b2Vec2 operator*(float32 f) const {
|
||||
return b2Vec2(f*x,f*y);
|
||||
}
|
||||
|
||||
/// Convert this vector into a unit vector. Returns the length.
|
||||
float32 Normalize()
|
||||
{
|
||||
float32 length = Length();
|
||||
if (length < b2_epsilon)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
float32 invLength = 1.0f / length;
|
||||
x *= invLength;
|
||||
y *= invLength;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/*
|
||||
/// Does this vector contain finite coordinates?
|
||||
bool IsValid() const
|
||||
{
|
||||
return b2IsValid(x) && b2IsValid(y);
|
||||
}
|
||||
*/
|
||||
|
||||
float32 x, y;
|
||||
};
|
||||
|
||||
inline b2Vec2 operator*(float32 f,const b2Vec2& p_v) {
|
||||
return b2Vec2(f*p_v.x,f*p_v.y);
|
||||
}
|
||||
|
||||
/// Perform the dot product on two vectors.
|
||||
inline float32 b2Dot(const b2Vec2& a, const b2Vec2& b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y;
|
||||
}
|
||||
|
||||
/// Perform the cross product on two vectors. In 2D this produces a scalar.
|
||||
inline float32 b2Cross(const b2Vec2& a, const b2Vec2& b)
|
||||
{
|
||||
return a.x * b.y - a.y * b.x;
|
||||
}
|
||||
|
||||
/// Perform the cross product on a vector and a scalar. In 2D this produces
|
||||
/// a vector.
|
||||
inline b2Vec2 b2Cross(const b2Vec2& a, float32 s)
|
||||
{
|
||||
return b2Vec2(s * a.y, -s * a.x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Eric Jordan
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_POLYGON_H
|
||||
#define B2_POLYGON_H
|
||||
|
||||
#include "b2Triangle.h"
|
||||
#include "stdio.h"
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
namespace b2ConvexDecomp {
|
||||
|
||||
static bool B2_POLYGON_REPORT_ERRORS = false;
|
||||
|
||||
class b2Polygon;
|
||||
|
||||
int32 remainder(int32 x, int32 modulus);
|
||||
int32 TriangulatePolygon(float32* xv, float32* yv, int32 vNum, b2Triangle* results);
|
||||
bool IsEar(int32 i, float32* xv, float32* yv, int32 xvLength); //Not for external use
|
||||
int32 PolygonizeTriangles(b2Triangle* triangulated, int32 triangulatedLength, b2Polygon* polys, int32 polysLength);
|
||||
int32 DecomposeConvex(b2Polygon* p, b2Polygon* results, int32 maxPolys);
|
||||
//void DecomposeConvexAndAddTo(b2Polygon* p, b2Body* bd, b2FixtureDef* prototype);
|
||||
|
||||
void ReversePolygon(float32* x, float32* y, int n);
|
||||
|
||||
b2Polygon TraceEdge(b2Polygon* p); //For use with self-intersecting polygons, finds outline
|
||||
|
||||
class b2Polygon {
|
||||
|
||||
public:
|
||||
const static int32 maxVerticesPerPolygon = b2_maxPolygonVertices;
|
||||
|
||||
float32* x; //vertex arrays
|
||||
float32* y;
|
||||
int32 nVertices;
|
||||
|
||||
float32 area;
|
||||
bool areaIsSet;
|
||||
|
||||
b2Polygon(float32* _x, float32* _y, int32 nVert);
|
||||
b2Polygon(b2Vec2* v, int32 nVert);
|
||||
b2Polygon();
|
||||
~b2Polygon();
|
||||
|
||||
float32 GetArea();
|
||||
|
||||
void MergeParallelEdges(float32 tolerance);
|
||||
b2Vec2* GetVertexVecs();
|
||||
b2Polygon(b2Triangle& t);
|
||||
void Set(const b2Polygon& p);
|
||||
bool IsConvex();
|
||||
bool IsCCW();
|
||||
bool IsUsable(bool printError);
|
||||
bool IsUsable();
|
||||
bool IsSimple();
|
||||
// void AddTo(b2FixtureDef& pd);
|
||||
|
||||
b2Polygon* Add(b2Triangle& t);
|
||||
|
||||
void print(){
|
||||
printFormatted();
|
||||
/*
|
||||
for (int32 i=0; i<nVertices; ++i){
|
||||
printf("i: %d, x:%f, y:%f\n",i,x[i],y[i]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void printFormatted(){
|
||||
printf("float xv[] = {");
|
||||
for (int32 i=0; i<nVertices; ++i){
|
||||
printf("%ff,",x[i]);
|
||||
}
|
||||
printf("};\nfloat yv[] = {");
|
||||
for (int32 i=0; i<nVertices; ++i){
|
||||
printf("%ff,",y[i]);
|
||||
}
|
||||
printf("};\n");
|
||||
}
|
||||
|
||||
b2Polygon(const b2Polygon& p){
|
||||
nVertices = p.nVertices;
|
||||
area = p.area;
|
||||
areaIsSet = p.areaIsSet;
|
||||
x = new float32[nVertices];
|
||||
y = new float32[nVertices];
|
||||
memcpy(x, p.x, nVertices * sizeof(float32));
|
||||
memcpy(y, p.y, nVertices * sizeof(float32));
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
const int32 MAX_CONNECTED = 32;
|
||||
const float32 COLLAPSE_DIST_SQR = CMP_EPSILON*CMP_EPSILON;//0.1f;//1000*CMP_EPSILON*1000*CMP_EPSILON;
|
||||
|
||||
class b2PolyNode{
|
||||
public:
|
||||
b2Vec2 position;
|
||||
b2PolyNode* connected[MAX_CONNECTED];
|
||||
int32 nConnected;
|
||||
bool visited;
|
||||
|
||||
b2PolyNode(b2Vec2& pos);
|
||||
b2PolyNode();
|
||||
void AddConnection(b2PolyNode& toMe);
|
||||
void RemoveConnection(b2PolyNode& fromMe);
|
||||
void RemoveConnectionByIndex(int32 index);
|
||||
bool IsConnectedTo(b2PolyNode& me);
|
||||
b2PolyNode* GetRightestConnection(b2PolyNode* incoming);
|
||||
b2PolyNode* GetRightestConnection(b2Vec2& incomingDir);
|
||||
};
|
||||
|
||||
|
||||
b2Polygon ConvexHull(b2Vec2* v, int nVert);
|
||||
b2Polygon ConvexHull(float32* cloudX, float32* cloudY, int32 nVert);
|
||||
}
|
||||
#endif
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Eric Jordan
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "b2Triangle.h"
|
||||
|
||||
namespace b2ConvexDecomp {
|
||||
|
||||
//Constructor automatically fixes orientation to ccw
|
||||
b2Triangle::b2Triangle(float32 x1, float32 y1, float32 x2, float32 y2, float32 x3, float32 y3){
|
||||
x = new float32[3];
|
||||
y = new float32[3];
|
||||
float32 dx1 = x2-x1;
|
||||
float32 dx2 = x3-x1;
|
||||
float32 dy1 = y2-y1;
|
||||
float32 dy2 = y3-y1;
|
||||
float32 cross = dx1*dy2-dx2*dy1;
|
||||
bool ccw = (cross>0);
|
||||
if (ccw){
|
||||
x[0] = x1; x[1] = x2; x[2] = x3;
|
||||
y[0] = y1; y[1] = y2; y[2] = y3;
|
||||
} else{
|
||||
x[0] = x1; x[1] = x3; x[2] = x2;
|
||||
y[0] = y1; y[1] = y3; y[2] = y2;
|
||||
}
|
||||
}
|
||||
|
||||
b2Triangle::b2Triangle(){
|
||||
x = new float32[3];
|
||||
y = new float32[3];
|
||||
}
|
||||
|
||||
b2Triangle::~b2Triangle(){
|
||||
delete[] x;
|
||||
delete[] y;
|
||||
}
|
||||
|
||||
void b2Triangle::Set(const b2Triangle& toMe) {
|
||||
for (int32 i=0; i<3; ++i) {
|
||||
x[i] = toMe.x[i];
|
||||
y[i] = toMe.y[i];
|
||||
}
|
||||
}
|
||||
|
||||
bool b2Triangle::IsInside(float32 _x, float32 _y){
|
||||
if (_x < x[0] && _x < x[1] && _x < x[2]) return false;
|
||||
if (_x > x[0] && _x > x[1] && _x > x[2]) return false;
|
||||
if (_y < y[0] && _y < y[1] && _y < y[2]) return false;
|
||||
if (_y > y[0] && _y > y[1] && _y > y[2]) return false;
|
||||
|
||||
float32 vx2 = _x-x[0]; float32 vy2 = _y-y[0];
|
||||
float32 vx1 = x[1]-x[0]; float32 vy1 = y[1]-y[0];
|
||||
float32 vx0 = x[2]-x[0]; float32 vy0 = y[2]-y[0];
|
||||
|
||||
float32 dot00 = vx0*vx0+vy0*vy0;
|
||||
float32 dot01 = vx0*vx1+vy0*vy1;
|
||||
float32 dot02 = vx0*vx2+vy0*vy2;
|
||||
float32 dot11 = vx1*vx1+vy1*vy1;
|
||||
float32 dot12 = vx1*vx2+vy1*vy2;
|
||||
float32 invDenom = 1.0f / (dot00*dot11 - dot01*dot01);
|
||||
float32 u = (dot11*dot02 - dot01*dot12)*invDenom;
|
||||
float32 v = (dot00*dot12 - dot01*dot02)*invDenom;
|
||||
|
||||
return ((u>=0)&&(v>=0)&&(u+v<=1));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Eric Jordan
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_TRIANGLE_H
|
||||
#define B2_TRIANGLE_H
|
||||
|
||||
#include "b2Glue.h"
|
||||
|
||||
namespace b2ConvexDecomp {
|
||||
|
||||
|
||||
|
||||
class b2Triangle{
|
||||
public:
|
||||
float* x;
|
||||
float* y;
|
||||
b2Triangle();
|
||||
b2Triangle(float32 x1, float32 y1, float32 x2, float32 y2, float32 x3, float32 y3);
|
||||
~b2Triangle();
|
||||
bool IsInside(float32 _x, float32 _y);
|
||||
void Set(const b2Triangle& toMe);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -28,7 +28,8 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "b2d_decompose.h"
|
||||
#include "b2Polygon.h"
|
||||
|
||||
#include "thirdparty/b2d_convexdecomp/b2Polygon.h"
|
||||
|
||||
namespace b2ConvexDecomp {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user