| 1 | // Copyright (C) 2009 - 2012 Mathias Froehlich - [email protected] |
| 2 | // |
| 3 | // This library is free software; you can redistribute it and/or |
| 4 | // modify it under the terms of the GNU Library General Public |
| 5 | // License as published by the Free Software Foundation; either |
| 6 | // version 2 of the License, or (at your option) any later version. |
| 7 | // |
| 8 | // This library is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | // Library General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with this program; if not, write to the Free Software |
| 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 | // |
| 17 | |
| 18 | #ifdef HAVE_CONFIG_H |
| 19 | #include <config.h> |
| 20 | #endif |
| 21 | |
| 22 | #include "HLAPerspectiveViewer.hxx" |
| 23 | |
| 24 | #include "HLAPerspectiveViewerClass.hxx" |
| 25 | |
| 26 | namespace fgviewer { |
| 27 | |
| 28 | HLAPerspectiveViewer::HLAPerspectiveViewer(HLAPerspectiveViewerClass* objectClass, const SGWeakPtr<simgear::HLAFederate>& federate) : |
| 29 | HLAViewer(objectClass), |
| 30 | _view(federate), |
| 31 | _zoomFactor(1), |
| 32 | _eyeTracker(federate) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | HLAPerspectiveViewer::~HLAPerspectiveViewer() |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | HLAPerspectiveViewer::createAttributeDataElements() |
| 42 | { |
| 43 | HLAViewer::createAttributeDataElements(); |
| 44 | |
| 45 | assert(dynamic_cast<HLAPerspectiveViewerClass*>(getObjectClass().get())); |
| 46 | HLAPerspectiveViewerClass& objectClass = static_cast<HLAPerspectiveViewerClass&>(*getObjectClass()); |
| 47 | |
| 48 | setAttributeDataElement(objectClass.getViewNameIndex(), _view.getDataElement()); |
| 49 | setAttributeDataElement(objectClass.getPositionIndex(), _position.getDataElement()); |
| 50 | setAttributeDataElement(objectClass.getOrientationIndex(), _orientation.getDataElement()); |
| 51 | setAttributeDataElement(objectClass.getZoomFactorIndex(), _zoomFactor.getDataElement()); |
| 52 | setAttributeDataElement(objectClass.getEyeTrackerNameIndex(), _eyeTracker.getDataElement()); |
| 53 | } |
| 54 | |
| 55 | const HLAView* |
| 56 | HLAPerspectiveViewer::getView() const |
| 57 | { |
| 58 | return _view.getObject(); |
| 59 | } |
| 60 | |
| 61 | HLAView* |
| 62 | HLAPerspectiveViewer::getView() |
| 63 | { |
| 64 | return _view.getObject(); |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | HLAPerspectiveViewer::setView(HLAView* view) |
| 69 | { |
| 70 | _view.setObject(view); |
| 71 | } |
| 72 | |
| 73 | const HLAEyeTracker* |
| 74 | HLAPerspectiveViewer::getEyeTracker() const |
| 75 | { |
| 76 | return _eyeTracker.getObject(); |
| 77 | } |
| 78 | |
| 79 | HLAEyeTracker* |
| 80 | HLAPerspectiveViewer::getEyeTracker() |
| 81 | { |
| 82 | return _eyeTracker.getObject(); |
| 83 | } |
| 84 | |
| 85 | void |
| 86 | HLAPerspectiveViewer::setEyeTracker(HLAEyeTracker* eyeTracker) |
| 87 | { |
| 88 | _eyeTracker.setObject(eyeTracker); |
| 89 | } |
| 90 | |
| 91 | SGLocationd |
| 92 | HLAPerspectiveViewer::getLocation(const SGTimeStamp& simTime) const |
| 93 | { |
| 94 | const HLAView* view = getView(); |
| 95 | if (!view) |
| 96 | return SGLocationd(getPosition(), getOrientation()); |
| 97 | return view->getLocation(simTime).getAbsoluteLocation(SGLocationd(getPosition(), getOrientation())); |
| 98 | } |
| 99 | |
| 100 | SGVec3d |
| 101 | HLAPerspectiveViewer::getLeftEyeOffset() const |
| 102 | { |
| 103 | const HLAEyeTracker* eyeTracker = getEyeTracker(); |
| 104 | if (!eyeTracker) |
| 105 | return SGVec3d(0, 0, 0); |
| 106 | return eyeTracker->getLeftEyeOffset(); |
| 107 | } |
| 108 | |
| 109 | SGVec3d |
| 110 | HLAPerspectiveViewer::getRightEyeOffset() const |
| 111 | { |
| 112 | const HLAEyeTracker* eyeTracker = getEyeTracker(); |
| 113 | if (!eyeTracker) |
| 114 | return SGVec3d(0, 0, 0); |
| 115 | return eyeTracker->getRightEyeOffset(); |
| 116 | } |
| 117 | |
| 118 | } // namespace fgviewer |