1+ using static Box2D . NET . B2Worlds ;
2+ using static Box2D . NET . B2Types ;
3+ using static Box2D . NET . B2MathFunction ;
4+ using static Box2D . NET . B2Bodies ;
5+ using static Box2D . NET . B2Shapes ;
6+
7+ namespace Box2D . NET . Samples . Samples . Worlds ;
8+
9+ public class WorkbenchWorld : Sample
10+ {
11+ private static readonly int SampleLargeWorld = SampleFactory . Shared . RegisterSample ( "World" , "Workbench World" , Create ) ;
12+
13+ private static Sample Create ( SampleAppContext ctx , Settings settings )
14+ {
15+ return new WorkbenchWorld ( ctx , settings ) ;
16+ }
17+
18+ public WorkbenchWorld ( SampleAppContext ctx , Settings settings ) : base ( ctx , settings )
19+ {
20+ if ( settings . restart == false )
21+ {
22+ m_context . camera . m_center = new B2Vec2 ( 0.0f , 5.0f ) ;
23+ m_context . camera . m_zoom = 25.0f * 0.5f ;
24+ }
25+
26+ B2ShapeId shapeIdA = CreateCircle ( m_worldId , new B2Vec2 ( 0.0f , 0.0f ) , 1.0f ) ;
27+ B2ShapeId shapeIdB = CreateCircle ( m_worldId , new B2Vec2 ( 1.0f , 1.0f ) , 1.0f ) ;
28+ }
29+
30+ public static B2ShapeId CreateCircle ( B2WorldId worldId , B2Vec2 position , float radius )
31+ {
32+ B2BodyDef bodyDef = b2DefaultBodyDef ( ) ;
33+ bodyDef . type = B2BodyType . b2_dynamicBody ;
34+ bodyDef . position = position ;
35+ bodyDef . gravityScale = 0.0f ;
36+ var bodyIdA = b2CreateBody ( worldId , ref bodyDef ) ;
37+
38+ B2ShapeDef shapeDef = b2DefaultShapeDef ( ) ;
39+ shapeDef . density = 1.0f ;
40+ shapeDef . material . friction = 0.5f ;
41+
42+ B2Circle circle = new B2Circle ( new B2Vec2 ( 0.0f , 0.0f ) , radius ) ;
43+ B2ShapeId shapeId = b2CreateCircleShape ( bodyIdA , ref shapeDef , ref circle ) ;
44+
45+ return shapeId ;
46+ }
47+
48+ }
0 commit comments