Question

How can I rotate single object in DirectX9? I know how to rotate all objects :

static D3DXMATRIX rotation_matrix;

static float X = XX; X += 0.01f;
D3DXMatrixRotationX(&rotation_matrix, X);
d3ddev->SetTransform(D3DTS_WORLD,
                     &rotation_matrix);

That's how I can rotate all objects, right? But how can I rotate one object? Thank you.

Was it helpful?

Solution

Need to know, that you do not apply transformations to objects. DirectX even doesn't know what "object" is. You always apply transformations to vertex positions.

With fixed function pipeline of DirectX 9 by calling SetTransform(), you applying transformations to all vertices being drawn on next draw call. So, to apply other transforms to other vertices you need a separate draw call (pseudocode):

device->SetStreamSource(vertexBuffer1,...); // "object1"
device->SetTransform(transform1);
device->Draw(...); // draw object1

device->SetStreamSource(vertexBuffer2,...); // "object2"
device->SetTransform(transform2); // rotation2
device->Draw(..); // draw object2

Note, that whis will increase number of draw calls proportionally to number of objects and to number their transforms. Draw calls is expensive. For optimized solutions look for shaders.

Hope it helps. Happy coding!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top