当前位置: 首页>>代码示例>>C#>>正文


C# Body.CreateShape方法代码示例

本文整理汇总了C#中Box2DX.Dynamics.Body.CreateShape方法的典型用法代码示例。如果您正苦于以下问题:C# Body.CreateShape方法的具体用法?C# Body.CreateShape怎么用?C# Body.CreateShape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Box2DX.Dynamics.Body的用法示例。


在下文中一共展示了Body.CreateShape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DistanceTest

		public DistanceTest()
		{
			PolygonDef sd = new PolygonDef();
			sd.SetAsBox(1.0f, 1.0f);
			sd.Density = 0.0f;

			BodyDef bd = new BodyDef();
			bd.Position.Set(0.0f, 10.0f);
			_body1 = _world.CreateBody(bd);
			_shape1 = _body1.CreateShape(sd);

			PolygonDef sd2 = new PolygonDef();
			sd2.VertexCount = 3;
			sd2.Vertices[0].Set(-1.0f, 0.0f);
			sd2.Vertices[1].Set(1.0f, 0.0f);
			sd2.Vertices[2].Set(0.0f, 15.0f);
			sd2.Density = 1.0f;

			BodyDef bd2 = new BodyDef();

			bd2.Position.Set(0.0f, 10.0f);

			_body2 = _world.CreateBody(bd2);
			_shape2 = _body2.CreateShape(sd2);
			_body2.SetMassFromShapes();

			_world.Gravity = new Vec2(0.0f, 0.0f);
		}
开发者ID:colgreen,项目名称:box2dx,代码行数:28,代码来源:DistanceTest.cs

示例2: PolyCollision

		public PolyCollision()
		{
			_localPoints[0].state = ContactState.ContactRemoved;
			_localPoints[1].state = ContactState.ContactRemoved;

			{
				PolygonDef sd = new PolygonDef();
				sd.Vertices[0].Set(-9.0f, -1.1f);
				sd.Vertices[1].Set(7.0f, -1.1f);
				sd.Vertices[2].Set(5.0f, -0.9f);
				sd.Vertices[3].Set(-11.0f, -0.9f);
				sd.VertexCount = 4;
				sd.Density = 0.0f;

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, 10.0f);
				_body1 = _world.CreateBody(bd);
				_body1.CreateShape(sd);
			}

			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(0.5f, 0.5f);
				sd.Density = 1.0f;

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, 10.0f);
				_body2 = _world.CreateBody(bd);
				_body2.CreateShape(sd);
				_body2.SetMassFromShapes();
			}

			_world.Gravity = Vec2.Zero;
		}
开发者ID:colgreen,项目名称:box2dx,代码行数:34,代码来源:PolyCollision.cs

示例3: ShapeEditing

		public ShapeEditing()
		{
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(50.0f, 10.0f);

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, -10.0f);

				Body ground = _world.CreateBody(bd);
				ground.CreateShape(sd);
			}

			BodyDef bodydef = new BodyDef();
			bodydef.Position.Set(0.0f, 10.0f);
			_body = _world.CreateBody(bodydef);

			PolygonDef sd_ = new PolygonDef();
			sd_.SetAsBox(4.0f, 4.0f, new Vec2(0.0f, 0.0f), 0.0f);
			sd_.Density = 10.0f;
			_shape1 = _body.CreateShape(sd_);
			_body.SetMassFromShapes();

			_shape2 = null;
		}
开发者ID:colgreen,项目名称:box2dx,代码行数:25,代码来源:ShapeEditing.cs

示例4: TimeOfImpact

		public TimeOfImpact()
		{
			{
				PolygonDef sd = new PolygonDef();
				sd.Density = 0.0f;

				sd.SetAsBox(0.1f, 10.0f, new Vec2(10.0f, 0.0f), 0.0f);

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, 20.0f);
				bd.Angle = 0.0f;
				_body1 = _world.CreateBody(bd);
				_shape1 = _body1.CreateShape(sd);
			}

			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(0.25f, 0.25f);
				sd.Density = 1.0f;

				BodyDef bd = new BodyDef();
				bd.Position.Set(9.6363468f, 28.050615f);
				bd.Angle = 1.6408679f;
				_body2 = _world.CreateBody(bd);
				_shape2 = (PolygonShape)_body2.CreateShape(sd);
				_body2.SetMassFromShapes();
			}
		}
