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

📄 b04e4667e0c5001d1cd1e38dc83e3a87

📁 使用java实现applet插件
💻
📖 第 1 页 / 共 2 页
字号:

                                pixX   = nextX + 1;
                                nextX += picW;
                        }

                        pixY   = nextY + 1;
                        nextY += picH;
                }

                for (int i = 0; i < HeightMap.length; i++) {  HeightMap[i] &= 0xff;  }

                Width = ROIWidth;


               //--- flight -------------------------------------------------------------------------

                ObjRoot.removeChild(0);

                TextureFile = null;

                initTerrain();
        }



        private String createFileName(int x, int y) {

	        // strings of numbers should be at least 3 digits long

	        String sx, sy;

                if      (x <  10) {  sx = "00" + x;  }
                else if (x < 100) {  sx = "0"  + x;  }
                else              {  sx = ""   + x;  }

                if      (y <  10) {  sy = "00" + y;  }
                else if (y < 100) {  sy = "0"  + y;  }
                else              {  sy = ""   + y;  }

                return "HeightMap_" + sx + "_" + sy + ".png";
        }


        private void loadHeightData(String hFile) {

               //--- load height file -------------------------------------------------

                TextureLoader    texLoader = null;
                ImageComponent2D ic2d      = null;

                LoadImage = getImage(getCodeBase(), hFile);
                texLoader = new TextureLoader(LoadImage, this);
                ic2d      = texLoader.getImage();
                Width     = checkWidth(Math.min(ic2d.getWidth(), ic2d.getHeight()));
        }

        

        private void grabPixels(Image img, int x, int y, int w, int h, int[] pix, int off,
                                int scansize) {

                PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pix, off, scansize);

                try {
                        pg.grabPixels();
                }
                catch (InterruptedException e) {

                        System.err.println("interrupted waiting for pixels!");
                }
        }
        
        

        private void initTerrain() {

               //--- determine files to be loaded -----------------------------------------------------

                if (TextureFile == null)  {  TextureFile = getParameter("Texture"    );  }
                if (HeightFile  == null)  {  HeightFile  = getParameter("HeightField");  }


               //--- (select and) load height data ----------------------------------------------------

                if (HeightMap == null) {  
                
                        loadHeightData(HeightFile);  


                       //--- fill array with height values --------------------------------------

                        HeightMap = new int[Width * Width];
                        
                        grabPixels(LoadImage, 0, 0, Width, Width, HeightMap, 0, Width);

                        for (int i = 0; i < HeightMap.length; i++) {  HeightMap[i] &= 0xff;  }
                }


               //--- load TextureMap ------------------------------------------------------------------

                if (TextureFile != null) {

                        TextureLoader    texLoader = null;
                        ImageComponent2D ic2d      = null;

                        LoadImage =     getImage(getCodeBase(), TextureFile);
                        texLoader = new TextureLoader(LoadImage, this);
                        ic2d      =     texLoader.getImage();
                        Texture   = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, ic2d.getWidth(),
                                                                                   ic2d.getHeight());

                        Texture.setImage(0, ic2d);
                        Texture.setEnable(true);
                        Texture.setMinFilter(Texture.NICEST);
                        Texture.setMagFilter(Texture.NICEST);
                }


               //--- create SceneGraph ----------------------------------------------------------------

                BranchGroup scene = createSceneGraph(SimpleU);

                ObjRoot.addChild(scene);


                HeightMap = null;
        }



        private int checkWidth(int w) {

                int possibleW = 3;      // 0, 3, 5, 9, 17, 33, 65, 129, 257, ...

                if (w < 3) return 0;

                while (w > possibleW)  {  possibleW = (2 * possibleW) - 1;  }

                if     (w == possibleW)   return  possibleW;
                else /*(w <  possibleW)*/ return (possibleW + 1) / 2;
        }



        private BranchGroup createSceneGraph(SimpleUniverse su) {

               //--- Create the root of the branch graph ----------------------------------------------

                BranchGroup    terRoot = new BranchGroup();
                TransformGroup vpTrans = su.getViewingPlatform().getViewPlatformTransform();


               //--- set initial viewpoint ------------------------------------------------------------

                Transform3D t3d = new Transform3D();

                t3d.lookAt(new Point3d(15, 15, 15), new Point3d(), new Vector3d(0, 1, 0));
                t3d.invert();
                vpTrans.setTransform(t3d);


               //--- Create a terrain leaf node, add it to the scene graph ----------------------------

                Terrain terrain = new Terrain(su, HeightMap, Texture, 0.0f, 0.0f, 
                                              30.0f / (float) Width, 3.0f);

                terRoot.addChild(terrain);


               //--- add a background color -----------------------------------------------------------

                BranchGroup back       = new BranchGroup();             // Background's BranchGroup
                Background  background = new Background(new Color3f(Color.blue));

                background.setApplicationBoundingLeaf(AlwaysOnBoundingLeaf);

                back.addChild(background);
                back.compile();

                terRoot.addChild(back);


               //--- setup mouse navigation -----------------------------------------------------------

	        MouseBeh.setup(vpTrans, 0.008f, false);


               //--- add keyboard navigation ----------------------------------------------------------

	        BranchGroup  kbg    = new BranchGroup();
                TKeyBehavior keyBeh = new TKeyBehavior(terrain, 0.5f);

                keyBeh.setSchedulingBoundingLeaf(AlwaysOnBoundingLeaf);
		kbg.addChild(keyBeh);
                NavRoot.addChild(kbg);


               //--- add View Updater -----------------------------------------------------------------

                TEachFrameBehavior efBeh = new TEachFrameBehavior(terrain, vpTrans, keyBeh, MouseBeh);

                efBeh.setSchedulingBoundingLeaf(AlwaysOnBoundingLeaf);
                terRoot.addChild(efBeh);



                terRoot.compile();

                return terRoot;
        }

        

        public String getAppletInfo() {

                return "TeVi v. 0.5,  written by Martin Barbisch 2002";
        }



        public String[][] getParameterInfo() {

                return AppletInfo;
        }



        public void destroy() {

                SimpleU.removeAllLocales();
        }



       //--- The following allows this to be run as an application as well as an applet -----

        public static void main(String[] args) {

               //--- get command line arguments -------------------------------------------

                if (args.length >= 3) {

                        MapFile   = args[0];
                        NumTilesX = Integer.parseInt(args[1]);
                        NumTilesY = Integer.parseInt(args[2]);

                        if (args.length >= 4) {  ROIWidth = Integer.parseInt(args[3]);  }
                        else                  {  ROIWidth = 129;                        }
                }
                else {
                        NumTilesX = NumTilesY = 0;

                        if (args.length >= 1) {  HeightFile  = args[0];  }
                        if (args.length >= 2) {  TextureFile = args[1];  }
                }


               //--- set unspecified variables to default ---------------------------------

                if (HeightFile  == null) {  HeightFile  = "Default_HeightMap.png";  }
                if (TextureFile == null) {  TextureFile = "Default_TexMap.png";     }


               //--- start the program ----------------------------------------------------

                Frame frame = new MainFrame(new Tevi(), 512, 512);
        }
}

⌨️ 快捷键说明

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