Xna 像 photoshop 转换工具一样转换 2d 纹理 [英] Xna transform a 2d texture like photoshop transforming tool

查看:29
本文介绍了Xna 像 photoshop 转换工具一样转换 2d 纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 XNA 4 上创建与 Photoshop 相同的转换效果:变换工具通常用于缩放、旋转、倾斜和扭曲您正在处理的任何图形的透视图

I want to create the same transforming effect on XNA 4 as Photoshop does: Transform tool is used to scale, rotate, skew, and just distort the perspective of any graphic you’re working with in general

这就是我想在 XNA 中使用任何纹理做的所有事情 http://www.tutorial9.net/tutorials/photoshop-tutorials/using-transform-in-photoshop/

This is what all the things i want to do in XNA with any textures http://www.tutorial9.net/tutorials/photoshop-tutorials/using-transform-in-photoshop/

倾斜:倾斜变换使对象垂直或水平倾斜.扭曲:扭曲变换允许您在任何方向上自由拉伸图像.透视:透视变换允许您为对象添加透视.扭曲对象(我最感兴趣).

Skew: Skew transformations slant objects either vertically or horizontally. Distort: Distort transformations allow you to stretch an image in ANY direction freely. Perspective: The Perspective transformation allows you to add perspective to an object. Warping an Object(Im interesting the most).

希望你能帮助我一些教程或一些已经制作的东西:D,我认为顶点有解决方案,但也许.

Hope you can help me with some tutorial or somwthing already made :D, iam think vertex has the solution but maybe.

谢谢.

推荐答案

可能在 XNA 中最简单的方法是将 Matrix 传递给 SpriteBatch.Begin.这是您要使用的重载:MSDN(transformMatrix 参数).

Probably the easiest way to do this in XNA is to pass a Matrix to SpriteBatch.Begin. This is the overload you want to use: MSDN (the transformMatrix argument).

您也可以对原始顶点执行此操作,通过设置其 World 矩阵,具有类似 BasicEffect 的效果.或者通过手动设置顶点位置,也许用 Vector3.Transform() 来转换它们.

You can also do this with raw vertices, with an effect like BasicEffect by setting its World matrix. Or by setting vertex positions manually, perhaps transforming them with Vector3.Transform().

您需要的大多数变换矩阵都由 Matrix.Create*() 方法提供 (MSDN).例如,CreateScaleCreateRotationZ.

Most of the transformation matrices you want are provided by the Matrix.Create*() methods (MSDN). For example, CreateScale and CreateRotationZ.

没有提供创建偏斜矩阵的方法.应该是这样的:

There is no provided method for creating a skew matrix. It should be something like this:

Matrix skew = Matrix.Identity;
skew.M12 = (float)Math.Tan(MathHelper.ToRadians(36.87f));

(即倾斜 36.87f 度,这是我摘下的我的这个旧答案.你应该能够通过 Google 找到倾斜矩阵的完整数学.)

(That is to skew by 36.87f degrees, which I pulled off this old answer of mine. You should be able to find the full maths for a skew matrix via Google.)

请记住,变换发生在世界空间 (0,0) 的原点附近.例如,如果您想围绕精灵的中心进行缩放,则需要将该精灵的中心平移到原点,应用缩放,然后再将其平移回来.您可以通过相乘来组合矩阵变换.此示例(未经测试)将围绕其中心缩放 200x200 图像:

Remember that transformations happen around the origin of world space (0,0). If you want to, for example, scale around the centre of your sprite, you need to translate that sprite's centre to the origin, apply a scale, and then translate it back again. You can combine matrix transforms by multiplying them. This example (untested) will scale a 200x200 image around its centre:

Matrix myMatrix = Matrix.CreateTranslation(-100, -100, 0)
                * Matrix.CreateScale(2f, 0.5f, 1f)
                * Matrix.CreateTranslation(100, 100, 0);

注意:避免将 Z 轴缩放为 0,即使在 2D 中也是如此.

Note: avoid scaling the Z axis to 0, even in 2D.

对于透视,有CreatePerspective.这将创建一个 projection 矩阵,它是一种特定类型的矩阵,用于将 3D 场景投影到 2D 显示器上,因此在设置(例如)BasicEffect.Projection.在这种情况下,您最好进行适当的 3D 渲染.

For perspective there is CreatePerspective. This creates a projection matrix, which is a specific kind of matrix for projecting a 3D scene onto a 2D display, so it is better used with vertices when setting (for example) BasicEffect.Projection. In this case you're best off doing proper 3D rendering.

对于扭曲,只需使用顶点并将它们手动放置在您需要的任何位置.

For distort, just use vertices and place them manually wherever you need them.

这篇关于Xna 像 photoshop 转换工具一样转换 2d 纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