Jump to content
  • Advertisement
Sign in to follow this  
judeclarke

DirectX Math function confusion

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

While I was going over some older DirectX code, I came by the functions D3DXVec3Transform and D3DXVec3TransformCoord. Upon looking up the descriptions for them, they seemed rather similar but I don't see what the difference between the two are. Can someone please explain what is the difference between D3DXVec3Transform and D3DXVec3TransformCoord are, along with the math behind them?

Share this post


Link to post
Share on other sites
Advertisement
D3DXVec3Transform() assumes the input vector is a vector with a w coordinate of 0. D3DXVec3TransformCoord() assumes the input vector is a point with a w coordinate of 1. In somewhat simplified terms, basically it's the difference between using the translation part of the matrix or not.

Share this post


Link to post
Share on other sites
I believe I somewhat understand it more now, do you (or anyone) happen to have an example of how the code behind those functions are impelemented? I feel like that will help me understand it more.

Share this post


Link to post
Share on other sites
The matrices are 4x4, right? The difference between the two is if the matrix is multiplied by [x y z 0] or [x y z 1]. They're just normal matrix multiplications otherwise.

Share this post


Link to post
Share on other sites
From trying to figure out the math, would this be the correct way to calculate them?


D3DXVECTOR3 Vec3Transform(D3DXVECTOR3 &vCoordinate, D3DXMATRIX &mTransform)
{
D3DXVECTOR4 vWorking;

vWorking.x = (vCoordinate.x * mTransform._11) + (vCoordinate.y * mTransform._21) + (vCoordinate.z * mTransform._31) + mTransform._41;
vWorking.y = (vCoordinate.x * mTransform._12) + (vCoordinate.y * mTransform._22) + (vCoordinate.z * mTransform._32) + mTransform._42;
vWorking.z = (vCoordinate.x * mTransform._13) + (vCoordinate.y * mTransform._23) + (vCoordinate.z * mTransform._33) + mTransform._43;

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

D3DXVECTOR3 Vec3TransformCoordinate(D3DXVECTOR3 &vCoordinate, D3DXMATRIX &mTransform)
{
D3DXVECTOR4 vWorking;

vWorking.x = (vCoordinate.x * mTransform._11) + (vCoordinate.y * mTransform._21) + (vCoordinate.z * mTransform._31) + mTransform._41;
vWorking.y = (vCoordinate.x * mTransform._12) + (vCoordinate.y * mTransform._22) + (vCoordinate.z * mTransform._32) + mTransform._42;
vWorking.z = (vCoordinate.x * mTransform._13) + (vCoordinate.y * mTransform._23) + (vCoordinate.z * mTransform._33) + mTransform._43;
vWorking.w = 1 / ((vCoordinate.x * mTransform._14) + (vCoordinate.y * mTransform._24) + (vCoordinate.z * mTransform._34) + mTransform._44);

return D3DXVECTOR3(vWorking.x * vWorking.w, vWorking.y * vWorking.w, vWorking.z * vWorking.w);
}

Share this post


Link to post
Share on other sites

If row 1 is multiplied by X, row 2 by Y and row 3 by Z, then row 4? That's the thing to consider to fix the errors in that math.


This is what it seems like I did there, what error are you refering to?

Share this post


Link to post
Share on other sites

[quote name='Narf the Mouse' timestamp='1325206505' post='4897996']
If row 1 is multiplied by X, row 2 by Y and row 3 by Z, then row 4? That's the thing to consider to fix the errors in that math.


This is what it seems like I did there, what error are you refering to?
[/quote]
When transforming a Vector3 by a 4x4 matrix, you need an assumed W cordinate of either 1 or 0, depending on whether it's a cordinate transform or a direction transform, as discussed.

What happens with the matrix 41, 42 and 43 position changes in the first Transform function, when you multiply them by an assumed W cordinate of 0?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!