• Create Account

### #Actualiedoc

Posted 06 May 2012 - 10:13 PM

are you sure your adding to the tanks forward correctly? i mean, if you want the tank to move forward (+z in tank space), and only add to the tanks z axis, it will move towards the +z in world space, no matter which way your tank is facing or how you rotated it. working with vectors for these kinds of things work well. so, when you rotate the tank, you should also rotate the tanks "forward" vector, then just add that forward vector to the tanks final position, something like this:

D3DXMATRIX matRot;

D3DXMATRIX matCenter;

D3DXMATRIX matScale;

D3DXMATRIX posZUnitVec;

D3DXVECTOR3 vecTankForward;

D3DXMatrixTranslation(&posZUnitVec, 0.0f, 0.0f, 1.0f); // matrix holding position of vector pointing to positive z

D3DXMATRIX m = posZUinitVec * matRot;

vecTankForward = D3DXVECTOR3(m._41,m._42,m._43); // Get vector from the matrix

// move the tank forward (speed is the speed you want to move the tank every time this function is called)

tankPosX += speed * vecTankForward.x;

tankPosZ += speed * vecTankForward.z;

D3DXMatrixTranslation(&matCenter, 0.0f, 0.0f, 0.0f); // *** Rotation point ***

D3DXMatrixTranslation(&matPos, tankPosX, -240.0f, tankPosZ);

D3DXMatrixScaling(&matScale, 1.0f, 1.0f, 1.0f);

d3ddev->SetTransform(D3DTS_WORLD, &(matScale * matCenter * matRot * matPos));

### #4iedoc

Posted 06 May 2012 - 10:13 PM

are you sure your adding to the tanks forward correctly? i mean, if you want the tank to move forward (+z in tank space), and only add to the tanks z axis, it will move towards the +z in world space, no matter which way your tank is facing or how you rotated it. working with vectors for these kinds of things work well. so, when you rotate the tank, you should also rotate the tanks "forward" vector, then just add that forward vector to the tanks final position, something like this:

D3DXMATRIX matRot;

D3DXMATRIX matCenter;

D3DXMATRIX matScale;

D3DXMATRIX posZUnitVec;

D3DXVECTOR3 vecTankForward;

D3DXMatrixTranslation(&posZUnitVec, 0.0f, 0.0f, 1.0f); // matrix holding position of vector pointing to positive z

D3DXMATRIX m = posZUinitVec * matRot;

vecTankForward = D3DXVECTOR3(m._41,m._42,m._43); // Get vector from the matrix

// move the tank forward (speed is the speed you want to move the tank every time this function is called)

tankPosX += speed * vecTankForward.x;

tankPosZ += speed * vecTankForward.z;

D3DXMatrixTranslation(&matCenter, 0.0f, 0.0f, 0.0f); // *** Rotation point ***

D3DXMatrixTranslation(&matPos, tankPosX, -240.0f, tankPosZ);

D3DXMatrixScaling(&matScale, 1.0f, 1.0f, 1.0f);

d3ddev->SetTransform(D3DTS_WORLD, &(matScale * matCenter * matRot * matPos));

### #3iedoc

Posted 06 May 2012 - 10:13 PM

are you sure your adding to the tanks forward correctly? i mean, if you want the tank to move forward (+z in tank space), and only add to the tanks z axis, it will move towards the +z in world space, no matter which way your tank is facing or how you rotated it. working with vectors for these kinds of things work well. so, when you rotate the tank, you should also rotate the tanks "forward" vector, then just add that forward vector to the tanks final position, something like this:

D3DXMATRIX matRot;

D3DXMATRIX matCenter;

D3DXMATRIX matScale;

D3DXMATRIX posZUnitVec;

D3DXVECTOR3 vecTankForward;

D3DXMatrixTranslation(&posZUnitVec, 0.0f, 0.0f, 1.0f); // matrix holding position of vector pointing to positive z

D3DXMATRIX m = posZUinitVec * matRot;

vecTankForward = D3DXVECTOR3(m._41,m._42,m._43); // Get vector from the matrix

