[osg-users] setViewMatrixAsLookAt not working to set the initial camera position

Rodrigo Dias rodrigo1406 at gmail.com
Mon Jan 7 18:48:35 PST 2019


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







More information about the osg-users mailing list