Mmm, but isn't the lookAt vector just a direction vector pointing to the "camera target"?. So, if your camera has no rotation, the lookAt vector should stay the same, regardless of the camera position?
If you wanted it to be affected by the camera translation and scale too, you could do camMatrix.transform( worldLookAt ). To be honest, I'm not sure what Maya (or is it for another 3D package?) expects for its lookAt vector, but I would assume it's just a direction vector, based on the center of the camera? On Mon, Mar 7, 2011 at 3:45 PM, Frank Rueter <[email protected]> wrote: > hm, I'm having trouble getting the right lookAt vector. > this is what I'm doing: > > def getWorldMatrix( node ): > m = nuke.math.Matrix4() > for i in range(0,16): > m[i] = node['world_matrix'].value(i%4, i/4) > return m > > camNode = nuke.createNode( 'Camera2' ) > camNode['translate'].setValue( (1,2,3) ) > > camMatrix = getWorldMatrix( camNode ) > worldLookAt = nuke.math.Vector3(0,0,-1) > localLookAt = camMatrix.vtransform( worldLookAt ) > localLookAt = camMatrix.vtransform( worldLookAt ) > print localLookAt > > > > > > The result for the lookAt vector stays at { 0,0,-1} even though the > camera's position is {1,2,3}. > What am I missing? > > Cheers, > frank > > > > > On Mar 7, 2011, at 3:42 PM, Ivan Busquets wrote: > > Hallo, Frank. > Despite writing that tutorial, I am by no means an expert in matrix and > maths. :) > > But I've learnt a thing or two about how they apply to things like camera > transforms, etc., so hopefully I'll be able to help with this one. > > I think the easiest in your case (easiest to code, not necessarily to > understand :p) is to start with the camera's transformation matrix instead > of the Euler rotations. If you want to use Euler angles as a starting point, > then you'll need to check for rotation order and such. > > To get the camera's transformation matrix, i usually do one on the > following: > > - If your camera doesn't have any other Cameras or Axis driving its final > transformation, you can simply do: > > cam_transform = nuke.toNode('camera_name')['transform'].value() > > - If you're interested in getting the final transformation matrix of a > concatenated set of transforms, I usually use the following to wrap the > contents of the 'world_matrix' knob into a nuke.math.Matrix4 object: > > ######### > def getCameraTransformMatrix(cameraNode): > m = nuke.math.Matrix4() > try: > for i in range(0,16): > m[i] = cameraNode['world_matrix'].value(i%4, i/4) > except: > print "couldn't get all values for a 4x4 Matrix. Identity matrix returned > instead" > m.makeIdentity() > return m > ############## > > > Finally, once you have your transformation matrix in a nuke.math.Matrix4 > object, getting the lookAt and the Up vectors should be a matter of setting > the initial direction of those two vectors, and then transform them using > the matrix. > > I.E. > > # For a single, non concatenated camera. Otherwise use the helper funcion > above. > cam_matrix = nuke.toNode('camera_name')['transform'].value() > > # set up initial lookAt vector > lookAt = nuke.math.Vector3(0,0,-1) # because Nuke's default cam looks at -Z > > # Initial up vector > up = nuke.math.Vector3(0,1,0) > > #Final lookAt vector > lookAt = cam_matrix.vtransform(lookAt) > > #Final up vector > up = cam_matrix.vtransform(up) > > # Note that the key here is to use the "vtransform" method instead of > "transform", since you want to apply the transformation to a direction > vector, but ignore any scaling or translation. > > I think this should get you the right values to go from a Nuke camera to, > say, a Camera + Aim + Up in Maya (don't have Maya here to check, though). > > Hope that helps! > > Cheers, > Ivan > > > On Sun, Mar 6, 2011 at 3:06 PM, Frank Rueter <[email protected]>wrote: > >> Hola, >> >> has anybody converted a nuke camera (Euler rotations) to LookAt and Up >> vectors? as used by some other applications >> I am just starting to read Ivan's tutorial on Nukepedia hoping it will >> shed some light on this for somebody with very limited understanding of 3D >> rotational maths (aka "me") but thought I'd spread my feelers in here at the >> same time. >> >> Cheers, >> frank_______________________________________________ >> Nuke-python mailing list >> [email protected] >> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python >> > > _______________________________________________ > Nuke-python mailing list > [email protected] > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python > > > > _______________________________________________ > Nuke-python mailing list > [email protected] > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python > >
_______________________________________________ Nuke-python mailing list [email protected] http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
