Skip to content

Commit

Permalink
joint hot-cold split
Browse files Browse the repository at this point in the history
body disable wip
  • Loading branch information
erincatto committed Apr 14, 2024
1 parent d976ef4 commit ef39d4c
Show file tree
Hide file tree
Showing 24 changed files with 522 additions and 479 deletions.
14 changes: 7 additions & 7 deletions samples/sample_joints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ class Cantilever : public Sample
e_count = 8
};

Cantilever(Settings& settings)
explicit Cantilever(Settings& settings)
: Sample(settings)
{
if (settings.restart == false)
Expand Down Expand Up @@ -1017,11 +1017,13 @@ class Cantilever : public Sample

b2WeldJointDef jointDef = b2DefaultWeldJointDef();

b2BodyDef bodyDef = b2DefaultBodyDef();
bodyDef.type = b2_dynamicBody;
bodyDef.isAwake = false;

b2BodyId prevBodyId = groundId;
for (int32_t i = 0; i < e_count; ++i)
{
b2BodyDef bodyDef = b2DefaultBodyDef();
bodyDef.type = b2_dynamicBody;
bodyDef.position = {(1.0f + 2.0f * i) * hx, 0.0f};
m_bodyIds[i] = b2CreateBody(m_worldId, &bodyDef);
b2CreateCapsuleShape(m_bodyIds[i], &shapeDef, &capsule);
Expand Down Expand Up @@ -1138,7 +1140,7 @@ class FixedRotation : public Sample
e_count = 6
};

FixedRotation(Settings& settings)
explicit FixedRotation(Settings& settings)
: Sample(settings)
{
if (settings.restart == false)
Expand Down Expand Up @@ -1180,7 +1182,6 @@ class FixedRotation : public Sample
b2Vec2 position = {-12.5f, 10.0f};
b2BodyDef bodyDef = b2DefaultBodyDef();
bodyDef.type = b2_dynamicBody;
bodyDef.enableSleep = false;
bodyDef.fixedRotation = m_fixedRotation;

b2Polygon box = b2MakeBox(1.0f, 1.0f);
Expand Down Expand Up @@ -1221,13 +1222,12 @@ class FixedRotation : public Sample
b2ShapeDef shapeDef = b2DefaultShapeDef();
b2CreatePolygonShape(m_bodyIds[index], &shapeDef, &box);

b2Vec2 pivot = {position.x - 1.0f, position.y};
b2MotorJointDef jointDef = b2DefaultMotorJointDef();
jointDef.bodyIdA = m_groundId;
jointDef.bodyIdB = m_bodyIds[index];
jointDef.linearOffset = position;
jointDef.maxForce = 200.0f;
jointDef.maxTorque = 200.0f;
jointDef.maxTorque = 20.0f;
m_jointIds[index] = b2CreateMotorJoint(m_worldId, &jointDef);
}

Expand Down
3 changes: 2 additions & 1 deletion src/block_array.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-FileCopyrightText: 2023 Erin Catto
// SPDX-License-Identifier: MIT

#include "block_allocator.h"
#include "block_array.h"

#include "block_allocator.h"
#include "body.h"
#include "contact.h"
#include "core.h"
#include "island.h"
#include "joint.h"

Expand Down
1 change: 1 addition & 0 deletions src/block_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ b2IslandSim* b2AddIsland(b2BlockAllocator* allocator, b2IslandArray* array);
b2Joint* b2AddJoint(b2BlockAllocator* allocator, b2JointArray* array);

// Returns the index of the element moved into the empty slot (or B2_NULL_INDEX)
// todo have these return the id directly?
int b2RemoveBodySim(b2BodySimArray* array, int index);
int b2RemoveBodyState(b2BodyStateArray* array, int index);
int b2RemoveContact(b2ContactArray* array, int index);
Expand Down
Loading

0 comments on commit ef39d4c

Please sign in to comment.