转换ID3D11Buffer的一部分(Transform part of an ID3D11Buffer)

编程入门 行业动态 更新时间:2024-10-06 22:27:14
转换ID3D11Buffer的一部分(Transform part of an ID3D11Buffer)

我正在使用DirectX 11制作赛车游戏作为任务的一部分,我已经将车型加载到ID3D11Buffer中。 由此,我想知道如何将汽车的车轮分别旋转到模型的其余部分。 我有汽车每个部分的起点和终点指数,所以我知道要旋转哪个部分,而不是如何单独翻译它。 (我不确定我是否包含代码会有所帮助,但如果是这样,请告诉我)

I am making a racing game as part of an assignment using DirectX 11, and I have loaded in a model of a car into a ID3D11Buffer. From this, I was wondering how to rotate the wheels of the car separately to the rest of the model. I have the start and end indices of each part of the car, so I know which part it is to be rotated, just not how to translate it separately. (I'm not sure if me including code would help, but if so, just let me know)

最满意答案

为什么不加载模型来搞乱? 车轮是汽车的一部分,因而是汽车的一部分。 使用子混乱,您可以单独转换和渲染它而无需更改其他部分。

如果你真的想把它加载到ID3DBuffer中,我建议你创建两个缓冲区,一个保持汽车的静态部分,另一个保持轮子,这样,你可以转换和渲染轮子,同时保持静态部分不变。

Immediately after asking, I figured it out, and now I have it implemented so that it works fine.

Given that .obj files support groups of vertices, when you load in the file, store the start and end location of each group of vertices, the name of each part that's preceded in the .obj file with a 'g' at the beginning of a line, and calculate the centre point of each group.

Then, make sure that you have a XMFLOAT4X4 for each part that you want to transform separately, as well as one for the whole object. In this case, I have objectMatrix, and wheel1-4Matrix. I apply any transformations I want to the objectMatrix that is general world transformations to do with moving the car. For each wheel, do the following translation

XMMATRIX translate; translate = XMMatrixTranslation(-centre.x, -centre.y, -centre.z); translate *= XMMatrixRotationX(angleToBeMoved); translate *= XMMatrixTranslation(centre.x, centre.y, centre.z); translate = XMMatrixMultiply(translate, XMLoadFloat4x4(&objectMatrix)); XMStoreFloat4x4(&wheel1, translate);

Apply this to each wheel during the update. During the Draw method, make sure that you're using the DrawIndexed method, pass it both the start and end index for each group, and update your constant buffer's world view matrix with the relevant wheel matrix if it's a wheel, or with the objectMatrix in all other circumstances.

更多推荐

本文发布于:2023-07-27 08:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287719.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ID3D11Buffer   Transform   part

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!