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 

getting the world coordinate by screen coordinate in a sky shpere


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


Joined: 20 Sep 2018
Posts: 2

PostPosted: Tue Jan 08, 2019 1:58 am    Post subject:
getting the world coordinate by screen coordinate in a sky shpere
Reply with quote

Hi,all

I am a new to osg and I use the following method to get the world coordinate by screen corrdiante and it works well:
osg::Matrix VPW = viewer->getCamera()->getViewMatrix() *
viewer->getCamera()->getProjectionMatrix() *viewer->
getCamera()->getViewport()_>computeWindowMatrix();
osg::Matrix Inm = osg::Matrix::inverse(VPW);
osg::Vec3d world = (osg::Vec3d(pos.x(), pos.y(), 0)) * Inm;

My scene is quite sample,the root has only one child:
root->addchild(osgDB::readNodeFile("cow.osg"));


When i add a big sky shpere that surrounds the cow,scene changing to:
root->addchild(osgDB::readNodeFile("cow.osg"));
osg::ref_ptr<osg::Drawable> drawable = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), 100));
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(drawable.get());
root->addchild(geode);

I cannot get the right world coordinate when my camera move inside the sphere by the above method.

Did I miss something?Is there some way to ignore the sphere and then to get the world coordinate by screen coordinate?

If anyone could point me in the right direction with some simple code,it is very much appreciated. Thanks a lot!

Thank you!

Cheers,
Qi Very Happy
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 problem about reconstructing world co... swaggydong General 0 Sun Jun 23, 2019 8:26 am View latest post
No new posts off screen rendering with OSG Sorin General 0 Mon May 13, 2019 8:14 am View latest post
No new posts [Help] OSG + ArKit: Problem convertin... Brayner General 4 Mon Oct 08, 2018 7:07 pm View latest post
No new posts Absolute final world position matrix ... Steal General 1 Mon Sep 24, 2018 11:25 am View latest post
No new posts EXTERNAL: Re: World space normal. Rowley, Marlin R General 1 Wed Jul 11, 2018 4:30 pm 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