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.leop...@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@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>


-- 
trajce nikolov nick
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to