001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/visualtools/KBRotPosScaleSplinePathInterpolatorVisualTool.java,v 1.1 2005/04/20 22:21:29 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is the Java 3D(tm) Scene Graph Editor.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dedit.scenegrapheditor.visualtools;
019:
020: import javax.vecmath.Point3f;
021: import com.sun.j3d.utils.behaviors.interpolators.KBKeyFrame;
022:
023: /**
024: * @author Paul Byrne
025: * @version 1.8, 01/18/02
026: */
027: public class KBRotPosScaleSplinePathInterpolatorVisualTool extends
028: VisualTool {
029:
030: private PointHighlightControl pointHighlights;
031: private InterpolatorPathView pathView;
032:
033: /** Creates new PathInterpolatorVisualTool */
034: public KBRotPosScaleSplinePathInterpolatorVisualTool(
035: PointSelectionListener listener) {
036: pointHighlights = new PointHighlightControl(listener);
037: pathView = new InterpolatorPathView();
038: this .addChild(pointHighlights);
039: this .addChild(pathView);
040: pointHighlights.setPointSize(0.1f);
041: this .setCapability(ALLOW_BOUNDS_READ);
042: }
043:
044: /**
045: * Set the point selection listener
046: */
047: public void setPointSelectionListener(
048: PointSelectionListener listener) {
049: pointHighlights.setPointSelectionListener(listener);
050: }
051:
052: /**
053: * Set the interpolator on which this tool acts
054: */
055: public void setInterpolator(
056: com.sun.j3d.utils.behaviors.interpolators.KBRotPosScaleSplinePathInterpolator interp) {
057: //System.out.println("setting KB interpolator ");
058: pointHighlights.clear();
059: pointHighlights.setTarget(interp.getTarget());
060: Point3f pos = new Point3f();
061: KBKeyFrame keyFrame;
062: for (int i = 0; i < interp.getArrayLength(); i++) {
063: keyFrame = interp.getKeyFrame(i);
064: pointHighlights.addPoint(keyFrame.position);
065: }
066:
067: pathView.setInterpolator(interp);
068: pathView.setTarget(interp.getTarget());
069: pathView.interpolatorChanged();
070: }
071:
072: /**
073: * Should be called whenever the keyFrames of an interpolator have changed
074: * Updates the visual of this interpolator.
075: * startIndex, endIndex are the range of KeyFrames that have changed
076: */
077: public void interpolatorChanged(
078: com.sun.j3d.utils.behaviors.interpolators.KBRotPosScaleSplinePathInterpolator interp,
079: int startIndex, int endIndex) {
080: //System.out.println("update KB interpolator "+startIndex+" "+endIndex+" "+pointHighlights.getPointCount() );
081: //System.out.println( interp.getArrayLength()+" "+pointHighlights.getPointCount() );
082: Point3f pos = new Point3f();
083: KBKeyFrame keyFrame;
084:
085: if (interp.getArrayLength() > pointHighlights.getPointCount()) {
086: int count = interp.getArrayLength()
087: - pointHighlights.getPointCount();
088: for (int i = 0; i < count; i++) {
089: keyFrame = interp.getKeyFrame(startIndex + i);
090: pointHighlights.insertPoint(startIndex + i,
091: keyFrame.position);
092: }
093:
094: startIndex += count;
095: }
096:
097: for (int i = startIndex; i <= endIndex; i++) {
098: keyFrame = interp.getKeyFrame(i);
099: pointHighlights.movePoint(i, keyFrame.position);
100: }
101:
102: pathView.interpolatorChanged();
103: }
104:
105: public void selectPoint(int index) {
106: pointHighlights.selectPoint(index);
107: }
108:
109: public void reset() {
110: pointHighlights.clear();
111: pathView.clear();
112: }
113:
114: }
|