小编Mat*_*ttB的帖子

XNA/Monogame,绘制多个剪切/倾斜精灵的最快方法

我通常SpriteBatch在XNA/Monogame中使用2D游戏,并且最近刚刚研究DrawUserIndexedPrimatives过诸如此类的3D绘图方法.我正在开展一个项目,我们的动画师希望能够剪切精灵和纹理.

有了SpriteBatch你可以在一个矩阵传递SpriteBatch开始剪切的对象.就像是:

//translate object to origin
Matrix translate1 = Matrix.CreateTranslation(-rectangle.X, -rectangle.Y, 0);

//skew the sprite 33 degrees on the X and Y axis
Matrix skew = Matrix.Identity;
skew.M12 = (float)Math.Tan(33 * 0.0174532925f);
skew.M21 = (float)Math.Tan(33 * 0.0174532925f);

//translate object back
Matrix translate2 = Matrix.CreateTranslation(rectangle.X, rectangle.Y, 0);
Matrix transform = translate1 * skew * translate2;

_spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied,
                    SamplerState.PointWrap, DepthStencilState.Default,
                    RasterizerState.CullCounterClockwise, null, transform);
_spriteBatch.Draw(_texture, rectangle, Color.White);
_spriteBatch.End();
Run Code Online (Sandbox Code Playgroud)

明显的缺点是它需要你SpriteBatch为每个剪切的精灵进行一个新的开始和结束调用.我们目前只需要2个电话即可SpriteBatch开始游戏.一个用于UI,一个用于世界的东西.我们的艺术家想要使用剪切来做摇晃的树木或动物的腿和四肢的动物,所以如果我们给他们选择,我可以看到这个数字跳到10多个不同的批次.

平均水平有大约250个元素,每个元素包含10-20个精灵.

我已经为Android编写了一个测试,调用1000个精灵.没有任何偏斜,它可以在大约11秒或大约53fps中绘制所有1000,600次.但是,如果我倾斜每十个精灵(增加100个新的 …

3d xna drawing monogame spritebatch

7
推荐指数
1
解决办法
2817
查看次数

利用旋转卡尺在XNA中寻找凸壳的定向边界框

也许这更像是一个数学问题,而不是编程问题,但我一直在尝试在XNA中实现旋转卡尺算法.

我在维基百科上详细介绍了使用单调链从我的点集推导出一个凸包.

现在,我正在尝试对我的算法进行建模,以便在找到OBB之后找到OBB:http: //www.cs.purdue.edu/research/technical_reports/1983/TR%2083-463.pdf

但是,我不明白它在最终页面上提到的DOTPR和CROSSPR方法应该返回什么.

我知道如何获得两点的Dot Product和两点的Cross Product,但似乎这些函数应该返回两个边/线段的Dot和Cross Products.我的数学知识无疑是有限的,但这是我对算法所寻求的最佳猜测

    public static float PolygonCross(List<Vector2> polygon, int indexA, int indexB)
    {
        var segmentA1 = NextVertice(indexA, polygon) - polygon[indexA];
        var segmentB1 = NextVertice(indexB, polygon) - polygon[indexB];

        float crossProduct1 = CrossProduct(segmentA1, segmentB1);
        return crossProduct1;
    }

    public static float CrossProduct(Vector2 v1, Vector2 v2)
    {
        return (v1.X * v2.Y - v1.Y * v2.X);
    }

    public static float PolygonDot(List<Vector2> polygon, int indexA, int indexB)
    {
        var segmentA1 = NextVertice(indexA, polygon) - polygon[indexA];
        var segmentB1 = …
Run Code Online (Sandbox Code Playgroud)

xna rotation bounding-box convex computational-geometry

6
推荐指数
1
解决办法
1560
查看次数