Update to box2d 2.4.1

This commit is contained in:
Garrett Brown
2020-10-17 22:15:18 -04:00
parent 7d24beab90
commit 77f238767f
58 changed files with 879 additions and 367 deletions
+17 -14
View File
@@ -23,20 +23,22 @@
#ifndef B2_MATH_H
#define B2_MATH_H
#include <math.h>
#include "b2_api.h"
#include "b2_settings.h"
#include <cmath>
/// This function is used to ensure that a floating point number is not a NaN or infinity.
inline bool b2IsValid(float x)
{
return std::isfinite(x);
return isfinite(x);
}
#define b2Sqrt(x) sqrtf(x)
#define b2Atan2(y, x) atan2f(y, x)
/// A 2D column vector.
struct b2Vec2
struct B2_API b2Vec2
{
/// Default constructor does nothing (for performance).
b2Vec2() {}
@@ -52,7 +54,7 @@ struct b2Vec2
/// Negate this vector.
b2Vec2 operator -() const { b2Vec2 v; v.Set(-x, -y); return v; }
/// Read from and indexed element.
float operator () (int32 i) const
{
@@ -70,7 +72,7 @@ struct b2Vec2
{
x += v.x; y += v.y;
}
/// Subtract a vector from this vector.
void operator -= (const b2Vec2& v)
{
@@ -127,7 +129,7 @@ struct b2Vec2
};
/// A 2D column vector with 3 elements.
struct b2Vec3
struct B2_API b2Vec3
{
/// Default constructor does nothing (for performance).
b2Vec3() {}
@@ -166,7 +168,7 @@ struct b2Vec3
};
/// A 2-by-2 matrix. Stored in column-major order.
struct b2Mat22
struct B2_API b2Mat22
{
/// The default constructor does nothing (for performance).
b2Mat22() {}
@@ -240,7 +242,7 @@ struct b2Mat22
};
/// A 3-by-3 matrix. Stored in column-major order.
struct b2Mat33
struct B2_API b2Mat33
{
/// The default constructor does nothing (for performance).
b2Mat33() {}
@@ -282,7 +284,7 @@ struct b2Mat33
};
/// Rotation
struct b2Rot
struct B2_API b2Rot
{
b2Rot() {}
@@ -333,7 +335,7 @@ struct b2Rot
/// A transform contains translation and rotation. It is used to represent
/// the position and orientation of rigid frames.
struct b2Transform
struct B2_API b2Transform
{
/// The default constructor does nothing.
b2Transform() {}
@@ -363,7 +365,7 @@ struct b2Transform
/// Shapes are defined with respect to the body origin, which may
/// no coincide with the center of mass. However, to support dynamics
/// we must interpolate the center of mass position.
struct b2Sweep
struct B2_API b2Sweep
{
/// Get the interpolated transform at a specific time.
/// @param transform the output transform
@@ -387,7 +389,7 @@ struct b2Sweep
};
/// Useful constant
extern const b2Vec2 b2Vec2_zero;
extern B2_API const b2Vec2 b2Vec2_zero;
/// Perform the dot product on two vectors.
inline float b2Dot(const b2Vec2& a, const b2Vec2& b)
@@ -681,10 +683,11 @@ inline bool b2IsPowerOfTwo(uint32 x)
return result;
}
// https://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
inline void b2Sweep::GetTransform(b2Transform* xf, float beta) const
{
xf->p = c0 + beta * (c - c0);
float angle = a0 + beta * (a - a0);
xf->p = (1.0f - beta) * c0 + beta * c;
float angle = (1.0f - beta) * a0 + beta * a;
xf->q.Set(angle);
// Shift to origin