コード例 #1
0
        public override void initialize()
        {
            base.initialize();

            var data = new uint[_subtexture.sourceRect.Width * _subtexture.sourceRect.Height];

            _subtexture.texture2D.GetData(0, _subtexture.sourceRect, data, 0, data.Length);

            var verts = PolygonTools.createPolygonFromTextureData(data, _subtexture.sourceRect.Width);

            verts = SimplifyTools.douglasPeuckerSimplify(verts, 2);

            var decomposedVerts = Triangulate.convexPartition(verts, TriangulationAlgorithm.Bayazit);

            for (var i = 0; i < decomposedVerts.Count; i++)
            {
                var polygon = decomposedVerts[i];
                polygon.translate(-_subtexture.center);
            }

            // add the fixtures
            var fixtures = body.attachCompoundPolygon(decomposedVerts, 1);

            // fetch all the Vertices and save a copy in case we need to scale them later
            foreach (var fixture in fixtures)
            {
                _verts.Add(new Vertices((fixture.shape as PolygonShape).vertices));
            }
        }