I'm confused too, speed reading, and a few unfamiliar aspects to you
coding style set me off on the wrong route.

Robert.

On 6/28/07, Morné Pistorius <[EMAIL PROTECTED]> wrote:
On 6/28/07, Robert Osfield <[EMAIL PROTECTED]> wrote:
> On 6/28/07, Morné Pistorius <[EMAIL PROTECTED]> wrote:
>
> This looks wrong...
> >     LookAt = LookAt * Xform;
>
> Also use ^ to get the cross product rather than * which gives you the
> dot product,

Eh?  Now I'm even more confused :)  Xform is the 4x4 Transformation
matrix computed with
osg::computeLocalToWorld().  LookAt is the point I want the camera to
face in local object coordinates.  I do

  LookAt = LookAt * Xform;

to convert LookAt to world coordinates.  As I understood things, this
is just a pre-multiplication.  Why is that wrong? Similarly, I convert
the up vector to world coordinates.

I thought that would work, but it seems I have to compute the up
vector using cross products.  Thanks for the tip, Robert!

This is the code that I used and works for me - I paste it here for
newbies with the same problem:

    // get the node path from this node to the scene root
    osg::NodePathList paths = i_pNode->getParentalNodePaths();
    osg::NodePath & nodePath = paths[0];

    // accumulate all the transforms in the node path to get to the
    // world coordinate transform for this node
    osg::Matrix Xform = osg::computeLocalToWorld( nodePath );

    // transform the local viewpoint to world coordinates
    osg::Vec3 LookFrom, LookAt, Up;
    i_pNode->BestView( LookFrom, LookAt );

    LookFrom = LookFrom * Xform;
    LookAt = LookAt * Xform;

    // compute up vector
    osg::Vec3 v1 = LookAt - LookFrom;
// vector between object and viewpoint (world coords)
    osg::Vec3 v2 = Xform.getTrans() - (osg::Vec3(-1,0,0) * Xform);
// vector in object's xy plane (world coords)
    Up = v1^v2;

    m_Viewer->getCameraManipulator()->setHomePosition( LookFrom, LookAt, Up );


Thanks again,
Morne
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to