Skip to main content
GameDev.net gamedev.net
🔒 Locked

D3DXVec3TransformCoord and D3DXVec3TransformNormal

Started by luasitdown Jan 22, 2006 at 2:38 AM 3 replies 4.5k views
Original Post
luasitdown
luasitdown
what is different between them? I think D3DXVec3TransformCoord only do for translation. I think D3DXVec3TransformNormal only do for rotation. BTW who give me a simple example for D3DXVec3TransformCoordArray?
Muhammad Haggag
Muhammad Haggag
D3DXVec3TransformCoord transforms a point/coordinate/vertex-position by directly transforming it with the given matrix.

D3DXVec3TransformNormal transforms a normal using the transpose of the inverse of the given matrix. That is necessary so that normals don't get sheared or translated, only rotated.

D3DXVec3TransformCoordArray usage #1:
D3DXVECTOR3 input[50];// Fill it with data...D3DXVECTOR3 output[50];D3DXMATRIX mat = ...;D3DXVec3TransformCoordArray(output, sizeof(D3DXVECTOR3), input, sizeof(D3DXVECTOR3), &mat, 50);


D3DXVec3TransformCoordArray usage #2:
struct input_vertex_t{    D3DXVECTOR3 position;    DWORD diffuse;};input_vertex_t input[50];// Fill it...D3DXVECTOR3 output[50];D3DXMATRIX mat = ...;D3DXVec3TransformCoordArray(output, sizeof(D3DXVECTOR3), input, sizeof(input_vertex_t), &mat, 50);

luasitdown
luasitdown
it is cool! but still something unkown.

1.
struct input_vertex_t
{
D3DXVECTOR3 position;
DWORD diffuse;
};

but how does D3DXVec3TransformCoordArray know where is D3DXVECTOR3 in input_vertex_t? if I define this ,it still work?

struct input_vertex_t
{
DWORD diffuse;
D3DXVECTOR3 position;
};
2.
look below:
void TransformRay(d3d::Ray* ray, D3DXMATRIX* T){      // transform the ray's origin, w = 1.      D3DXVec3TransformCoord(           &ray->_origin,           &ray->_origin,           T);      // transform the ray's direction, w = 0.      D3DXVec3TransformNormal(           &ray->_direction,           &ray->_direction,           T);      // normalize the direction      D3DXVec3Normalize(&ray->_direction, &ray->_direction);}


the D3DXVec3TransformNormal and D3DXVec3TransformCoord take same Matrix.
so do them take different part of the matrix to do different job?
Muhammad Haggag
Muhammad Haggag
Quote:
Original post by luasitdown
it is cool! but still something unkown.

1.
struct input_vertex_t
{
D3DXVECTOR3 position;
DWORD diffuse;
};

but how does D3DXVec3TransformCoordArray know where is D3DXVECTOR3 in input_vertex_t? if I define this ,it still work?

struct input_vertex_t
{
DWORD diffuse;
D3DXVECTOR3 position;
};

You give it a pointer to the first position, and it adds InputStride bytes to the pointer every time it needs to access the next position. For the structure I used, the position was the first thing in the structure, so the address of the first element of the structure (input) was the address of the first position. If we were to use your last input_vertex_t, we'd do:

D3DXVec3TransformCoordArray(output, sizeof(D3DXVECTOR3), &input[0].Position, sizeof(input_vertex_t), &mat, 50)

Quote:
the D3DXVec3TransformNormal and D3DXVec3TransformCoord take same Matrix.
so do them take different part of the matrix to do different job?

D3DXVec3TransformNormal should invert the matrix first, transpose it, then use it.

Illco
Illco
Quote:

But how does D3DXVec3TransformCoordArray know where is D3DXVECTOR3 in input_vertex_t? if I define this ,it still work?

The function takes the pointer you give it as the first vector to transform. So, without extra work the structure starting with a DWORD will not work. However, you can pass the function the actual array plus one DWORD's size offset and it will work again.

Quote:

the D3DXVec3TransformNormal and D3DXVec3TransformCoord take same Matrix.
so do them take different part of the matrix to do different job?

Sort of. Only they do not use different 'parts'; they process the incoming matrix differently. The first one does nothing to it and the other inverses and transposes it before applying.

Illco

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.