Shouldn't the vector that is multipled with the projection matrix be 4D?

Started by
4 comments, last by MJP 10 years, 9 months ago

I'm talking about the API.When the vector is multiplied with the projection matrix it's first moved to homogeneous clip space(by puting the z into the y) and after that the projection is done.

However,if I pass a 3D vector,will DirectX just add the 4th component to it or...? If there is no w,where is the z coppied?

Advertisement

The W-component is typically assumed to be 1 if not given explicitly.

Yes but if I use 3D coords what does it do? does it just add the w component? Because you do need it to store the z in it.

If you use 3D coordinates then you don't specify the W-component, so it is assumed to be 1. The library always works with 4-dimensional homogeneous coordinates. If you don't, the library will expand your vectors to 4-dimensional homogeneous space.


the library will expand your vectors to 4-dimensional homogeneous space.

That's what I wanted to see,thanks.

However,if I pass a 3D vector,will DirectX just add the 4th component to it or...? If there is no w,where is the z coppied?

It depends on the math library that you're using, and which function you're using. Both the D3DX and DirectXMath libraries have 2 different vector/matrix transformation functions: one that uses 0 as the W component, and one that uses 1. The functions that end with "Coord" use 1 as the W component, and the functions that end with "Normal" use 0 as the W component.

EDIT: actually let me correct that, there are 3 functions:

D3DXVec3Transform/XMVector3Transform - this uses 1 as a the W component, and returns a 4D vector containing the result of the multiplication

D3DXVec3TransformCoord/XMVector3TransformCoord - this uses 1 as a the W component, and returns a 3D vector containing the XYZ result divided by the W result

D3DXVec3TransformNormal/XMVector3TransformNormal - this uses 0 as a the W component, and returns a 3D vector containing the XYZ result

This topic is closed to new replies.

Advertisement