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 

setViewMatrixAsLookAt not working to set the initial camera position


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


Joined: 01 Mar 2017
Posts: 24

PostPosted: Tue Jan 08, 2019 2:48 am    Post subject:
setViewMatrixAsLookAt not working to set the initial camera position
Reply with quote

Hi,

I'm able to change the camera's position with TrackballManipulator. However, I'd like to change the camera's initial position, but all the examples I've found just won't work. My source code is:

Code:
#include <iostream>
#include <osg/Camera>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <osgViewer/Viewer>
#include <osgEarth/ImageLayer>
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarthDrivers/gdal/GDALOptions>

using namespace std;
using namespace osg;
using namespace osgEarth;
using namespace osgEarth::Drivers;

int main (int argc, char** argv) {
   MapOptions mapOpt;
   mapOpt.coordSysType() = MapOptions::CSTYPE_PROJECTED;
   mapOpt.profile() = ProfileOptions("plate-carre");
   osg::ref_ptr<Map> map = new Map(mapOpt);
   {
      GDALOptions gdal;
      gdal.url() = "br_modified.tif";
      osg::ref_ptr<ImageLayer> layer = new ImageLayer( "BR", gdal );
      map->addLayer( layer );
   }
   {
      GDALOptions gdal;
      gdal.url() = "BRalt.tif";
      osg::ref_ptr<ElevationLayer> layer = new ElevationLayer( "SRTM", gdal );
      map->addLayer( layer );
   }
   osg::ref_ptr<MapNode> mapNode = new MapNode( map );
   osgViewer::Viewer viewer;
   viewer.setSceneData( mapNode.get() );
   viewer.setCameraManipulator( new osgGA::TrackballManipulator );

   Vec3 eye( 10000.0, 50000.0, 100000.0 ); // The position of your camera
   Vec3 center( 0.0, 0.0, 0.0 ); // The point your camera is looking at
   Vec3 up( 0.0, 1.0, 0.0 ); // The up-vector of your camera - this controls how your viewport will be rotated about its center and should be equal to [0, 1, 0] in a conventional graphics coordinate system
   viewer.getCamera()->setViewMatrixAsLookAt( eye, center, up );

   while ( !viewer.done() ) {
      viewer.frame();
   }
   return 0;
}


No matter which values I use for "eye", the camera always begins in the same position. Why is that?

Thank you!

Cheers,
Rodrigo
Back to top
View user's profile Send private message
sbrkopac
Newbie


Joined: 14 Jun 2018
Posts: 19

PostPosted: Tue Jan 08, 2019 3:02 am    Post subject:
setViewMatrixAsLookAt not working to set the initial camera position
Reply with quote

Hey Rodrigo,


You have to set the home position of your camera manipulator and make a call to home(1). You can force the delta time with a 1.


Sam



On Mon, Jan 7, 2019 at 6:48 PM Rodrigo Dias < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:
Hi,

I'm able to change the camera's position with TrackballManipulator. However, I'd like to change the camera's initial position, but all the examples I've found just won't work. My source code is:


Code:
#include <iostream>
#include <osg/Camera>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <osgViewer/Viewer>
#include <osgEarth/ImageLayer>
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarthDrivers/tms/TMSOptions>
#include <osgEarthDrivers/gdal/GDALOptions>

using namespace std;
using namespace osg;
using namespace osgEarth;
using namespace osgEarth::Drivers;

int main (int argc, char** argv) {
        MapOptions mapOpt;
        mapOpt.coordSysType() = MapOptions::CSTYPE_PROJECTED;
        mapOpt.profile() = ProfileOptions("plate-carre");
        osg::ref_ptr<Map> map = new Map(mapOpt);
        {
                GDALOptions gdal;
                gdal.url() = "br_modified.tif";
                osg::ref_ptr<ImageLayer> layer = new ImageLayer( "BR", gdal );
                map->addLayer( layer );
        }
        {
                GDALOptions gdal;
                gdal.url() = "BRalt.tif";
                osg::ref_ptr<ElevationLayer> layer = new ElevationLayer( "SRTM", gdal );
                map->addLayer( layer );
        }
        osg::ref_ptr<MapNode> mapNode = new MapNode( map );
        osgViewer::Viewer viewer;
        viewer.setSceneData( mapNode.get() );
        viewer.setCameraManipulator( new osgGA::TrackballManipulator );

        Vec3 eye( 10000.0, 50000.0, 100000.0 ); // The position of your camera
        Vec3 center( 0.0, 0.0, 0.0 ); // The point your camera is looking at
        Vec3 up( 0.0, 1.0, 0.0 ); // The up-vector of your camera - this controls how your viewport will be rotated about its center and should be equal to [0, 1, 0] in a conventional graphics coordinate system
        viewer.getCamera()->setViewMatrixAsLookAt( eye, center, up );
        while ( !viewer.done() ) {
                viewer.frame();
        }
        return 0;
}




No matter which values I use for "eye", the camera always begins in the same position. Why is that?

Thank you!

Cheers,
Rodrigo

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





_______________________________________________
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
Rodrigo
User


Joined: 01 Mar 2017
Posts: 24

PostPosted: Tue Jan 08, 2019 3:17 am    Post subject:
Reply with quote

Hi Sam,

By "home" I think you mean

Code:
viewer.getCameraManipulator()->setHomePosition( eye, center, up );


This really changed camera's position, though it's totally freaking out now (I'm still fiddling with the values in eye, center and up).

But I have no idea what you meant by "delta time", something to go inside the loop?

Thank you!

Cheers,
Rodrigo
Back to top
View user's profile Send private message
sbrkopac
Newbie


Joined: 14 Jun 2018
Posts: 19

PostPosted: Tue Jan 08, 2019 3:40 am    Post subject:
setViewMatrixAsLookAt not working to set the initial camera position
Reply with quote

After you set the home position try: viewer.getCameraManipulator()->home(1);



Sorry I'm not right in front of my computer right now.


On Mon, Jan 7, 2019 at 7:26 PM Rodrigo Dias < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:
Hi Sam,

By "home" I think you mean


Code:
viewer.getCameraManipulator()->setHomePosition( eye, center, up );




This really changed camera's position, though it's totally freaking out now (I'm still fiddling with the values in eye, center and up).

But I have no idea what you meant by "delta time", something to go inside the loop?

Thank you!

Cheers,
Rodrigo

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





_______________________________________________
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
Rodrigo
User


Joined: 01 Mar 2017
Posts: 24

PostPosted: Tue Jan 08, 2019 3:54 am    Post subject:
Reply with quote

I just tried it, but still the camera is messed up. No matter which numbers I choose to eye, center and up, it never behaves as default. I have not even a clue about the difference between 10, 100 and 1000, which one should I use? (I'm using osgEarth's Map and MapNode, btw, which are displaying a whole flat white Earth, with only the desired country drawn with a texture) I tried using getViewMatrixAsLookAt with the default values, but it's still a mess. I've looked at many questions here, and in some of the source code, but nothing clears this up.

Thank you!

Cheers,
Rodrigo
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 Keeping camera fixed alasca General 3 Fri May 31, 2019 10:08 am View latest post
No new posts osgQt & osgEarth not working with... Db80 General 1 Thu May 16, 2019 2:15 pm View latest post
No new posts AddSlave & removeSlave camera see... bclay General 2 Wed Apr 10, 2019 6:52 pm View latest post
No new posts FPS camera Ligvest General 0 Mon Apr 01, 2019 1:03 pm View latest post
No new posts First Person Camera disable inertial ... Ligvest General 3 Thu Mar 28, 2019 1:01 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