Ohh, that explains it! I was confused because I was getting the values from world_matrix, and assumed it would be consistent

def get_campos(wtc):
    campos = wtc.inverse() * nuke.math.Vector4(0, 0, 0, 1)

    campos_xyz = nuke.math.Vector3(
        campos.x/campos.w,
        campos.y/campos.w,
        campos.z/campos.w)

mtx = {}

for view in nuke.views():
    worldm = node['world_matrix']

    mtx[view] = nuke.math.Matrix4()
    for i in range(4*4):
        val = worldm.getValue(i, view)
        mtx[view][i] = val

    mtx[view].transpose()

get_campos(mtx['left']) # > {0,1,2} or something

..works as expected. Thanks Ivan!

As an aside, is the manual division of the w component-thingy necessary, or is there a simpler way to do this?

Ivan Busquets wrote:
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] <mailto:[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] <mailto:[email protected]>
 > rising sun pictures | www.rsp.com.au <http://www.rsp.com.au>
 > _______________________________________________
 > Nuke-python mailing list
> [email protected] <mailto:[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

--
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

Reply via email to