Esempio n. 1
0
  /**
   * Calculates the distance from a spatial to the camera. Distance is a squared distance.
   *
   * @param spat Spatial to check distance.
   * @return Distance from Spatial to current context's camera.
   */
  protected double distanceToCam(final Spatial spat) {
    if (spat._queueDistance != Double.NEGATIVE_INFINITY) {
      return spat._queueDistance;
    }

    final Camera cam = Camera.getCurrentCamera();

    if (spat.getWorldBound() != null && Vector3.isValid(spat.getWorldBound().getCenter())) {
      spat._queueDistance = spat.getWorldBound().distanceToEdge(cam.getLocation());
    } else {
      final ReadOnlyVector3 spatPosition = spat.getWorldTranslation();
      if (!Vector3.isValid(spatPosition)) {
        spat._queueDistance = Double.POSITIVE_INFINITY;
      } else {
        spat._queueDistance = cam.getLocation().distance(spatPosition);
      }
    }

    return spat._queueDistance;
  }
Esempio n. 2
0
 @Override
 public void add(final Spatial spatial) {
   spatial._queueDistance = Double.NEGATIVE_INFINITY;
   if (_currentListSize >= _currentList.length) {
     // grow if necessary
     final Spatial[] temp = new Spatial[_currentListSize * 2];
     System.arraycopy(_currentList, 0, temp, 0, _currentListSize);
     _currentList = temp;
     if (_tempList.length < temp.length) {
       _tempList = new Spatial[temp.length];
     }
   }
   _currentList[_currentListSize++] = spatial;
 }