开发者ID:colgreen,项目名称:box2dx,代码行数:28,代码来源:TimeOfImpact.cs

示例5: RaycastTest

		public RaycastTest()
		{
			Body ground = null;
			{
				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, -10.0f);
				ground = _world.CreateBody(bd);

				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(50.0f, 10.0f);
				ground.CreateShape(sd);
			}

			{
				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, 1.0f);
				laserBody = _world.CreateBody(bd);

				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(5.0f, 1.0f);
				sd.Density = 4.0f;
				laserBody.CreateShape(sd);
				laserBody.SetMassFromShapes();

				Body body;
				//Create a few shapes
				bd.Position.Set(-5.0f, 10.0f);
				body = _world.CreateBody(bd);

				CircleDef cd = new CircleDef();
				cd.Radius = 3;
				body.CreateShape(cd);

				bd.Position.Set(5.0f, 10.0f);
				body = _world.CreateBody(bd);

				body.CreateShape(cd);
			}
		}
开发者ID:colgreen,项目名称:box2dx,代码行数:39,代码来源:RaycastTest.cs

示例6: PopulateWorld

        /// <summary>
        /// Add objects to the Box2d world.
        /// </summary>
        protected override void PopulateWorld()
        {
		// ==== Define the ground body ====
			BodyDef groundBodyDef = new BodyDef();
			groundBodyDef.Position.Set(_trackLengthHalf, -1f);

   			// Call the body factory which creates the ground box shape.
			// The body is also added to the world.
			Body groundBody = _world.CreateBody(groundBodyDef);

			// Define the ground box shape.
			PolygonDef groundShapeDef = new PolygonDef();

			// The extents are the half-widths of the box.
			groundShapeDef.SetAsBox(_trackLengthHalf + 1f, 1f);
            groundShapeDef.Friction = _simParams._defaultFriction;
            groundShapeDef.Restitution = _simParams._defaultRestitution;
            groundShapeDef.Filter.CategoryBits = 0x3;

			// Add the ground shape to the ground body.
            groundBody.CreateShape(groundShapeDef);

        // ==== Define walker torso.
            BodyDef torsoBodyDef = new BodyDef();
            torsoBodyDef.Position.Set(0f, 1.45f);
            torsoBodyDef.IsBullet = true;

            // Create walker torso.
            _torsoBody = _world.CreateBody(torsoBodyDef);
            PolygonDef torsoShapeDef = new PolygonDef();
            torsoShapeDef.SetAsBox(0.10f, 0.45f);
            torsoShapeDef.Friction = _simParams._defaultFriction;
            torsoShapeDef.Restitution = 0f;
            torsoShapeDef.Density = 2f;
            torsoShapeDef.Filter.CategoryBits = 0x2;
            _torsoBody.CreateShape(torsoShapeDef);
            _torsoBody.SetMassFromShapes();

        // ===== Create legs.
            // Leg joint definition.
            RevoluteJointDef jointDef = new RevoluteJointDef();
            jointDef.CollideConnected = false;
            jointDef.EnableMotor = true;
            jointDef.MaxMotorTorque = 0f;

            // Other re-usable stuff .
            const float legRadius = 0.05f;	// Half the thickness of the leg
            Vec2 upperLegPosBase = new Vec2(0f, 1.05f);
            Vec2 lowerLegPosBase = new Vec2(0f, 0.55f);

        // ===== Create left leg.
            // Upper leg.
            Body upperLeftLegBody = CreatePole(upperLegPosBase, 0.5f, (float)SysMath.PI, legRadius, 2f, 0x1);
            // Join to torso (hip joint)
            jointDef.Initialize(_torsoBody, upperLeftLegBody, upperLegPosBase);
            _leftHipJoint = (RevoluteJoint)_world.CreateJoint(jointDef);

            // Lower leg.
            _leftLowerLegBody = CreatePole(lowerLegPosBase, __lowerLegLength, (float)SysMath.PI, legRadius, 2f, 0x1);
            // Join to upper leg (knee joint)
            jointDef.Initialize(upperLeftLegBody, _leftLowerLegBody, lowerLegPosBase);
            _leftKneeJoint = (RevoluteJoint)_world.CreateJoint(jointDef);

        // ===== Create right leg.
            // Upper leg.
            Body upperRightLegBody = CreatePole(upperLegPosBase, 0.5f, (float)SysMath.PI, legRadius, 2f, 0x1);
            // Join to torso (hip joint)
            jointDef.Initialize(_torsoBody, upperRightLegBody, upperLegPosBase);
            _rightHipJoint = (RevoluteJoint)_world.CreateJoint(jointDef);

            // Lower leg.
            _rightLowerLegBody = CreatePole(lowerLegPosBase, __lowerLegLength, (float)SysMath.PI, legRadius, 2f, 0x1);
            // Join to upper leg (knee joint)
            jointDef.Initialize(upperRightLegBody, _rightLowerLegBody, lowerLegPosBase);
            _rightKneeJoint = (RevoluteJoint)_world.CreateJoint(jointDef);
        }
