[osg-users] Trackball and view question

J.P. Delport jpdelport at csir.co.za
Thu Sep 27 23:36:17 PDT 2007


I am attaching an old email below that I think addressed some of the 
same issues you are having.

Also attached is a code snippet of a modified manipulator base class I use.


/** get by distance, rotation, center. */
virtual void getDRC(double& distance, osg::Quat& rotation, osg::Vec3d& 
center) {
    distance = _distance;
    rotation = _rotation;
    center = _center;

/** set by distance, rotation, center. This keeps the focus point 
correct. */
virtual void setByDRC(double distance, osg::Quat rotation, osg::Vec3d 
center) {
    _distance = distance;
    _rotation = rotation;
    _center = center;
    _thrown = false;

Old email:
Hi Morne,

I've done something like this, though not exactly the same. One gotcha I
found was that getting the matrix from the Trackball was not enough to
reset it later. Internally the trackball works with a distance, rotation
and center, (thats a scalar, quat and vec3) and all this info is not
encoded in the final matrix used for drawing. I added getDRC and
setByDRC to the cameras I have.

You can prob find the code for these in the list archives. If you don't,
let me know.


ps. are you in South Africa by any chance?

Morné Pistorius wrote:
 > > Hi,
 > >
 > > I have a scene with various models loaded.  I want to be able to double
 > > click on a model and have the camera move and position itself in front
 > > of the model, and afterwards return to the default trackball 
 > >
 > > I looked at the osgcamera and osganimation examples and I'm trying to
 > > come up with a way of doing this.  These are my thoughts:
 > >
 > > 1. Somehow get the current camera position and attitude from the
 > > trackball manipulator.
 > > 2. Compute an animation path from this point to a point in front of the
 > > model.
 > > 3. Replace the trackball manipulator with an AnimationPathManipulator
 > > and set the animation
 > > 4. Once it is done, replace it with with the original trackball
 > > manipulator and set its home position to the current camera position.
 > >
 > > Does this sound like the right way to go forward?  I would appreciate
 > > any feedback on this, pointers or gothcas from people with more
 > > experience than I have.  Also, if there are any examples that 
better fit
 > > what I am trying to do, I would be much obliged.
 > >
 > > Thank you kindly,
 > > Morne
 > >


Poirier, Guillaume wrote:
> Well this is what I was trying, using viewer.getCamera()->getViewMatrixAsLookAt(osg::Vec3 &eye, osg::Vec3 
> &center, osg::Vec3 &up, float lookDistance=1.0f). In step 2 (with trackball manipulator) I read back the 
> eye, center, and up values in the camera post draw callback. When the pose is almost identical as in the 
> first step, I read the values and they look quite different than what I was setting in the first step. I am still 
> unclear whether this is "normal" or not. So my question is, if it's "normal", is there a transformation 
> I can do to recuperate the step 1 values ? Or do I need to implement a custom view manipulator to achieve
> what I am looking for ?
> regards,
> bill
> -----Original Message-----
> From: osg-users-bounces at lists.openscenegraph.org on behalf of Alberto Luaces
> Sent: Thu 9/27/2007 4:38 AM
> To: OpenSceneGraph Users
> Subject: Re: [osg-users] Trackball and view question
> Hi Robert et al.
> Let me explain what I want to do accomplish an example:
> I load a model with no camera manipulator. I know the camera parameters
> (eye, ctr, up)
> that yield a desired pose. I set the viewer camera with those parameters and
> obtain the
> desired pose.
> Now I want to assume that I don't know those parameters. A user loads a
> model with a trackball
> manipulator. He / she can manipulate the model until the desired pose is
> obtained and
> recuperate the camera parameters (eye, ctr, up), which should be what I used
> in the previous
> step...
> Is that more clear ? How would I achieve this ?
> regards,
> Bill
> What about osg::Camera::getViewMatrixAsLookAt (osg::Vec3 &eye, osg::Vec3 
> &center, osg::Vec3 &up, float lookDistance=1.0f) ?
> Alberto

This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.

More information about the osg-users mailing list