1 // placement.cxx - manage the placment of a 3D model.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain, and comes with no warranty.
7 #include <simgear_config.h>
10 #include <simgear/compiler.h>
12 #include <string.h> // for strcmp()
16 #include "location.hxx"
17 #include "placementtrans.hxx"
19 #include "placement.hxx"
23 ////////////////////////////////////////////////////////////////////////
24 // Implementation of SGModelPlacement.
25 ////////////////////////////////////////////////////////////////////////
27 SGModelPlacement::SGModelPlacement ()
34 _selector(new osg::Switch),
35 _position(new SGPlacementTransform),
36 _location(new SGLocation)
40 SGModelPlacement::~SGModelPlacement ()
46 SGModelPlacement::init( osg::Node * model )
49 _position->addChild(model);
51 _selector->addChild(_position.get());
52 // _selector->setNodeMask(_selector->getNodeMask() & ~SG_HOT_TRAVERSAL_BIT);
53 _selector->setValue(0, 1);
57 SGModelPlacement::update()
59 _location->setPosition( _lon_deg, _lat_deg, _elev_ft );
60 _location->setOrientation( _roll_deg, _pitch_deg, _heading_deg );
62 const sgVec4 *t = _location->getTransformMatrix();
64 for (unsigned i = 0; i < 4; ++i)
65 for (unsigned j = 0; j < 4; ++j)
66 rotation(i, j) = t[j][i];
67 SGVec3d pos(_location->get_absolute_view_pos());
68 _position->setTransform(pos, rotation);
72 SGModelPlacement::getVisible () const
74 return _selector->getValue(0);
78 SGModelPlacement::setVisible (bool visible)
80 _selector->setValue(0, visible);
84 SGModelPlacement::setLongitudeDeg (double lon_deg)
90 SGModelPlacement::setLatitudeDeg (double lat_deg)
96 SGModelPlacement::setElevationFt (double elev_ft)
102 SGModelPlacement::setPosition (double lon_deg, double lat_deg, double elev_ft)
110 SGModelPlacement::setPosition(const SGGeod& position)
112 _lon_deg = position.getLongitudeDeg();
113 _lat_deg = position.getLatitudeDeg();
114 _elev_ft = position.getElevationFt();
118 SGModelPlacement::setRollDeg (double roll_deg)
120 _roll_deg = roll_deg;
124 SGModelPlacement::setPitchDeg (double pitch_deg)
126 _pitch_deg = pitch_deg;
130 SGModelPlacement::setHeadingDeg (double heading_deg)
132 _heading_deg = heading_deg;
136 SGModelPlacement::setOrientation (double roll_deg, double pitch_deg,
139 _roll_deg = roll_deg;
140 _pitch_deg = pitch_deg;
141 _heading_deg = heading_deg;
145 SGModelPlacement::setOrientation (const SGQuatd& orientation)
147 orientation.getEulerDeg(_heading_deg, _pitch_deg, _roll_deg);