开发者ID:MrChocolateMoose,项目名称:DeepHyperNEAT,代码行数:79,代码来源:WalkerWorld.cs

示例7: AddToWorld

        public void AddToWorld()
        {
            body = world.CreateBody(bodyDef);
            foreach (ShapeDef shape in shapes)
                body.CreateShape(shape);
            body.SetMassFromShapes();
            body.SetUserData(this);

            foreach (Controller controller in controllers)
            {
                controller.AddBody(body);
                world.AddController(controller);
            }

            foreach (PhysicsObject child in children)
                child.AddToWorld();
        }
开发者ID:danielpcox,项目名称:Crisis-at-Swiss-Station,代码行数:17,代码来源:PhysicsObject.cs

示例8: LoadContent

        protected override void LoadContent()
        {
            poligonDef = new PolygonDef();

            poligonDef.VertexCount = CollisionBody.Length;

            poligonDef.Vertices = CollisionBody;

            poligonDef.Density = 2000f;

            poligonDef.Friction = 100f;

            BodyDef bodyDef = new BodyDef();

            bodyDef.Position = new Vec2(Position.X, Position.Y);

            Body = Game1.world.CreateBody(bodyDef);

            PolygonShape shape = (PolygonShape)Body.CreateShape(poligonDef);

            Body.SetMassFromShapes();

            base.LoadContent();
        }
开发者ID:RadekBednar,项目名称:RacingGame,代码行数:24,代码来源:Object.cs

