HDK: Finding the current camera

   5851   4   1
User Avatar
Member
30 posts
Joined: July 2007
Offline
Hi,

I'm writing a SOP node that creates a curve very similar to the way that the Curve SOP does in freehand mode. I have a class that inherits from MSS_SingleOpBaseState and overloads handleMouseEvent. That all works fine, but I need to get access to the viewport where the mouse event happened, so that I can get the camera being used in that viewport. That way, I can draw a curve that is parallel to the viewing plane of the camera.

Thanks in advance!

~Joel
Joel Van Eenwyk
Programmer and FX Artist
Homepage: VFX Journal [vfxjournal.net]
User Avatar
Staff
1072 posts
Joined: July 2005
Offline
In the state code, workbench().currentViewport() will give you the DM_Viewport you want. To get at the camera node being used by a viewport, you can use OP_Node::lookupNode(viewport->getCameraId()).
User Avatar
Member
30 posts
Joined: July 2007
Offline
Ondrej: Thanks for the response! I figured it might have something to do with the workbench. The problem is that I do not have DM_Workbench or DM_Viewport header files. It was easy enough to create my own, and after some work finding the proper signatures, it does indeed link.

The problem is that DM_Workbench does not seem to have a currentViewport member function (I'm using Houdini 9.0.653). I did find that DM_SceneManager has that function, however. So, I did the following:

DM_SceneManager &dm_manager = (DM_SceneManager &)sceneManager();
DM_Viewport *viewport = dm_manager.currentViewport();
OP_Node *node = OP_Node::lookupNode( viewport->getCameraId() );

Again, it compiles and links, but it locks when accessing parameters specific to the Camera OBJ. Also, getCameraId() always returns zero. I'm guessing the problem is that I'm automagically casting BM_SceneManager to DM_SceneManager. I was prompted to do this rediculous act after seeing somthing similar in MSS_SingleOpBaseState. Here's the area I'm referring to:

DM_Workbench &workbench()
{ return (DM_Workbench &)sceneManager(); }

How can they just cast it like that? What is the difference between BM_* and DM_*? This cast seems completely unsafe, so I figured it may have been a mistake?

After the lookup, I figure I should be able to do the following:

if ( node->getOpTypeID() == OBJ_OPTYPE_ID )
{
OBJ_Camera *camera = (OBJ_Camera *)node;
fpreal x = camera->getX();
fpreal y = camera->getY();
fpreal n = camera->getNEAR(0.0);
x += n;
}

Right now, it is locking on the getNEAR line, which is to be expected. Any thoughts on how to make this work? I'm feeling very close, so just a few more hints and I should be able to get it.

Thanks so much!

~Joel
Joel Van Eenwyk
Programmer and FX Artist
Homepage: VFX Journal [vfxjournal.net]
User Avatar
Staff
1072 posts
Joined: July 2005
Offline
joelvaneenwyk
Ondrej: Thanks for the response! I figured it might have something to do with the workbench. The problem is that I do not have DM_Workbench or DM_Viewport header files. It was easy enough to create my own, and after some work finding the proper signatures, it does indeed link.

They're not part of the HDK?

joelvaneenwyk
The problem is that DM_Workbench does not seem to have a currentViewport member function (I'm using Houdini 9.0.653). I did find that DM_SceneManager has that function, however. So, I did the following:

DM_SceneManager &dm_manager = (DM_SceneManager &)sceneManager();
DM_Viewport *viewport = dm_manager.currentViewport();
OP_Node *node = OP_Node::lookupNode( viewport->getCameraId() );

DM_Workbench is a derived class of DM_SceneManager, which in turn is a derived class of BM_SceneManager, so you should be good so far.

joelvaneenwyk
Again, it compiles and links, but it locks when accessing parameters specific to the Camera OBJ. Also, getCameraId() always returns zero. I'm guessing the problem is that I'm automagically casting BM_SceneManager to DM_SceneManager. I was prompted to do this rediculous act after seeing somthing similar in MSS_SingleOpBaseState. Here's the area I'm referring to:

DM_Workbench &workbench()
{ return (DM_Workbench &)sceneManager(); }

How can they just cast it like that? What is the difference between BM_* and DM_*? This cast seems completely unsafe, so I figured it may have been a mistake?

Just to make sure, are you assigning the viewport a camera object? A value of 0 seems to indicate that you're not (though this is a bug and should really return -1 in this case).

The casts should be perfectly safe as DM_Workbench is ultimately a derived class of BM_SceneManager, and all states in geometry viewers can expect to be using one. Only COP states in the image viewer will be working with a different derived class.

joelvaneenwyk
After the lookup, I figure I should be able to do the following:

if ( node->getOpTypeID() == OBJ_OPTYPE_ID )
{
OBJ_Camera *camera = (OBJ_Camera *)node;
fpreal x = camera->getX();
fpreal y = camera->getY();
fpreal n = camera->getNEAR(0.0);
x += n;
}

Right now, it is locking on the getNEAR line, which is to be expected. Any thoughts on how to make this work? I'm feeling very close, so just a few more hints and I should be able to get it.

You can actually just use:
if ((obj = CAST_OBJNODE(node)) && (camera = obj->castToOBJCamera()))

The getX(), getY() methods query the tile position, which is not what you want. You'll want to use the OBJ_Node::T(float *v, float t) method to query the camera position instead. I wouldn't expect it to be getting into that code though if the camera id being returned by the viewport is 0.
User Avatar
Member
30 posts
Joined: July 2007
Offline
Excellent! That is just the information I needed! Thanks so much!

Unfortunately, those classes are indeed not part of the HDK. They are defined where they are needed like this:

class DM_Workbench;

But that doesn't help when you need to know what member functions and/or variables that class has. It also doesn't help if you want to know the class hierarchy, which sometimes (as in my case) makes certain casting operations look unsafe.

At any rate, it is now working extremely well. Thanks again for all the help!

~Joel
Joel Van Eenwyk
Programmer and FX Artist
Homepage: VFX Journal [vfxjournal.net]
  • Quick Links