Java3D的Quats和AxisAngle4f的参数各代表什么意义?
先把代码贴上来:
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
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.ColoringAttributes;
import javax.media.j3d.PositionPathInterpolator;
import javax.media.j3d.RotPosPathInterpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.AxisAngle4f;
import javax.vecmath.Point3f;
import javax.vecmath.Quat4f;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.Viewer;
import com.sun.j3d.utils.universe.ViewingPlatform;
/**
* 用这个类尝试将立方体旋转后做动画。
*
*/
public class RotateTest extends Applet
{
public RotateTest()
{
setLayout(new BorderLayout());
GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D=new Canvas3D(config);
add("Center",canvas3D);
Viewer mainViewer=new Viewer(canvas3D);//主Viewer
ViewingPlatform mainViewingPlatform=new ViewingPlatform();//主ViewingPlatfor
m
Vector3f mainViewPoint=new Vector3f(0f,0f,12f);//这里实现主ViewingPlatform的
平移。
Transform3D t=new Transform3D();
t.setTranslation(mainViewPoint);
TransformGroup transformGroup=mainViewingPlatform.getViewPlatformTransform()
;//getViewPlatform函数返回TransformGroup
transformGroup.setTransform(t);
SimpleUniverse simpleUniverse=new SimpleUniverse(mainViewingPlatform,mainVie
wer);
BranchGroup scene=createSceneGraph();
simpleUniverse.addBranchGraph(scene);
}
public BranchGroup createSceneGraph()
{
BranchGroup objRoot = new BranchGroup();
TransformGroup TG=new TransformGroup();
TG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
TG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D tt=new Transform3D();//平移
Vector3f v3=new Vector3f(0f,-1f,0f);
tt.setTranslation(v3);
TG.setTransform(tt);
objRoot.addChild(TG);
TG.addChild(new ColorCube(0.5));
//添加黑色球
TransformGroup sphereTG=new TransformGroup();
Transform3D spherett=new Transform3D();
Vector3f spherev3=new Vector3f(0f,0.5f,0.5f);
spherett.setTranslation(spherev3);
sphereTG.setTransform(spherett);
Appearance sphereAppear = new Appearance();
ColoringAttributes sphereCA = new ColoringAttributes();
sphereCA.setColor(0.0f, 0.0f, 0.0f);
sphereAppear.setColoringAttributes(sphereCA);
sphereTG.addChild(new Sphere(0.1f,sphereAppear));
TG.addChild(sphereTG);
// 动画的PositionPathInterpolator节点。
Alpha alpha = new Alpha(1, 5000);
Transform3D axisOfPos = new Transform3D();
float[] knots = {0.0f,0.5f, 1.0f};
Point3f[] position = new Point3f[3];
position[0]=new Point3f(0f,-1f,0f);
position[1]=new Point3f(0f,1f,0f);
position[2]=new Point3f(1f,1f,0f);
Quat4f[] quats = new Quat4f[3];
quats[0] = new Quat4f(0.0f, 0.0f, 0.0f, 0.0f);
quats[1] = new Quat4f(0.0f, 0.0f, 0.0f, 0.0f);
quats[2] = new Quat4f(0.0f, 0.0f, 0.0f, 0.0f);
AxisAngle4f axis = new AxisAngle4f(1.0f,0.0f,0.0f,0.0f);
axisOfPos.set(axis);
RotPosPathInterpolator rotPosPath = new RotPosPathInterpolator(
alpha, TG, axisOfPos, knots, quats, position);
rotPosPath.setSchedulingBounds(new BoundingSphere());
objRoot.addChild(rotPosPath);
return objRoot;
}
public static void main(String[] args)
{
Frame frame = new MainFrame(new RotateTest(), 500, 500);
}
}
我的想法是在立方体运动到第二个点后旋转90度,以便继续向第三个点运动时仍然保持带
黑色点那头朝向第三个点,只是模糊的知道应该修改Quats和AxisAngle4f,但因为不清楚
这两个类各个参数的意义,不知道该怎样改,请高手指点。