91 const float inv3 = 1.0f / 3.0f;
93 for (
int32 i = 0; i < count; ++i)
98 b2Vec2 p3 = i + 1 < count ? vs[i+1] - s : vs[0] - s;
105 float triangleArea = 0.5f * D;
106 area += triangleArea;
109 c += triangleArea * inv3 * (p1 + p2 + p3);
114 c = (1.0f / area) * c + s;
132 for (
int32 i = 0; i < n; ++i)
137 for (
int32 j = 0; j < tempCount; ++j)
167 for (
int32 i = 1; i < n; ++i)
170 if (x > x0 || (x == x0 && ps[i].y < ps[i0].y))
187 for (
int32 j = 1; j < n; ++j)
195 b2Vec2 r = ps[ie] - ps[hull[m]];
196 b2Vec2 v = ps[j] - ps[hull[m]];
230 for (
int32 i = 0; i < m; ++i)
236 for (
int32 i = 0; i < m; ++i)
239 int32 i2 = i + 1 < m ? i + 1 : 0;
243 m_normals[i].Normalize();
288 if (denominator == 0.0
f)
290 if (numerator < 0.0
f)
301 if (denominator < 0.0
f && numerator < lower * denominator)
305 lower = numerator / denominator;
308 else if (denominator > 0.0
f && numerator < upper * denominator)
312 upper = numerator / denominator;
348 lower =
b2Min(lower, v);
349 upper =
b2Max(upper, v);
393 const float k_inv3 = 1.0f / 3.0f;
403 float triangleArea = 0.5f * D;
404 area += triangleArea;
407 center += triangleArea * k_inv3 * (e1 + e2);
409 float ex1 = e1.
x, ey1 = e1.
y;
410 float ex2 = e2.
x, ey2 = e2.
y;
412 float intx2 = ex1*ex1 + ex2*ex1 + ex2*ex2;
413 float inty2 = ey1*ey1 + ey2*ey1 + ey2*ey2;
415 I += (0.25f * k_inv3 * D) * (intx2 + inty2);
419 massData->
mass = density * area;
423 center *= 1.0f / area;
424 massData->
center = center + s;
427 massData->
I = density * I;
438 int32 i2 = i < m_count - 1 ? i1 + 1 : 0;
444 if (j == i1 || j == i2)
float mass
The mass of the shape, usually in kilograms.
b2Vec2 b2Mul(const b2Mat22 &A, const b2Vec2 &v)
static b2Vec2 ComputeCentroid(const b2Vec2 *vs, int32 count)
float b2Dot(const b2Vec2 &a, const b2Vec2 &b)
Perform the dot product on two vectors.
b2Vec2 lowerBound
the lower vertex
b2Vec2 center
The position of the shape's centroid relative to the shape's origin.
void SetZero()
Set this vector to all zeros.
doubleAcc dot(const VectorAcc &lhs, const VectorAcc &rhs)
void ComputeMass(b2MassData *massData, float density) const override
bool RayCast(b2RayCastOutput *output, const b2RayCastInput &input, const b2Transform &transform, int32 childIndex) const override
float b2DistanceSquared(const b2Vec2 &a, const b2Vec2 &b)
void SetAsBox(float hx, float hy)
bool TestPoint(const b2Transform &transform, const b2Vec2 &p) const override
void * Allocate(int32 size)
Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize.
float LengthSquared() const
void ComputeAABB(b2AABB *aabb, const b2Transform &transform, int32 childIndex) const override
void Set(float x_, float y_)
Set this vector to some specified coordinates.
float b2Cross(const b2Vec2 &a, const b2Vec2 &b)
Perform the cross product on two vectors. In 2D this produces a scalar.
b2Vec2 m_vertices[b2_maxPolygonVertices]
float I
The rotational inertia of the shape about the local origin.
An axis aligned bounding box.
void Set(const b2Vec2 *points, int32 count)
b2Vec2 b2MulT(const b2Mat22 &A, const b2Vec2 &v)
int32 GetChildCount() const override
#define b2_maxPolygonVertices
b2Shape * Clone(b2BlockAllocator *allocator) const override
Implement b2Shape.
This holds the mass data computed for a shape.
b2Vec2 m_normals[b2_maxPolygonVertices]
void Set(float angle)
Set using an angle in radians.
b2Vec2 upperBound
the upper vertex