SetDisplayUnitToSimUnitRatio() public static method

public static SetDisplayUnitToSimUnitRatio ( float displayUnitsPerSimUnit ) : void
displayUnitsPerSimUnit float
return void
Example #1
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Font = Content.Load <SpriteFont>(@"Font");

            // Unit conversion rule to get the right position data between simulation space and display space
            ConvertUnits.SetDisplayUnitToSimUnitRatio(MeterInPixels);

            _light = new PointLight
            {
                Position   = new Vector2(-250, 0),
                Color      = new Color(50, 50, 255),
                Scale      = new Vector2(1300),
                ShadowType = ShadowType.Solid
            };
            penumbra.Lights.Add(_light);

            // Loading the texture of the physics object
            tBodyTexture = Content.Load <Texture2D>(@"object");

            // Creating the physics object
            tBody = CreateComplexBody(world, tBodyTexture, 1f);
            tBody.SleepingAllowed = false;
            tBody.Position        = ConvertUnits.ToSimUnits(new Vector2(400f, 240f));
            tBody.BodyType        = BodyType.Dynamic;
            tBody.AngularDamping  = 2f;
            tBody.Restitution     = 1f;

            // Create Hulls from the fixtures of the body
            foreach (Fixture f in tBody.FixtureList)
            {
                // Creating the Hull out of the Shape (respectively Vertices) of the fixtures of the physics body
                Hull h = new Hull(((PolygonShape)f.Shape).Vertices);

                // We need to scale the Hull according to our "MetersInPixels-Simulation-Value"
                h.Scale = new Vector2(MeterInPixels);

                // A Hull of Penumbra is set in Display space but the physics body is set in Simulation space
                // Thats why we need to convert the simulation units of the physics object to the display units
                // of the Hull object
                h.Position = ConvertUnits.ToDisplayUnits(tBody.Position);

                // We are adding the new Hull to our physics body hull list
                // This is necessary to update the Hulls in the Update method (see below)
                tBodyHull.Add(h);

                // Adding the Hull to Penumbra
                penumbra.Hulls.Add(h);
            }
        }