【问题标题】:Mirror Body built with vertexes in box2d and libgdx用 box2d 和 libgdx 中的顶点构建的镜体
【发布时间】:2012-03-18 06:52:14
【问题描述】:

如何在一个轴(x 或 y)上镜像一个物体的夹具,因为当我只想在一个轴上镜像它时,会发生断言错误,但是当我在两个轴上镜像它时,不会出现问题.

public Vector2[][] getPolygons(String bodyName, float scaleX, float scaleY)
{
    Vector2[][] vectors = null;

    Element fixture;
    Element semiPolygon;
    float auxX, auxY;

    this.element = reader.parse(xml);
    fixture = this.element.getChildByName(bodyName);

    vectors = new Vector2[fixture.getChildCount()][]; 
    for(int child = 0; child < fixture.getChildCount(); child++)
    {
        semiPolygon = fixture.getChild(child);
        vectors[child] = new Vector2[semiPolygon.getChildCount()];
        for(int part = 0; part < semiPolygon.getChildCount(); part++)
        {
            auxX = semiPolygon.getChild(part).getFloatAttribute("x")*-scaleX;
            auxY = semiPolygon.getChild(part).getFloatAttribute("y")*-scaleY;
            vectors[child][part] = World.toGameCoordinates(auxX, auxY);
        }
    }

    return vectors;
}

【问题讨论】:

  • 所以...断言发生在哪里?

标签: java libgdx box2d mirroring


【解决方案1】:

多边形顶点必须按逆时针顺序指定。每次镜像形状时,缠绕顺序都会颠倒,所以只有一面镜子,顺序会倒过来,然后如果你再次镜像它就可以了,正如你所发现的那样。所以如果你只镜像一个轴,你需要颠倒顶点的顺序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多