示例9: ElasticBody

		// Main...
		public ElasticBody()
		{
			// Bottom static body
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(50.0f, 2.0f);
				sd.Friction = 0.1f;
				sd.Restitution = 0.1f;
				BodyDef bd = new BodyDef();
				bd.Position.Set(-1.0f, -7.5f);
				_ground = _world.CreateBody(bd);
				_ground.CreateShape(sd);
			}
			// Upper static body
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(20.0f, 0.50f, new Vec2(0.0f, 0.0f), 0.047f * Box2DX.Common.Settings.Pi);
				sd.Friction = 0.01f;
				sd.Restitution = 0.001f;
				BodyDef bd = new BodyDef();
				bd.Position.Set(-20.0f, 93.0f);
				Body g = _world.CreateBody(bd);
				g.CreateShape(sd);
				sd.SetAsBox(15.0f, 0.50f, new Vec2(-15.0f, 12.5f), 0.0f);
				g.CreateShape(sd);

				sd.SetAsBox(20.0f, 0.5f, new Vec2(0.0f, -25.0f), -0.5f);
				g.CreateShape(sd);
			}
			// Left channel left wall
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(0.7f, 55.0f);
				sd.Friction = 0.1f;
				sd.Restitution = 0.1f;
				BodyDef bd = new BodyDef();
				bd.Position.Set(-49.3f, 50.0f);
				Body g = _world.CreateBody(bd);
				g.CreateShape(sd);
			}
			// Right wall
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(0.7f, 55.0f);
				sd.Friction = 0.1f;
				sd.Restitution = 0.1f;
				BodyDef bd = new BodyDef();
				bd.Position.Set(45.0f, 50.0f);
				Body g = _world.CreateBody(bd);
				g.CreateShape(sd);
			}
			// Left channel right upper wall  
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(0.5f, 20.0f);
				sd.Friction = 0.05f;
				sd.Restitution = 0.01f;
				BodyDef bd = new BodyDef();
				bd.Position.Set(-42.0f, 70.0f);
				bd.Angle = -0.03f * Box2DX.Common.Settings.Pi;
				Body g = _world.CreateBody(bd);
				g.CreateShape(sd);
			}
			// Left channel right lower wall
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(0.50f, 23.0f);
				sd.Friction = 0.05f;
				sd.Restitution = 0.01f;
				BodyDef bd = new BodyDef();
				bd.Position.Set(-44.0f, 27.0f);
				Body g = _world.CreateBody(bd);
				g.CreateShape(sd);
				// Bottom motors
				CircleDef cd = new CircleDef();
				cd.Radius = 3.0f;
				cd.Density = 15.0f;
				cd.Friction = 1.0f;
				cd.Restitution = 0.2f;
				// 1. 
				bd.Position.Set(-40.0f, 2.5f);
				Body body = _world.CreateBody(bd);
				body.CreateShape(cd);
				body.SetMassFromShapes();
				RevoluteJointDef jr = new RevoluteJointDef();
				jr.Initialize(g, body, body.GetWorldCenter() + new Vec2(0.0f, 1.0f));
				jr.MaxMotorTorque = 30000.0f;
				jr.EnableMotor = true;
				jr.MotorSpeed = 20.0f;
				_world.CreateJoint(jr);
				// 1. left down
				bd.Position.Set(-46.0f, -2.5f);
				cd.Radius = 1.5f; jr.MotorSpeed = -20.0f;
				body = _world.CreateBody(bd);
				body.CreateShape(cd);
				sd.SetAsBox(2.0f, 0.50f);
				body.CreateShape(sd);
				body.SetMassFromShapes();
				jr.Initialize(g, body, body.GetWorldCenter());
//.........这里部分代码省略.........
开发者ID:colgreen,项目名称:box2dx,代码行数:101,代码来源:ElasticBody.cs

