Oh I see.
If you get it from a world_matrix knob, I usually fill in my Matrix4 object
like this:
mtx = nuke.math.Matrix4()
k = cameranode['world_matrix']
for y in range(k.height()):
for x in range(k.width()):
mtx[x+(y*k.width())] = k.value(x,y)
Which fills in the matrix in the correct order already.
As for dividing by w, you shouldn't need to do it unless you're using a
projection matrix. If all you want is to get a point in the origin
transformed by your transformation matrix, you could do:
mt.transform(nuke.math.Vector3(0,0,0))
Also, if you're trying to get the final position of your camera/axis based
on its world_matrix, you shouldn't need to invert the matrix.
mtx.transform(Vector3) should give you that, unless I'm misreading what
you're trying to do.
On Thu, Jun 30, 2011 at 9:42 AM, Ben Dickson <[email protected]> wrote:
> 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
>> >
>> Nuke-python@support.**thefoundry.co.uk<[email protected]><mailto:
>> Nuke-python@support.**thefoundry.co.uk<[email protected]>>,
>> http://forums.thefoundry.co.**uk/ <http://forums.thefoundry.co.uk/>
>>
>> > http://support.thefoundry.co.**uk/cgi-bin/mailman/listinfo/**
>> nuke-python<http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python>
>>
>>
>> ------------------------------**------------------------------**
>> ------------
>>
>>
>> ______________________________**_________________
>> Nuke-python mailing list
>> Nuke-python@support.**thefoundry.co.uk<[email protected]>,
>> http://forums.thefoundry.co.**uk/ <http://forums.thefoundry.co.uk/>
>> http://support.thefoundry.co.**uk/cgi-bin/mailman/listinfo/**nuke-python<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
> Nuke-python@support.**thefoundry.co.uk<[email protected]>,
> http://forums.thefoundry.co.**uk/ <http://forums.thefoundry.co.uk/>
> http://support.thefoundry.co.**uk/cgi-bin/mailman/listinfo/**nuke-python<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