コード例 #1
0
ファイル: DistanceLOD.java プロジェクト: miho/ExtJ3D
  /**
   * Process stimulus method that computes appropriate level of detail.
   *
   * @param criteria an enumeration of the criteria that caused the stimulus
   */
  @Override
  public void processStimulus(Enumeration criteria) {

    // compute distance in virtual world
    View v = this.getView();
    if (v == null) {
      wakeupOn(wakeupFrame);
      return;
    }

    ViewPlatform vp = v.getViewPlatform();
    if (vp == null) {
      return;
    }

    // Handle stimulus
    double viewDistance = 0.0;
    int nSwitches, i, index = 0;

    Transform3D localToWorldTrans = new Transform3D();

    localToWorldTrans.set(((NodeRetained) this.retained).getCurrentLocalToVworld());

    //  DistanceLOD's location in virutal world
    localToWorldTrans.transform(position, center);

    viewPosition.x = (float) ((ViewPlatformRetained) vp.retained).schedSphere.center.x;
    viewPosition.y = (float) ((ViewPlatformRetained) vp.retained).schedSphere.center.y;
    viewPosition.z = (float) ((ViewPlatformRetained) vp.retained).schedSphere.center.z;
    viewDistance = center.distance(viewPosition);

    // convert distance into local coordinates
    viewDistance = viewDistance / localToWorldTrans.getDistanceScale();

    nSwitches = numSwitches();

    index = distances.length; // viewDistance > distances[n-1]

    if (viewDistance <= distances[0]) {
      index = 0;
    } else {
      for (i = 1; i < distances.length; i++) {
        if ((viewDistance > distances[i - 1]) && (viewDistance <= distances[i])) {
          index = i;
          break;
        }
      }
    }

    for (i = nSwitches - 1; i >= 0; i--) {
      Switch sw = getSwitch(i);
      // Optimize, this behavior is passive
      // Note that we skip the capability check for getWhichChild()
      if (((SwitchRetained) sw.retained).getWhichChild() != index) {
        sw.setWhichChild(index);
      }
    }
    // Insert wakeup condition into queue
    wakeupOn(wakeupFrame);
  }
コード例 #2
0
ファイル: DistanceLOD.java プロジェクト: miho/ExtJ3D
 /**
  * Retrieves the current position of this LOD node. This position is in the local coordinates of
  * this node.
  *
  * @param position the object that will receive the current position
  */
 public void getPosition(Point3f position) {
   if (((NodeRetained) retained).staticTransform != null) {
     Transform3D invTransform = ((NodeRetained) retained).staticTransform.getInvTransform();
     invTransform.transform(this.position, position);
   } else {
     position.set(this.position);
   }
 }