我正在使用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.
更多推荐
发布评论