Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update b2_common.h #1

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ settings.ini
CMakeSettings.json
out/
.vs/
*.os
2 changes: 1 addition & 1 deletion include/box2d/b2_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#endif

#define B2_NOT_USED(x) ((void)(x))
#define b2Assert(A) assert(A)
#define b2Assert(A) ((void)(A))

#define b2_maxFloat FLT_MAX
#define b2_epsilon FLT_EPSILON
Expand Down
4 changes: 2 additions & 2 deletions include/box2d/b2_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ struct B2_API b2Filter
}

/// The collision category bits. Normally you would just set one bit.
uint16 categoryBits;
uint32 categoryBits;

/// The collision mask bits. This states the categories that this
/// shape would accept for collision.
uint16 maskBits;
uint32 maskBits;

/// Collision groups allow a certain group of objects to never collide (negative)
/// or always collide (positive). Zero means no collision group. Non-zero group
Expand Down
7 changes: 7 additions & 0 deletions include/box2d/b2_joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class B2_API b2Joint
/// the flag is only checked when fixture AABBs begin to overlap.
bool GetCollideConnected() const;

void SetCollideConnected(bool collideConnected);

/// Dump this joint to the log file.
virtual void Dump() { b2Dump("// Dump is not supported for this joint type.\n"); }

Expand Down Expand Up @@ -230,4 +232,9 @@ inline bool b2Joint::GetCollideConnected() const
return m_collideConnected;
}

inline void b2Joint::SetCollideConnected(bool collideConnected)
{
m_collideConnected = collideConnected;
}

#endif
2 changes: 1 addition & 1 deletion include/box2d/b2_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct B2_API b2Vec2
float Normalize()
{
float length = Length();
if (length < b2_epsilon)
if (length == 0.0)
{
return 0.0f;
}
Expand Down
1 change: 0 additions & 1 deletion src/collision/b2_chain_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void b2ChainShape::CreateLoop(const b2Vec2* vertices, int32 count)
b2Vec2 v1 = vertices[i-1];
b2Vec2 v2 = vertices[i];
// If the code crashes here, it means your vertices are too close together.
b2Assert(b2DistanceSquared(v1, v2) > b2_linearSlop * b2_linearSlop);
}

m_count = count + 1;
Expand Down
5 changes: 2 additions & 3 deletions src/collision/b2_polygon_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static b2Vec2 ComputeCentroid(const b2Vec2* vs, int32 count)
}

// Centroid
b2Assert(area > b2_epsilon);
b2Assert(area != 0);
c = (1.0f / area) * c + s;
return c;
}
Expand Down Expand Up @@ -155,7 +155,6 @@ void b2PolygonShape::Set(const b2Hull& hull)
int32 i1 = i;
int32 i2 = i + 1 < m_count ? i + 1 : 0;
b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
b2Assert(edge.LengthSquared() > b2_epsilon * b2_epsilon);
m_normals[i] = b2Cross(edge, 1.0f);
m_normals[i].Normalize();
}
Expand Down Expand Up @@ -336,7 +335,7 @@ void b2PolygonShape::ComputeMass(b2MassData* massData, float density) const
massData->mass = density * area;

// Center of mass
b2Assert(area > b2_epsilon);
b2Assert(area != 0.0);
center *= 1.0f / area;
massData->center = center + s;

Expand Down
30 changes: 0 additions & 30 deletions src/dynamics/b2_island.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,21 +284,6 @@ void b2Island::Solve(b2Profile* profile, const b2TimeStep& step, const b2Vec2& g
b2Vec2 v = m_velocities[i].v;
float w = m_velocities[i].w;

// Check for large velocities
b2Vec2 translation = h * v;
if (b2Dot(translation, translation) > b2_maxTranslationSquared)
{
float ratio = b2_maxTranslation / translation.Length();
v *= ratio;
}

float rotation = h * w;
if (rotation * rotation > b2_maxRotationSquared)
{
float ratio = b2_maxRotation / b2Abs(rotation);
w *= ratio;
}

// Integrate
c += h * v;
a += h * w;
Expand Down Expand Up @@ -482,21 +467,6 @@ void b2Island::SolveTOI(const b2TimeStep& subStep, int32 toiIndexA, int32 toiInd
b2Vec2 v = m_velocities[i].v;
float w = m_velocities[i].w;

// Check for large velocities
b2Vec2 translation = h * v;
if (b2Dot(translation, translation) > b2_maxTranslationSquared)
{
float ratio = b2_maxTranslation / translation.Length();
v *= ratio;
}

float rotation = h * w;
if (rotation * rotation > b2_maxRotationSquared)
{
float ratio = b2_maxRotation / b2Abs(rotation);
w *= ratio;
}

// Integrate
c += h * v;
a += h * w;
Expand Down