| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <osgSim/DOFTransform> |
|---|
| 14 | |
|---|
| 15 | using namespace osgSim; |
|---|
| 16 | using namespace osg; |
|---|
| 17 | |
|---|
| 18 | static const unsigned int TRANSLATION_X_LIMIT_BIT = 0x80000000u >> 0; |
|---|
| 19 | static const unsigned int TRANSLATION_Y_LIMIT_BIT = 0x80000000u >> 1; |
|---|
| 20 | static const unsigned int TRANSLATION_Z_LIMIT_BIT = 0x80000000u >> 2; |
|---|
| 21 | static const unsigned int ROTATION_PITCH_LIMIT_BIT = 0x80000000u >> 3; |
|---|
| 22 | static const unsigned int ROTATION_ROLL_LIMIT_BIT = 0x80000000u >> 4; |
|---|
| 23 | static const unsigned int ROTATION_YAW_LIMIT_BIT = 0x80000000u >> 5; |
|---|
| 24 | static const unsigned int SCALE_X_LIMIT_BIT = 0x80000000u >> 6; |
|---|
| 25 | static const unsigned int SCALE_Y_LIMIT_BIT = 0x80000000u >> 7; |
|---|
| 26 | static const unsigned int SCALE_Z_LIMIT_BIT = 0x80000000u >> 8; |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | DOFTransform::DOFTransform(): |
|---|
| 30 | _previousTraversalNumber(osg::UNINITIALIZED_FRAME_NUMBER), |
|---|
| 31 | _previousTime(0.0), |
|---|
| 32 | _limitationFlags(0), |
|---|
| 33 | _animationOn(false), |
|---|
| 34 | _increasingFlags(0xffff), |
|---|
| 35 | _multOrder(PRH) |
|---|
| 36 | { |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | DOFTransform::DOFTransform(const DOFTransform& dof, const osg::CopyOp& copyop): |
|---|
| 40 | osg::Transform(dof, copyop), |
|---|
| 41 | _previousTraversalNumber(dof._previousTraversalNumber), |
|---|
| 42 | _previousTime(dof._previousTime), |
|---|
| 43 | _minHPR(dof._minHPR), |
|---|
| 44 | _maxHPR(dof._maxHPR), |
|---|
| 45 | _currentHPR(dof._currentHPR), |
|---|
| 46 | _incrementHPR(dof._incrementHPR), |
|---|
| 47 | _minTranslate(dof._minTranslate), |
|---|
| 48 | _maxTranslate(dof._maxTranslate), |
|---|
| 49 | _currentTranslate(dof._currentTranslate), |
|---|
| 50 | _incrementTranslate(dof._incrementTranslate), |
|---|
| 51 | _minScale(dof._minScale), |
|---|
| 52 | _maxScale(dof._maxScale), |
|---|
| 53 | _currentScale(dof._currentScale), |
|---|
| 54 | _incrementScale(dof._incrementScale), |
|---|
| 55 | _Put(dof._Put), |
|---|
| 56 | _inversePut(dof._inversePut), |
|---|
| 57 | _limitationFlags(dof._limitationFlags), |
|---|
| 58 | _animationOn(dof._animationOn), |
|---|
| 59 | _increasingFlags(dof._increasingFlags), |
|---|
| 60 | _multOrder(dof._multOrder) |
|---|
| 61 | { |
|---|
| 62 | if (_animationOn) setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | void DOFTransform::traverse(osg::NodeVisitor& nv) |
|---|
| 66 | { |
|---|
| 67 | if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR) |
|---|
| 68 | { |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | if ((nv.getTraversalNumber()!=_previousTraversalNumber) && nv.getFrameStamp()) |
|---|
| 73 | { |
|---|
| 74 | double newTime = nv.getFrameStamp()->getSimulationTime(); |
|---|
| 75 | |
|---|
| 76 | animate((float)(newTime-_previousTime)); |
|---|
| 77 | |
|---|
| 78 | _previousTraversalNumber = nv.getTraversalNumber(); |
|---|
| 79 | _previousTime = newTime; |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | Transform::traverse(nv); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | bool DOFTransform::computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const |
|---|
| 87 | { |
|---|
| 88 | |
|---|
| 89 | osg::Matrix l2w(getPutMatrix()); |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | osg::Matrix current; |
|---|
| 93 | current.makeTranslate(getCurrentTranslate()); |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | if(_multOrder == PRH) |
|---|
| 97 | { |
|---|
| 98 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 99 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 100 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 101 | } |
|---|
| 102 | else if(_multOrder == PHR) |
|---|
| 103 | { |
|---|
| 104 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 105 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 106 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 107 | } |
|---|
| 108 | else if(_multOrder == HPR) |
|---|
| 109 | { |
|---|
| 110 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 111 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 112 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 113 | } |
|---|
| 114 | else if(_multOrder == HRP) |
|---|
| 115 | { |
|---|
| 116 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 117 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 118 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 119 | } |
|---|
| 120 | else if(_multOrder == RHP) |
|---|
| 121 | { |
|---|
| 122 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 123 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 124 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 125 | } |
|---|
| 126 | else |
|---|
| 127 | { |
|---|
| 128 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 129 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 130 | current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | current.preMultScale(getCurrentScale()); |
|---|
| 136 | |
|---|
| 137 | l2w.postMult(current); |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | l2w.postMult(getInversePutMatrix()); |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | if (_referenceFrame==RELATIVE_RF) |
|---|
| 144 | { |
|---|
| 145 | matrix.preMult(l2w); |
|---|
| 146 | } |
|---|
| 147 | else |
|---|
| 148 | { |
|---|
| 149 | matrix = l2w; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | return true; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | bool DOFTransform::computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const |
|---|
| 157 | { |
|---|
| 158 | |
|---|
| 159 | osg::Matrix w2l(getInversePutMatrix()); |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | osg::Matrix current; |
|---|
| 163 | current.makeTranslate(-getCurrentTranslate()); |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | if(_multOrder == PRH) |
|---|
| 167 | { |
|---|
| 168 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 169 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 170 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 171 | } |
|---|
| 172 | else if(_multOrder == PHR) |
|---|
| 173 | { |
|---|
| 174 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 175 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 176 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 177 | } |
|---|
| 178 | else if(_multOrder == HPR) |
|---|
| 179 | { |
|---|
| 180 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 181 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 182 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 183 | } |
|---|
| 184 | else if(_multOrder == HRP) |
|---|
| 185 | { |
|---|
| 186 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 187 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 188 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 189 | } |
|---|
| 190 | else if(_multOrder == RHP) |
|---|
| 191 | { |
|---|
| 192 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 193 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 194 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 195 | } |
|---|
| 196 | else |
|---|
| 197 | { |
|---|
| 198 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[0], 0.0, 0.0, 1.0)); |
|---|
| 199 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[1], 1.0, 0.0, 0.0)); |
|---|
| 200 | current.postMult(osg::Matrix::rotate(-getCurrentHPR()[2], 0.0, 1.0, 0.0)); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | current.postMultScale(osg::Vec3d(1./getCurrentScale()[0], 1./getCurrentScale()[1], 1./getCurrentScale()[2])); |
|---|
| 205 | |
|---|
| 206 | w2l.postMult(current); |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | w2l.postMult(getPutMatrix()); |
|---|
| 210 | |
|---|
| 211 | if (_referenceFrame==RELATIVE_RF) |
|---|
| 212 | { |
|---|
| 213 | |
|---|
| 214 | matrix.postMult(w2l); |
|---|
| 215 | } |
|---|
| 216 | else |
|---|
| 217 | { |
|---|
| 218 | matrix = w2l; |
|---|
| 219 | } |
|---|
| 220 | return true; |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | void DOFTransform::updateCurrentHPR(const osg::Vec3& hpr) |
|---|
| 225 | { |
|---|
| 226 | |
|---|
| 227 | if (_limitationFlags & ROTATION_ROLL_LIMIT_BIT) |
|---|
| 228 | { |
|---|
| 229 | |
|---|
| 230 | if(_minHPR[2] != _maxHPR[2]) |
|---|
| 231 | { |
|---|
| 232 | _currentHPR[2] = hpr[2]; |
|---|
| 233 | unsigned short this_flag = (unsigned short)1<<4; |
|---|
| 234 | |
|---|
| 235 | if(_currentHPR[2] < _minHPR[2]) |
|---|
| 236 | { |
|---|
| 237 | _currentHPR[2] = _minHPR[2]; |
|---|
| 238 | |
|---|
| 239 | _increasingFlags |= this_flag; |
|---|
| 240 | } |
|---|
| 241 | else if(_currentHPR[2] > _maxHPR[2]) |
|---|
| 242 | { |
|---|
| 243 | _currentHPR[2] = _maxHPR[2]; |
|---|
| 244 | |
|---|
| 245 | _increasingFlags &= ~this_flag; |
|---|
| 246 | } |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | else |
|---|
| 250 | { |
|---|
| 251 | _currentHPR[2] = hpr[2]; |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | if (_limitationFlags & ROTATION_PITCH_LIMIT_BIT) |
|---|
| 255 | { |
|---|
| 256 | if(_minHPR[1] != _maxHPR[1]) |
|---|
| 257 | { |
|---|
| 258 | _currentHPR[1] = hpr[1]; |
|---|
| 259 | unsigned short this_flag = (unsigned short)1<<3; |
|---|
| 260 | |
|---|
| 261 | if(_currentHPR[1] < _minHPR[1]) |
|---|
| 262 | { |
|---|
| 263 | _currentHPR[1] = _minHPR[1]; |
|---|
| 264 | _increasingFlags |= this_flag; |
|---|
| 265 | } |
|---|
| 266 | else if(_currentHPR[1] > _maxHPR[1]) |
|---|
| 267 | { |
|---|
| 268 | _currentHPR[1] = _maxHPR[1]; |
|---|
| 269 | _increasingFlags &= ~this_flag; |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 273 | else |
|---|
| 274 | { |
|---|
| 275 | _currentHPR[1] = hpr[1]; |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | if (_limitationFlags & ROTATION_YAW_LIMIT_BIT) |
|---|
| 279 | { |
|---|
| 280 | if(_minHPR[0] != _maxHPR[0]) |
|---|
| 281 | { |
|---|
| 282 | _currentHPR[0] = hpr[0]; |
|---|
| 283 | |
|---|
| 284 | unsigned short this_flag = (unsigned short)1<<5; |
|---|
| 285 | |
|---|
| 286 | if(_currentHPR[0] < _minHPR[0]) |
|---|
| 287 | { |
|---|
| 288 | _currentHPR[0] = _minHPR[0]; |
|---|
| 289 | _increasingFlags |= this_flag; |
|---|
| 290 | } |
|---|
| 291 | else if(_currentHPR[0] > _maxHPR[0]) |
|---|
| 292 | { |
|---|
| 293 | _currentHPR[0] = _maxHPR[0]; |
|---|
| 294 | _increasingFlags &= ~this_flag; |
|---|
| 295 | } |
|---|
| 296 | } |
|---|
| 297 | } |
|---|
| 298 | else |
|---|
| 299 | { |
|---|
| 300 | _currentHPR[0] = hpr[0]; |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | dirtyBound(); |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | void DOFTransform::updateCurrentTranslate(const osg::Vec3& translate) |
|---|
| 308 | { |
|---|
| 309 | if (_limitationFlags & TRANSLATION_Z_LIMIT_BIT) |
|---|
| 310 | { |
|---|
| 311 | if(_minTranslate[2] != _maxTranslate[2]) |
|---|
| 312 | { |
|---|
| 313 | _currentTranslate[2] = translate[2]; |
|---|
| 314 | unsigned short this_flag = (unsigned short)1<<2; |
|---|
| 315 | |
|---|
| 316 | if(_currentTranslate[2] < _minTranslate[2]) |
|---|
| 317 | { |
|---|
| 318 | _currentTranslate[2] = _minTranslate[2]; |
|---|
| 319 | _increasingFlags |= this_flag; |
|---|
| 320 | } |
|---|
| 321 | else if(_currentTranslate[2] > _maxTranslate[2]) |
|---|
| 322 | { |
|---|
| 323 | _currentTranslate[2] = _maxTranslate[2]; |
|---|
| 324 | _increasingFlags &= ~this_flag; |
|---|
| 325 | } |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | else |
|---|
| 329 | { |
|---|
| 330 | _currentTranslate[2] = translate[2]; |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | if (_limitationFlags & TRANSLATION_Y_LIMIT_BIT) |
|---|
| 334 | { |
|---|
| 335 | if(_minTranslate[1] != _maxTranslate[1]) |
|---|
| 336 | { |
|---|
| 337 | _currentTranslate[1] = translate[1]; |
|---|
| 338 | unsigned short this_flag = (unsigned short)1<<1; |
|---|
| 339 | |
|---|
| 340 | if(_currentTranslate[1] < _minTranslate[1]) |
|---|
| 341 | { |
|---|
| 342 | _currentTranslate[1] = _minTranslate[1]; |
|---|
| 343 | _increasingFlags |= this_flag; |
|---|
| 344 | } |
|---|
| 345 | else if(_currentTranslate[1] > _maxTranslate[1]) |
|---|
| 346 | { |
|---|
| 347 | _currentTranslate[1] = _maxTranslate[1]; |
|---|
| 348 | _increasingFlags &= ~this_flag; |
|---|
| 349 | } |
|---|
| 350 | } |
|---|
| 351 | } |
|---|
| 352 | else |
|---|
| 353 | { |
|---|
| 354 | _currentTranslate[1] = translate[1]; |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | if (_limitationFlags & TRANSLATION_X_LIMIT_BIT) |
|---|
| 358 | { |
|---|
| 359 | if(_minTranslate[0] != _maxTranslate[0]) |
|---|
| 360 | { |
|---|
| 361 | _currentTranslate[0] = translate[0]; |
|---|
| 362 | unsigned short this_flag = (unsigned short)1; |
|---|
| 363 | |
|---|
| 364 | if(_currentTranslate[0] < _minTranslate[0]) |
|---|
| 365 | { |
|---|
| 366 | _currentTranslate[0] = _minTranslate[0]; |
|---|
| 367 | _increasingFlags |= this_flag; |
|---|
| 368 | } |
|---|
| 369 | else if(_currentTranslate[0] > _maxTranslate[0]) |
|---|
| 370 | { |
|---|
| 371 | _currentTranslate[0] = _maxTranslate[0]; |
|---|
| 372 | _increasingFlags &= ~this_flag; |
|---|
| 373 | } |
|---|
| 374 | } |
|---|
| 375 | } |
|---|
| 376 | else |
|---|
| 377 | { |
|---|
| 378 | _currentTranslate[0] = translate[0]; |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | dirtyBound(); |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | void DOFTransform::updateCurrentScale(const osg::Vec3& scale) |
|---|
| 386 | { |
|---|
| 387 | if (_limitationFlags & SCALE_Z_LIMIT_BIT) |
|---|
| 388 | { |
|---|
| 389 | if(_minScale[2] != _maxScale[2]) |
|---|
| 390 | { |
|---|
| 391 | _currentScale[2] = scale[2]; |
|---|
| 392 | unsigned short this_flag = (unsigned short)1<<8; |
|---|
| 393 | |
|---|
| 394 | if(_currentScale[2] < _minScale[2]) |
|---|
| 395 | { |
|---|
| 396 | _currentScale[2] = _minScale[2]; |
|---|
| 397 | _increasingFlags |= this_flag; |
|---|
| 398 | } |
|---|
| 399 | else if(_currentScale[2] > _maxScale[2]) |
|---|
| 400 | { |
|---|
| 401 | _currentScale[2] = _maxScale[2]; |
|---|
| 402 | _increasingFlags &= ~this_flag; |
|---|
| 403 | } |
|---|
| 404 | } |
|---|
| 405 | } |
|---|
| 406 | else |
|---|
| 407 | { |
|---|
| 408 | _currentScale[2] = scale[2]; |
|---|
| 409 | } |
|---|
| 410 | |
|---|
| 411 | if (_limitationFlags & SCALE_Y_LIMIT_BIT) |
|---|
| 412 | { |
|---|
| 413 | if(_minScale[1] != _maxScale[1]) |
|---|
| 414 | { |
|---|
| 415 | _currentScale[1] = scale[1]; |
|---|
| 416 | unsigned short this_flag = (unsigned short)1<<7; |
|---|
| 417 | |
|---|
| 418 | if(_currentScale[1] < _minScale[1]) |
|---|
| 419 | { |
|---|
| 420 | _currentScale[1] = _minScale[1]; |
|---|
| 421 | _increasingFlags |= this_flag; |
|---|
| 422 | } |
|---|
| 423 | else if(_currentScale[1] > _maxScale[1]) |
|---|
| 424 | { |
|---|
| 425 | _currentScale[1] = _maxScale[1]; |
|---|
| 426 | _increasingFlags &= ~this_flag; |
|---|
| 427 | } |
|---|
| 428 | } |
|---|
| 429 | } |
|---|
| 430 | else |
|---|
| 431 | { |
|---|
| 432 | _currentScale[1] = scale[1]; |
|---|
| 433 | } |
|---|
| 434 | |
|---|
| 435 | if (_limitationFlags & SCALE_X_LIMIT_BIT) |
|---|
| 436 | { |
|---|
| 437 | if(_minScale[0] != _maxScale[0]) |
|---|
| 438 | { |
|---|
| 439 | _currentScale[0] = scale[0]; |
|---|
| 440 | unsigned short this_flag = (unsigned short)1<<6; |
|---|
| 441 | |
|---|
| 442 | if(_currentScale[0] < _minScale[0]) |
|---|
| 443 | { |
|---|
| 444 | _currentScale[0] = _minScale[0]; |
|---|
| 445 | _increasingFlags |= this_flag; |
|---|
| 446 | } |
|---|
| 447 | else if(_currentScale[0] > _maxScale[0]) |
|---|
| 448 | { |
|---|
| 449 | _currentScale[0] = _maxScale[0]; |
|---|
| 450 | _increasingFlags &= ~this_flag; |
|---|
| 451 | } |
|---|
| 452 | } |
|---|
| 453 | } |
|---|
| 454 | else |
|---|
| 455 | { |
|---|
| 456 | _currentScale[0] = scale[0]; |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | dirtyBound(); |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | void DOFTransform::setAnimationOn(bool do_animate) |
|---|
| 463 | { |
|---|
| 464 | if (_animationOn == do_animate) return; |
|---|
| 465 | |
|---|
| 466 | int delta = 0; |
|---|
| 467 | |
|---|
| 468 | if (_animationOn) --delta; |
|---|
| 469 | if (do_animate) ++delta; |
|---|
| 470 | |
|---|
| 471 | _animationOn = do_animate; |
|---|
| 472 | |
|---|
| 473 | if (_animationOn) setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+delta); |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | void DOFTransform::animate(float deltaTime) |
|---|
| 477 | { |
|---|
| 478 | if(!_animationOn) return; |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | osg::Vec3 new_value = _currentTranslate; |
|---|
| 482 | |
|---|
| 483 | if(_increasingFlags & 1) |
|---|
| 484 | new_value[0] += _incrementTranslate[0]*deltaTime; |
|---|
| 485 | else |
|---|
| 486 | new_value[0] -= _incrementTranslate[0]*deltaTime; |
|---|
| 487 | |
|---|
| 488 | if(_increasingFlags & 1<<1) |
|---|
| 489 | new_value[1] += _incrementTranslate[1]*deltaTime; |
|---|
| 490 | else |
|---|
| 491 | new_value[1] -= _incrementTranslate[1]*deltaTime; |
|---|
| 492 | |
|---|
| 493 | if(_increasingFlags & 1<<2) |
|---|
| 494 | new_value[2] += _incrementTranslate[2]*deltaTime; |
|---|
| 495 | else |
|---|
| 496 | new_value[2] -= _incrementTranslate[2]*deltaTime; |
|---|
| 497 | |
|---|
| 498 | updateCurrentTranslate(new_value); |
|---|
| 499 | |
|---|
| 500 | new_value = _currentHPR; |
|---|
| 501 | |
|---|
| 502 | if(_increasingFlags & ((unsigned short)1<<3)) |
|---|
| 503 | new_value[1] += _incrementHPR[1]*deltaTime; |
|---|
| 504 | else |
|---|
| 505 | new_value[1] -= _incrementHPR[1]*deltaTime; |
|---|
| 506 | |
|---|
| 507 | if(_increasingFlags & ((unsigned short)1<<4)) |
|---|
| 508 | new_value[2] += _incrementHPR[2]*deltaTime; |
|---|
| 509 | else |
|---|
| 510 | new_value[2] -= _incrementHPR[2]*deltaTime; |
|---|
| 511 | |
|---|
| 512 | if(_increasingFlags & ((unsigned short)1<<5)) |
|---|
| 513 | new_value[0] += _incrementHPR[0]*deltaTime; |
|---|
| 514 | else |
|---|
| 515 | new_value[0] -= _incrementHPR[0]*deltaTime; |
|---|
| 516 | |
|---|
| 517 | updateCurrentHPR(new_value); |
|---|
| 518 | |
|---|
| 519 | new_value = _currentScale; |
|---|
| 520 | |
|---|
| 521 | if(_increasingFlags & 1<<6) |
|---|
| 522 | new_value[0] += _incrementScale[0]*deltaTime; |
|---|
| 523 | else |
|---|
| 524 | new_value[0] -= _incrementScale[0]*deltaTime; |
|---|
| 525 | |
|---|
| 526 | if(_increasingFlags & 1<<7) |
|---|
| 527 | new_value[1] += _incrementScale[1]*deltaTime; |
|---|
| 528 | else |
|---|
| 529 | new_value[1] -= _incrementScale[1]*deltaTime; |
|---|
| 530 | |
|---|
| 531 | if(_increasingFlags & 1<<8) |
|---|
| 532 | new_value[2] += _incrementScale[2]*deltaTime; |
|---|
| 533 | else |
|---|
| 534 | new_value[2] -= _incrementScale[2]*deltaTime; |
|---|
| 535 | |
|---|
| 536 | updateCurrentScale(new_value); |
|---|
| 537 | |
|---|
| 538 | } |
|---|