| | 84 | class ModelPositionCallback : public osg::NodeCallback |
| | 85 | { |
| | 86 | public: |
| | 87 | |
| | 88 | ModelPositionCallback(): |
| | 89 | _latitude(0.0), |
| | 90 | _longitude(0.0), |
| | 91 | _height(1000.0) |
| | 92 | {} |
| | 93 | |
| | 94 | void updateParameters() |
| | 95 | { |
| | 96 | _longitude += (2.0*osg::PI)/360.0; |
| | 97 | } |
| | 98 | |
| | 99 | |
| | 100 | virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) |
| | 101 | { |
| | 102 | updateParameters(); |
| | 103 | |
| | 104 | osg::NodePath nodePath = nv->getNodePath(); |
| | 105 | |
| | 106 | osg::MatrixTransform* mt = nodePath.empty() ? 0 : dynamic_cast<osg::MatrixTransform*>(nodePath.back()); |
| | 107 | if (mt) |
| | 108 | { |
| | 109 | osg::CoordinateSystemNode* csn = 0; |
| | 110 | |
| | 111 | // find coordinate system node from our parental chain |
| | 112 | unsigned int i; |
| | 113 | for(i=0; i<nodePath.size() && csn==0; ++i) |
| | 114 | { |
| | 115 | csn = dynamic_cast<osg::CoordinateSystemNode*>(nodePath[i]); |
| | 116 | } |
| | 117 | |
| | 118 | if (csn) |
| | 119 | { |
| | 120 | |
| | 121 | |
| | 122 | osg::EllipsoidModel* ellipsoid = csn->getEllipsoidModel(); |
| | 123 | if (ellipsoid) |
| | 124 | { |
| | 125 | osg::Matrixd matrix; |
| | 126 | for(i+=1; i<nodePath.size()-1; ++i) |
| | 127 | { |
| | 128 | osg::Transform* transform = nodePath[i]->asTransform(); |
| | 129 | if (transform) transform->computeLocalToWorldMatrix(matrix, nv); |
| | 130 | } |
| | 131 | |
| | 132 | //osg::Matrixd matrix; |
| | 133 | ellipsoid->computeLocalToWorldTransformFromLatLongHeight(_latitude,_longitude,_height,matrix); |
| | 134 | matrix.preMult(osg::Matrixd::rotate(_rotation)); |
| | 135 | |
| | 136 | mt->setMatrix(matrix); |
| | 137 | } |
| | 138 | |
| | 139 | } |
| | 140 | } |
| | 141 | |
| | 142 | traverse(node,nv); |
| | 143 | } |
| | 144 | |
| | 145 | double _latitude; |
| | 146 | double _longitude; |
| | 147 | double _height; |
| | 148 | osg::Quat _rotation; |
| | 149 | }; |
| | 150 | |
| | 151 | |