简体   繁体   English

Java3D - 是否有可能有一个跟踪移动对象的查看平台

[英]Java3D - Is it possible to have a viewingPlatform that tracks a moving object

I have a very simple Java3D application, it contains two cubes, of which one of them orbits the other.我有一个非常简单的 Java3D 应用程序,它包含两个立方体,其中一个围绕另一个运行。

Like so:像这样:

在此处输入图片说明

As you can see, the default position for the viewing platform is from a 'kind of' birds eye view.如您所见,观景台的默认位置是从“某种”鸟瞰图。

The code that looks like so看起来像这样的代码

TransformGroup cameraTG = u.getViewingPlatform().
                   getViewPlatformTransform();
Vector3f translate = new Vector3f(); 
Transform3D T3D = new Transform3D();
translate.set( 0.0f, 0.0f, 20.0f);
T3D.setTranslation(translate);
cameraTG.setTransform(T3D);

My question is, is it possible to set the viewing platform to track the larger cube (the cube that rotates around the smaller square).我的问题是,是否可以将观景台设置为跟踪较大的立方体(围绕较小正方形旋转的立方体)。 Or more straight forward, is it possible for the viewing platform to rotate around a given body?或者更直接地说,观景台是否有可能围绕给定的身体旋转?

More information: My goal is to have a miniature solar system, containing the Sun, Earth and moon.更多信息:我的目标是拥有一个包含太阳、地球和月球的微型太阳系。 And I would like to view it from the point of view of the earth (almost like a view from the ISS)我想从地球的角度来看它(几乎就像从国际空间站的角度来看)

在此处输入图片说明

Any help or pointers would be fantastic.任何帮助或指示都会很棒。 Please feel free to ask for more information if needed.如果需要,请随时询问更多信息。

You have a nice example here http://java3d.nl/Tutorials/Java/Java3d/Controlthecamera_12.php你在这里有一个很好的例子http://java3d.nl/Tutorials/Java/Java3d/Controlthecamera_12.php

The original http://java3d.nl website is no longer available, but you can still use the cached version from the Internet Archive: https://web.archive.org/web/20131218022035/http://java3d.nl/Tutorials/Java/Java3d/Controlthecamera_12.php原来的http://java3d.nl网站不再可用,但您仍然可以使用 Internet Archive 中的缓存版本: https ://web.archive.org/web/20131218022035/http: //java3d.nl/教程/Java/Java3d/Controlthecamera_12.php

         this.camera = this.universe.getViewingPlatform().getViewPlatformTransform();

         //Add things to the universe
         this.root = new BranchGroup();
         this.root.addChild(new ColorCube(0.2));
         this.universe.addBranchGraph(root);

My idea is like this:我的想法是这样的:

BranchGroup b=new BranchGroup();
b.addChild(cube);
b.addChild(camera);

then in a loop where you rotate the block:然后在循环中旋转块:

while(true) {
  ... b.getChild()......... etc
  apply transform
}

or more specifically或更具体地说

for(j=0; j<group.numChildren(); j++) {
    Node ni=group.getChild(j);
    if(ni instanceof TransformGroup) {
      Transform3D tdi=new Transform3D();
      TransformGroup tgi=(TransformGroup)group.getChild(j);
      tgi.getTransform(tdi);
      Transform3D rotation = new Transform3D();
      rotation.rotX(Math.toRadians(0.001*i));
      tdi.mul(rotation);
      tgi.setTransform(tdi);
    }
}

There is a simpler solution.有一个更简单的解决方案。 Instaed of trying to control the viewer gaze using angles and rotation, you can merely say what 3D point to look at.不再尝试使用角度和旋转来控制观看者的凝视,您只需说出要观看的 3D 点即可。 In the ViewingTransform, you can call "lookAt(...)":在 ViewingTransform 中,您可以调用“lookAt(...)”:

        TransformGroup viewingTransformGroup = simpleUniv.getViewingPlatform().getViewPlatformTransform();
    Transform3D viewingTransform = new Transform3D();
    Point3d eye = viewersLocation;
    Point3d center = gazePoint;
    Vector3d up = new Vector3d(0,1,0); //assumes  +y-axis points up
    viewingTransform.lookAt(eye, center, up);
    viewingTransform.invert();
    viewingTransformGroup.setTransform(viewingTransform);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM