Strange hou.GeometryViewportCamera.translation() values

   1096   7   1
User Avatar
Member
41 posts
Joined: Feb. 2018
Offline
Following my question yesterday [www.sidefx.com]..

So I wrote a simple custom viewport camera manipulator in Python. It's working well, though certainly more expensive than the built-in camera manipulator..

However, while trying to figure out how things work, I wrote:
self.camera = self.view_port.defaultCamera()
cam_xlate = hou.Vector3(self.camera.translation())
print (cam_xlate)
which prints a vector that is complete nonsense to me. I thought it would return the world position of the camera, like the doc [www.sidefx.com] suggested, but it's not.

After some eyeballing, I realized the returned value was, in fact, the camera's pivot's world position plus the camera's position in its rotated local space w.r.t. its pivot. That is:
cam_xform = self.view_port.viewTransform().explode() #Actual world transformation of the camera
pivot = hou.Vector3(self.camera.pivot())
print (cam_xlate == pivot + (cam_xform['translate'] - pivot) * self.camera.rotation())
# True

My question: adding a world-space vector and a local-space vector doesn't seem to make sense. Why is hou.GeometryViewportCamera.translation() returning these values? Is it some convention that I'm unaware of? Or is it just a bug?
User Avatar
Staff
397 posts
Joined: Feb. 2018
Offline
Some answers here [www.sidefx.com]
Edited by mabelzile - Jan. 12, 2020 14:36:40
User Avatar
Member
41 posts
Joined: Feb. 2018
Offline
mabelzile
Some answers here [www.sidefx.com]

It seems I don't have access to the page? It says “403 Please login with an authorized account”
Edited by AlanZ - Jan. 12, 2020 14:39:02
User Avatar
Staff
397 posts
Joined: Feb. 2018
Offline
AlanZ
mabelzile
Some answers here [www.sidefx.com]

It seems I don't have access to the page? It says “403 Please login with an authorized account”
Ah sorry. Here's the answers:

I'm using the hou.GeometryViewportCamera class to modify the camera, and I noticed that for example the .translation() member function doesn't seem to return world space values, is that correct?
Translation for the viewport camera is applied after its rotation is, so it's basis is oriented by the camera.

Are some these functions work in some sort of camera-relative space? (The pivot() for instance seems to return world-space values)
Pivot is the world space location of the pivot. Translation and pivot are the only methods there where the space matters. Most of the space change methods are on the GeometryViewport. GeometryViewportCamera is mostly just a parameter class, meant for stashing and applying later on.
User Avatar
Staff
5158 posts
Joined: July 2005
Offline
The docs are incorrect. The translation is done after the camera rotation is applied, so it's in camera space. The pivot is in world space though (as it affects the rotation).
User Avatar
Member
41 posts
Joined: Feb. 2018
Offline
mabelzile
GeometryViewportCamera is mostly just a parameter class, meant for stashing and applying later on.

Thanks guys, that makes sense.

Still wondering why .translation() would add two vectors in different spaces together though?
User Avatar
Staff
5158 posts
Joined: July 2005
Offline
Translation, rotation, and pivot are the components used to create the camera transform matrix, which is in TRS order. Which should probably be in the docs.
User Avatar
Member
41 posts
Joined: Feb. 2018
Offline
twod
Translation, rotation, and pivot are the components used to create the camera transform matrix, which is in TRS order. Which should probably be in the docs.

I understand. But still, .translation() returns the sum of .pivot() and (world_position - .pivot()) * .rotation(). Note that the first one, .pivot(), is in world space; the latter, is in camera space. For what reason does anyone ever want to add them together?

I know this is probably trivial in practice, but I'm just asking in case I miss something obvious..
Edited by AlanZ - Jan. 13, 2020 09:41:45
  • Quick Links