Why is this XMVector3Transform call not returning the right result?

The situation is as follows:

XMVECTOR posVec = XMLoadFloat3(&(pVertexInfos[j].pos));

// At this point posVec equals {6143.72119, -714.767151, -16615.9004, 0.000000000} 
// and new newModelMatrix's rows are as follows:
// Row 0: {1.00000000, 0.000000000, 0.000000000, 0.000000000}
// Row 1: {0.000000000, 0.000000000, -1.00000000, 0.000000000} 
// Row 2: {0.000000000, 1.00000000, 0.000000000, 0.000000000}
// Row 3: {0.000000000, 0.000000000, 0.000000000, 1.00000000}

posVec = XMVector3Transform(posVec, newModelMatrix);

// But then posVec equals **{6143.72119, -16615.9004, 714.767151, 1.00000000}** 

According to my repeated pencil and paper calculations (Khan academy confirmed that I'm doing it right) and what the correct program execution is should equal {6143.72119, 16615.9004, -714.767151, 1.00000000}

Just in case I'm going crazy, here's a screenshot of the debugger before:

and after:

So what's going on here? According to my research XMVector3Transform should be doing exactly what I want, which is Matrix times Vector = Vector, but for some reason it looks like the negative signs get messed up. As you can imagine, this causes a pretty bad visual bug later on in the app (I confirmed that correctly hacking the operation resolves the problem).

Thank you in advance for any help, Nico

Answers


There doesn't appear to be anything wrong with the result you're getting.

The matrix you've setup takes a position (X, Y, Z) and multiplies it by a matrix that swaps the Y and Z axes and negates the resulting Z.

As you multiply through the vector by the matrix, you go across one column at a time and work down, not along the row, the same way you would with matrix multiplication.

The resulting calculation should be:

X = (6143.72119 * 1.0f) + (-714.767151 * 0.0f) + (-16615.9004 * 0.0f) = 6143.72219

Y = (6143.72119 * 0.0f) + (-714.767151 * 0.0f) + (-16615.9004 * 1.0f) = -16615.9004

Z = (6143.72119 * 0.0f) + (-714.767151 * -1.0f) + (-16615.9004 * 0.0f) = 714.767151

This is exactly what the function gives you. Perhaps you're just misunderstanding how to do vector/matrix multiplication?


Need Your Help

TCL obtain the proc name in which I am

tcl proc

How to know what is the name of the proc in which I am. I mean I need this:

Spinner onItemSelected called erroneously (without user action)

android spinner android-spinner

I have a spinner which I am showing in a dialog view, and the moment the dialog starts onItemSelected is called. I don't really want to process this but only when user makes the selection. So I e...