示例10: TheoJansen

		public TheoJansen()
		{
			_offset.Set(0.0f, 8.0f);
			_motorSpeed = 2.0f;
			_motorOn = true;
			Vec2 pivot = new Vec2(0.0f, 0.8f);

			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(50.0f, 10.0f);

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, -10.0f);
				Body ground = _world.CreateBody(bd);
				ground.CreateShape(sd);

				sd.SetAsBox(0.5f, 5.0f, new Vec2(-50.0f, 15.0f), 0.0f);
				ground.CreateShape(sd);

				sd.SetAsBox(0.5f, 5.0f, new Vec2(50.0f, 15.0f), 0.0f);
				ground.CreateShape(sd);
			}

			for (int i = 0; i < 40; ++i)
			{
				CircleDef sd = new CircleDef();
				sd.Density = 1.0f;
				sd.Radius = 0.25f;

				BodyDef bd = new BodyDef();
				bd.Position.Set(-40.0f + 2.0f * i, 0.5f);

				Body body = _world.CreateBody(bd);
				body.CreateShape(sd);
				body.SetMassFromShapes();
			}

			{
				PolygonDef sd = new PolygonDef();
				sd.Density = 1.0f;
				sd.SetAsBox(2.5f, 1.0f);
				sd.Filter.GroupIndex = -1;
				BodyDef bd = new BodyDef();
				bd.Position = pivot + _offset;
				_chassis = _world.CreateBody(bd);
				_chassis.CreateShape(sd);
				_chassis.SetMassFromShapes();
			}

			{
				CircleDef sd = new CircleDef();
				sd.Density = 1.0f;
				sd.Radius = 1.6f;
				sd.Filter.GroupIndex = -1;
				BodyDef bd = new BodyDef();
				bd.Position = pivot + _offset;
				_wheel = _world.CreateBody(bd);
				_wheel.CreateShape(sd);
				_wheel.SetMassFromShapes();
			}

			{
				RevoluteJointDef jd = new RevoluteJointDef();
				jd.Initialize(_wheel, _chassis, pivot + _offset);
				jd.CollideConnected = false;
				jd.MotorSpeed = _motorSpeed;
				jd.MaxMotorTorque = 400.0f;
				jd.EnableMotor = _motorOn;
				_motorJoint = (RevoluteJoint)_world.CreateJoint(jd);
			}

			Vec2 wheelAnchor;
			
			wheelAnchor = pivot + new Vec2(0.0f, -0.8f);

			CreateLeg(-1.0f, wheelAnchor);
			CreateLeg(1.0f, wheelAnchor);

			_wheel.SetXForm(_wheel.GetPosition(), 120.0f * Box2DX.Common.Settings.Pi / 180.0f);
			CreateLeg(-1.0f, wheelAnchor);
			CreateLeg(1.0f, wheelAnchor);

			_wheel.SetXForm(_wheel.GetPosition(), -120.0f * Box2DX.Common.Settings.Pi / 180.0f);
			CreateLeg(-1.0f, wheelAnchor);
			CreateLeg(1.0f, wheelAnchor);
		}
开发者ID:colgreen,项目名称:box2dx,代码行数:86,代码来源:TheoJansen.cs

示例11: Keyboard

		public override void Keyboard(System.Windows.Forms.Keys key)
		{
			switch (key)
			{
				case System.Windows.Forms.Keys.S:
					if (_bullet != null)
					{
						_world.DestroyBody(_bullet);
						_bullet = null;
					}
					{
						CircleDef sd = new CircleDef();
						sd.Density = 20.0f;
						sd.Radius = 0.25f;
						sd.Restitution = 0.05f;

						BodyDef bd = new BodyDef();
						bd.IsBullet = true;
						bd.AllowSleep = false;
						bd.Position.Set(-31.0f, 5.0f);

						_bullet = _world.CreateBody(bd);
						_bullet.CreateShape(sd);
						_bullet.SetMassFromShapes();

						_bullet.SetLinearVelocity(new Vec2(400.0f, 0.0f));
					}
					break;
			}
		}
开发者ID:colgreen,项目名称:box2dx,代码行数:30,代码来源:VerticalStack.cs

