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

📄 phongshadingglsl.java

📁 java 3d编程的一些例子源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        case DIRECTIONAL_LIGHT:            lgt1 = new DirectionalLight(lColor1, lDirect1);//            lgt2 = new DirectionalLight(lColor2, lDirect2);            break;        case POINT_LIGHT:            assert false : "can't get here";            lgt1 = new PointLight(lColor1, lPoint, atten);//            lgt2 = new PointLight(lColor2, lPoint, atten);            break;        case SPOT_LIGHT:            assert false : "can't get here";            lgt1 = new SpotLight(lColor1, lPoint, atten, lDirect1,                                 25.0f * (float)Math.PI / 180.0f, 10.0f);//            lgt2 = new SpotLight(lColor2, lPoint, atten, lDirect2,//                                 25.0f * (float)Math.PI / 180.0f, 10.0f);            break;        }        // Set the influencing bounds        aLgt.setInfluencingBounds(bounds);        lgt1.setInfluencingBounds(bounds);//        lgt2.setInfluencingBounds(bounds);        // Add the lights into the scene graph        objScale.addChild(aLgt);        l1Trans.addChild(lgt1);//        l2Trans.addChild(lgt2);        // Create a new Behavior object that will perform the desired        // operation on the specified transform object and add it into the        // scene graph.        yAxis = new Transform3D();        Alpha rotor1Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE,                                     0, 0,                                     4000, 0, 0,                                     0, 0, 0);        RotationInterpolator rotator1 =            new RotationInterpolator(rotor1Alpha,                                     l1RotTrans,                                     yAxis,                                     0.0f, (float) Math.PI*2.0f);        rotator1.setSchedulingBounds(bounds);        l1RotTrans.addChild(rotator1);        // Create a new Behavior object that will perform the desired        // operation on the specified transform object and add it into the        // scene graph.        Alpha rotor2Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE,                                     0, 0,                                     1000, 0, 0,                                     0, 0, 0);        RotationInterpolator rotator2 =            new RotationInterpolator(rotor2Alpha,                                     l2RotTrans,                                     yAxis,                                     0.0f, 0.0f);        bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);        rotator2.setSchedulingBounds(bounds);        l2RotTrans.addChild(rotator2);        return objRoot;    }    private Canvas3D initScene() {        GraphicsConfiguration config =            SimpleUniverse.getPreferredConfiguration();        Canvas3D c = new Canvas3D(config);        univ = new SimpleUniverse(c);        // Add a ShaderErrorListener        univ.addShaderErrorListener(new ShaderErrorListener() {            public void errorOccurred(ShaderError error) {                error.printVerbose();                JOptionPane.showMessageDialog(PhongShadingGLSL.this,                              error.toString(),                              "ShaderError",                              JOptionPane.ERROR_MESSAGE);            }        });        // This will move the ViewPlatform back a bit so the        // objects in the scene can be viewed.        univ.getViewingPlatform().setNominalViewingTransform();        BranchGroup scene = createSceneGraph();        univ.addBranchGraph(scene);        return c;    }    /**     * Creates new form PhongShadingGLSL     */    public PhongShadingGLSL() {        // Initialize the GUI components        initComponents();        // Create the scene and add the Canvas3D to the drawing panel        Canvas3D c = initScene();        drawingPanel.add(c, java.awt.BorderLayout.CENTER);    }    // ----------------------------------------------------------------        /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents    private void initComponents() {        java.awt.GridBagConstraints gridBagConstraints;        shaderButtonGroup = new javax.swing.ButtonGroup();        guiPanel = new javax.swing.JPanel();        jPanel1 = new javax.swing.JPanel();        gouraudButton = new javax.swing.JRadioButton();        phongButton = new javax.swing.JRadioButton();        drawingPanel = new javax.swing.JPanel();        jMenuBar1 = new javax.swing.JMenuBar();        fileMenu = new javax.swing.JMenu();        exitMenuItem = new javax.swing.JMenuItem();        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        setTitle("Phong Shading Test");        guiPanel.setLayout(new java.awt.GridBagLayout());        jPanel1.setLayout(new java.awt.GridBagLayout());        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Shader"));        shaderButtonGroup.add(gouraudButton);        gouraudButton.setSelected(true);        gouraudButton.setText("Per-Vertex Lighting (Gouraud)");        gouraudButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));        gouraudButton.setMargin(new java.awt.Insets(0, 0, 0, 0));        gouraudButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                gouraudButtonActionPerformed(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);        jPanel1.add(gouraudButton, gridBagConstraints);        shaderButtonGroup.add(phongButton);        phongButton.setText("Per-Pixel Lighting (Phong)");        phongButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));        phongButton.setMargin(new java.awt.Insets(0, 0, 0, 0));        phongButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                phongButtonActionPerformed(evt);            }        });        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 1;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);        jPanel1.add(phongButton, gridBagConstraints);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);        guiPanel.add(jPanel1, gridBagConstraints);        getContentPane().add(guiPanel, java.awt.BorderLayout.NORTH);        drawingPanel.setLayout(new java.awt.BorderLayout());        drawingPanel.setPreferredSize(new java.awt.Dimension(500, 500));        getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER);        fileMenu.setText("File");        exitMenuItem.setText("Exit");        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                exitMenuItemActionPerformed(evt);            }        });        fileMenu.add(exitMenuItem);        jMenuBar1.add(fileMenu);        setJMenuBar(jMenuBar1);        pack();    }// </editor-fold>//GEN-END:initComponents    private void phongButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_phongButtonActionPerformed        sApp.setShaderProgram(phongSP);    }//GEN-LAST:event_phongButtonActionPerformed    private void gouraudButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gouraudButtonActionPerformed        sApp.setShaderProgram(gouraudSP);    }//GEN-LAST:event_gouraudButtonActionPerformed    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed        System.exit(0);    }//GEN-LAST:event_exitMenuItemActionPerformed        /**     * @param args the command line arguments     */    public static void main(String args[]) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new PhongShadingGLSL().setVisible(true);            }        });    }        // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JPanel drawingPanel;    private javax.swing.JMenuItem exitMenuItem;    private javax.swing.JMenu fileMenu;    private javax.swing.JRadioButton gouraudButton;    private javax.swing.JPanel guiPanel;    private javax.swing.JMenuBar jMenuBar1;    private javax.swing.JPanel jPanel1;    private javax.swing.JRadioButton phongButton;    private javax.swing.ButtonGroup shaderButtonGroup;    // End of variables declaration//GEN-END:variables    }

⌨️ 快捷键说明

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