Hello,
At first... sorry for my english...
Well... I'm trying to develop a directx application to move a simple object (like a square) in the world space... This movement consist of all kind of rotation (yaw, pitch and roll) and the translation.
I created an object class which contains some methods, variables and four versores (vPos, vUp, vRight, vLook) to store transformations object's informations...
When user pushes the left and right keys I want to execute yaw rotation around the square's local Y-axis...
I associated left key with this method:
void CObject::YawLeft(void)
{
yaw -= rotationSpeed;
D3DXMATRIX m;
D3DXMatrixRotationAxis(&m, &vUp, -rotationSpeed);
// rotate another axis around Y-axis
D3DXVec3TransformCoord(&vRight, &vRight, &m);
D3DXVec3TransformCoord(&vLook, &vLook, &m);
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
Similarly for right key:
void CObject::YawRight(void)
{
yaw += rotationSpeed;
D3DXMATRIX m;
D3DXMatrixRotationAxis(&m, &vUp, rotationSpeed);
// rotate another axis around Y-axis
D3DXVec3TransformCoord(&vRight, &vRight, &m);
D3DXVec3TransformCoord(&vLook, &vLook, &m);
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
When user pushes the 'A' and 'D' keys I want to execute roll rotation around the square's local Z-axis...
for A key:
void CObject::RollLeft(void)
{
roll += rotationSpeed;
D3DXMATRIX m;
D3DXMatrixRotationAxis(&m, &vLook, rotationSpeed);
// rotate another axis around Z-axis
D3DXVec3TransformCoord(&vUp, &vUp, &m);
D3DXVec3TransformCoord(&vRight, &vRight, &m);
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
and for D key:
void CObject::RollRight(void)
{
roll -= rotationSpeed;
D3DXMATRIX m;
D3DXMatrixRotationAxis(&m, &vLook, -rotationSpeed);
// rotate another axis around Z-axis
D3DXVec3TransformCoord(&vUp, &vUp, &m);
D3DXVec3TransformCoord(&vRight, &vRight, &m);
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
For pitch:
void CObject::PitchUp(void)
{
pitch -= rotationSpeed;
D3DXMATRIX m;
D3DXMatrixRotationAxis(&m, &vRight, -rotationSpeed);
// rotate another axis around X-axis
D3DXVec3TransformCoord(&vUp, &vUp, &m);
D3DXVec3TransformCoord(&vLook, &vLook, &m);
rota=2;
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
void CObject::PitchDown(void)
{
pitch += rotationSpeed;
D3DXMATRIX m;
D3DXMatrixRotationAxis(&m, &vRight, rotationSpeed);
// rotate another axis around X-axis
D3DXVec3TransformCoord(&vUp, &vUp, &m);
D3DXVec3TransformCoord(&vLook, &vLook, &m);
rota=2;
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
For movements I tried this:
void CObject::MoveRight(void)
{
vPos += vRight * movementSpeed;
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
void CObject::MoveLeft(void)
{
vPos -= vRight * movementSpeed;
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
void CObject::MoveForward(void)
{
vPos += vLook * movementSpeed;
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
void CObject::MoveBackward(void)
{
vPos -= vLook * movementSpeed;
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
Finally this is the code in the render function:
......
D3DXMATRIX world;
D3DXMATRIX trans;
D3DXMATRIX rot,rot2,rot3;
D3DXMatrixTranslation(&trans, vPos.x, vPos.y, vPos.z);
D3DXMatrixRotationAxis(&rot, &vUp, yaw);
D3DXMatrixRotationAxis(&rot2, &vRight, pitch);
D3DXMatrixRotationAxis(&rot3, &vLook, roll);
world = rot * rot2 * rot3 * trans;
pD3DDevice->SetTransform(D3DTS_WORLD, &world);
......
Well... this code works fine for one rotation... but for other rotations the code doesn't work as I want!!!
Please, how can I fix this problem?
thx.