示例12: PlayerCharacter

        public PlayerCharacter(World _world, Vector2 _position)
            : base(_world, _position)
        {
            playerIndex = playerCount++;
            color = PlayerCharacter.Colors[playerIndex];
            accelerate = 0;
            rotate = 0;

            isDead = false;

            this.angVelocity = 0;
            //build the unicycle
            CircleDef circleDef = new CircleDef();
            circleDef.Radius = 1;
            circleDef.Density = 1f;
            circleDef.Friction = 1.0f;
            circleDef.Restitution = 0.0f;
            circleDef.LocalPosition.Set(0, 0);

            wheel = body.CreateShape(circleDef);
            body.SetMassFromShapes();
            body.SetUserData(this); // link body and this to register collisions in this

            //build the head and connect with the wheel
            BodyDef bodydef = new BodyDef();
            bodydef.Position = _position + new Vector2(0.0f, 3.5f);
            bodydef.Angle = 0f;

            chest = _world.CreateBody(bodydef);

            //add the head
            circleDef.Density = 0.0001f;
            circleDef.Radius = 0.75f;
            circleDef.LocalPosition.Set(0, 3);
            head = chest.CreateShape(circleDef);

            rotationHead = _position;

            PolygonDef Boxdef = new PolygonDef();
            Boxdef.SetAsBox(1, 1.5f);
            Boxdef.Density = 0.25f;
            Boxdef.Friction = 0.4f;
            Box2DX.Collision.Shape s2 = chest.CreateShape(Boxdef);
            chest.SetMassFromShapes();
            chest.SetUserData(this);

            //Jointshit
            RevoluteJointDef jointDefKW = new RevoluteJointDef();
            jointDefKW.Body2 = chest;
            jointDefKW.Body1 = body;
            jointDefKW.CollideConnected = false;
            jointDefKW.LocalAnchor2 = new Vector2(-0.0f, -3.8f);
            jointDefKW.LocalAnchor1 = new Vector2(0, 0);
            jointDefKW.EnableLimit = false;

            _world.CreateJoint(jointDefKW);

            // add visuals
            Texture wheelTexture = AssetManager.getTexture(AssetManager.TextureName.ShoopWheel);
            wheelSprite = new AnimatedSprite(wheelTexture, 1.0f, 1, (Vector2)wheelTexture.Size);
            wheelSprite.Scale = Constants.windowScaleFactor * new Vector2(0.2f, 0.2f); //(Vector2.One / (Vector2)wheelTexture.Size * 2F * circleDef.Radius).toScreenCoord() - Vector2.Zero.toScreenCoord();//new Vector2(0.08f, 0.08f);
            wheelSprite.Origin = ((Vector2)wheelSprite.spriteSize) / 2F;

            sheepSprite = new Sprite(AssetManager.getTexture(AssetManager.TextureName.ShoopInfronUnicycle));
            sheepSprite.Origin = ((Vector2)sheepSprite.Texture.Size) / 2F;
            sheepSprite.Scale = Constants.windowScaleFactor *  new Vector2(_position.X > Constants.worldSizeX / 2F ? -0.2f : 0.2f, 0.2f);
        }
开发者ID:Gnaarf,项目名称:UnicycleSheep,代码行数:67,代码来源:PlayerCharacter.cs

示例13: InitPhysics

        public virtual void InitPhysics()
        {
            if (_physBody != null)
            {
                Log.Instance.Log("WARNING: Call to InitPhysics had no effect.  Actor has already had physics initialized.");
                return;
            }

            ShapeType shapeType = ShapeType.Box;
            Box2D.World physicsWorld = Angel.World.Instance.PhysicsWorld;

            ShapeDef shape;
            switch (shapeType)
            {
                case ShapeType.Box:
                    PolygonDef box = new PolygonDef();
                    box.SetAsBox(0.5f * Size.X, 0.5f * Size.Y);
                    shape = box;
                    break;
                case ShapeType.Circle:
                    CircleDef circle = new CircleDef();
                    circle.Radius = 0.5f * Size.X;
                    shape = circle;
                    break;
                default:
                    Log.Instance.Log("InitPhysics(): Invalid shape type given");
                    return;
            }

            shape.Density = _fDensity;
            shape.Friction = _fFriction;
            shape.Restitution = _fRestitution;
            shape.IsSensor = _bIsSensor;
            if (_iCollisionFlags != -1)
            {
                //shape->maskBits = (short)collisionFlags;
                //shape->categoryBits = (short)collisionFlags;
            }

            // InitShape( shape );

            BodyDef bodyDef = new BodyDef();
            bodyDef.UserData = this;
            bodyDef.Position = this.Position;
            bodyDef.Angle = MathHelper.ToRadians(-Rotation);
            bodyDef.FixedRotation = _bFixedRotation;

            _physBody = physicsWorld.CreateBody(bodyDef);
            _physBody.CreateShape(shape);
            _physBody.SetMassFromShapes();

            CustomInitPhysics();
        }
开发者ID:darrentorpey,项目名称:define_yourself,代码行数:53,代码来源:PhysicsActor.cs

