[osg-users] Orient a node to face another

Trajce Nikolov NICK trajce.nikolov.nick at gmail.com
Wed Oct 2 09:11:13 PDT 2019


Hi Paul,

you subtract the two input vectors and by this you get the direction from
one to the other, then normalize and make the Quaternion to rotate the axis
(in the code bellow is Y-forward) to the normalized vector. Something like
this:

osg::Quat GetRotation(const osg::Vec3& tgtPos, const osg::Vec3& subjectPos)
{

osg::Vec3 v = tgtPos - subjectPos;
v.normalize();

osg::Quat ret;
ret.makeRotate(osg::Vec3(0, 1, 0), v);

return Quat;
}

Nick

On Wed, Oct 2, 2019 at 6:04 PM Paul Leopard <paul.leopard at gmail.com> wrote:

> Hi,
>
> What would be the best approach to solve the following problem where I
> need one node to be updated through a callback to face another node? I
> understand how to get a node to face the screen with a billboard but that's
> not the problem here...
>
> Here is the problem:
>
> I've got a satellite node that is a child of a PAT and currently, I am
> updating that PAT position only to orbit the satellite around a planet
> node. I want to update the satellite PAT rotation also so that the
> satellite Z-Axis always faces the planet node origin. So, I need to compute
> the proper rotation Quat …
>
>
> Code:
>
> Quat GetRotation( const Vec3& tgtPos, const Vec3& subjectPos )
> {
> Quat ret = what?;
> return Quat;
> }
>
> Vec3 targetPosition(...);
> Vec3 satellitePosition(...);
> Quat rotation = GetRotation( satellitePosition, targetPosition );
>
> satellitePAT->setPosition( satellitePosition );
> satellitePAT->setRotation( rotation );
>
>
>
>
> What would be the best approach for the calculations in GetRotation(...)
> using OSG functions? I can work out the math on my own but I'd like to know
> if there are any cool OSG utilities to do this.
>
> Thank you!
>
> Cheers,
> Paul
>
> ------------------------
> things are more like they are now than they have ever been before
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=76770#76770
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>


-- 
trajce nikolov nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20191002/e418fe20/attachment.html>


More information about the osg-users mailing list