D3DXMatrixTranslation(&matCenter, 0.0f, 0.0f, 0.0f); // *** Rotation point ***

// move the tank forward (speed is the speed you want to move the tank every time this function is called)

tankPosX += speed * vecTankForward.x;

tankPosZ += speed * vecTankForward.z;

D3DXMatrixTranslation(&matPos, tankPosX, -240.0f, tankPosZ);

D3DXMatrixScaling(&matScale, 1.0f, 1.0f, 1.0f);

d3ddev->SetTransform(D3DTS_WORLD, &(matScale * matCenter * matRot * matPos));

### #2iedoc

Posted 06 May 2012 - 10:12 PM

are you sure your adding to the tanks forward correctly? i mean, if you want the tank to move forward (+z in tank space), and only add to the tanks z axis, it will move towards the +z in world space, no matter which way your tank is facing or how you rotated it. working with vectors for these kinds of things work well. so, when you rotate the tank, you should also rotate the tanks "forward" vector, then just add that forward vector to the tanks final position, something like this:

D3DXMATRIX matRot;

D3DXMATRIX matCenter;

D3DXMATRIX matScale;

D3DXMATRIX posZUnitVec;

D3DXVECTOR3 vecTankForward;

vecTankForward = D3DXVECTOR3(0.0f, 0.0f, 1.0f); // Unit vector pointing to positive z

D3DXMatrixTranslation(&posZUnitVec, 0.0f, 0.0f, 1.0f); // matrix holding position of vector pointing to positive z

D3DXMATRIX m = posZUinitVec * matRot;

vecTankForward = D3DXVECTOR3(m._41,m._42,m._43); // Get vector from the matrix

D3DXMatrixTranslation(&matCenter, 0.0f, 0.0f, 0.0f); // *** Rotation point ***

// move the tank forward (speed is the speed you want to move the tank every time this function is called)

tankPosX += speed * vecTankForward.x;

tankPosZ += speed * vecTankForward.z;

D3DXMatrixTranslation(&matPos, tankPosX, -240.0f, tankPosZ);

D3DXMatrixScaling(&matScale, 1.0f, 1.0f, 1.0f);

d3ddev->SetTransform(D3DTS_WORLD, &(matScale * matCenter * matRot * matPos));

### #1iedoc

Posted 06 May 2012 - 10:11 PM

are you sure your adding to the tanks forward correctly? i mean, if you want the tank to move forward (+z in tank space), and only add to the tanks z axis, it will move towards the +z in world space, no matter which way your tank is facing or how you rotated it. working with vectors for these kinds of things work well. so, when you rotate the tank, you should also rotate the tanks "forward" vector, then just add that forward vector to the tanks final position, something like this:

D3DXMATRIX matRot;

D3DXMATRIX matCenter;

D3DXMATRIX matScale;

D3DXMATRIX

posZUnitVec;

D3DXVECTOR3 vecTankForward;

vecTankForward = D3DXVECTOR3(0.0f, 0.0f, 1.0f); // Unit vector pointing to positive z

D3DXMatrixRotationYawPitchRoll(&

matRot

D3DXMatrixTranslation(&posZUnitVec, 0.0f, 0.0f, 1.0f); // matrix holding position of vector pointing to positive z

D3DXMATRIX m = posZUinitVec * matRot;

vecTankForward = D3DXVECTOR3(

m

._41,

m

._42,

m

._43); // Get vector from the matrix

d3ddev->SetTransform(D3DTS_WORLD, &(matScale * matCenter * matRot * matPos));

D3DXMatrixTranslation(&matCenter, 0.0f, 0.0f, 0.0f); // *** Rotation point ***

// move the tank forward (speed is the speed you want to move the tank every time this function is called)

tankPosX += speed * vecTankForward.x;

tankPosZ += speed * vecTankForward.z;

D3DXMatrixTranslation(&matPos, tankPosX, -240.0f, tankPosZ);

D3DXMatrixScaling(&matScale, 1.0f, 1.0f, 1.0f);

d3ddev->SetTransform(D3DTS_WORLD, &(matScale * matCenter * matRot * matPos));

PARTNERS