[31] | 1 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer |
---|
| 2 | * |
---|
| 3 | * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under |
---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
---|
| 7 | * |
---|
| 8 | * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. |
---|
| 9 | * You have to aquire licenses for all used proprietary modules. |
---|
| 10 | * |
---|
| 11 | * This library is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * OpenSceneGraph Public License for more details. |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #include <object_updater.h> |
---|
| 18 | |
---|
| 19 | using namespace osgVisual; |
---|
| 20 | |
---|
| 21 | object_updater::object_updater(osgVisual::visual_object* object_ ) |
---|
| 22 | { |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | object_updater::~object_updater(void) |
---|
| 26 | { |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | void object_updater::preUpdate(osgVisual::visual_object* object_ ) |
---|
| 30 | { |
---|
| 31 | OSG_NOTIFY( osg::INFO ) << "preUpdate visual Object " << object_->getName() << std::endl; |
---|
| 32 | // perform this preUpdater... |
---|
| 33 | //For each visual_object.member, |
---|
| 34 | // try to search according variable in dataIO with direction TO_OBJ and copy value to visual_object. |
---|
| 35 | |
---|
[215] | 36 | if(!updater_lat.empty()) |
---|
| 37 | object_->lat = osg::DegreesToRadians(osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble(updater_lat, osgVisual::dataIO_slot::TO_OBJ )); |
---|
| 38 | if(!updater_lon.empty()) |
---|
| 39 | object_->lon = osg::DegreesToRadians(osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble(updater_lon, osgVisual::dataIO_slot::TO_OBJ )); |
---|
| 40 | if(!updater_alt.empty()) |
---|
| 41 | object_->alt = osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble(updater_alt, osgVisual::dataIO_slot::TO_OBJ ); |
---|
| 42 | if(!updater_rot_z.empty()) |
---|
| 43 | object_->azimuthAngle_psi = osg::DegreesToRadians(osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble(updater_rot_z, osgVisual::dataIO_slot::TO_OBJ )); |
---|
| 44 | if(!updater_rot_y.empty()) |
---|
| 45 | object_->pitchAngle_theta = osg::DegreesToRadians(osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble(updater_rot_y, osgVisual::dataIO_slot::TO_OBJ )); |
---|
| 46 | if(!updater_rot_x.empty()) |
---|
| 47 | object_->bankAngle_phi = osg::DegreesToRadians(osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble(updater_rot_x, osgVisual::dataIO_slot::TO_OBJ )); |
---|
| 48 | if(!updater_label.empty()) |
---|
[218] | 49 | object_->updateLabelText("default", osgVisual::visual_dataIO::getInstance()->getSlotDataAsString(updater_label, osgVisual::dataIO_slot::TO_OBJ )); |
---|
[31] | 50 | |
---|
| 51 | // Finally execute nested PreUpdater |
---|
| 52 | if ( updater.valid() ) |
---|
| 53 | updater->preUpdate(object_); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | void object_updater::postUpdate(osgVisual::visual_object* object_ ) |
---|
| 57 | { |
---|
| 58 | OSG_NOTIFY( osg::INFO ) << "postUpdate visual Object " << object_->getName() << std::endl; |
---|
| 59 | |
---|
| 60 | // Finally execute nested PostUpdater |
---|
| 61 | if ( updater.valid() ) |
---|
| 62 | updater->postUpdate(object_); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | void object_updater::addUpdater( object_updater* updater_ ) |
---|
| 66 | { |
---|
| 67 | if (updater.valid()) |
---|
| 68 | updater->addUpdater( updater_ ); |
---|
| 69 | else |
---|
| 70 | updater = updater_; |
---|
[209] | 71 | } |
---|
| 72 | |
---|
| 73 | void object_updater::setUpdaterSlotNames( osgVisual::visual_object* object_, std::string lat_, std::string lon_, std::string alt_, std::string rot_x_, std::string rot_y_, std::string rot_z_, std::string label_) |
---|
| 74 | { |
---|
| 75 | if(lat_!="") |
---|
| 76 | updater_lat = lat_; |
---|
| 77 | else |
---|
| 78 | updater_lat = object_->getName()+"_POS_LAT"; |
---|
| 79 | |
---|
| 80 | if(lon_!="") |
---|
| 81 | updater_lon = lon_; |
---|
| 82 | else |
---|
| 83 | updater_lon = object_->getName()+"_POS_LON"; |
---|
| 84 | |
---|
| 85 | if(alt_!="") |
---|
| 86 | updater_alt = alt_; |
---|
| 87 | else |
---|
| 88 | updater_alt = object_->getName()+"_POS_ALT"; |
---|
| 89 | |
---|
| 90 | if(rot_x_!="") |
---|
| 91 | updater_rot_x = rot_x_; |
---|
| 92 | else |
---|
| 93 | updater_rot_x = object_->getName()+"_ROT_X"; |
---|
| 94 | |
---|
| 95 | if(rot_y_!="") |
---|
| 96 | updater_rot_y = rot_y_; |
---|
| 97 | else |
---|
| 98 | updater_rot_y = object_->getName()+"_ROT_Y"; |
---|
| 99 | |
---|
| 100 | if(rot_z_!="") |
---|
| 101 | updater_rot_z = rot_z_; |
---|
| 102 | else |
---|
| 103 | updater_rot_z = object_->getName()+"_ROT_Z"; |
---|
| 104 | |
---|
| 105 | if(label_!="") |
---|
| 106 | updater_label = label_; |
---|
| 107 | else |
---|
[210] | 108 | { |
---|
[209] | 109 | updater_label = object_->getName()+"_LABEL"; |
---|
[210] | 110 | object_->addLabel("autoupdated", " "); |
---|
| 111 | } |
---|
[31] | 112 | } |
---|