]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/placement.cxx
Small cleanups to the SGGeo[dc] classes, provide more hooks to use them directly
[simgear.git] / simgear / scene / model / placement.cxx
1 // placement.cxx - manage the placment of a 3D model.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain, and comes with no warranty.
5
6 #ifdef HAVE_CONFIG_H
7 #include <simgear_config.h>
8 #endif
9
10 #include <simgear/compiler.h>
11
12 #include <string.h>             // for strcmp()
13
14 #include <plib/sg.h>
15 #include <plib/ssg.h>
16 #include <plib/ul.h>
17
18 #include "location.hxx"
19 #include "placementtrans.hxx"
20
21 #include "placement.hxx"
22
23
24 \f
25 ////////////////////////////////////////////////////////////////////////
26 // Implementation of SGModelPlacement.
27 ////////////////////////////////////////////////////////////////////////
28
29 SGModelPlacement::SGModelPlacement ()
30   : _lon_deg(0),
31     _lat_deg(0),
32     _elev_ft(0),
33     _roll_deg(0),
34     _pitch_deg(0),
35     _heading_deg(0),
36     _selector(new ssgSelector),
37     _position(new ssgPlacementTransform),
38     _location(new SGLocation)
39 {
40 }
41
42 SGModelPlacement::~SGModelPlacement ()
43 {
44 }
45
46 void
47 SGModelPlacement::init( ssgBranch * model )
48 {
49   if (model != 0) {
50       _position->addKid(model);
51   }
52   _selector->addKid(_position);
53   _selector->clrTraversalMaskBits(SSGTRAV_HOT);
54 }
55
56 void
57 SGModelPlacement::update()
58 {
59   _location->setPosition( _lon_deg, _lat_deg, _elev_ft );
60   _location->setOrientation( _roll_deg, _pitch_deg, _heading_deg );
61
62   sgMat4 rotation;
63   sgCopyMat4( rotation, _location->getTransformMatrix() );
64   _position->setTransform(_location->get_absolute_view_pos(), rotation);
65 }
66
67 bool
68 SGModelPlacement::getVisible () const
69 {
70   return (_selector->getSelect() != 0);
71 }
72
73 void
74 SGModelPlacement::setVisible (bool visible)
75 {
76   _selector->select(visible);
77 }
78
79 void
80 SGModelPlacement::setLongitudeDeg (double lon_deg)
81 {
82   _lon_deg = lon_deg;
83 }
84
85 void
86 SGModelPlacement::setLatitudeDeg (double lat_deg)
87 {
88   _lat_deg = lat_deg;
89 }
90
91 void
92 SGModelPlacement::setElevationFt (double elev_ft)
93 {
94   _elev_ft = elev_ft;
95 }
96
97 void
98 SGModelPlacement::setPosition (double lon_deg, double lat_deg, double elev_ft)
99 {
100   _lon_deg = lon_deg;
101   _lat_deg = lat_deg;
102   _elev_ft = elev_ft;
103 }
104
105 void
106 SGModelPlacement::setPosition(const SGGeod& position)
107 {
108   _lon_deg = position.getLongitudeDeg();
109   _lat_deg = position.getLatitudeDeg();
110   _elev_ft = position.getElevationFt();
111 }
112
113 void
114 SGModelPlacement::setRollDeg (double roll_deg)
115 {
116   _roll_deg = roll_deg;
117 }
118
119 void
120 SGModelPlacement::setPitchDeg (double pitch_deg)
121 {
122   _pitch_deg = pitch_deg;
123 }
124
125 void
126 SGModelPlacement::setHeadingDeg (double heading_deg)
127 {
128   _heading_deg = heading_deg;
129 }
130
131 void
132 SGModelPlacement::setOrientation (double roll_deg, double pitch_deg,
133                                   double heading_deg)
134 {
135   _roll_deg = roll_deg;
136   _pitch_deg = pitch_deg;
137   _heading_deg = heading_deg;
138 }
139
140 void
141 SGModelPlacement::setOrientation (const SGQuatd& orientation)
142 {
143   orientation.getEulerDeg(_heading_deg, _pitch_deg, _roll_deg);
144 }
145
146 // end of model.cxx