Archived

This topic is now archived and is closed to further replies.

Matrix Question

Recommended Posts

I''m trying to have a certain object rotate constantly, and move itself around based on user input, while still rotating. The code I have for this is as follows: NOTE THIS IS 2D IN 3D

if (KEYDOWN(KEY_LEFT))
{
D3DXMatrixTranslation(&Position, test, 0.0f, 0.0f);
pDirect3D->GetDevice()->SetTransform(D3DTS_WORLD, &Position);
test--;
}

pDirect3D->GetDevice()->MultiplyTransform(D3DTS_PROJECTION, &matRotate);

pDirect3D->GetDevice()->BeginScene();
pDirect3D->GetDevice()->SetTexture(0, pTexture);
pDirect3D->GetDevice()->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
pDirect3D->GetDevice()->EndScene();
pDirect3D->PresentScene();

Now it rotates fine enough, but when I press left, instead of just translating left, the object''s rotation point sort-of grows...I''m not sure how to explain it... It stops just rotating, and starts to orbit the point using a pixed radius. How would I properly apply the various transformations to just make it move around while rotating?

Share on other sites
Rotate your object then translate it, otherwise it will rotate around the origin point.

Also, why are you multiplying your rotation into your projection? You should be multiplying it into the world transform for that object.

Share on other sites
Oops about the view matrix I''m only dealing with 1 object right now so I forgot to put it back

Anyway I basically got it working, thanks to your help, but there is still a small problem. When I press left or right, it snaps back to the original direction while moving, then when I let go of the key, it starts rotating. How would I keep it rotating while moving? Let me show the new source:

  		if (KEYDOWN(KEY_LEFT))		{			D3DXMatrixTranslation(&Position, test, 0.0f, 0.0f);			pDirect3D->GetDevice()->SetTransform(D3DTS_WORLD, &Position);			test--;		}		if (KEYDOWN(KEY_RIGHT))		{			D3DXMatrixTranslation(&Position, test, 0.0f, 0.0f);			pDirect3D->GetDevice()->SetTransform(D3DTS_WORLD, &Position);			test++;		}		pDirect3D->GetDevice()->MultiplyTransform(D3DTS_WORLD, &matRotate);

• Forum Statistics

• Total Topics
628306
• Total Posts
2981946

• 10
• 11
• 12
• 11
• 10