# Matrix math

This topic is 3651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Are these two functions equivalent? Also, is it safe to drop the 4th component of the resulting matrix like the author did? I assume it is, when the result has a 1 in the 4th component, but will it? The only way I see it having a 1 is if the 4th column of the rotation matrix is 0,0,0,1. However I do not know if the rotation matrix always will? Original:
void FlightCamera::TransformAxis(D3DXVECTOR3 & axis)
{
// Build a matrix from the camera's orientation
D3DXMATRIX	matRotation;
D3DXMatrixRotationQuaternion(&matRotation, &m_orientation);

// Transform the queried axis vector by the matrix.
D3DVECTOR	newAxis;
newAxis.x = axis.x * matRotation._11 + axis.y * matRotation._21 + axis.z * matRotation._31 + matRotation._41;
newAxis.y = axis.x * matRotation._12 + axis.y * matRotation._22 + axis.z * matRotation._32 + matRotation._42;
newAxis.z = axis.x * matRotation._13 + axis.y * matRotation._23 + axis.z * matRotation._33 + matRotation._43;

axis = newAxis;
}


Mine:
D3DXVECTOR3 ITransformable::WorldToObjectAxis(const D3DXVECTOR3 & worldAxis)
{
// Build a matrix from the 3D object's orientation
D3DXMATRIX	matRotation;
D3DXMatrixRotationQuaternion(&matRotation, &m_orientation);

// Transform the axis vector by the matrix.
D3DXVECTOR4	objectAxis;
D3DXVec3Transform(&objectAxis, &worldAxis, &matRotation);

return D3DXVECTOR3(objectAxis.x, objectAxis.y, objectAxis.z);
}



##### Share on other sites
Besides that the "original" overwrites the input vector while "yours" does not (but that is obvious), AFAIK the both ways are equivalent (but I'm not a D3D programmer, so you may verify this elsewhere). The "original" handles the input vector "axis" to be a position vector (see the addition of matRotation._4*), and so does D3DXVec3Transform(...) (see documentation).

However, IMHO the usage and the nomenclature is not consistent. If you pick an object/camera orientation you normally get a part of the local-to-global) transformation. But the naming of the function WorldToObjectAxis(..) and its parameter worldAxis as well as its result objectAxis let me think that the transform should be applied as a global-to-local transformation.

##### Share on other sites
After smoking a cigarette or two I think I understand. if I put in 0,1,0 that vector is the object's y axis and I am transforming it into the world. Thanks!

##### Share on other sites
If you want the result of the transformation to be a 3-dimensional vector, you can use D3DXVec3TransformCoord. You can also use D3DXVec3TransformNormal, which will only apply the rotation portion of a matrix to a vector (it doesn't matter in this case, since your matrix only has rotation anyway).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 10
• 9
• 35
• 16
• ### Forum Statistics

• Total Topics
634125
• Total Posts
3015677
×