@@ -1040,3 +1040,72 @@ class SetVelocity : public Sample
1040
1040
};
1041
1041
1042
1042
static int sampleSetVelocity = RegisterSample( " Bodies" , " Set Velocity" , SetVelocity::Create );
1043
+
1044
+ class WakeTouching : public Sample
1045
+ {
1046
+ public:
1047
+ explicit WakeTouching ( SampleContext* context )
1048
+ : Sample( context )
1049
+ {
1050
+ if ( m_context->restart == false )
1051
+ {
1052
+ m_context->camera .m_center = { 0 .0f , 4 .0f };
1053
+ m_context->camera .m_zoom = 8 .0f ;
1054
+ }
1055
+
1056
+ {
1057
+ b2BodyDef bodyDef = b2DefaultBodyDef ();
1058
+ m_groundId = b2CreateBody ( m_worldId, &bodyDef );
1059
+
1060
+ b2Segment segment = { { -20 .0f , 0 .0f }, { 20 .0f , 0 .0f } };
1061
+ b2ShapeDef shapeDef = b2DefaultShapeDef ();
1062
+ b2CreateSegmentShape ( m_groundId, &shapeDef, &segment );
1063
+ }
1064
+
1065
+ b2Polygon box = b2MakeBox ( 0 .5f , 0 .5f );
1066
+
1067
+ b2ShapeDef shapeDef = b2DefaultShapeDef ();
1068
+ shapeDef.density = 1 .0f ;
1069
+
1070
+ b2BodyDef bodyDef = b2DefaultBodyDef ();
1071
+ bodyDef.type = b2_dynamicBody;
1072
+
1073
+ float x = -1 .0f * ( m_count - 1 );
1074
+
1075
+ for ( int i = 0 ; i < m_count; ++i )
1076
+ {
1077
+ bodyDef.position = { x, 4 .0f };
1078
+ b2BodyId bodyId = b2CreateBody ( m_worldId, &bodyDef );
1079
+ b2CreatePolygonShape ( bodyId, &shapeDef, &box );
1080
+ x += 2 .0f ;
1081
+ }
1082
+ }
1083
+
1084
+ void UpdateGui () override
1085
+ {
1086
+ float fontSize = ImGui::GetFontSize ();
1087
+ float height = 5 .0f * fontSize;
1088
+ ImGui::SetNextWindowPos ( ImVec2 ( 0 .5f * fontSize, m_camera->m_height - height - 2 .0f * fontSize ), ImGuiCond_Once );
1089
+ ImGui::SetNextWindowSize ( ImVec2 ( 10 .0f * fontSize, height ) );
1090
+
1091
+ ImGui::Begin ( " Wake Touching" , nullptr , ImGuiWindowFlags_NoResize );
1092
+
1093
+ if ( ImGui::Button ( " Wake Touching" ) )
1094
+ {
1095
+ b2Body_WakeTouching ( m_groundId );
1096
+ }
1097
+
1098
+ ImGui::End ();
1099
+ }
1100
+
1101
+ static Sample* Create ( SampleContext* context )
1102
+ {
1103
+ return new WakeTouching ( context );
1104
+ }
1105
+
1106
+ static constexpr int m_count = 10 ;
1107
+
1108
+ b2BodyId m_groundId;
1109
+ };
1110
+
1111
+ static int sampleWakeTouching = RegisterSample( " Bodies" , " Wake Touching" , WakeTouching::Create );
0 commit comments