⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wrapmovie3d.java

📁 这是java3d三维动画播放的资料,需要的人可以下载学习一下.
💻 JAVA
字号:
package j3d_movie;///**场景图/* 2.创建一个棋盘世界与环幕电影。   该环幕电影,以及计时器,使电影前进,   设立在addmoviescreen ( ) 。   其余的Java 3D的代码在这里已复制从checkers3d ,   第一Java 3D的例子,在第15章    “杀手游戏娱乐编程在Java ”    ( http://fivedots.coe.psu.ac.th/ \u301C广告/ jg )*/import javax.swing.*;import java.awt.*;import com.sun.j3d.utils.universe.*;import com.sun.j3d.utils.geometry.*;import javax.media.j3d.*;import javax.vecmath.*;import com.sun.j3d.utils.behaviors.vp.*;public class WrapMovie3D extends JPanel// Holds the 3D canvas where the loaded image is displayed//拥有三维画布的地方装上的形象,是展示{  private static final int PWIDTH = 512;   // size of panel  private static final int PHEIGHT = 512;  private static final int BOUNDSIZE = 100;  // larger than world  private static final Point3d USERPOSN = new Point3d(0,1.8,5.5);//三维空间    // initial user position    //初始用户三维空间  private SimpleUniverse su; //虚拟空间  private BranchGroup sceneBG; //包含对象的数据结构 、子场景图的根结点  private BoundingSphere bounds;   // for environment nodes 场景  private JMFMovieScreen ms;   // the movie screen 动画屏幕  private TimeBehavior timer;  // for updating the screen 更新屏幕  public WrapMovie3D(String fnm)  // A panel holding a 3D canvas: the usual way of linking Java 3D to Swing  {    setLayout( new BorderLayout() );    setOpaque( false );    setPreferredSize( new Dimension(PWIDTH, PHEIGHT));    GraphicsConfiguration config =    SimpleUniverse.getPreferredConfiguration();    Canvas3D canvas3D = new Canvas3D(config);    add("Center", canvas3D);    canvas3D.setFocusable(true);     // give focus to the canvas    canvas3D.requestFocus();    su = new SimpleUniverse(canvas3D);    createSceneGraph(fnm);    initUserPosition();        // set user's viewpoint    orbitControls(canvas3D);   // controls for moving the viewpoint    su.addBranchGraph( sceneBG );  } // end of WrapMovie3D()  private void createSceneGraph(String fnm)  // initilise the scene  //初始化场景图  {    sceneBG = new BranchGroup();    bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE);    //lightScene();         // add the lights    addBackground();      // add the sky    //sceneBG.addChild( new CheckerFloor().getBG() );  // add the floor 增加背景    addMovieScreen(fnm);  //增加动画    sceneBG.compile();   // fix the scene 修复场景  } // end of createSceneGraph()/*  //灯光效果  private void lightScene()  // One ambient light, 2 directional lights  {    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);    // Set up the ambient light    AmbientLight ambientLightNode = new AmbientLight(white);    ambientLightNode.setInfluencingBounds(bounds);    sceneBG.addChild(ambientLightNode);    // Set up the directional lights    Vector3f light1Direction  = new Vector3f(-1.0f, -1.0f, -1.0f);       // left, down, backwards    Vector3f light2Direction  = new Vector3f(1.0f, -1.0f, 1.0f);       // right, down, forwards    DirectionalLight light1 =            new DirectionalLight(white, light1Direction);    light1.setInfluencingBounds(bounds);    sceneBG.addChild(light1);    DirectionalLight light2 =        new DirectionalLight(white, light2Direction);    light2.setInfluencingBounds(bounds);    sceneBG.addChild(light2);  }  // end of lightScene()*/  private void addBackground()  // A blue sky  //设置蓝色背景天空  { Background back = new Background();    back.setApplicationBounds( bounds );    back.setColor(0.17f, 0.65f, 0.92f);    // sky colour    sceneBG.addChild( back );  }  // end of addBackground()  private void orbitControls(Canvas3D c)  /* OrbitBehaviour allows the user to rotate around the scene, and to     zoom in and out.  */  {    OrbitBehavior orbit =                new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL);    orbit.setSchedulingBounds(bounds);    ViewingPlatform vp = su.getViewingPlatform();    vp.setViewPlatformBehavior(orbit);  }  // end of orbitControls()  private void initUserPosition()  // Set the user's initial viewpoint using lookAt()  {    ViewingPlatform vp = su.getViewingPlatform();    TransformGroup steerTG = vp.getViewPlatformTransform();    Transform3D t3d = new Transform3D();    steerTG.getTransform(t3d);    // args are: viewer posn, where looking, up direction    t3d.lookAt( USERPOSN, new Point3d(0,0,0), new Vector3d(0,1,0));    t3d.invert();    steerTG.setTransform(t3d);  }  // end of initUserPosition()  // -------------------- movie screen / 观看动画播放 -----------------------  private void addMovieScreen(String fnm)  {    // put the movie specified on the command line onto a movie screen    //把fnm形式的动画投放到动画屏幕上    ms = new JMFMovieScreen( new Point3f(0,0,0.0f), 2.0f, fnm);    sceneBG.addChild( ms );    // set up the timer for animating the movie    //为animating动画建立计时器对象    timer = new TimeBehavior(40, ms);               // update the movie every 40ms (== 25 frames/sec)               //更新动画每40ms一次(25帧/秒)    timer.setSchedulingBounds( bounds );    sceneBG.addChild( timer );  }  // end of addMovieScreen()  public void stopMovie()  { timer.stopUpdate();    // shut down the timer    ms.stopMovie();        // terminate the movie screen  }} // end of WrapMovie3D class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -