Skip to main content

Interpolator - from Point3f to Point3f

2 replies [Last post]
mattn
Offline
Joined: 2010-06-25
Points: 0

Hi i want to move a TransformGroup from Point3f to Point3f fluently (x,y,z direction)
which interpolator is working like this....
(i know the PositionsInterpolator dosnt work)

i tryed the PositionPathInterpolator
think this one should be working but I got a problem...
can any one help me...
its just a trial demo...

i added a box in a transformgroup...with a absolute vector...
now whant to move the transformgroup of the box to the point (0,0,0)

the interpolator starts by clicking the box

here the code

package snipplets;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.awt.TextField;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.media.j3d.Alpha;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Node;
import javax.media.j3d.PositionInterpolator;
import javax.media.j3d.PositionPathInterpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

import com.eigeneImports.PickTranslateBehavior;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
import com.sun.j3d.utils.behaviors.picking.PickZoomBehavior;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.picking.PickCanvas;
import com.sun.j3d.utils.picking.PickResult;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class jmpDemo extends Applet implements MouseListener{

TransformGroup tg;
Transform3D tmpT3D;
Vector3f tmpVec;
BoundingSphere BigBounds = new BoundingSphere(new Point3d(),100000);
Canvas3D c;
GraphicsConfiguration config;
SimpleUniverse u ;
BranchGroup sceneBG,rootBG,boxBG;
PickCanvas pickC;
TransformGroup vpTG;
Transform3D vpT3D;

int i = 1;
Vector3f target;

public void init(){
System.out.println("init");
setLayout(new BorderLayout());
config = SimpleUniverse.getPreferredConfiguration();
c= new Canvas3D(config);
add("Center", c);
u = new SimpleUniverse(c);
// verschiebe ViewingPlatform:
vpT3D = new Transform3D();
vpTG = u.getViewingPlatform().getViewPlatformTransform();
vpT3D.set(new Vector3f(0.0f, 0.0f, 10.0f));
vpTG.setTransform(vpT3D);

Vector3f vec = new Vector3f();
vpT3D.get(vec);

// Einstellung für die Größe des SimpleUniverse
View v = u.getViewer().getView();
v.setFrontClipDistance(0.01);
v.setBackClipDistance(1000000); // backDistance = 1000000;z.B
v.getPhysicalBody().setNominalEyeOffsetFromNominalScreen(0.0);
u.addBranchGraph(createSceneGraph());

}

private BranchGroup createSceneGraph() {
// TODO Auto-generated method stub
rootBG = new BranchGroup();
rootBG.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);

//Box
Box box = new Box();
box.setName("box");
box.setAppearance(new Appearance());

tg = new TransformGroup();
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
tg.setName("tg");
Transform3D t3d = new Transform3D();
target = new Vector3f(1f,-1f,2f);
t3d.set(target);

tg.setTransform(t3d);
tg.addChild(box);

rootBG.addChild(tg);

//Licht
DirectionalLight dl = new DirectionalLight( new Color3f(0.8f, 0.8f, 0.8f),
new Vector3f(-30f, -30f, 30f));
dl.setInfluencingBounds(new BoundingSphere( new Point3d(0.0,0.0,0.0), Double.MAX_VALUE));
rootBG.addChild(dl);

//PickCanvas
pickC = new PickCanvas(c, rootBG);
pickC.setTolerance((float) 10.0);
c.addMouseListener(this);

rootBG.compile();
return rootBG;
}

@Override
public void mouseClicked(MouseEvent e) {
pickC.setShapeLocation(e);
pickC.setTolerance((float) 0.0);
PickResult result = pickC.pickClosest();
//kein Objekt getroffen
if (result == null) {
System.out.println("Nothing picked");
}
else{
//es wurde ein Würfel getroffen
Node picktPrimitive = result.getNode(PickResult.PRIMITIVE);
if (picktPrimitive != null) {

tmpT3D = new Transform3D();
TransformGroup foo = (TransformGroup) picktPrimitive.getParent();
foo.getTransform(tmpT3D);
tmpVec = new Vector3f();
tmpT3D.get(tmpVec);
System.out.println(tmpVec.x);
System.out.println(tmpVec.y);
System.out.println(tmpVec.z);

//move u´r ASS
BranchGroup intBG = new BranchGroup();
Alpha a = new Alpha(1,
Alpha.INCREASING_ENABLE,
0, 0,
5000, 0, 0,
5000, 0, 0);

float[] knots = new float[2];
knots[0] = 0;
knots[1] = 1;

Point3f interpolatorStart = new Point3f();
interpolatorStart.x = target.x;
interpolatorStart.y = target.y;
interpolatorStart.z = target.z;

Point3f[] positions = new Point3f[2];
positions[0] = interpolatorStart;
positions[1] = new Point3f(0f,0f,0f);

Transform3D axisOfTranslationX = new Transform3D();
axisOfTranslationX.rotX(-Math.PI/2.0);
PositionPathInterpolator inter = new PositionPathInterpolator( a,
tg,
axisOfTranslationX,
knots,
positions);
inter.setSchedulingBounds(BigBounds);
intBG.addChild(inter);

rootBG.addChild(intBG);
}
}
}

@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub

}

}
___________________

I solved the problem... i have to use the TG of the box

Solve

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
aces
Offline
Joined: 2003-07-17
Points: 0

Use PositionPathInterpolator.

Check example SplimAnim.java about how to start/stop animation.
btw, your Alpha is not ok.

mattn
Offline
Joined: 2010-06-25
Points: 0

thx.... yes the start time was missing
thats my new one
Alpha a = new Alpha(
1, // loop count
Alpha.INCREASING_ENABLE, // mode
0, // triggerTime
50, // phaseDelayDuration,
5000, //increasingAlphaDuration
5000, // increasingAlphaRampDuration
1000, //alphaAtOneDuration
0, // decreasingAlphaDuration
0, // decreasingAlphaRampDuration,
0// alphaAtZeroDuration
);
a.setStartTime(System.currentTimeMillis());