Main content of PointBenchmark Java3D benchmark, showing the three different methods of manipulating the point arrays.

Power Java
High-Performance Java Software Development
James Schatzman and Roy Donehower
Listing 3. Main content of PointBenchmark Java3D benchmark, showing the three different methods of manipulating the point arrays.


// The Java 3D behavior scheduler invokes a Behavior node’s
// processStimulus method when a ViewPlatform’s activation volume
// intersects a Behavior object’s scheduling region and all of that
// behavior’s wakeup criteria are satisfied.

private WakeupCondition condition = new
          WakeupOnElapsedFrames(0);
public void processStimulus(final Enumeration criteria) {
     while (criteria.hasMoreElements()) {
          final WakeupCriterion wakeup =
           (WakeupCriterion)criteria.nextElement();
          if (wakeup instanceof WakeupOnElapsedFrames) {
             myPointTransform.translateZ();
          }
     }
     wakeupOn(condition);
}

public interface ITrans {
      public void translateZ();
}

// This is the slowest way to implement the animation—by adding
// to every point the amount of translation (in the z direction) to be
// translated.
public class TransformPoints1 implements ITrans {
     private final Point3f myTemppoint = new Point3f();
     private int myNumPoints;
     private PointArray myStarPointArray = null;
     private float myAmountToTranslate = 0.0f;
     public TransformPoints1(final int
            numPoints, final PointArray pointArray, final float amount){
          myNumPoints = numPoints;
          myStarPointArray = pointArray;
          myAmountToTranslate = amount;
   }
   public void translateZ() {
          for (int i = 0; i < mynumpoints;="" ++i)="" {="" mypointarray.getcoordinate(i,="" mytemppoint);="" mytemppoint.set(mytemppoint.x,="" mytemppoint.y,="" mytemppoint.z="" -="" myamounttotranslate);="" mypointarray.setcoordinate(i,="" mytemppoint);="" }="" }="" }="" this="" is="" a="" slightly="" faster="" way="" to="" translate="" each="" point="" by="" a="" fixed="" amount="" in="" the="" z="" direction.="" instead="" of="" getting="" each="" coordinate,="" calculating="" the="" new="" coordinate,="" and="" setting="" the="" coordinate="" to="" the="" new="" value,="" we="" place="" all="" the="" coordinates="" in="" a="" local="" array="" of="" points,="" modify="" this="" array="" with="" the="" new="" point="" values,="" and="" set="" all="" the="" points="" in="" the="" point="" array="" at="" once.="" public="" class="" transformpoints2="" implements="" itrans="" {="" private="" final="" point3f="" mytemppoint="new" point3f();="" private="" int="" mynumpoints;="" private="" pointarray="" mypointarray="null;" private="" float="" myamounttotranslate="0.0f;" private="" point3f="" mypoints[]="null;" public="" transformpoints2(final="" int="" numpoints,="" final="" pointarray="" pointarray,="" final="" float="" amount,="" final="" point3f[]="" points){="" mynumpoints="numPoints;" mypointarray="pointArray;" myamounttotranslate="amount;" mypoints="points;" }="" public="" void="" translatez()="" {="" for="" (int="" i="0;">