I 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.
This commit is contained in:
ehofman 2005-04-29 14:37:27 +00:00
parent e0decf1233
commit eccd4d0325
2 changed files with 169 additions and 0 deletions

View File

@ -0,0 +1,98 @@
// placementtrans.hxx -- class for carrying transforms for placing models in the world
//
// Written by Mathias Froehlich, started April 2005.
//
// Copyright (C) 2005 Mathias Froehlich
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#ifndef __cplusplus
# error This library requires C++
#endif
#include <simgear/compiler.h>
#include <simgear/constants.h>
#include <plib/sg.h>
#include <plib/ssg.h>
#include "placementtrans.hxx"
ssgPlacementTransform::ssgPlacementTransform(void)
{
}
ssgPlacementTransform::~ssgPlacementTransform(void)
{
}
ssgBase *ssgPlacementTransform::clone(int clone_flags)
{
ssgPlacementTransform *b = new ssgPlacementTransform;
b->copy_from(this, clone_flags);
return b;
}
void
ssgPlacementTransform::copy_from(ssgPlacementTransform *src, int clone_flags)
{
ssgBaseTransform::copy_from(src, clone_flags);
sgdCopyVec3(_placement_offset, src->_placement_offset);
sgdCopyVec3(_scenery_center, src->_scenery_center);
}
void ssgPlacementTransform::setTransform(sgdVec3 off)
{
sgdCopyVec3(_placement_offset, off);
sgdVec3 tmp;
sgdSubVec3(tmp, _placement_offset, _scenery_center);
sgMat4 tmat;
sgZeroVec4(tmat[0]);
tmat[0][0] = 1;
sgZeroVec4(tmat[1]);
tmat[1][1] = 1;
sgZeroVec4(tmat[2]);
tmat[2][2] = 1;
sgSetVec3(tmat[3], tmp);
tmat[3][3] = 1;
ssgTransform::setTransform(tmat);
}
void ssgPlacementTransform::setTransform(sgdVec3 off, sgMat4 rot)
{
sgdCopyVec3(_placement_offset, off);
sgdVec3 tmp;
sgdSubVec3(tmp, _placement_offset, _scenery_center);
sgMat4 tmat;
sgCopyVec4(tmat[0], rot[0]);
sgCopyVec4(tmat[1], rot[1]);
sgCopyVec4(tmat[2], rot[2]);
sgSetVec3(tmat[3], tmp);
tmat[3][3] = 1;
ssgTransform::setTransform(tmat);
}
void ssgPlacementTransform::setSceneryCenter(sgdVec3 xyz)
{
sgdCopyVec3(_scenery_center, xyz);
sgdVec3 tmp;
sgdSubVec3(tmp, _placement_offset, _scenery_center);
sgMat4 tmat;
getTransform(tmat);
sgSetVec3(tmat[3], tmp);
ssgTransform::setTransform(tmat);
}

View File

@ -0,0 +1,71 @@
// placementtrans.hxx -- class for carrying transforms for placing models in the world
//
// Written by Mathias Froehlich, started April 2005.
//
// Copyright (C) 2005 Mathias Froehlich
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#ifndef _SG_PLACEMENTTRANS_HXX
#define _SG_PLACEMENTTRANS_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <simgear/compiler.h>
#include <simgear/constants.h>
#include <plib/sg.h>
#include <plib/ssg.h>
class ssgPlacementTransform : public ssgTransform
{
public:
ssgPlacementTransform(void);
virtual ~ssgPlacementTransform(void);
// using ssgTransform::addKid(ssgEntity*);
virtual ssgBase *clone(int clone_flags);
protected:
void copy_from(ssgPlacementTransform *src, int clone_flags);
private:
// virtual void setTransform(sgVec3 xyz);
// virtual void setTransform(sgCoord *xform);
// virtual void setTransform(sgCoord *xform, float sx, float sy, float sz);
// virtual void setTransform(sgMat4 xform);
public:
void setTransform(sgdVec3 off);
void setTransform(sgdVec3 off, sgMat4 rot);
void setSceneryCenter(sgdVec3 xyz);
private:
//////////////////////////////////////////////////////////////////
// private data //
//////////////////////////////////////////////////////////////////
sgdVec3 _placement_offset;
sgdVec3 _scenery_center;
};
#endif // _SG_LOCATION_HXX