directx 旋转 c++

发布于 2024-09-24 12:39:19 字数 107 浏览 4 评论 0原文

好吧,这是一个很难的问题。我正在一个顶点数组中创建一个立方体和一个金字塔。我的问题是仅旋转金字塔顶点而不是立方体顶点,但我不知道任何可以旋转某些顶点的函数。如果我尝试旋转顶点,金字塔和立方体就会旋转。

Okay this is a hard question. I'm creating a cube and a pyramid in one vertex array. My problem is to rotate only pyramid vertex not the cube vertex but I don't know any function that can rotate some vertex. If I try to rotate the vertex I'll get pyramid and cube rotated.

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

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

发布评论

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

评论(2

凡间太子 2024-10-01 12:39:20

要么

  • 把立方体和金字塔放进去
    不同的顶点数组和使用
    不同的变换来渲染每个数组

  • 在顶点中应用旋转
    着色器,并传入一些辅助
    每个顶点信息让顶点
    着色器决定每个顶点是否
    应被视为立方体或金字塔的一部分(即在每种情况下应用不同的变换)。这有点像使用“混合权重”进行“顶点混合”;除非您只对二进制情况感兴趣。

Either

  • put the cube and the pyramid in
    different vertex arrays and use
    different transforms to render each array

or

  • apply the rotations in a vertex
    shader, and pass in some auxiliary
    per-vertex info which lets the vertex
    shader decide whether each vertex
    should be treated as part of the cube or the pyramid (ie apply different transforms in each case). This'd be a bit like using a "blend weight" to do "vertex blending"; except you're only interested in the binary case.
雾里花 2024-10-01 12:39:20

第一个想法 - 确保金字塔和立方体的顶点占据数组中单独的非重叠范围。旋转金字塔顶点时,仅告诉 DirectX 数组的范围(使用基指针和范围的大小,而不是完整数组)。

现在将检查 DirectX API...

编辑

已确认。关键功能是...

D3DXVECTOR4 * D3DXVec4TransformArray(D3DXVECTOR4 * pOut,
                                     UINT OutStride,
                                     CONST D3DXVECTOR4* pV,
                                     UINT VStride,
                                     CONST D3DXMATRIX* pM,
                                     UINT n
                                    );

在 C++ 中,数组的子范围在很多方面本身就是一个数组,或者更重要的是,它主要只是一个内存块,其内部没有指示其边界在哪里。因此,您只需传入不同的 pV 和不同的 n 来指示要应用变换的子范围,就函数而言,是整个数组。您可能需要单独复制未转换的部分 - 我希望这是 memcpy 的工作。

步幅值通常只是向量的大小加上任何对齐填充,但也可以对此“撒谎”,并变换例如数组中的每三个向量。

First thought - ensure the vertices for the pyramid and cube occupy separate non-overlapping ranges in the array. When rotating the pyramid vertices, only tell DirectX about that range of the array (use the base pointer and size of the range rather than the full array).

Will now check the DirectX APIs...

EDIT

Confirmed. The key function is...

D3DXVECTOR4 * D3DXVec4TransformArray(D3DXVECTOR4 * pOut,
                                     UINT OutStride,
                                     CONST D3DXVECTOR4* pV,
                                     UINT VStride,
                                     CONST D3DXMATRIX* pM,
                                     UINT n
                                    );

In C++, a subrange of an array is in many ways an array in its own right, or more to the point, it's mostly just a block of memory with no indication within itself of where its bounds are. So you just pass in a different pV and a different n to indicate the subrange you want to apply the transform to, and as far as the function is concerned, that is the whole array. You'll probably need to copy the untransformed part separately - a job for memcpy, I expect.

The stride values are normally just the size of a vector plus any alignment padding, but it's possible to "lie" about this too, and transform e.g. every third vector in the array.

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