We are trying to replace this direct x method with our own method. We tried just multiplying a matrix by a vector and got some very different results. What is this method doing that's different from simple multiplication?

**0**

# Question about D3DXVec3TransformCoord

Started by daedalic, Apr 12 2011 06:16 PM

5 replies to this topic

Sponsor:

###
#3
Crossbones+ - Reputation: **1879**

Posted 12 April 2011 - 07:03 PM

When you multiply a 3D vector and a matrix the result is a 4D vector with w != 1. On the other hand D3DXVec3TransformCoord returns a 3D vector, which is a 4D vector projected back to w = 1.

Tiago Costa

Aqua Engine - my DirectX 11 game "engine" - In development

Aqua Engine - my DirectX 11 game "engine" - In development

###
#4
Members - Reputation: **104**

Posted 12 April 2011 - 08:07 PM

Here's an example of a transform matrix we are using:

0 0 -1 0

1 0 0 0

0 -1 0 0

0 0 0 1

When we multiply this matrix by the unit vector: (0, 0, 1) using D3DXVecTransformCoord, we get (0, -1, 0) as a result. However, when we use our multiplication method we get (-1, 0, 0) as a result.

Here's our multiplication method: It ignores the 4th dimension since it shouldn't be needed for our purposes... as you can see, the transform matrix is equal to the identity matrix in the 4th dimensional positions.

0 0 -1 0

1 0 0 0

0 -1 0 0

0 0 0 1

When we multiply this matrix by the unit vector: (0, 0, 1) using D3DXVecTransformCoord, we get (0, -1, 0) as a result. However, when we use our multiplication method we get (-1, 0, 0) as a result.

Here's our multiplication method: It ignores the 4th dimension since it shouldn't be needed for our purposes... as you can see, the transform matrix is equal to the identity matrix in the 4th dimensional positions.

INLINE Vector3D Matrix::operator* (const Vector3D vector) { return Vector3D (m11 * vector.x + m12 * vector.y + m13 * vector.z, m21 * vector.x + m22 * vector.y + m23 * vector.z, m31 * vector.x + m32 * vector.y + m33 * vector.z); }

###
#5
Crossbones+ - Reputation: **3818**

Posted 12 April 2011 - 10:20 PM

It appears you should be multiplying the row vector by the matrix columns, rather than the other way 'round. I.e.,

m11*x + m21*y + m31*z = 0

m12*x + m22*y + m32*z = -1

m13*x + m23*y + m33*z = 0

Also, if you're going to "ignore" the 4th elements, then you should be using/comparing-to D3DXTransformNormal.

m11*x + m21*y + m31*z = 0

m12*x + m22*y + m32*z = -1

m13*x + m23*y + m33*z = 0

Also, if you're going to "ignore" the 4th elements, then you should be using/comparing-to D3DXTransformNormal.

Please don't PM me with questions. Post them in the forums for *everyone's* benefit, and I can embarrass myself publicly.