2002-04-03 23:54:44 +00:00
|
|
|
// FGAIEntity - abstract base class an artificial intelligence entity
|
|
|
|
//
|
|
|
|
// Written by David Luff, started March 2002.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2002 David C. Luff - david.luff@nottingham.ac.uk
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
*
|
|
|
|
* WARNING - Curt has some ideas about AI traffic so anything in here
|
2004-11-19 22:10:41 +00:00
|
|
|
* may get rewritten or scrapped. Contact Curt http://www.flightgear.org/~curt
|
2002-04-03 23:54:44 +00:00
|
|
|
* before spending any time or effort on this code!!!
|
|
|
|
*
|
|
|
|
******************************************************************/
|
|
|
|
|
2002-12-03 14:59:24 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
#include <Main/globals.hxx>
|
|
|
|
#include <Scenery/scenery.hxx>
|
2003-12-19 02:42:32 +00:00
|
|
|
#include <simgear/constants.h>
|
2002-04-03 23:54:44 +00:00
|
|
|
#include <simgear/math/point3d.hxx>
|
|
|
|
#include <simgear/math/sg_geodesy.hxx>
|
|
|
|
#include <simgear/misc/sg_path.hxx>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "AIEntity.hxx"
|
|
|
|
|
2004-01-23 17:18:24 +00:00
|
|
|
FGAIEntity::FGAIEntity() {
|
|
|
|
}
|
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
FGAIEntity::~FGAIEntity() {
|
2004-01-23 17:18:24 +00:00
|
|
|
//cout << "FGAIEntity dtor called..." << endl;
|
2005-10-15 14:51:52 +00:00
|
|
|
ssgDeRefDelete(_model); // Ought to check valid?
|
2004-01-23 17:18:24 +00:00
|
|
|
//cout << "Removing model from scene graph..." << endl;
|
|
|
|
globals->get_scenery()->get_scene_graph()->removeKid(_aip.getSceneGraph());
|
Mathias:
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.
2005-04-29 14:38:24 +00:00
|
|
|
// Unregister that one at the scenery manager
|
|
|
|
globals->get_scenery()->unregister_placement_transform(_aip.getTransform());
|
|
|
|
|
2004-01-23 17:18:24 +00:00
|
|
|
//cout << "Done!" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGAIEntity::SetModel(ssgBranch* model) {
|
|
|
|
_model = model;
|
|
|
|
_model->ref();
|
|
|
|
_aip.init(_model);
|
|
|
|
_aip.setVisible(false);
|
|
|
|
globals->get_scenery()->get_scene_graph()->addKid(_aip.getSceneGraph());
|
Mathias:
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.
2005-04-29 14:38:24 +00:00
|
|
|
// Register that one at the scenery manager
|
|
|
|
globals->get_scenery()->register_placement_transform(_aip.getTransform());
|
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
}
|
|
|
|
|
2002-10-02 15:27:49 +00:00
|
|
|
void FGAIEntity::Update(double dt) {
|
|
|
|
}
|
|
|
|
|
2005-10-25 13:49:55 +00:00
|
|
|
const string &FGAIEntity::GetCallsign() {
|
|
|
|
static string s = "";
|
|
|
|
return(s);
|
2004-01-23 17:18:24 +00:00
|
|
|
}
|
|
|
|
|
2003-03-20 11:53:44 +00:00
|
|
|
void FGAIEntity::RegisterTransmission(int code) {
|
|
|
|
}
|
|
|
|
|
2002-04-03 23:54:44 +00:00
|
|
|
// Run the internal calculations
|
2002-10-02 15:27:49 +00:00
|
|
|
//void FGAIEntity::Update() {
|
|
|
|
void FGAIEntity::Transform() {
|
2004-01-23 17:18:24 +00:00
|
|
|
_aip.setPosition(_pos.lon(), _pos.lat(), _pos.elev() * SG_METER_TO_FEET);
|
|
|
|
_aip.setOrientation(_roll, _pitch, _hdg);
|
2005-09-05 13:25:09 +00:00
|
|
|
_aip.update();
|
2002-04-03 23:54:44 +00:00
|
|
|
}
|