[osg-users] Setting up a camera
Hi, I'm trying to write something like a flightsimulator for simulating a sensor. For this I have some world data for my scene. Now I'm trying to create a camera. But the camera doesen't look to where I want it to look at. I get the following values - the position in lat[deg], lon[deg] and height[meter] - the orientation in pitch, roll and yawn in [rad] - the field of view in [rad] splittedt in fov_x_begin, fov_x_end etc - the distance sensing in [meter] from a server. Position and orientation are changing constantly, but first of all I would be happy if I get the right view with some default values. I tried it with setViewMatrix() and setHomePosition() but nothing happens. Maybe I used it wrong but maybe someone can tell me how I have to realize it. Im using osg 2.8.1 with vc8. The camera coordinate have to be with positive z-Axis as the camera view, +y-Axis up and +x-axis to the left. Thank you! Cheers, Diana -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40190#40190 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Setting up a camera
Hi Diana, If you are controlling the camera from a user defined path or simulation then you are best to not attach a camera manipulator to the viewer and just set the viewer's master camera directly yourself. If you do try to set the camera's view matrix yourself but still have a camera manipualtor attached the value you set will be overwritten. The osgViewer::Viewer by default will not attach a camera manipulator, but if you call viewer.run() it will know assume there isn't anything else settings the view matrix so will attach a camera manipulator as a fallback to at least provide some interactive view. For your own app I'd expect something like: osgViewer::Viewer viewer; viewer.setSceneDat(mySceneGraph); viewer.realize(); while(!viewer.done()) { viewer.getCamera()-setViewMatrix(myViewMatrix); // or use setViewMatrixAsLookAt(..) viewer.frame(); } Robert. On Wed, Jun 8, 2011 at 8:38 AM, Diana Kittelmann diana.kittelm...@gmx.de wrote: Hi, I'm trying to write something like a flightsimulator for simulating a sensor. For this I have some world data for my scene. Now I'm trying to create a camera. But the camera doesen't look to where I want it to look at. I get the following values - the position in lat[deg], lon[deg] and height[meter] - the orientation in pitch, roll and yawn in [rad] - the field of view in [rad] splittedt in fov_x_begin, fov_x_end etc - the distance sensing in [meter] from a server. Position and orientation are changing constantly, but first of all I would be happy if I get the right view with some default values. I tried it with setViewMatrix() and setHomePosition() but nothing happens. Maybe I used it wrong but maybe someone can tell me how I have to realize it. Im using osg 2.8.1 with vc8. The camera coordinate have to be with positive z-Axis as the camera view, +y-Axis up and +x-axis to the left. Thank you! Cheers, Diana -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40190#40190 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Setting up a camera
Thanks Robert, but when I try viewer.setSceneData(loadedModel); viewer.realize(); while(!viewer.done()) { ... viewer.frame(); } it doesen't display my scene. viewer.run() works fine. Diana. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40194#40194 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Setting up a camera
Hi Diana, On Wed, Jun 8, 2011 at 9:29 AM, Diana Kittelmann diana.kittelm...@gmx.de wrote: it doesen't display my scene. viewer.run() works fine. What do you mean, doesn't display your scene. What do you see? Just the default blue backgroud? Did you set your view matrix to look at the scene? If you don't have a camera manipulator doing this for you'll need to set this yourself. Is it that you are struggiling with the maths of how to set a view matrix? Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Setting up a camera
Yeah, I'm just seeing the blue background. And yaeh im struggeling with the math to set up my matrix. I set it up like this: while(!viewer.done()) { osg::EllipsoidModel convert; convert.convertLatLonHeightToXYZ(lat, lon, height, x, y, z); osg::Vec3 pos(x, y, z); osg::Matrixd matrix; matrix.setRotate(osg::Quat(osg::DegreesToRadians(0.0), osg::X_AXIS, osg::DegreesToRadians(0.0), osg::Y_AXIS, osg::DegreesToRadians(0.0), osg::Z_AXIS)); matrix.setTrans(pos); viewer.getCamera(); viewer.frame(); } But I'm not sure if this is right. Diana -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40200#40200 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Setting up a camera
Hi Diana, I'm afraid I don't have the time to write up a full tutorual on maths of setting view matrixes and matrix maths, the topic has been covered lots of time by the community so I'd recommend you have a look through the archhives. As a quite note, I'd mention that in OpenGL and the OSG the view matrix translates the world coordinates into the eye coordinates, and eye coordinates are +ve X to the right, +ve Y up, +veZ out from the screen. While in vis-sim the convention is that world coordinates of the scene have +ve X to the east, +ve Y north +ve Z up. Please note that the scene is in world coordinates, and the view matrix transforms the world cooridnates into eye coordinates, the view matrix doesn't position the eye into the scene but the other way around - this is important as it's the inverse matrix of a matrix that positions an object in the scene in world coordinates. This later point is probably where you have gone wrong. I won't dive in any further as teaching users about maths is not my role - I have plenty of other work to do. Please spend some time looking into the background maths, there are a huge number of articles on the web and posts on osg-users over the years. Robert. On Wed, Jun 8, 2011 at 9:59 AM, Diana Kittelmann diana.kittelm...@gmx.de wrote: Yeah, I'm just seeing the blue background. And yaeh im struggeling with the math to set up my matrix. I set it up like this: while(!viewer.done()) { osg::EllipsoidModel convert; convert.convertLatLonHeightToXYZ(lat, lon, height, x, y, z); osg::Vec3 pos(x, y, z); osg::Matrixd matrix; matrix.setRotate(osg::Quat(osg::DegreesToRadians(0.0), osg::X_AXIS, osg::DegreesToRadians(0.0), osg::Y_AXIS, osg::DegreesToRadians(0.0), osg::Z_AXIS)); matrix.setTrans(pos); viewer.getCamera(); viewer.frame(); } But I'm not sure if this is right. Diana -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40200#40200 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Setting up a camera
On 8/06/11 10:59 , Diana Kittelmann wrote: Yeah, I'm just seeing the blue background. And yaeh im struggeling with the math to set up my matrix. I set it up like this: while(!viewer.done()) { osg::EllipsoidModel convert; convert.convertLatLonHeightToXYZ(lat, lon, height, x, y, z); osg::Vec3 pos(x, y, z); osg::Matrixd matrix; matrix.setRotate(osg::Quat(osg::DegreesToRadians(0.0), osg::X_AXIS, osg::DegreesToRadians(0.0), osg::Y_AXIS, osg::DegreesToRadians(0.0), osg::Z_AXIS)); matrix.setTrans(pos); viewer.getCamera(); viewer.frame(); } But I'm not sure if this is right. Did you forget to include the bit where you set the matrix to the camera? Something like: viewer.getCamera()-setViewMatrix(matrix); /ulrich ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Setting up a camera
Thanks alot Robert. I try to teach me some math on my own now, but your answers were really helpful. @ulrich I did include I just missed to write it in my Post. Diana -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40207#40207 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Setting up a camera
Hi Diana, I find it pretty convenient to use Code: getCamera()-setViewMatrixAsLookAt (const osg::Vec3 eye, const osg::Vec3 center, const osg::Vec3 up) for setting up the view matrix, it was one of Robert's suggestions but I thought I'd re-emphasize it. Vec3 eye will be the position you're getting from the server. Vec3 center will be the point the camera is aiming at - it doesn't have to be the center of the scene, if you are given or can calculate the direction vector the camera is pointing along, (0,1,0) for example to look along the y-axis, you can add that to your eye point and use the result as center. Vec3 up orients the camera, think about taking a photo in portrait vs landscape vs some other angle. To start if you know the coordinates of some point in the scene, you could use that as center and just play with changing eye, the camera will always look at the same point (center) but from different places. After that, you could then work on calculating center based on the orientation you're receiving from the server. HTH, Cheers, Tom -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40217#40217 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Setting up a camera
Diana, First off, I don't see where you're setting the view matrix for the camera in your code below. You compute the transform, but you'll need to attach it to the camera. Since it looks like you're navigating on a sphere, I would try the following in your while loop below... osg::EllipsoidModel convert; osg::Matrixd position; osg::Matrixd t_matrix; convert.computeLocalToWorldTransformFromLatLongHeight(lat,lon,height,pos ition); t_matrix = position; t_matrix.invert(t_matrix); osg::Matrixd rotate2YUp; rotate2YUp.makeRotate(-M_PI_2, osg::Vec3f(1.0, 0.0, 0.0)); t_matrix *= rotate2YUp; viewer.getCamera()-setViewMatrix(t_matrix); viewer.frame(); Of course, I'm assuming that you have all the other camera state (i.e. projection matrix, viewport, etc.) set up correctly. The above doesn't include an orientation transform so you will need to add that. When you do, it will be concatenated with the position matrix. Make sure that lat, lon are in RADIANS when you call computeLocalToWorldTransformFromLatLongHeight. Height is usually in meters. One more thing...it would probably be best to move the code outside of the while loop and place it in an UpdateCallback... -Shayne -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Diana Kittelmann Sent: Wednesday, June 08, 2011 2:59 AM To: osg-users@lists.openscenegraph.org Subject: Re: [osg-users] Setting up a camera Yeah, I'm just seeing the blue background. And yaeh im struggeling with the math to set up my matrix. I set it up like this: while(!viewer.done()) { osg::EllipsoidModel convert; convert.convertLatLonHeightToXYZ(lat, lon, height, x, y, z); osg::Vec3 pos(x, y, z); osg::Matrixd matrix; matrix.setRotate(osg::Quat(osg::DegreesToRadians(0.0), osg::X_AXIS, osg::DegreesToRadians(0.0), osg::Y_AXIS, osg::DegreesToRadians(0.0), osg::Z_AXIS)); matrix.setTrans(pos); viewer.getCamera(); viewer.frame(); } But I'm not sure if this is right. Diana -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40200#40200 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or g ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org