1 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2011 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 | |
---|
36 | if(!updater_lat_deg.empty()) |
---|
37 | object_->lat = osg::DegreesToRadians(osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble(updater_lat_deg, osgVisual::dataIO_slot::TO_OBJ )); |
---|
38 | if(!updater_lon_deg.empty()) |
---|
39 | object_->lon = osg::DegreesToRadians(osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble(updater_lon_deg, 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_deg.empty()) |
---|
43 | object_->azimuthAngle_psi = osg::DegreesToRadians(osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble(updater_rot_z_deg, osgVisual::dataIO_slot::TO_OBJ )); |
---|
44 | if(!updater_rot_y_deg.empty()) |
---|
45 | object_->pitchAngle_theta = osg::DegreesToRadians(osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble(updater_rot_y_deg, osgVisual::dataIO_slot::TO_OBJ )); |
---|
46 | if(!updater_rot_x_deg.empty()) |
---|
47 | object_->bankAngle_phi = osg::DegreesToRadians(osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble(updater_rot_x_deg, osgVisual::dataIO_slot::TO_OBJ )); |
---|
48 | if(!updater_label.empty()) |
---|
49 | object_->updateLabelText("default", osgVisual::visual_dataIO::getInstance()->getSlotDataAsString(updater_label, osgVisual::dataIO_slot::TO_OBJ )); |
---|
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_; |
---|
71 | } |
---|
72 | |
---|
73 | void object_updater::setUpdaterSlotNames( osgVisual::visual_object* object_, std::string lat_deg_, std::string lon_deg_, std::string alt_, std::string rot_x_deg_, std::string rot_y_deg_, std::string rot_z_deg_, std::string label_) |
---|
74 | { |
---|
75 | if(lat_deg_!="") |
---|
76 | updater_lat_deg = lat_deg_; |
---|
77 | else |
---|
78 | updater_lat_deg = object_->getName()+"_POS_LAT"; |
---|
79 | |
---|
80 | if(lon_deg_!="") |
---|
81 | updater_lon_deg = lon_deg_; |
---|
82 | else |
---|
83 | updater_lon_deg = 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_deg_!="") |
---|
91 | updater_rot_x_deg = rot_x_deg_; |
---|
92 | else |
---|
93 | updater_rot_x_deg = object_->getName()+"_ROT_X"; |
---|
94 | |
---|
95 | if(rot_y_deg_!="") |
---|
96 | updater_rot_y_deg = rot_y_deg_; |
---|
97 | else |
---|
98 | updater_rot_y_deg = object_->getName()+"_ROT_Y"; |
---|
99 | |
---|
100 | if(rot_z_deg_!="") |
---|
101 | updater_rot_z_deg = rot_z_deg_; |
---|
102 | else |
---|
103 | updater_rot_z_deg = object_->getName()+"_ROT_Z"; |
---|
104 | |
---|
105 | if(label_!="") |
---|
106 | updater_label = label_; |
---|
107 | else |
---|
108 | { |
---|
109 | updater_label = object_->getName()+"_LABEL"; |
---|
110 | object_->addLabel("autoupdated", " "); |
---|
111 | } |
---|
112 | } |
---|