directx 旋转 c++
好吧,这是一个很难的问题。我正在一个顶点数组中创建一个立方体和一个金字塔。我的问题是仅旋转金字塔顶点而不是立方体顶点,但我不知道任何可以旋转某些顶点的函数。如果我尝试旋转顶点,金字塔和立方体就会旋转。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要么
不同的顶点数组和使用
不同的变换来渲染每个数组
或
着色器,并传入一些辅助
每个顶点信息让顶点
着色器决定每个顶点是否
应被视为立方体或金字塔的一部分(即在每种情况下应用不同的变换)。这有点像使用“混合权重”进行“顶点混合”;除非您只对二进制情况感兴趣。
Either
different vertex arrays and use
different transforms to render each array
or
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.
第一个想法 - 确保金字塔和立方体的顶点占据数组中单独的非重叠范围。旋转金字塔顶点时,仅告诉 DirectX 数组的范围(使用基指针和范围的大小,而不是完整数组)。
现在将检查 DirectX API...
编辑
已确认。关键功能是...
在 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...
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 differentn
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.