<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 303  文章 - 883  trackbacks - 0
    <2007年3月>
    25262728123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    歡迎光臨! 
    閑聊 QQ:1074961813

    隨筆分類(357)

    我管理的群

    公共blog

    • n維空間
    • Email : java3d@126.com 群 : 12999758

    參與管理的論壇

    好友的blog

    我的其他blog

    朋友的網(wǎng)站

    搜索

    •  

    最新評論

    大家晚上好啊 我是尋覓!


    以后會有文章給大家介紹一個java 3D 游戲引擎現(xiàn)在,先委屈大家看個簡單例子了,呵呵;

    先給大家個游戲引擎下載地址大家可以先下去看看:在這里要感謝新朋友守護(hù)天使的推薦

    http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/j/ji/jirr/


    呵呵,廢話少說了 開始解析代碼

    大家先要下載些東西,說實話java就是這樣,功能不錯就是麻煩

    下載:


    jmf-2_1_1e-windows-i586.exe

    http://java.sun.com/products/java-media/jmf/2.1.1/download.html


    Java 3D for Windows (32bit).exe

    http://www.downloadjava3d.com/windows.php

    https://java3d.dev.java.net/binary-builds.html


    接著,安裝就不說了,easy very

    當(dāng)然希望大家把doc也下來看看。

    裝好后,給大家一個經(jīng)過我修改的簡單實驗代碼:(由于時間關(guān)系,解說會放在以后)

      1 import  java.awt. * ;
      2 import  javax.swing. * ;
      3 import  javax.media.j3d. * ;
      4 import  javax.vecmath. * ;
      5 import  java.awt.event. * ;
      6 import  com.sun.j3d.utils.geometry. *
      7
      8   public   class  MyJava3D  extends  JFrame
      9 {
     10     //   Virtual Universe object.
     11     private  VirtualUniverse universe; 
     12
     13     //   Locale of the scene graph.
     14     private  Locale locale;
     15   
     16
     17     //  BranchGroup for the Content Branch of the scene
     18     private  BranchGroup contentBranch; 
     19
     20     //   TransformGroup  node of the scene contents
     21     private  TransformGroup contentsTransGr;
     22   
     23
     24     //  BranchGroup for the View Branch of the scene
     25     private  BranchGroup viewBranch; 
     26
     27     //  ViewPlatform node, defines from where the scene is viewed.
     28     private  ViewPlatform viewPlatform; 
     29
     30     //   Transform group for the ViewPlatform node
     31     private  TransformGroup vpTransGr; 
     32
     33     //   View node, defines the View parameters.
     34     private  View view; 
     35
     36     //  A PhysicalBody object can specify the user's head
     37    PhysicalBody body; 
     38
     39     //  A PhysicalEnvironment object can specify the physical
     40     //  environment in which the view will be generated
     41    PhysicalEnvironment environment; 
     42
     43     //  Drawing canvas for 3D rendering
     44     private  Canvas3D canvas; 
     45
     46     //  Screen3D Object contains screen's information
     47     private  Screen3D screen; 
     48
     49     private  Bounds bounds;
     50  
     51 // ***********************MyJava3D******************************/
     52    public  MyJava3D()
     53    {
     54      super ( " My First Java3D Example " ); 
     55
     56 // ****************************************************************************************/ 
     57
     58 GraphicsDevice dev  =
     59 GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
     60 GraphicsConfigTemplate3D template  =   new  GraphicsConfigTemplate3D();
     61 GraphicsConfiguration config  =
     62 GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(template);
     63 canvas  =   new  Canvas3D(config); 
     64
     65   
     66
     67   
     68
     69
     70      //  Creating and setting the Canvas3D
     71      // canvas = new Canvas3D(null);                                    // 改了這里
     72   
     73 // ****************************************************************************************/
     74   
     75   
     76     getContentPane().setLayout(  new  BorderLayout( ) );
     77     getContentPane().add(canvas,  " Center " ); 
     78
     79      //  Setting the VirtualUniverse and the Locale nodes
     80     setUniverse(); 
     81
     82      //  Setting the content branch
     83     setContent(); 
     84
     85      //  Setting the view branch
     86     setViewing(); 
     87
     88      //  To avoid problems between Java3D and Swing
     89     JPopupMenu.setDefaultLightWeightPopupEnabled( false ); 
     90
     91      //  enabling window closing
     92     addWindowListener( new  WindowAdapter()  {
     93                         public   void  windowClosing(WindowEvent e)
     94                                             {System.exit( 0 ); }    }
    );
     95     setSize( 600 600 );
     96     bounds  =   new  BoundingSphere( new  Point3d( 0.0 , 0.0 , 0.0 ), Double.MAX_VALUE);
     97   }

     98 // ***********************MyJava3D******************************/ 
     99
    100 // ***********************setUniverse******************************/
    101    private   void  setUniverse()
    102      {
    103          //  Creating the VirtualUniverse and the Locale nodes
    104         universe  =   new  VirtualUniverse();
    105         locale  =   new  Locale(universe);
    106     }

    107 // ***********************setUniverse******************************/
    108  
    109 // ***********************setContent******************************/
    110    private   void  setContent()
    111      {
    112          //  Creating the content branch 
    113
    114         contentsTransGr  =   new  TransformGroup();
    115         contentsTransGr.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 
    116
    117         setLighting(); 
    118
    119         ColorCube cube1  =   new  ColorCube( 0.1 ); 
    120
    121         Appearance appearance  =   new  Appearance();
    122         cube1.setAppearance(appearance); 
    123
    124         contentsTransGr.addChild(cube1);
    125   
    126
    127         ColorCube cube2  =   new  ColorCube( 0.25 ); 
    128
    129         Transform3D t1  =   new  Transform3D();
    130         t1.rotZ( 0.5 );
    131         Transform3D t2  =   new  Transform3D();
    132         t2.set( new  Vector3f( 0.7f 0.6f , - 1.0f ));
    133         t2.mul(t1);
    134         TransformGroup trans2  =   new  TransformGroup(t2);
    135         trans2.addChild(cube2);
    136         contentsTransGr.addChild(trans2);
    137   
    138
    139         Sphere sphere  =   new  Sphere( 0.2f );
    140         Transform3D t3  =   new  Transform3D();
    141         t3.set( new  Vector3f( - 0.2f 0.5f , - 0.2f ));
    142         TransformGroup trans3  =   new  TransformGroup(t3); 
    143
    144         Appearance appearance3  =   new  Appearance(); 
    145
    146         Material mat  =   new  Material();
    147         mat.setEmissiveColor( - 0.2f 1.5f 0.1f );
    148         mat.setShininess( 5.0f );
    149         appearance3.setMaterial(mat);
    150         sphere.setAppearance(appearance3);
    151         trans3.addChild(sphere);
    152         contentsTransGr.addChild(trans3);
    153   
    154
    155         contentBranch  =   new  BranchGroup();
    156         contentBranch.addChild(contentsTransGr);
    157          //  Compiling the branch graph before making it live
    158         contentBranch .compile(); 
    159
    160          //  Adding a branch graph into a locale makes its nodes live (drawable)
    161         locale.addBranchGraph(contentBranch);
    162     }

    163 // ***********************setContent******************************/ 
    164
    165 // ***********************setLighting******************************/
    166     private   void  setLighting()
    167      {
    168         AmbientLight ambientLight  =    new  AmbientLight();
    169         ambientLight.setEnable( true );
    170         ambientLight.setColor( new  Color3f( 0.10f 0.1f 1.0f ) );
    171         ambientLight.setCapability(AmbientLight.ALLOW_STATE_READ);
    172         ambientLight.setCapability(AmbientLight.ALLOW_STATE_WRITE);
    173         ambientLight.setInfluencingBounds(bounds);
    174         contentsTransGr.addChild(ambientLight); 
    175
    176         DirectionalLight dirLight  =    new  DirectionalLight();
    177         dirLight.setEnable( true );
    178         dirLight.setColor(  new  Color3f(  1.0f 0.0f 0.0f  ) );
    179         dirLight.setDirection(  new  Vector3f(  1.0f - 0.5f - 0.5f  ) );
    180         dirLight.setCapability( AmbientLight.ALLOW_STATE_WRITE );
    181         dirLight.setInfluencingBounds(bounds);
    182         contentsTransGr.addChild(dirLight);
    183     }
     
    184
    185 // ***********************setLighting******************************/ 
    186
    187 // ***********************setViewing******************************/
    188    private   void  setViewing()
    189       {
    190          //  Creating the viewing branch 
    191
    192          viewBranch  =   new  BranchGroup(); 
    193
    194           //  Setting the viewPlatform
    195          viewPlatform  =   new  ViewPlatform();
    196          viewPlatform.setActivationRadius(Float.MAX_VALUE);
    197          viewPlatform.setBounds(bounds); 
    198
    199          Transform3D t  =   new  Transform3D();
    200          t.set( new  Vector3f( 0.3f 0.7f 3.0f ));
    201          vpTransGr  =   new  TransformGroup(t); 
    202
    203       //  Node capabilities control (granding permission) read and write access
    204      //   after a node is live or compiled
    205       //   The number of capabilities small to allow more optimizations during compilation
    206          vpTransGr.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    207          vpTransGr.setCapability( TransformGroup.ALLOW_TRANSFORM_READ); 
    208
    209          vpTransGr.addChild(viewPlatform);
    210          viewBranch.addChild(vpTransGr); 
    211
    212           //  Setting the view
    213           view  =   new  View();
    214           view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION );
    215           view.addCanvas3D(canvas); 
    216
    217           body  =   new  PhysicalBody();
    218           view.setPhysicalBody(body);
    219           environment  =   new  PhysicalEnvironment();
    220           view.setPhysicalEnvironment(environment); 
    221
    222           view.attachViewPlatform(viewPlatform); 
    223
    224           view.setWindowResizePolicy(View.PHYSICAL_WORLD); 
    225
    226           locale.addBranchGraph(viewBranch);
    227      }
     
    228
    229 // ***********************setViewing******************************/ 
    230
    231
    232
    233
    234   // ***********************************************************/
    235    public   static   void  main(String[] args)
    236    {
    237     JFrame frame  =   new  MyJava3D();
    238     frame.setVisible( true ); 
    239
    240   }

    241 }
     
    242


    地震讓大伙知道:居安思危,才是生存之道。
    posted on 2007-03-22 00:03 小尋 閱讀(1232) 評論(1)  編輯  收藏 所屬分類: j2se/j2ee/j2me

    FeedBack:
    # re: 簡單簡單java 3D入門~~~~~加簡單代碼講解 2013-04-20 20:20 樊瑜
    您好,我看您在編寫一些關(guān)于Java3D的相關(guān)操作,我想問一下怎么做,才能使用鼠標(biāo)分別對universe里面添加的兩個物體進(jìn)行拖拽操作呢??  回復(fù)  更多評論
      
    主站蜘蛛池模板: 国产色爽免费视频| 人妻仑乱A级毛片免费看| 亚洲影院天堂中文av色| 亚洲人成77777在线播放网站| 国产亚洲精AA在线观看SEE| 亚洲午夜精品久久久久久人妖| 亚洲剧场午夜在线观看| 亚洲七久久之综合七久久| 黄色免费在线观看网址| a视频在线免费观看| 亚洲成人免费电影| 午夜dj免费在线观看| 久久精品亚洲福利| 中文字幕亚洲精品资源网| 亚洲熟妇AV一区二区三区浪潮 | 久久乐国产精品亚洲综合| 亚洲AV午夜成人片| 亚洲国产91在线| 日韩成人毛片高清视频免费看| 国产综合免费精品久久久| 国产成人免费在线| 波多野结衣一区二区免费视频| 国产精一品亚洲二区在线播放| 亚洲国产韩国一区二区| 二级毛片免费观看全程| 久久久免费精品re6| 日产乱码一卡二卡三免费| 国产亚洲综合久久系列| 亚洲性线免费观看视频成熟| 国产精品免费αv视频| 黄色永久免费网站| 亚洲女人被黑人巨大进入| 亚洲电影唐人社一区二区| 视频一区二区三区免费观看| 91精品啪在线观看国产线免费| 国产亚洲福利一区二区免费看| 久久亚洲AV成人无码国产| 国产亚洲精品美女久久久久久下载| 无码免费一区二区三区免费播放| 拔擦拔擦8x华人免费久久| 青青草原精品国产亚洲av|