Bridge.cs
上传用户:gb3593
上传日期:2022-01-07
资源大小:3028k
文件大小:2k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Box2D.Net;
  5. namespace TestBed.Net.Tests
  6. {
  7.     public class Bridge : TestBed.Net.Test
  8.     {
  9.         public Bridge()
  10.         {            
  11.         Body ground;
  12.             {
  13.                 PolygonDef sd = new PolygonDef();
  14.                 sd.ShapeType = ShapeType.e_polygonShape;
  15.                 sd.SetAsBox(50.0f, 10.0f);
  16.                 BodyDef bd = new BodyDef();
  17.                 bd.Position = new Vector(0, -10);
  18.                 
  19.                 ground = world.CreateBody(bd);
  20.                 ground.CreateShape(sd);
  21.             }
  22.             {
  23.                 PolygonDef sd = new PolygonDef();
  24.                 sd.SetAsBox(0.5f, 0.125f);
  25.                 sd.Density = 20.0f;
  26.                 sd.Friction = 0.2f;
  27.                 BodyDef bd = new BodyDef();
  28.     bd.BodyType = BodyType.e_dynamicBody;
  29.                 RevoluteJointDef jd = new RevoluteJointDef();
  30.     const float numPlanks = 30;
  31.                 Body prevBody = ground;
  32.                 for (float i = 0; i < numPlanks; ++i)
  33.                 {
  34.                     bd.Position = new Vector(-14.5f + i, 5);
  35.                     Body body = world.CreateBody(bd);
  36.     body.CreateShape(sd);
  37.                     body.SetMassFromShapes();
  38.     Vector anchor = new Vector(-15 + i, 5);
  39.                     jd.Initialize(prevBody, body, anchor);
  40.                     world.CreateJoint(jd);
  41.     prevBody = body;
  42.                 }
  43.                 Vector anchor2 = new Vector(-15 + numPlanks, 5);
  44.     jd.Initialize(prevBody, ground, anchor2);
  45.     world.CreateJoint(jd);
  46.             }
  47.         }
  48.     }
  49. }