Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Tyson May Sep 24 '14 at 11:48

1 Answer 1

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.

share|improve this answer
    
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. –  Tyson May Sep 24 '14 at 11:28
    
So basically you wanted them to keep spinning at there places, isn't it? –  The Light Spark Sep 24 '14 at 12:15
    
Easiest way I can describe it is I wanted the capability of one to be able to rotate clockwise and the other anti-clockwise. –  Tyson May Sep 26 '14 at 1:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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