From e0decf12338960b9ce291ba97829873eb5efd0a1 Mon Sep 17 00:00:00 2001 From: ehofman Date: Fri, 29 Apr 2005 14:36:50 +0000 Subject: [PATCH] Mathias: have done a patch to eliminate the jitter of 3D-objects near the viewpoint (for example 3D cockpit objects). The problem is the roundoff accuracy of the float values used in the scenegraph together with the transforms of the eyepoint relative to the scenery center. The solution will be to move the scenery center near the view point. This way floats relative accuracy is enough to show a stable picture. To get that right I have introduced a transform node for the scenegraph which is responsible for that shift and uses double values as long as possible. The scenery subsystem now has a list of all those transforms required to place objects in the world and will tell all those transforms that the scenery center has changed when the set_scenery_center() of the scenery subsystem is called. The problem was not solvable by SGModelPlacement and SGLocation, since not all objects, especially the scenery, are placed using these classes. The first approach was to have the scenery center exactly at the eyepoint. This works well for the cockpit. But then the ground jitters a bit below the aircraft. With our default views you can't see that, but that F-18 has a camera view below the left engine intake with the nose gear and the ground in its field of view, here I could see that. Having the scenery center constant will still have this roundoff problems, but like it is now too, the roundoff error here is exactly the same in each frame, so you will not notice any jitter. The real solution is now to keep the scenery center constant as long as it is in a ball of 30m radius around the view point. If the scenery center is outside this ball, just put it at the view point. As a sideeffect of now beeing able to switch the scenery center in the whole scenegraph with one function call, I was able to remove a one half of a problem when switching views, where the scenery center was far off for one or two frames past switching from one view to the next. Also included is a fix to the other half of this problem, where the view position was not yet copied into a view when it is switched (at least under glut). This was responsible for the 'Error: ...' messages of the cloud subsystem when views were switched. --- simgear/scene/model/Makefile.am | 6 ++++-- simgear/scene/model/location.hxx | 9 ++++++--- simgear/scene/model/placement.cxx | 14 ++++++++------ simgear/scene/model/placement.hxx | 11 ++++++----- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/simgear/scene/model/Makefile.am b/simgear/scene/model/Makefile.am index d376bdb2..e12c5829 100644 --- a/simgear/scene/model/Makefile.am +++ b/simgear/scene/model/Makefile.am @@ -11,7 +11,8 @@ include_HEADERS = \ model.hxx \ modellib.hxx \ personality.hxx \ - placement.hxx + placement.hxx \ + placementtrans.hxx libsgmodel_a_SOURCES = \ animation.cxx \ @@ -20,6 +21,7 @@ libsgmodel_a_SOURCES = \ model.cxx \ modellib.cxx \ personality.cxx \ - placement.cxx + placement.cxx \ + placementtrans.cxx INCLUDES = -I$(top_srcdir) diff --git a/simgear/scene/model/location.hxx b/simgear/scene/model/location.hxx index 4c2ac30f..f1da39ca 100644 --- a/simgear/scene/model/location.hxx +++ b/simgear/scene/model/location.hxx @@ -109,19 +109,21 @@ public: void set_cur_elev_m ( double elev ) { _cur_elev_m = elev; } inline double get_cur_elev_m () { return _cur_elev_m; } // Interface to current buckets for use with tilemgr... - void set_tile_center ( Point3D tile_center ) { _tile_center = tile_center; } + void set_tile_center ( Point3D tile_center ) { set_dirty(); _tile_center = tile_center; } inline Point3D get_tile_center () { return _tile_center; } // Matrices... virtual const sgVec4 *getTransformMatrix( const Point3D scenery_center ) { - if ( _dirty ) { + if ( _dirty || scenery_center != _scenery_center ) { + _scenery_center = scenery_center; recalc( scenery_center ); } return TRANS; } virtual const sgVec4 *getCachedTransformMatrix() { return TRANS; } virtual const sgVec4 *getUpMatrix( const Point3D scenery_center ) { - if ( _dirty ) { + if ( _dirty || scenery_center != _scenery_center ) { + _scenery_center = scenery_center; recalc( scenery_center ); } return UP; @@ -153,6 +155,7 @@ private: // elevation of ground under this location... double _cur_elev_m; Point3D _tile_center; + Point3D _scenery_center; // surface vector heading south sgVec3 _surface_south; diff --git a/simgear/scene/model/placement.cxx b/simgear/scene/model/placement.cxx index cbee20f5..38a622ad 100644 --- a/simgear/scene/model/placement.cxx +++ b/simgear/scene/model/placement.cxx @@ -11,18 +11,15 @@ #include // for strcmp() -#include - #include #include #include #include "location.hxx" +#include "placementtrans.hxx" #include "placement.hxx" -SG_USING_STD(vector); - //////////////////////////////////////////////////////////////////////// @@ -37,7 +34,7 @@ SGModelPlacement::SGModelPlacement () _pitch_deg(0), _heading_deg(0), _selector(new ssgSelector), - _position(new ssgTransform), + _position(new ssgPlacementTransform), _location(new SGLocation) { } @@ -73,7 +70,12 @@ SGModelPlacement::update( const Point3D scenery_center ) POS[i][j] += (tmp * trans[j]); } } - _position->setTransform(POS); +// _position->setTransform(POS); + _position->setTransform(_location->get_absolute_view_pos(scenery_center), POS); + sgdVec3 center; + sgdSetVec3(center, + scenery_center.x(), scenery_center.y(), scenery_center.z()); + _position->setSceneryCenter(center); } bool diff --git a/simgear/scene/model/placement.hxx b/simgear/scene/model/placement.hxx index cf399676..99919a41 100644 --- a/simgear/scene/model/placement.hxx +++ b/simgear/scene/model/placement.hxx @@ -11,10 +11,6 @@ # error This library requires C++ #endif -#include - -SG_USING_STD(vector); - #include #include @@ -24,6 +20,7 @@ SG_USING_STD(vector); // Don't pull in the headers, since we don't need them here. class SGLocation; +class ssgPlacementTransform; // Has anyone done anything *really* stupid, like making min and max macros? @@ -86,6 +83,9 @@ public: // Allows multiplayer to get players position transform virtual const sgVec4 *get_POS() { return POS; } + ssgPlacementTransform * getTransform(void) + { return _position; } + private: // Geodetic position @@ -99,7 +99,8 @@ private: double _heading_deg; ssgSelector * _selector; - ssgTransform * _position; +// ssgTransform * _position; + ssgPlacementTransform * _position; // Location SGLocation * _location;