使用Direct2D将角映射到任意位置 [英] Mapping corners to arbitrary positions using Direct2D

查看:332
本文介绍了使用Direct2D将角映射到任意位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WIC和Direct2D(通过SharpDX)将照片合成为视频帧.对于每一帧,我都有可以找到每个角的确切坐标.尽管照片本身是标准的长宽比(例如4:3或16:9),但是插入点却不是,它们可以旋转,缩放和倾斜.

I'm using WIC and Direct2D (via SharpDX) to composite photos into video frames. For each frame I have the exact coordinates where each corner will be found. While the photos themselves are a standard aspect ratio (e.g. 4:3 or 16:9) the insertion points are not -- they may be rotated, scaled, and skewed.

现在我知道在Direct2D中我可以应用矩阵转换来完成此操作...但是我不确定如何做到这一点.我看到的示例更多地是关于应用特定的变换(例如旋转30度),而不是尝试匹配确切的目的地.

Now I know in Direct2D I can apply matrix transformations to accomplish this... but I'm not exactly sure how. The examples I've seen are more about applying specific transformations (e.g. rotate 30 degrees) than trying to match an exact destination.

鉴于我知道上面的确切坐标(A,B,C,D),有没有一种简单的方法可以将源图像映射到目标上?或者在给定源坐标和目标坐标的情况下,如何生成矩阵?

Given that I know the exact coordinates (A,B,C,D) above, is there an easy way to map the source image onto the target? Alternately how would I generate the matrix given the source and destination coordinates?

推荐答案

使用Direct2D确实不可能实现这一目标.带有自定义顶点着色器的Direct2D1.1(来自Win8 Metro)可能是可行的,但最后,如ananthonline所言,使用Direct3D11会更容易.

It is not really possible to achieve this with Direct2D. That could be possible with Direct2D1.1 (from Win8 Metro) with a custom vertex shader, but in the end, as ananthonline suggest, It will be much easier to do it with Direct3D11.

此外,您可以使用更易于设置的三角形带状图元(无需创建索引缓冲区).对于坐标,您可以直接将坐标发送到顶点着色器,而无需任何变换(顶点着色器会将输入SV_POSITION直接复制到像素着色器).您只需要将坐标映射为x [-1,1]和y [-1,1].建议您从SharpDX MiniCubeTexture示例开始,更改矩阵以执行正交投影(而不是示例透视图).

Also you can use triangle strip primitives that are easier to setup (you don't need to create an index buffer). For the coordinates, you can directly sends coordinates to a vertex shader without any transforms (the vertex shaders will copy input SV_POSITION directly to the pixel shader). You just have to map your coordinates into x [-1,1] and y[-1,1]. I suggest you to start with SharpDX MiniCubeTexture sample, change the matrix to perform an orthonormal projection (instead of the sample perspective).

这篇关于使用Direct2D将角映射到任意位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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