| 75 | | This Node manages the different levels of detail available for a |
|---|
| 76 | | Geometry and decides which one should be rendered, according to the |
|---|
| 77 | | distance from the current camera. The details of the selection process |
|---|
| 78 | | are taken from VRML97 standard. |
|---|
| 79 | | |
|---|
| 80 | | The node chooses which child to render based on the range values in the |
|---|
| 81 | | Range multi-field and the current distance of the camera from the |
|---|
| 82 | | object. The children should be ordered from the highest level of |
|---|
| 83 | | detail to the lowest level of detail. The range values specify the |
|---|
| 84 | | distances at which to switch between the different children. |
|---|
| 85 | | |
|---|
| 86 | | The center field is a translation offset in the local coordinate system |
|---|
| 87 | | that specifies the center of the object for distance calculations. In |
|---|
| 88 | | order to calculate which level to display, first the distance from the |
|---|
| 89 | | viewpoint to the center point of the LOD node (with corresponding |
|---|
| 90 | | transformations) is computed. If the distance is less than the first |
|---|
| 91 | | range value, then the first LOD is drawn. If it is between the first |
|---|
| 92 | | and the second values, then the second LOD is drawn, and so on. |
|---|
| | 75 | This Node manages the different levels of detail available for a Geometry |
|---|
| | 76 | and decides which one should be rendered, according to the distance from the |
|---|
| | 77 | current camera. The details of the selection process are taken from VRML97 |
|---|
| | 78 | standard. |
|---|
| | 79 | |
|---|
| | 80 | The node chooses which child to render based on the range values in the Range |
|---|
| | 81 | multi-field and the current distance of the camera from the object. |
|---|
| | 82 | The children should be ordered from the highest level of detail to the |
|---|
| | 83 | lowest level of detail. The range values specify the distances at which to |
|---|
| | 84 | switch between the different children. |
|---|
| | 85 | |
|---|
| | 86 | The center field is a translation offset in the local coordinate system that |
|---|
| | 87 | specifies the center of the object for distance calculations. In order to |
|---|
| | 88 | calculate which level to display, first the distance from the |
|---|
| | 89 | viewpoint to the center point of the LOD node (with corresponding |
|---|
| | 90 | transformations) is computed. If the distance is less than the first range |
|---|
| | 91 | value, then the first LOD is drawn. If it is between the first and the second |
|---|
| | 92 | values, then the second LOD is drawn, and so on. |
|---|
| 99 | | \code DistanceLOD lod = DistanceLOD::create(); |
|---|
| 100 | | |
|---|
| 101 | | // this is supposed to be the center of the LOD model, // that is, this |
|---|
| 102 | | is the point the distance is measured from lod->setCenter(12,1,5); // |
|---|
| 103 | | now we add the distances when models will change |
|---|
| | 99 | \code |
|---|
| | 100 | DistanceLOD lod = DistanceLOD::create(); |
|---|
| | 101 | |
|---|
| | 102 | // this is supposed to be the center of the LOD model, |
|---|
| | 103 | // that is, this is the point the distance is measured from |
|---|
| | 104 | lod->setCenter(12,1,5); |
|---|
| | 105 | // now we add the distances when models will change |
|---|
| | 351 | /*********************************** Non-ptr code ********************************/ |
|---|
| | 352 | void DistanceLODBase::pushToRange(const Real32& value) |
|---|
| | 353 | { |
|---|
| | 354 | editMField(RangeFieldMask, _mfRange); |
|---|
| | 355 | _mfRange.push_back(value); |
|---|
| | 356 | } |
|---|
| | 357 | |
|---|
| | 358 | void DistanceLODBase::insertIntoRange(UInt32 uiIndex, |
|---|
| | 359 | const Real32& value ) |
|---|
| | 360 | { |
|---|
| | 361 | editMField(RangeFieldMask, _mfRange); |
|---|
| | 362 | |
|---|
| | 363 | MFReal32::iterator fieldIt = _mfRange.begin(); |
|---|
| | 364 | |
|---|
| | 365 | fieldIt += uiIndex; |
|---|
| | 366 | |
|---|
| | 367 | _mfRange.insert(fieldIt, value); |
|---|
| | 368 | } |
|---|
| | 369 | |
|---|
| | 370 | void DistanceLODBase::replaceInRange(UInt32 uiIndex, |
|---|
| | 371 | const Real32& value ) |
|---|
| | 372 | { |
|---|
| | 373 | if(uiIndex >= _mfRange.size()) |
|---|
| | 374 | return; |
|---|
| | 375 | |
|---|
| | 376 | editMField(RangeFieldMask, _mfRange); |
|---|
| | 377 | |
|---|
| | 378 | _mfRange[uiIndex] = value; |
|---|
| | 379 | } |
|---|
| | 380 | |
|---|
| | 381 | void DistanceLODBase::replaceInRange(const Real32& pOldElem, |
|---|
| | 382 | const Real32& pNewElem) |
|---|
| | 383 | { |
|---|
| | 384 | Int32 elemIdx = _mfRange.findIndex(pOldElem); |
|---|
| | 385 | |
|---|
| | 386 | if(elemIdx != -1) |
|---|
| | 387 | { |
|---|
| | 388 | editMField(RangeFieldMask, _mfRange); |
|---|
| | 389 | |
|---|
| | 390 | MFReal32::iterator fieldIt = _mfRange.begin(); |
|---|
| | 391 | |
|---|
| | 392 | fieldIt += elemIdx; |
|---|
| | 393 | |
|---|
| | 394 | (*fieldIt) = pNewElem; |
|---|
| | 395 | } |
|---|
| | 396 | } |
|---|
| | 397 | |
|---|
| | 398 | void DistanceLODBase::removeFromRange(UInt32 uiIndex) |
|---|
| | 399 | { |
|---|
| | 400 | if(uiIndex < _mfRange.size()) |
|---|
| | 401 | { |
|---|
| | 402 | editMField(RangeFieldMask, _mfRange); |
|---|
| | 403 | |
|---|
| | 404 | MFReal32::iterator fieldIt = _mfRange.begin(); |
|---|
| | 405 | |
|---|
| | 406 | fieldIt += uiIndex; |
|---|
| | 407 | _mfRange.erase(fieldIt); |
|---|
| | 408 | } |
|---|
| | 409 | } |
|---|
| | 410 | |
|---|
| | 411 | void DistanceLODBase::removeFromRange(const Real32& value) |
|---|
| | 412 | { |
|---|
| | 413 | Int32 iElemIdx = _mfRange.findIndex(value); |
|---|
| | 414 | |
|---|
| | 415 | if(iElemIdx != -1) |
|---|
| | 416 | { |
|---|
| | 417 | editMField(RangeFieldMask, _mfRange); |
|---|
| | 418 | |
|---|
| | 419 | MFReal32::iterator fieldIt = _mfRange.begin(); |
|---|
| | 420 | |
|---|
| | 421 | fieldIt += iElemIdx; |
|---|
| | 422 | |
|---|
| | 423 | _mfRange.erase(fieldIt); |
|---|
| | 424 | } |
|---|
| | 425 | } |
|---|
| | 426 | |
|---|
| | 427 | void DistanceLODBase::clearRange(void) |
|---|
| | 428 | { |
|---|
| | 429 | editMField(RangeFieldMask, _mfRange); |
|---|
| | 430 | |
|---|
| | 431 | _mfRange.clear(); |
|---|
| | 432 | } |
|---|
| | 433 | |
|---|
| | 434 | |
|---|