Name: Anonymous 2012-08-29 13:57
I'm pretty shitty with matrices, I've noticed. I've got a normalized vector pointing at a certain direction.
I've been trying to make a rotation matrix that turns a (1,0,0) the same as the direction vector. I seem to be doing something wrong as the z field of the vector is wrong after I've applied the rotation matrix. Could any of you take a look at it?
The language is C++, the utility is DirectX although I am not allowed to use finished functions like D3DXMatrixRotationAxis() or D3DXVec3TransformCoord(). I need the rotation matrix to be correct so I can invert it, and rotate the camera view matrix to then rotate along the x-axis. In other words, I am trying to rotate my view matrix along a fixed axis, but it stops at simply finding the rotation matrix for the direction vector.
void Camera::makeRotationMatrix( D3DXMATRIX *out, D3DXVECTOR3 *direction )
{
D3DXVECTOR3 x_dir(0.0,0.0,1.0), y_dir;
double d = direction->z;
if(d>-0.999999999 && d<0.999999999) //to avoid normalizing in special cases
{
x_dir=x_dir-(*direction)*d;
normalizeVector3(&x_dir);
crossVector3(&y_dir, direction, &x_dir);
}
else
{
x_dir.x = direction->z;
x_dir.y = 0;
x_dir.z = -direction->x;
y_dir.x = 0;
y_dir.y = 1;
y_dir.z = 0;
}
//the default arrow is pointing along the x-axis
out->_11 = direction->x;
out->_12 = direction->y;
out->_13 = direction->z;
out->_14 = 0;
out->_21 = y_dir.x;
out->_22 = y_dir.y;
out->_23 = y_dir.z;
out->_24 = 0;
out->_31 = x_dir.x;
out->_32 = x_dir.y;
out->_33 = x_dir.z;
out->_34 = 0;
out->_41 = 0;
out->_42 = 0;
out->_43 = 0;
out->_44 = 1;
}
I've been trying to make a rotation matrix that turns a (1,0,0) the same as the direction vector. I seem to be doing something wrong as the z field of the vector is wrong after I've applied the rotation matrix. Could any of you take a look at it?
The language is C++, the utility is DirectX although I am not allowed to use finished functions like D3DXMatrixRotationAxis() or D3DXVec3TransformCoord(). I need the rotation matrix to be correct so I can invert it, and rotate the camera view matrix to then rotate along the x-axis. In other words, I am trying to rotate my view matrix along a fixed axis, but it stops at simply finding the rotation matrix for the direction vector.
void Camera::makeRotationMatrix( D3DXMATRIX *out, D3DXVECTOR3 *direction )
{
D3DXVECTOR3 x_dir(0.0,0.0,1.0), y_dir;
double d = direction->z;
if(d>-0.999999999 && d<0.999999999) //to avoid normalizing in special cases
{
x_dir=x_dir-(*direction)*d;
normalizeVector3(&x_dir);
crossVector3(&y_dir, direction, &x_dir);
}
else
{
x_dir.x = direction->z;
x_dir.y = 0;
x_dir.z = -direction->x;
y_dir.x = 0;
y_dir.y = 1;
y_dir.z = 0;
}
//the default arrow is pointing along the x-axis
out->_11 = direction->x;
out->_12 = direction->y;
out->_13 = direction->z;
out->_14 = 0;
out->_21 = y_dir.x;
out->_22 = y_dir.y;
out->_23 = y_dir.z;
out->_24 = 0;
out->_31 = x_dir.x;
out->_32 = x_dir.y;
out->_33 = x_dir.z;
out->_34 = 0;
out->_41 = 0;
out->_42 = 0;
out->_43 = 0;
out->_44 = 1;
}