diff --git a/samples/sample_events.cpp b/samples/sample_events.cpp index 0aba06695..4cffd5e13 100644 --- a/samples/sample_events.cpp +++ b/samples/sample_events.cpp @@ -400,7 +400,7 @@ class SensorBookend : public Sample void UpdateUI() override { - float height = 90.0f; + float height = 160.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); ImGui::SetNextWindowSize( ImVec2( 140.0f, height ) ); @@ -421,6 +421,18 @@ class SensorBookend : public Sample m_visitorBodyId = b2_nullBodyId; m_visitorShapeId = b2_nullShapeId; } + else + { + bool enabled = b2Body_IsEnabled( m_visitorBodyId ); + if ( enabled == true && ImGui::Button( "disable visitor" ) ) + { + b2Body_Disable( m_visitorBodyId ); + } + else if ( enabled == false && ImGui::Button( "enable visitor" ) ) + { + b2Body_Enable( m_visitorBodyId ); + } + } } if ( B2_IS_NULL( m_sensorBodyId ) ) @@ -438,6 +450,18 @@ class SensorBookend : public Sample m_sensorBodyId = b2_nullBodyId; m_sensorShapeId = b2_nullShapeId; } + else + { + bool enabled = b2Body_IsEnabled( m_sensorBodyId ); + if ( enabled == true && ImGui::Button( "disable sensor" ) ) + { + b2Body_Disable( m_sensorBodyId ); + } + else if ( enabled == false && ImGui::Button( "enable sensor" ) ) + { + b2Body_Enable( m_sensorBodyId ); + } + } } ImGui::End(); @@ -1360,6 +1384,7 @@ class BodyMove : public Sample for ( int32_t i = 0; i < 10 && m_count < e_count; ++i ) { bodyDef.position = { x, y }; + bodyDef.isBullet = (m_count % 12 == 0); bodyDef.userData = m_bodyIds + m_count; m_bodyIds[m_count] = b2CreateBody( m_worldId, &bodyDef ); m_sleeping[m_count] = false; @@ -1466,8 +1491,8 @@ class BodyMove : public Sample return new BodyMove( settings ); } - b2BodyId m_bodyIds[e_count]; - bool m_sleeping[e_count]; + b2BodyId m_bodyIds[e_count] = {}; + bool m_sleeping[e_count] = {}; int m_count; int m_sleepCount; b2Vec2 m_explosionPosition; diff --git a/src/sensor.c b/src/sensor.c index 8b66b6f6e..cb936e2ea 100644 --- a/src/sensor.c +++ b/src/sensor.c @@ -146,7 +146,17 @@ static void b2SensorTask( int startIndex, int endIndex, uint32_t threadIndex, vo sensor->overlaps2 = temp; b2ShapeRefArray_Clear( &sensor->overlaps2 ); - b2Transform transform = b2GetBodyTransform( world, sensorShape->bodyId ); + b2Body* body = b2BodyArray_Get( &world->bodies, sensorShape->bodyId ); + if (body->setIndex == b2_disabledSet) + { + if (sensor->overlaps1.count != 0) + { + b2SetBit( &taskContext->eventBits, sensorIndex ); + } + continue; + } + + b2Transform transform = b2GetBodyTransformQuick( world, body ); struct b2SensorQueryContext queryContext = { .world = world,