Exemplo n.º 1
0
  /**
   * Adds a SMRotationInterpolator Behavior to the SMGroup
   *
   * @param duration
   * @param start
   * @param rotXAxis Angle about x in which the axis of rotation is going to be rotated
   * @param rotYAxis Angle about y in which the axis of rotation is going to be rotated
   * @param rotZAxis Angle about z in which the axis of rotation is going to be rotated
   * @param startAngle
   * @param finsishAngle
   */
  public void addRotationAnim(
      long duration,
      long start,
      double rotXAxis,
      double rotYAxis,
      double rotZAxis,
      float startAngle,
      float finishAngle) {
    // Creates a necessary TransformGroup for the SMRotationInterpolator
    TransformGroup tg = new TransformGroup();

    // Adds the animation between the child and it Parent
    Group parent = (Group) _child.getParent();
    parent.removeChild(_child);
    tg.addChild(_child);
    parent.addChild(tg);

    // Allows writing on TransfomGroup
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // Creates an Alpha function
    Alpha rotationAlpha = new Alpha(1, duration);
    rotationAlpha.setStartTime(System.currentTimeMillis() + start);

    // Calculates the axis of rotation
    Transform3D rX = new Transform3D();
    Transform3D rY = new Transform3D();
    Transform3D rZ = new Transform3D();
    rX.rotX(rotXAxis);
    rY.rotY(rotYAxis);
    rZ.rotZ(rotZAxis);
    rY.mul(rZ);
    rX.mul(rY);

    // Creates the SMRotationInterpolator
    SMRotationInterpolator rotator =
        new SMRotationInterpolator(rotationAlpha, tg, rX, startAngle, finishAngle, start);

    // Sets the area to render
    rotator.setSchedulingBounds(_bounds);

    // Adds the rotation animation to the TransformGroup
    tg.addChild(rotator);
  }
Exemplo n.º 2
0
  // Override Behavior's stimulus method to handle the event
  public void processStimulus(Enumeration criteria) {

    // NOTE: This assumes 3 objects.  It should be generalized to
    // "n" objects.

    double val = alpha.value();
    if (val < 0.5) {
      double a = val * 2.0;
      weights[0] = 1.0 - a;
      weights[1] = a;
      weights[2] = 0.0;
    } else {
      double a = (val - 0.5) * 2.0;
      weights[0] = 0.0;
      weights[1] = 1.0f - a;
      weights[2] = a;
    }

    morph.setWeights(weights);

    // Set wakeup criteria for next time
    wakeupOn(w);
  }
  /**
   * Computes the new transform for this interpolator for a given alpha value.
   *
   * @param alphaValue alpha value between 0.0 and 1.0
   * @param transform object that receives the computed transform for the specified alpha value
   * @since Java 3D 1.3
   */
  public void computeTransform(float alphaValue, Transform3D transform) {
    // compute the current value of u from alpha and the
    // determine lower and upper knot points
    computePathInterpolation(alphaValue);

    // Determine the segment within which we will be interpolating
    currentSegmentIndex = this.lowerKnot - 1;

    // if we are at the start of the curve
    if (currentSegmentIndex == 0 && currentU == 0f) {
      iHeading = keyFrames[1].heading;
      iPitch = keyFrames[1].pitch;
      iBank = keyFrames[1].bank;
      iPos.set(keyFrames[1].position);
      iScale.set(keyFrames[1].scale);

      // if we are at the end of the curve
    } else if (currentSegmentIndex == (numSegments - 1) && currentU == 1.0) {
      iHeading = keyFrames[upperKnot].heading;
      iPitch = keyFrames[upperKnot].pitch;
      iBank = keyFrames[upperKnot].bank;
      iPos.set(keyFrames[upperKnot].position);
      iScale.set(keyFrames[upperKnot].scale);

      // if we are somewhere in between the curve
    } else {
      // Get a reference to the current spline segment i.e. the
      // one bounded by lowerKnot and upperKnot
      currentSegment = cubicSplineCurve.getSegment(currentSegmentIndex);

      // interpolate quaternions
      iHeading = currentSegment.getInterpolatedHeading(currentU);
      iPitch = currentSegment.getInterpolatedPitch(currentU);
      iBank = currentSegment.getInterpolatedBank(currentU);

      // interpolate position
      currentSegment.getInterpolatedPositionVector(currentU, iPos);

      // interpolate position
      currentSegment.getInterpolatedScale(currentU, iScale);
      // System.out.println("Pos :" + iPos);
    }

    // Modification by ReubenDB

    if (colorRampingInterpolate == true) {
      float[] curPos = new float[3];
      iPos.get(curPos);

      myColorRamp.getColor(curPos[1], histColor);
      // System.out.println("SETING COLOR:" + histColor + " CurPos: " + curPos[0] + ", " + curPos[1]
      // + ", " + curPos[2]);
      objectCA.setColor(histColor);
      // System.out.println("CurrentAlpha = " + myAlpha.value());
    }

    if (timeDisplayInterpolate == true) {
      myTimeDisplay.updateDisplayFromAlpha(myAlpha.value());
      // System.out.println(myAlpha.value());
    }

    // Generate a transformation matrix in tMat using interpolated
    // heading, pitch and bank
    pitchMat.setIdentity();
    pitchMat.rotX(-iPitch);
    bankMat.setIdentity();
    bankMat.rotZ(iBank);
    tMat.setIdentity();
    tMat.rotY(-iHeading);
    tMat.mul(pitchMat);
    tMat.mul(bankMat);

    // TODO: Vijay - Handle Non-Uniform scale
    // Currently this interpolator does not handle non uniform scale
    // We cheat by just taking the x scale component

    // Scale the transformation matrix
    sMat.set((double) iScale.x);
    tMat.mul(sMat);

    // Set the translation components.
    tMat.m03 = iPos.x;
    tMat.m13 = iPos.y;
    tMat.m23 = iPos.z;
    rotation.set(tMat);

    // construct a Transform3D from:  axis * rotation * axisInverse
    transform.mul(axis, rotation);
    transform.mul(transform, axisInverse);
  }
Exemplo n.º 4
0
  // Override Behavior's initialize method to setup wakeup criteria
  public void initialize() {
    alpha.setStartTime(System.currentTimeMillis());

    // Establish initial wakeup criteria
    wakeupOn(w);
  }