简体   繁体   中英

Transform part of an 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)

Why not load the model to mess? the wheels is part of the car, and thus a sub-mess of the car. with sub-mess, you can transform and render it separately without changes the other parts.

If you really want to load it into a ID3DBuffer, I recommend you create two buffers, one hold the static part of the car, another hold the wheels, in this way, you can transform and render the wheels while keep the static part unchanged.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM