cool, thanks. I got it all nice and tidy now I think. thanks so much for the help!
On Mar 8, 2011, at 2:28 PM, Ivan Busquets wrote: > I see. So you need the lookAt in reference to the world, and not to the > camera. > You have already figured that out, but all you need then is to take your > lookAt direction vector and add the camera position to it: > > To avoid the slicing of the original matrix, you could do the following: > > #LOOK AT POSITION > > > lookAt = camMatrix.vtransform(nuke.math.Vector3(0,0,-1) ) # This is just > the "direction vector" > lookAt += camPos > > or just this, which should be the same: > > lookAt = camMatrix.transform(nuke.math.Vector3(0,0,-1) ) > > Basically, what you were doing with: > lookAt = nuke.math.Vector3( camMatrix[8], camMatrix[9], camMatrix[10] ) > lookAt.negate() > > should always give you a (0,0,-1) vector when the camera is not rotated. So > the above should be equivalent, I think. > > > > Makes sense? > > > > On Mon, Mar 7, 2011 at 5:06 PM, Frank Rueter <[email protected]> wrote: > looks like I got confused on my side. I realised I don't need a lookAt > vector but a position in space that the camera is "looking at". > > a friend helped out and gave me this: > > camMatrix = getWorldMatrix( camNode ) #USING IVANS FUNCTION > > #POSITION > camPos = camMatrix.transform( nuke.math.Vector3(0,0,0) ) > > #UP VECTOR > upVect = camMatrix.yAxis() > > #LOOK AT POSITION > lookAt = nuke.math.Vector3( camMatrix[8], camMatrix[9], > camMatrix[10] ) > lookAt.negate() > lookAt += camVect > > > This seems to work like a charm. I do wonder if there is a more elegant way > to get the initial lookAt though without slicing? > > Cheers, > frank > > > On Mar 8, 2011, at 12:45 PM, Frank Rueter 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 > > > _______________________________________________ > 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
