OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

View coordinates of a 3D point


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Fri Mar 16, 2018 12:37 pm    Post subject:
View coordinates of a 3D point
Reply with quote

Dear OSG forum,

Knowing the 3D coordinates of a point, is there an easy way in OSG to compute its 2D projected equivalent (i.e. in pixel coordinates)?

Thanks,

Antoine.
Back to top
View user's profile Send private message
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 488
Location: France

PostPosted: Sun Mar 18, 2018 3:58 am    Post subject:
Re: View coordinates of a 3D point
Reply with quote

Short answer is no
The maths has been covered plenty of time search the forum
Why not use TransformFeedBack and readback Arrays from gpu..?
It's here for that kind of stuff

arennuit wrote:
Dear OSG forum,

Knowing the 3D coordinates of a point, is there an easy way in OSG to compute its 2D projected equivalent (i.e. in pixel coordinates)?

Thanks,

Antoine.
Back to top
View user's profile Send private message Visit poster's website
Wojtek
User


Joined: 02 Nov 2011
Posts: 89

PostPosted: Sun Mar 18, 2018 10:32 am    Post subject:
View coordinates of a 3D point
Reply with quote

Hi,

Quote:
Knowing the 3D coordinates of a point, is there an easy way in OSG to compute its 2D projected equivalent (i.e. in pixel coordinates)?


Yes. In general your pixel coord is computed as: 


pixel_coords = WindowMatrix * ProjectionMatrix * ViewMatrix * ModelMatrix * point;


Your solution may vary whether you compute it in Update/Cull stage. Visitiors may have some utility functions making it simpler. But here I present more general solution:


osg::Vec3 point; // Your 3D point somewhere in the graph as a coord of some vertex under some point_parent_node  Node
osg::Matrix ModelMatrix = point_parent_node->getWorldMatrices()[0]; // Assuming your point have single parental path
osg::Matrix ViewMatrix = camera->getViewMatrix();
osg::Matrix ProjectionMatrix = camera->getProjectionMatrix();
osg::Matrix WindowMatrix = camera->getViewport()->computeWindowMatrix();


osg::Vec3 pixel_coords = WindowMatrix * ProjectionMatrix * ViewMatrix * ModelMatrix * point;
// x i y are window screen coords z is depth coord


Cheers,
Wojtek




2018-03-16 13:37 GMT+01:00 Antoine Rennuit < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>:
Quote:
Dear OSG forum,

Knowing the 3D coordinates of a point, is there an easy way in OSG to compute its 2D projected equivalent (i.e. in pixel coordinates)?

Thanks,

Antoine.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=73112#73112





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Mon Mar 19, 2018 3:41 pm    Post subject:
Reply with quote

Wojtek,

This does work, thanks!

PS: the multiplication is in reverse order because it is OpenGL convention matrices.

Regards,

Antoine.
Back to top
View user's profile Send private message
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Mon Mar 19, 2018 3:42 pm    Post subject:
Reply with quote

@Julien,

You are right, sorry for the noise.

Regards,

Antoine.
Back to top
View user's profile Send private message
Wojtek
User


Joined: 02 Nov 2011
Posts: 89

PostPosted: Mon Mar 19, 2018 4:56 pm    Post subject:
View coordinates of a 3D point
Reply with quote

PS: the multiplication is in reverse order  
Ah, indeed, sorry multiplication order should be reversed. I wrote that from top of my mind. Even though I use OSG every day I sometimes make some silly mistakes too. 



Regards,
WL


2018-03-19 16:42 GMT+01:00 Antoine Rennuit < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>:
Quote:
@Julien,

You are right, sorry for the noise.

Regards,

Antoine.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=73134#73134





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Mapping texture coordinates to a port... ijwolf8 General 0 Thu Oct 25, 2018 8:11 pm View latest post
No new posts update node in view using cullcallback sirian_ye General 2 Wed Aug 29, 2018 11:40 pm View latest post
No new posts CompositeViewer with multiple view, a... Angel General 3 Tue Aug 28, 2018 1:15 pm View latest post
No new posts Load an obj file and mapping a given ... aaa3d General 3 Mon Aug 06, 2018 2:27 pm View latest post
No new posts LineSegmentIntersector doesn't give a... MaFa18 General 3 Thu Jun 21, 2018 10:12 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP