The Matrix4 object in Nuke stores a column-major matrix, like OpenGL. So, if
you're doing the multiplication by hand, you should multiply your vector by
each column of the matrix.
In your example, you expect 5 to be the x translation component, but it's
not. You can easily check the order the Matrix4 object is built in by
building the matrix from scratch:
m = nuke.math.Matrix4()
m.makeIdentity()
m.translate(5,0,0)
print m
# Result:
{1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
5, 0, 0, 1}
And that one would give you the result you were expecting:
print m * nuke.math.Vector4(0, 0, 0, 1)
# Result: {5, 0, 0, 1}
If you're not building from scratch, but building from matrices that are
row-major, you could just transpose the matrix and be ready to go.
Hope that helps.
Cheers,
Ivan
On Wed, Jun 29, 2011 at 5:18 AM, Ben Dickson <[email protected]> wrote:
>
> Noticed this a while ago and worked around it (by doing the multiplication
manually)
>
> Problem is when I multiple a vector by a matrix, it seems to be ignoring
the translation part:
>
> m = nuke.math.Matrix4()
> vals = [
> 1, 0, 0, 5,
> 0, 1, 0, 0,
> 0, 0, 1, 0,
> 0, 0, 0, 1
> ]
> for i, v in enumerate(vals):
> m[i] = v
>
> print m * nuke.math.Vector4(0, 0, 0, 1)
>
> I would expect this to return a value of 5 for x, because:
> 1*0 + 0*0 + 0*0 + 5*1 == 5
>
> Instead it seems to ignore the last column in the matrix and returns (0,
0, 0, 1)
>
> Is this correct? Seems like it could be a bug with the wrapping of the
nuke.math module (which... wouldn't be unheard of, thus the convoluted
method of initialising the matrix)
> --
> ben dickson
> 2D TD | [email protected]
> rising sun pictures | www.rsp.com.au
> _______________________________________________
> Nuke-python mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python