示例14: LaunchBomb

		public void LaunchBomb()
		{
			if (_bomb != null)
			{
				_world.DestroyBody(_bomb);
				_bomb = null;
			}

			BodyDef bd = new BodyDef();
			bd.AllowSleep = true;
			bd.Position.Set(Box2DX.Common.Math.Random(-15.0f, 15.0f), 30.0f);
			bd.IsBullet = true;
			_bomb = _world.CreateBody(bd);
			_bomb.SetLinearVelocity(-5.0f * bd.Position);

			CircleDef sd = new CircleDef();
			sd.Radius = 0.3f;
			sd.Density = 20.0f;
			sd.Restitution = 0.1f;
			_bomb.CreateShape(sd);

			_bomb.SetMassFromShapes();
		}
开发者ID:colgreen,项目名称:box2dx,代码行数:23,代码来源:Test.cs

示例15: Biped

        public Biped(World w, Vec2 position)
        {
            m_world = w;

            BipedDef def = new BipedDef();
            BodyDef bd;

            // create body parts
            bd = def.LFootDef;
            bd.Position += position;
            LFoot = w.CreateBody(bd);
            LFoot.CreateShape(def.LFootPoly);
            LFoot.SetMassFromShapes();

            bd = def.RFootDef;
            bd.Position += position;
            RFoot = w.CreateBody(bd);
            RFoot.CreateShape(def.RFootPoly);
            RFoot.SetMassFromShapes();

            bd = def.LCalfDef;
            bd.Position += position;
            LCalf = w.CreateBody(bd);
            LCalf.CreateShape(def.LCalfPoly);
            LCalf.SetMassFromShapes();

            bd = def.RCalfDef;
            bd.Position += position;
            RCalf = w.CreateBody(bd);
            RCalf.CreateShape(def.RCalfPoly);
            RCalf.SetMassFromShapes();

            bd = def.LThighDef;
            bd.Position += position;
            LThigh = w.CreateBody(bd);
            LThigh.CreateShape(def.LThighPoly);
            LThigh.SetMassFromShapes();

            bd = def.RThighDef;
            bd.Position += position;
            RThigh = w.CreateBody(bd);
            RThigh.CreateShape(def.RThighPoly);
            RThigh.SetMassFromShapes();

            bd = def.PelvisDef;
            bd.Position += position;
            Pelvis = w.CreateBody(bd);
            Pelvis.CreateShape(def.PelvisPoly);
            Pelvis.SetMassFromShapes();

            bd = def.PelvisDef;
            bd.Position += position;
            Stomach = w.CreateBody(bd);
            Stomach.CreateShape(def.StomachPoly);
            Stomach.SetMassFromShapes();

            bd = def.ChestDef;
            bd.Position += position;
            Chest = w.CreateBody(bd);
            Chest.CreateShape(def.ChestPoly);
            Chest.SetMassFromShapes();

            bd = def.NeckDef;
            bd.Position += position;
            Neck = w.CreateBody(bd);
            Neck.CreateShape(def.NeckPoly);
            Neck.SetMassFromShapes();

            bd = def.HeadDef;
            bd.Position += position;
            Head = w.CreateBody(bd);
            Head.CreateShape(def.HeadCirc);
            Head.SetMassFromShapes();

            bd = def.LUpperArmDef;
            bd.Position += position;
            LUpperArm = w.CreateBody(bd);
            LUpperArm.CreateShape(def.LUpperArmPoly);
            LUpperArm.SetMassFromShapes();

            bd = def.RUpperArmDef;
            bd.Position += position;
            RUpperArm = w.CreateBody(bd);
            RUpperArm.CreateShape(def.RUpperArmPoly);
            RUpperArm.SetMassFromShapes();

            bd = def.LForearmDef;
            bd.Position += position;
            LForearm = w.CreateBody(bd);
            LForearm.CreateShape(def.LForearmPoly);
            LForearm.SetMassFromShapes();

            bd = def.RForearmDef;
            bd.Position += position;
            RForearm = w.CreateBody(bd);
            RForearm.CreateShape(def.RForearmPoly);
            RForearm.SetMassFromShapes();

            bd = def.LHandDef;
            bd.Position += position;
//.........这里部分代码省略.........
开发者ID:CaptBrick,项目名称:Playground,代码行数:101,代码来源:Biped.cs


注:本文中的Box2DX.Dynamics.Body.CreateShape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。