C++ Direct2D 矩阵变换镜像

发布于 2024-12-16 19:16:07 字数 688 浏览 1 评论 0原文

我目前正在学习 DirectX(2010 年 6 月的 SDK)并正在将位图绘制到屏幕上。现在我希望能够对这些图像进行转换,并且无法沿 x 或 y 轴镜像图像。

在绘图之前,我可以设置一个将应用于绘图操作的变换矩阵。尽管 DirectX 使用 D2D1_MATRIX_3x2_F 类型,但根据 MSDN,只有该矩阵的 2x2 部分用于转换。例如,矩阵 { [1, 0], [0, 1], [0, 0] } 是使所有内容自然显示的单位矩阵。

据我了解,沿 x 轴镜像图像的矩阵变换应如下所示: { [1, 0], [0, -1], [0, 0] },沿 y 轴镜像图像那么将是 { [-1, 0], [0, 1], [0, 0] }。但是,如果我使用这些矩阵进行转换,则会出现黑屏。

对我来说,问题是,我现在有点陷入困境,不知道这个问题可能是由什么引起的,或者更确切地说,它是否是由其背后的数学或实现本身的逻辑错误引起的。不幸的是,除了 Direct2D RenderTarget 头文件中的一行注释“镜像必须通过矩阵变换来完成”之外,我找不到任何相关材料。

我目前用于测试的源代码是:

D2D1_MATRIX_3X2_F m;
m._11 = 1; m._12 = 0;
m._21 = 0; m._22 = -1;
m._31 = 0; m._32 = 0;
m_pDX2DRenderTarget->SetTransform( m );

I am currently learning DirectX (SDK of June 2010) and am drawing bitmaps to screen. Now I want to be able to do transformations on these images, and fail to mirror the images along the x- or y- axis.

Before drawing, I am able to set a transformation matrix that will be applied to the drawing operations. Though DirectX is using the D2D1_MATRIX_3x2_F type, according to MSDN, only a 2x2 part of this matrix is used for transformations. For example, the matrix { [1, 0], [0, 1], [0, 0] } is the identity matrix that causes everything to be displayed naturally.

As I understand it, a matrix transformation to mirror my image along the x-axis should look like this: { [1, 0], [0, -1], [0, 0] }, and along the y-axis it would then be { [-1, 0], [0, 1], [0, 0] }. If I use these matrices for the transformation however, I get a black screen.

The problem for me is, that I am kind of stuck at this point without ideas what this problem could be caused by, or rather whether it is caused by a logical error in the mathematics behind this, or the implementation itself. Unfortunately, I could not find any material on this, besides a one line comment that "mirroring has to be done with matrix transformations" in the header file of the Direct2D RenderTarget.

The source code I am currently using for testing this is:

D2D1_MATRIX_3X2_F m;
m._11 = 1; m._12 = 0;
m._21 = 0; m._22 = -1;
m._31 = 0; m._32 = 0;
m_pDX2DRenderTarget->SetTransform( m );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我还不会笑 2024-12-23 19:16:07

我完全错误地认为矩阵的第三行不相关。它实际上是转换的x-y- 偏移量。变形后我看不到任何东西的原因是,应用镜子后,不仅图像本身会被镜像,而且它在屏幕上的位置也会被镜像。

例如,如果我显示图像,使其左上角边缘位于 (100, 100),那么在应用 x 轴镜像的矩阵变换后,图像的右上角边缘将是在(-100, 100)。由于它始终位于渲染区域之外,因此不会显示。

I was completely mistaken about the third row of the matrix not being relevant. It is in fact the x- and y-offset for the transformation. The reason why I did not see anything after my transformation is that, after applying a mirror, not only the image itself will be mirrored, but also its position on screen.

For example, if I display an image so its top left edge will be at (100, 100), after applying the matrix transformation of a x-axis mirror, the top right edge of the image will be at (-100, 100). Since this is always out of the rendering area, it will not show.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文