Java 怎么使用Transform3D View Group

2019年7月29日20:04:09 评论 52

1.简介

Java 怎么使用Transform3D View Group?——请看下文。

2.代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import java.awt.Frame;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class Main extends Applet 
    SimpleUniverse simpleU; 

    public void init() {
        setLayout(new BorderLayout()); 
        Canvas3D c = new Canvas3D(
                SimpleUniverse.getPreferredConfiguration());
        add("Center", c);
        simpleU = new SimpleUniverse(c); 

        BranchGroup scene = createSceneGraph();
        scene.compile();

        simpleU.addBranchGraph(scene); 

    }

    public BranchGroup createSceneGraph() {
        BranchGroup objRoot = new BranchGroup();

        TransformGroup cctg = new TransformGroup(); 

        ColorCube c = new ColorCube(0.5f);
        cctg.addChild(c); 

        Transform3D cc3d = new Transform3D();
        cc3d.setTranslation(new Vector3f(0.8f, 1.0f, -2.0f));

        cctg.setTransform(cc3d); 

        objRoot.addChild(cctg); 

        cc3d.setTranslation(new Vector3f(0, 0, 0));
        cctg.setTransform(cc3d);

        ViewingPlatform vp = simpleU.getViewingPlatform(); 

        TransformGroup View_TransformGroup = vp.getMultiTransformGroup()
                .getTransformGroup(0); 

        Transform3D View_Transform3D = new Transform3D(); 
        View_TransformGroup.getTransform(View_Transform3D); 

        View_Transform3D.setTranslation(new Vector3f(0.0f, -1.0f, 5.0f)); 
        View_TransformGroup.setTransform(View_Transform3D); 

        return objRoot;
    }

    public void destroy() {

        simpleU.removeAllLocales();
    }

    public static void main(String[] args) {
        Frame frame = new MainFrame(new Main(), 500, 500);
    }

}

 

3.总结

示例代码演示了 Java 怎么使用Transform3D View Group,具体步骤参见示例代码。

  • A+
所属分类:3D

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: