Original Post
hello,
im trying to move an object in the direction it is pointing
an it works fine.
however when i rotate the object by setting the yaw
variable the object rotates around the coordinates 0,0,0
and not around the position of the object
any help would make me very-very happy..
//update x
Position.x += Velocity.x * Right.x;
Position.y += Velocity.x * Right.y;
Position.z += Velocity.x * Right.z;
//update y
Position.x += Velocity.y * Up.x;
Position.y += Velocity.y * Up.y;
Position.z += Velocity.y * Up.z;
//update z
Position.x += Velocity.z * LookAt.x;
Position.y += Velocity.z * LookAt.y;
Position.z += Velocity.z * LookAt.z;
D3DXMATRIX mPitch, mRoll, mYaw;
//Normalize vectors to correct rounding errors
D3DXVec3Normalize(&LookAt, &LookAt);
D3DXVec3Cross(&Right, &Up, &LookAt);
D3DXVec3Normalize(&Right, &Right);
D3DXVec3Cross(&Up, &LookAt, &Right);
D3DXVec3Normalize(&Up, &Up);
//set up the y rotation
D3DXMatrixRotationAxis(&mYaw,&Up,yaw);
D3DXVec3TransformCoord(&LookAt, &LookAt, &mYaw);
D3DXVec3TransformCoord(&Right, &Right, &mYaw);
//set up the x rotation
D3DXMatrixRotationAxis(&mPitch,&Right,pitch);
D3DXVec3TransformCoord(&LookAt, &LookAt, &mPitch);
D3DXVec3TransformCoord(&Up, &Up, &mPitch);
//set up the z rotation
D3DXMatrixRotationAxis(&mRoll,&LookAt,roll);
D3DXVec3TransformCoord(&Right, &Right, &mRoll);
D3DXVec3TransformCoord(&Up, &Up, &mRoll);
//init view matrix
ZeroMemory(&mView, sizeof(D3DXMATRIX));
D3DXMatrixIdentity(&mView);
mView(0,0) = Right.x;
mView(0,1) = Up.x;
mView(0,2) = LookAt.x;
mView(1,0) = Right.y;
mView(1,1) = Up.y;
mView(1,2) = LookAt.y;
mView(2,0) = Right.z;
mView(2,1) = Up.z;
mView(2,2) = LookAt.z;
mView(3,0) = - D3DXVec3Dot(&Position, &Right);
mView(3,1) = - D3DXVec3Dot(&Position, &Up);
mView(3,2) = - D3DXVec3Dot(&Position, &LookAt);