I don't really understand the behavior of a QMatrix4x4 * QVector3D. I really just want a usable 3x3 matrix. I've figured out that setting the last element (4,4) to 1.0 basically turns QMatrix4x4 into a 3x3, but why is it that this returns inf:

@

QMatrix4x4 A(1.0, 0.0, 0.0, 0.0,

0.0, 1.0, 0.0, 0.0,

0.0, 0.0, 1.0, 0.0,

0.0, 0.0, 0.0, 0.0);

QVector3D B(1.0, 2.0, 3.0);

qDebug() << A*B;@

returns QVector3D(inf, inf, inf).

And similarly,

if (4,4) = 2 the output is QVector3D(1.0, 2.0, 3.0).

if (4,4) = 2 the output is QVector3D(0.5, 1.0, 1.5).

if (4,4) = 0.5 the output is QVector3D(2.0, 4.0, 6.0).

So clearly (4,4) is some kind of inverse length and the last row/column also do some kind of skew or manipulate the geometry somehow.

Any information on this available?

Thanks!

]]>I don't really understand the behavior of a QMatrix4x4 * QVector3D. I really just want a usable 3x3 matrix. I've figured out that setting the last element (4,4) to 1.0 basically turns QMatrix4x4 into a 3x3, but why is it that this returns inf:

@

QMatrix4x4 A(1.0, 0.0, 0.0, 0.0,

0.0, 1.0, 0.0, 0.0,

0.0, 0.0, 1.0, 0.0,

0.0, 0.0, 0.0, 0.0);

QVector3D B(1.0, 2.0, 3.0);

qDebug() << A*B;@

returns QVector3D(inf, inf, inf).

And similarly,

if (4,4) = 2 the output is QVector3D(1.0, 2.0, 3.0).

if (4,4) = 2 the output is QVector3D(0.5, 1.0, 1.5).

if (4,4) = 0.5 the output is QVector3D(2.0, 4.0, 6.0).

So clearly (4,4) is some kind of inverse length and the last row/column also do some kind of skew or manipulate the geometry somehow.

Any information on this available?

Thanks!

]]>The three values in the vector resulting from applying the transform are normalised by the value in the additional cell of the augmented vector result:

[code]

w = vector.x() * matrix.m[3][0] +

vector.y() * matrix.m[3][1] +

vector.z() * matrix.m[3][2] +

matrix.m[3][3];

[/code]

(from src/gui/math3d/qmatrix4x4.h). In your example this evaluates to 0 and dividing by zero gives you infinite rather than an exception.

You want QGenericMatrix:

@

QGenericMatrix<3,3,qreal> m1;

int n = 0;

for (int r = 0; r < 3; ++r)

for (int c = 0; c < 3; ++c)

m1(r, c) = ++n;

```
QGenericMatrix<1,3,qreal> m2;
m2(0, 0) = 1.0;
m2(1, 0) = 3.0;
m2(2, 0) = 6.0;
QGenericMatrix<1,3,qreal> result = m1 * m2;
for (int r = 0; r < 3; ++r)
qDebug() << result(r, 0);
```

@

]]>You are not alone. Took a while for me to realise the column count came before the row count in the template instantiation.

]]>