| 153 | } |
| 154 | |
| 155 | void HudSystem::updateState() |
| 156 | { |
| 157 | bool showHud = false; |
| 158 | if (mEntity && mEnabled) |
| 159 | { |
| 160 | osg::Viewport* viewport = mParentCamera->getViewport(); |
| 161 | mHud->setAspectRatio(viewport->width() / viewport->height()); |
| 162 | |
| 163 | Node* node = mEntity->getFirstComponent<Node>().get(); |
| 164 | Motion* motion = mEntity->getFirstComponent<Motion>().get(); |
| 165 | |
| 166 | if (node && motion) |
| 167 | { |
| 168 | showHud = true; |
| 169 | mHud->clear(); |
| 170 | |
| 171 | LatLonAlt lla = toLatLonAlt(GeocentricPosition(node->getPosition())).position; |
| 172 | Quaternion ltpOrientation = toLtpNed(GeocentricOrientation(node->getOrientation()), toLatLon(lla)).orientation; |
| 173 | Vector3 euler = math::eulerFromQuat(ltpOrientation); |
| 174 | |
| 175 | mHeadingRibbon->draw(euler.z * math::radToDegD()); |
| 176 | |
| 177 | Quaternion uprightYawFrameOrientation = toGeocentric(LtpNedOrientation(glm::angleAxis(euler.z, Vector3(0, 0, 1))), toLatLon(lla)).orientation; |
| 178 | const Vector3 uprightLocalVel = glm::inverse(uprightYawFrameOrientation) * motion->linearVelocity; |
| 179 | const glm::vec2 uprightLocalVel2d(uprightLocalVel.x, uprightLocalVel.y); |
| 180 | |
| 181 | if (glm::length(uprightLocalVel2d) < 10) |
| 182 | { |
| 183 | mHoverVelModel->draw(uprightLocalVel2d); |
| 184 | } |
| 185 | |
| 186 | if (mPitchLadderVisible) |
| 187 | { |
| 188 | double verticalFov = mVerticalFovProvider(); |
| 189 | mPitchLadder->setPitchGapHeight(2.0 * pitchLadderAngleIncrement / verticalFov); |
| 190 | mPitchLadder->draw(euler.y, euler.x); |
| 191 | } |
| 192 | |
| 193 | mHud->drawText(glm::vec2(-0.4, 0.35), toIntString(glm::length(motion->linearVelocity) * metersPerSecToKnots)); |
| 194 | |
| 195 | mAltitudeBar->draw(lla.alt); |
| 196 | mHud->drawText(glm::vec2(0.4, 0.35), toIntString(lla.alt * metersToFeet)); |
| 197 | |
| 198 | mRollAngleRibbon->draw(euler.x * math::radToDegD()); |
| 199 | |
| 200 | drawVee(*mHud, glm::vec2(0)); |
| 201 | |
| 202 | ControlInputsComponent* controlInputsComponents = mEntity->getFirstComponent<ControlInputsComponent>().get(); |
| 203 | if (controlInputsComponents) |
| 204 | { |
| 205 | drawControlInputs(*mHud, glm::vec2(-0.8), *controlInputsComponents); |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if (showHud && !mInScene) |
| 211 | { |
| 212 | mParentCamera->addChild(mHud); |
nothing calls this directly
no test coverage detected