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: 60

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 "INSTALL.vcxproj" -- FAILED ceranco Build system [build] 0 Fri Dec 15, 2017 1:25 pm View latest post
No new posts When gets the view matrix of a camera... wernerM General 2 Sat Nov 18, 2017 4:08 pm View latest post
No new posts osgDB::ImagePaged don't have "Pa... tang General 0 Mon Nov 13, 2017 2:51 am View latest post
No new posts "Memory: Colors" game from ... kornerr General 3 Sat Oct 28, 2017 11:19 am View latest post
No new posts How to set field of view of second sl... kefaline General [forum] 2 Wed Oct 04, 2017 1:29 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