Box2DX.Dynamics.PolygonDef.SetAsBox C# (CSharp) Method

SetAsBox() public method

Build vertices to represent an axis-aligned box.
public SetAsBox ( float hx, float hy ) : void
hx float The half-width
hy float The half-height.
return void
        public void SetAsBox(float hx, float hy)
        {
            VertexCount = 4;
            Vertices[0] = new Vector2(-hx, -hy);
            Vertices[1] = new Vector2(hx, -hy);
            Vertices[2] = new Vector2(hx, hy);
            Vertices[3] = new Vector2(-hx, hy);
        }

Same methods

PolygonDef::SetAsBox ( float hx, float hy, System.Vector2 center, float angle ) : void

Usage Example

Example #1
0
		public CCDTest()
		{
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(10.0f, 0.2f);
				sd.Density = 0.0f;

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, -0.2f);
				Body body = _world.CreateBody(bd);
				body.CreateFixture(sd);

				sd.SetAsBox(0.2f, 1.0f, new Vec2(0.5f, 1.2f), 0.0f);
				body.CreateFixture(sd);
			}
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(2.0f, 0.1f);
				sd.Density = 1.0f;
				sd.Restitution = 0;

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, 20.0f);
				Body body = _world.CreateBody(bd);
				body.CreateFixture(sd);
				body.SetMassFromShapes();
				body.SetLinearVelocity(new Vec2(0.0f, -100.0f));
				body.SetAngularVelocity(Box2DX.Common.Math.Random(-50.0f, 50.0f));
			}
		}
All Usage Examples Of Box2DX.Dynamics.PolygonDef::SetAsBox