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 

How to change "field of view"(FOV), distance.


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


Joined: 27 Jul 2017
Posts: 5

PostPosted: Mon Aug 07, 2017 1:37 pm    Post subject:
How to change "field of view"(FOV), distance.
Reply with quote

Hi,
How to change "field of view"(FOV) and distance?
I used :
...

Thank you!

Cheers,
Maxim
Code:
osg::CameraView* cameraview = new osg::CameraView();
cameraview->addChild(group);
cameraview->setFieldOfView(120.0f);
osgViewer::Viewer viewer;
viewer.setSceneData(cameraview);

but it's not work. Help me please.
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 63

PostPosted: Fri Aug 18, 2017 10:28 am    Post subject:
Reply with quote

Hi,

Here's a dirty snippet. Not sure why I recalculate the aspect here also.

Your distance wouldbe the zFar. Don't put zNear too tiny, or you might get precision fighting.

Code:
double fovy, aspectRatio, zNear, zFar;
_camera->getProjectionMatrix().getPerspective(fovy, aspectRatio, zNear, zFar);

double aspect = (double)scrw / (double)scrh;
_camera->getProjectionMatrix().makePerspective(45, aspect, zNear, zFar);


Thank you!

Cheers,
Johny
Back to top
View user's profile Send private message
gambr
Appreciator


Joined: 22 Jun 2010
Posts: 355

PostPosted: Mon Aug 21, 2017 11:42 am    Post subject:
Reply with quote

Hi Arfaa,
here is my implementation:
Code:
bool ViewerWidget::setMainCameraFieldOfView(double iFov)
{
   osg::Camera* camera = mainView()->getCamera();
   double fovy, aspectRatio, zNear, zFar;
   bool result = camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
   if (true == result) {
      camera->setProjectionMatrixAsPerspective(iFov, aspectRatio, zNear, zFar);
   }
   return result;
}


ViewerWidget inherits from osgViewer::CompositeViewer. Anyway what I notice on your code is that you use a CameraViewer while I set the FOV to a osg::Camera. You could try the code on a osg::Camera and if it works then I guess there is something to investigate on the CameraViewer side.

HTH, Gianni
Back to top
View user's profile Send private message
arfaa
Newbie


Joined: 27 Jul 2017
Posts: 5

PostPosted: Tue Aug 22, 2017 9:02 am    Post subject:
Reply with quote

Hi,
thanks guys!!! Task resolved!
...

Thank you!

Cheers,
Maxim
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 Positioning an object based on the Vi... Takarashy General 0 Wed May 23, 2018 3:14 pm View latest post
No new posts "hooking" into the Trackbal... loopy General 2 Tue May 08, 2018 7:42 pm View latest post
No new posts get some "std::bad_alloc" e... surveyors General 3 Tue Apr 24, 2018 10:56 am View latest post
No new posts View coordinates of a 3D point arennuit General 5 Fri Mar 16, 2018 12:37 pm View latest post
No new posts How to make isometric view jgarneau General [forum] 3 Thu Mar 08, 2018 4:33 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