我刚开始使用java3D,我可以向上/向下/向左/向右/向前/向后移动相机,但我似乎无法弄清楚如何使相机角度发生变化,例如,从期待变为向左看。有人能举个例子吗?另外,我应该放置getViewingPlatform()。getViewPlatformTransform()。setTransform(test.position);在我的主要方法中,还是我应该做些什么?
我尝试过使用鼠标并旋转视图 OrbitBehavior orbit = new OrbitBehavior(canvas,OrbitBehavior.REVERSE_ROTATE);
orbit.setSchedulingBounds(new BoundingSphere());
orbit.setRotXFactor(2);
orbit.setRotYFactor(2);
但是当我添加getViewingPlatform()时它不起作用.getViewPlatformTransform()。setTransform(test.position); 到main方法中的while循环。视角反复重置。
答案 0 :(得分:2)
不是使用角度操纵观察者(相机),而是通过定义3D“凝视点”来引导它(注意力集中在点上)。要防止相机侧向倾斜,请定义upDir = [0,1,0](J3D假设+ y轴向上)。
然后,修改simpleUniverse中的viewingTransform。
以下是我的应用中的示例代码:
// ***********declare these variables in class where canvas3D lives *****
//J3D stuff
public InteractiveCanvas3D canvas3D;
public SimpleUniverse simpleUniv;
private Transform3D viewingTransform;
private TransformGroup viewingTransformGroup;
public static Point3d viewersLocation;
public static Point3d gazePoint; //point viewer is looking at
// and initialize as follows:
viewingTransformGroup = simpleUniv.getViewingPlatform().getViewPlatformTransform();
viewingTransform = new Transform3D();
//called to update viewer's location and gaze:
// *********************** UpdateViewerGeometryJ3D
public void UpdateViewerGeometryJ3D() {
Point3d eye = viewersLocation;
Point3d center = gazePoint;
Vector3d up = upDir;
viewingTransform.lookAt(eye, center, up);
viewingTransform.invert();
viewingTransformGroup.setTransform(viewingTransform);
我忘了为什么必须颠倒观看变换。希望这会有所帮助。