3
\$\begingroup\$

I'm trying to rotate models independently of each other however I cannot for the life of my figure out how. I have gotten to the stage of writing this:

std::vector<int>::size_type st = Models.size();
if (!Models.empty())
{
    for (unsigned x = 0; x < st; x++)
    {
        D3DXMATRIX matRotate;

        D3DXMatrixRotationY(&matRotate, D3DXToRadian((x + 1) * 60));

        cBuffer[x].Final = matRotate * matView * matProjection;
        cBuffer[x].Rotation = matRotate;

        devcon->UpdateSubresource(pCBuffer, 0, NULL, &cBuffer[x], 0, 0);

        devcon->VSSetShader(pVS, 0, 0);
        devcon->VSSetConstantBuffers(0, 1, &pCBuffer);
        devcon->PSSetShader(pPS, 0, 0);

        Models.at(x)->Render(devcon);       
    }
}
swapchain->Present(0, 0);

but this only updates for the first assignment of rotation. Why isn't it rotating and how do I make it? Thanks in advance.

\$\endgroup\$
  • \$\begingroup\$ Sorry this question was very stupid on my part. I was trying to rotate meshes inside of a super mesh and obviously that won't work. \$\endgroup\$ – Tyson May Sep 24 '14 at 11:48
  • \$\begingroup\$ Sounds like the user fixed there problem and has now abandoned this question. \$\endgroup\$ – Justin William Stanley Bryant Mar 18 '17 at 1:48
1
\$\begingroup\$

Your rotation will clearly always be the same every frame. The code you wrote there just sets the rotation to one single value every frame, if this code is run every frame, that is. Instead, have a variable , say rotation_offset that will be updated each frame, and will have a scope outside this for loop you have there. You should do something like this:

`

//somewhere out side that function
float rotation_offset = 0;

/*...*/

//right before the code you posted
rotation_offset += 0.01f;  //the amount to increase rotation each frame

std::vector<int>::size_type st = Models.size();
if (!Models.empty())
{
    for (unsigned x = 0; x < st; x++)
    {
        /* ... */
        D3DXMatrixRotationY(&matRotate, D3DXToRadian((x + rotation_offset) * 60));
        /* ... */
    }
    /*...*/
}

`

And that should make things keep rotating.

\$\endgroup\$
  • \$\begingroup\$ Keeping rotation is not the problem. The loop there reads each model and renders them. I want to be able to rotate each mesh by say 60 degrees multiplied by what position mesh it is. The problem is that it only rotates it to the first value of rotation. \$\endgroup\$ – Tyson May Sep 24 '14 at 11:28
  • \$\begingroup\$ So basically you wanted them to keep spinning at there places, isn't it? \$\endgroup\$ – The Light Spark Sep 24 '14 at 12:15
  • \$\begingroup\$ Easiest way I can describe it is I wanted the capability of one to be able to rotate clockwise and the other anti-clockwise. \$\endgroup\$ – Tyson May Sep 26 '14 at 1:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.