how do I use D3DX math functions return value?

Started by
2 comments, last by xyzzy00 18 years, 7 months ago
Good afternoon folks. There's this little remark that accompanies most of the D3DX math functions I use, and I have a question about it. It goes something like... "The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixRotationQuaternion function can be used as a parameter for another function. " Ok, that sounds great. So I translate my world transformation matrix by a matrix I produce right from the function. But then what the heck do I use for the pOut parameter in the quat function? If I pass in NULL, will it just it just disregard pOut for result placement, and return the proper result? In other words, what can I stick in as a meaningless value that won't make it blow up? Thanks, Mike
Advertisement
Well you could create a matrix and pass its address as the pOut parameter and have it fill the matrix that way or you can simpley assign the matrix a value by making it equal to the function call. The function will return the resultant matrix.

So

D3DXMATRIX myMatrix;

D3DXMatrixMultiply( &myMatrix, &anotherMatrix,&anotherMatrix );

OR:

myMatrix = D3DXMatrixMultiply( NULL, &anotherMatrix, &anotherMatrix );

What the SDK is also saying is that because the matrix math functions also return their result you can use the function as a parameter to another function.
Like this:

D3DXMatrixMultiply( &myMatrix, &anotherMatrix, D3DXMatrixMultiply(&anotherMatrix, &anotherMatrix) );

Thats the way it works pretty much.

Hope that helps.

ace
Right, I understand what they meant by using the function as a parameter to another function. That's exactly what I'd like to do; currently I just make a temp matrix ( as in your first example ) for storing the result.

I just wanted to make sure that passing in NULL for pOut isn't going to give me access violations. I mean I'd ASSUME that they check the input and wouldn't dereference NULL, but I just wanted to be sure.

Thanks =)
Mike
Actually, you cannot pass NULL in for pOut. The return value of the function is simply the pointer which you passed in as pOut. This is so you can do things like:

D3DXVec3Transform(D3DXVec3Normalize(&n, &v), &m)

xyzzy

This topic is closed to new replies.

Advertisement