| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1104 人关注过本帖
标题:Java3D的Quats和AxisAngle4f的参数各代表什么意义?
只看楼主 加入收藏
yayafree186
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-4-16
收藏
 问题点数:0 回复次数:1 
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,但因为不清楚
这两个类各个参数的意义,不知道该怎样改,请高手指点。
搜索更多相关主题的帖子: import javax media Quats awt 
2007-04-17 14:44
yayafree186
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-4-16
收藏
得分:0 
回复:(yayafree186)Java3D的Quats和AxisAngle4f的参...
问题已经解决了!
2007-04-17 20:52
快速回复:Java3D的Quats和AxisAngle4f的参数各代表什么意义?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026951 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved