00001
00002
00003
00004
00005
00006 #ifdef HAVE_CONFIG_H
00007 #include <simgear_config.h>
00008 #endif
00009
00010 #include "placement.hxx"
00011
00012 #include <simgear/compiler.h>
00013 #include <simgear/scene/util/SGSceneUserData.hxx>
00014
00015
00017
00019
00020 SGModelPlacement::SGModelPlacement () :
00021 _position(SGGeod::fromRad(0, 0)),
00022 _roll_deg(0),
00023 _pitch_deg(0),
00024 _heading_deg(0),
00025 _selector(new osg::Switch),
00026 _transform(new osg::PositionAttitudeTransform)
00027 {
00028 }
00029
00030 SGModelPlacement::~SGModelPlacement ()
00031 {
00032 }
00033
00034 void
00035 SGModelPlacement::init( osg::Node * model )
00036 {
00037 if (model != 0) {
00038 _transform->addChild(model);
00039 }
00040 _selector->addChild(_transform.get());
00041 _selector->setValue(0, 1);
00042 }
00043
00044 void
00045 SGModelPlacement::update()
00046 {
00047
00048 SGVec3d position = SGVec3d::fromGeod(_position);
00049 _transform->setPosition(toOsg(position));
00050
00051
00052
00053 SGQuatd orient = SGQuatd::fromLonLat(_position);
00054 orient *= SGQuatd::fromYawPitchRollDeg(_heading_deg, _pitch_deg, _roll_deg);
00055
00056
00057 orient *= SGQuatd::fromRealImag(0, SGVec3d(0, 1, 0));
00058
00059 _transform->setAttitude(toOsg(orient));
00060 }
00061
00062 bool
00063 SGModelPlacement::getVisible () const
00064 {
00065 return _selector->getValue(0);
00066 }
00067
00068 void
00069 SGModelPlacement::setVisible (bool visible)
00070 {
00071 _selector->setValue(0, visible);
00072 }
00073
00074 void
00075 SGModelPlacement::setLongitudeDeg (double lon_deg)
00076 {
00077 _position.setLongitudeDeg(lon_deg);
00078 }
00079
00080 void
00081 SGModelPlacement::setLatitudeDeg (double lat_deg)
00082 {
00083 _position.setLatitudeDeg(lat_deg);
00084 }
00085
00086 void
00087 SGModelPlacement::setElevationFt (double elev_ft)
00088 {
00089 _position.setElevationFt(elev_ft);
00090 }
00091
00092 void
00093 SGModelPlacement::setPosition (double lon_deg, double lat_deg, double elev_ft)
00094 {
00095 _position = SGGeod::fromDegFt(lon_deg, lat_deg, elev_ft);
00096 }
00097
00098 void
00099 SGModelPlacement::setPosition(const SGGeod& position)
00100 {
00101 _position = position;
00102 }
00103
00104 void
00105 SGModelPlacement::setRollDeg (double roll_deg)
00106 {
00107 _roll_deg = roll_deg;
00108 }
00109
00110 void
00111 SGModelPlacement::setPitchDeg (double pitch_deg)
00112 {
00113 _pitch_deg = pitch_deg;
00114 }
00115
00116 void
00117 SGModelPlacement::setHeadingDeg (double heading_deg)
00118 {
00119 _heading_deg = heading_deg;
00120 }
00121
00122 void
00123 SGModelPlacement::setOrientation (double roll_deg, double pitch_deg,
00124 double heading_deg)
00125 {
00126 _roll_deg = roll_deg;
00127 _pitch_deg = pitch_deg;
00128 _heading_deg = heading_deg;
00129 }
00130
00131 void
00132 SGModelPlacement::setOrientation (const SGQuatd& orientation)
00133 {
00134 orientation.getEulerDeg(_heading_deg, _pitch_deg, _roll_deg);
00135 }
00136
00137 void
00138 SGModelPlacement::setReferenceTime(const double& referenceTime)
00139 {
00140 SGSceneUserData* userData;
00141 userData = SGSceneUserData::getOrCreateSceneUserData(_transform);
00142 SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity();
00143 vel->referenceTime = referenceTime;
00144 }
00145
00146 void
00147 SGModelPlacement::setBodyLinearVelocity(const SGVec3d& linear)
00148 {
00149 SGSceneUserData* userData;
00150 userData = SGSceneUserData::getOrCreateSceneUserData(_transform);
00151 SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity();
00152 vel->linear = SGVec3d(-linear[0], linear[1], -linear[2]);
00153 }
00154
00155 void
00156 SGModelPlacement::setBodyAngularVelocity(const SGVec3d& angular)
00157 {
00158 SGSceneUserData* userData;
00159 userData = SGSceneUserData::getOrCreateSceneUserData(_transform);
00160 SGSceneUserData::Velocity* vel = userData->getOrCreateVelocity();
00161 vel->angular = SGVec3d(-angular[0], angular[1], -angular[2]);
00162 }
00163
00164